summaryrefslogtreecommitdiff
path: root/src/agent/watch.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 12:52:12 -0300
committerGabriel Schneider <[email protected]>2026-11-10 13:00:24 -0300
commit8b28a0a5101a62fd55c2d55433e0fa899d4623f9 (patch)
treede233408fc45f93e19bbcf637ed66242d569fc56 /src/agent/watch.zig
parent36d7f642e71207d04f5da80530da552e06447337 (diff)
downloadcomputeranim-8b28a0a5101a62fd55c2d55433e0fa899d4623f9.tar.gz
computeranim-8b28a0a5101a62fd55c2d55433e0fa899d4623f9.zip
agent: its handlers act with the thread's protection keys and float modes, not a handler's
The kernel starts a signal handler with default PKRU (key 0 only) and default MXCSR and x87 control word, the thread's own saved in the frame. The SIGSYS handler makes the thread's syscalls and clones its threads from there, so under --syscalls: - a pkey_alloc's new rights were undone when the handler returned; - a thread was born with no right to keyed memory (V8's compiler threads fault reading the code space: d8 died of SEGV_PKUERR, and the 35 seconds were its core dump, not a spin); - a buffer in keyed memory was EFAULT to the kernel, and a fault to the agent reading it for the event; - a thread started without its maker's float modes (flush-to-zero). Both handlers now take the thread's PKRU and control words from the frame first (signal.adopt), and the SIGSYS one writes PKRU back to the frame after the syscall. Watched memory is read, and hooked code patched, with every key open, so a key the thread itself cannot use hides nothing. test-agent: agent_pkey (a keyed page read, given to syscalls, watched, read by a later thread; skips itself without keys), and agent_sys's thread checks its MXCSR. README: --alloc and programs with their own malloc; the core dump. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'src/agent/watch.zig')
-rw-r--r--src/agent/watch.zig4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/agent/watch.zig b/src/agent/watch.zig
index 356dac8..fb46b09 100644
--- a/src/agent/watch.zig
+++ b/src/agent/watch.zig
@@ -7,6 +7,7 @@
const std = @import("std");
const linux = std.os.linux;
const agent = @import("agent.zig");
+const signal = @import("signal.zig");
const Region = struct {
addr: usize,
@@ -65,6 +66,9 @@ pub fn diff() void {
// Busy: another thread is at it, or this one is, below this frame.
if (busy.swap(true, .acquire)) return;
defer busy.store(false, .release);
+ // Whatever key the memory is behind, and whether this thread may read it now.
+ const rights = signal.keys.open();
+ defer if (rights) |was| signal.keys.set(was);
for (table[0..count]) |r| {
var changes: Changes = .{ .old = r.shadow[0..r.len], .new = @as([*]const u8, @ptrFromInt(r.addr))[0..r.len] };
while (changes.next()) |run| agent.write(r.addr + run.at, run.bytes);