summaryrefslogtreecommitdiff
path: root/src/agent/agent.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/agent/agent.zig')
-rw-r--r--src/agent/agent.zig10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/agent/agent.zig b/src/agent/agent.zig
index 2a32a05..0e23de9 100644
--- a/src/agent/agent.zig
+++ b/src/agent/agent.zig
@@ -45,6 +45,7 @@ pub fn init() void {
if (state.load(.acquire) != 0 or state.cmpxchgStrong(0, 1, .acquire, .monotonic) != null) return;
defer state.store(2, .release);
const r = client.get() orelse return;
+ signal.keys.detect();
var buf: [1 << 16]u8 = undefined;
const env = client.environ(&buf);
cut = if (client.getenv(env, "ZTRACE_CUT")) |v| std.fmt.parseInt(u64, v, 0) catch 0 else 0;
@@ -161,14 +162,17 @@ pub fn mark(label: []const u8, value: u64) void {
/// Names `memory` (a `variable` event), records it, and keeps recording what
/// changes in it: only the bytes that changed, before each event that ends a
-/// moment. At most `max_region` bytes, which must stay mapped. Watched from
-/// inside a hooked call, it is forgotten when that call returns.
+/// moment. At most `max_region` bytes, which must stay mapped; a protection
+/// key on it does not hide it. Watched from inside a hooked call, it is
+/// forgotten when that call returns.
pub fn watch(memory: []const u8, name: []const u8) void {
init();
if (ring == null or tooLarge(memory, "watch")) return;
const was = sud.selector;
sud.selector = sud.allow;
defer sud.selector = was;
+ const rights = signal.keys.open();
+ defer if (rights) |r| signal.keys.set(r);
const id = stringId(name);
emit(.string, 0, .{ id, 0, 0, 0, 0, 0 }, text(name, max_payload));
emit(.variable, 0, .{ @intFromPtr(memory.ptr), memory.len, id, 0, 0, 0 }, "");
@@ -180,6 +184,8 @@ pub fn watch(memory: []const u8, name: []const u8) void {
pub fn snapshot(memory: []const u8) void {
init();
if (ring == null or tooLarge(memory, "snapshot")) return;
+ const rights = signal.keys.open();
+ defer if (rights) |r| signal.keys.set(r);
write(@intFromPtr(memory.ptr), memory);
}