From 36d7f642e71207d04f5da80530da552e06447337 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 12:37:33 -0300 Subject: syscalls: what writev's buffers hold is captured, by the debugger and the agent musl's printf and Zig programs write through writev: pardes drawing an image showed nothing of the kitty graphics commands it sends until this. The README says what Lua and pardes were run with and what they showed. --- src/agent/sud.zig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/agent/sud.zig') diff --git a/src/agent/sud.zig b/src/agent/sud.zig index a32735d..5d2c6ad 100644 --- a/src/agent/sud.zig +++ b/src/agent/sud.zig @@ -168,10 +168,29 @@ fn argument(number: u64, a: [6]u64) []const u8 { nr(.open), nr(.stat), nr(.lstat), nr(.access), nr(.execve), nr(.chdir), nr(.unlink), nr(.readlink), nr(.mkdir), nr(.rmdir), nr(.truncate), nr(.chmod) => string(a[0]), nr(.openat), nr(.newfstatat), nr(.unlinkat), nr(.readlinkat), nr(.faccessat), nr(.faccessat2), nr(.statx), nr(.mkdirat), nr(.execveat) => string(a[1]), nr(.write), nr(.pwrite64), nr(.sendto) => if (a[1] == 0) "" else agent.text(@as([*]const u8, @ptrFromInt(a[1]))[0..a[2]], agent.capture), + nr(.writev), nr(.pwritev), nr(.pwritev2) => gathered(a[1], a[2]), else => "", }; } +/// A thread's vector of buffers copied end to end, until its event is emitted. +threadlocal var gather: [2048]u8 = undefined; + +/// What writev's buffers hold, as far as `capture` goes. +fn gathered(vec: u64, count: u64) []const u8 { + if (vec == 0) return ""; + const iov: [*]const std.posix.iovec_const = @ptrFromInt(vec); + const max = @min(agent.capture, gather.len); + var len: usize = 0; + for (iov[0..@min(count, 1024)]) |v| { + const n = @min(v.len, max - len); + @memcpy(gather[len..][0..n], v.base[0..n]); + len += n; + if (len == max) break; + } + return agent.text(gather[0..len], max); +} + fn string(addr: u64) []const u8 { if (addr == 0) return ""; const s: [*]const u8 = @ptrFromInt(addr); -- cgit v1.3