summaryrefslogtreecommitdiff
path: root/src/agent/sud.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 12:37:33 -0300
committerGabriel Schneider <[email protected]>2026-11-10 12:42:11 -0300
commit36d7f642e71207d04f5da80530da552e06447337 (patch)
tree97277b7180675d46782e513320b5ac4a18de3282 /src/agent/sud.zig
parentc0f5bd34d0f5339626d2c28c4012db7be46b55f3 (diff)
downloadcomputeranim-36d7f642e71207d04f5da80530da552e06447337.tar.gz
computeranim-36d7f642e71207d04f5da80530da552e06447337.zip
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.
Diffstat (limited to 'src/agent/sud.zig')
-rw-r--r--src/agent/sud.zig19
1 files changed, 19 insertions, 0 deletions
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);