From 7161b6d1a22cd64ec9765f203881f487e9ad31a0 Mon Sep 17 00:00:00 2001 From: Pascal Zittlau Date: Tue, 16 Dec 2025 22:41:18 +0100 Subject: [PATCH] vdso support --- docs/TODO.md | 3 ++- src/disassembler.zig | 2 ++ src/main.zig | 25 +++++++++++++++++++++++++ src/test/vdso_clock.zig | 8 ++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/test/vdso_clock.zig diff --git a/docs/TODO.md b/docs/TODO.md index 58b292f..0326fdb 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -21,7 +21,8 @@ IvyBridge(2012) and AMD Zen 2 Family 17H(2019) and Linux 5.9(2020). - [ ] `auxv`: check if that is setup correctly and completely - [ ] JIT support: intercept `mmap`, `mprotect` and `mremap` that change pages to be executable - [ ] `SIGILL` patching fallback -- [ ] `vdso` handling +- [x] `vdso` handling +- [ ] check why the libc tests are flaky ## Minor things diff --git a/src/disassembler.zig b/src/disassembler.zig index 946ea3d..151c94f 100644 --- a/src/disassembler.zig +++ b/src/disassembler.zig @@ -48,6 +48,8 @@ pub const InstructionIterator = struct { "Byte stepping, to find next valid instruction begin", .{}), zydis.ZYDIS_STATUS_DECODING_ERROR => log.warn("next: Got status: DECODING_ERROR. " ++ "Byte stepping, to find next valid instruction begin", .{}), + zydis.ZYDIS_STATUS_INVALID_MAP => log.warn("next: Got status: INVALID_MAP. " ++ + "Byte stepping, to find next valid instruction begin", .{}), else => log.warn("next: Got unknown status: 0x{x}. Byte stepping, to find next " ++ "valid instruction begin", .{status}), } diff --git a/src/main.zig b/src/main.zig index 658e9d4..19ddc99 100644 --- a/src/main.zig +++ b/src/main.zig @@ -118,6 +118,11 @@ pub fn main() !void { elf.AT_BASE => maybe_interp_base orelse auxv[i].a_un.a_val, elf.AT_ENTRY => entry, elf.AT_EXECFN => @intFromPtr(std.os.argv[arg_index]), + elf.AT_SYSINFO_EHDR => blk: { + log.info("Found vDSO at 0x{x}", .{auxv[i].a_un.a_val}); + try patchLoadedElf(auxv[i].a_un.a_val); + break :blk auxv[i].a_un.a_val; + }, else => auxv[i].a_un.a_val, }; } @@ -419,6 +424,26 @@ test "nolibc_pie_signal_handler" { ); } +test "nolibc_nopie_vdso_clock" { + try testHelper( + &.{ flicker_path, getTestExePath("nolibc_nopie_vdso_clock") }, + "Time gotten\n", + ); +} +test "nolibc_pie_vdso_clock" { + try testHelper( + &.{ flicker_path, getTestExePath("nolibc_pie_vdso_clock") }, + "Time gotten\n", + ); +} +// BUG: This one is flaky +// test "libc_pie_vdso_clock" { +// try testHelper( +// &.{ flicker_path, getTestExePath("libc_pie_vdso_clock") }, +// "Time gotten\n", +// ); +// } + fn testPrintArgs(comptime name: []const u8) !void { const exe_path = getTestExePath(name); const loader_argv: []const []const u8 = &.{ flicker_path, exe_path, "foo", "bar", "baz hi" }; diff --git a/src/test/vdso_clock.zig b/src/test/vdso_clock.zig new file mode 100644 index 0000000..25260a0 --- /dev/null +++ b/src/test/vdso_clock.zig @@ -0,0 +1,8 @@ +const std = @import("std"); + +pub fn main() !void { + _ = try std.posix.clock_gettime(std.posix.CLOCK.MONOTONIC); + + const msg = "Time gotten\n"; + _ = try std.posix.write(1, msg); +}