diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 12:23:33 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 12:23:41 -0300 |
| commit | 8008a2655c0f0c9b9890fb4866f774c9b50e170c (patch) | |
| tree | ec54af73611e686751dd74dd3f4a585198a91de5 /src/cli/probe.zig | |
| parent | 2e01933dc5c0c1903c1b7f86e453829fee9a541b (diff) | |
| download | computeranim-8008a2655c0f0c9b9890fb4866f774c9b50e170c.tar.gz computeranim-8008a2655c0f0c9b9890fb4866f774c9b50e170c.zip | |
kernel: on today's main
Symbols come from Symbols (perf.lookup is gone), string ids from
event.stringId, and ptrace.Process is used as it is now. A USDT
semaphore of the program itself is raised by the tracer: the kernel's
counter landed on the wrong word of a small lld-linked target, whose
page of the file is mapped writable twice. test-kernel also runs the
library tests of perf, usdt and bpf.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'src/cli/probe.zig')
| -rw-r--r-- | src/cli/probe.zig | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/cli/probe.zig b/src/cli/probe.zig index 539af5c..311f2c0 100644 --- a/src/cli/probe.zig +++ b/src/cli/probe.zig @@ -106,7 +106,7 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void { std.debug.print("{t} {s}: {s} +{x}", .{ p.kind, p.name, p.target, p.offset }); if (p.usdt) |u| std.debug.print(", semaphore at +{x}, arguments {s}", .{ if (u.semaphore == 0) 0 else p.elf.?.offset(u.semaphore) orelse 0, u.args }); std.debug.print("\n", .{}); - const id = zt.perf.stringId(p.name); + const id = zt.event.stringId(p.name); list("its program: a probe", if (p.usdt) |u| bpf.usdtProgram(maps, 0, id, u.args) catch fail("{s}: an argument of this probe ({s}) is in a form not understood yet\n", .{ p.name, u.args }) else bpf.probe(maps, 0, id, null, p.kind != .kprobe)); } std.debug.print("{s}\n", .{if (missing) |m| m else "nothing is missing to attach them"}); @@ -116,7 +116,7 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void { const argv = try util.targetArgv(arena, args[i..]); var proc = try zt.ptrace.Process.spawn(path, argv, init.minimal.environ.block.slice.ptr); - errdefer proc.kill(); + errdefer proc.close(); var rec = try zt.Recorder.create(init.gpa, init.io, out); if (max_bytes) |bytes| rec.max_bytes = bytes; // Two sources, the programs' ring and perf's: one sequence in the recording. @@ -126,10 +126,27 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void { defer tracer.close(); if (syscalls) tracer.syscalls() catch |err| refused(err, &tracer); if (sched) tracer.sched(btf) catch |err| refused(err, &tracer); + var symbols: zt.Symbols = .{ .gpa = init.gpa, .io = init.io }; + defer symbols.deinit(); + symbols.free(try symbols.refresh(proc.pid)); for (places.items) |p| { - const id = zt.perf.stringId(p.name); + const id = zt.event.stringId(p.name); try sorted.sink().emit(.{ .ts = zt.event.now(), .kind = .string, .a = .{ id, 0, 0, 0, 0, 0 } }, p.name); - (if (p.usdt) |u| tracer.usdtProbe(p.elf.?, p.target, u, id) else switch (p.kind) { + var static = p.usdt; + // A semaphore of the program itself is ours to raise: it is mapped, + // and held. The kernel's way, a counter at an offset of the file, + // lands on the wrong address when the linker has that page of the + // file mapped writable twice, as lld does; it is left what is not + // mapped yet, a library's. + if (static) |*u| if (u.semaphore != 0 and p.own and symbols.modules.items.len > 0) { + const at = u.semaphore +% symbols.modules.items[0].bias; + var count: [2]u8 = undefined; + if (proc.read(at, &count) != 2) fail("{s}: its semaphore is not in the program's memory\n", .{p.name}); + std.mem.writeInt(u16, &count, std.mem.readInt(u16, &count, .little) +% 1, .little); + try proc.write(at, &count); + u.semaphore = 0; + }; + (if (static) |u| tracer.usdtProbe(p.elf.?, p.target, u, id) else switch (p.kind) { .kprobe => tracer.kprobe(p.target, id), else => tracer.uprobe(p.target, p.offset, id), }) catch |err| switch (err) { @@ -148,7 +165,7 @@ pub fn run(init: std.process.Init, args: []const [:0]const u8) !void { error.RecordingFull => null, else => |e| return e, }; - if (exit_code == null) proc.kill(); + if (exit_code == null) proc.close(); try perf.finish(init, &rec, out, exit_code, tracer.lost() + session.lost, zt.event.now() - start, &.{}, &.{}); } @@ -184,6 +201,8 @@ const Place = struct { name: []const u8, target: [:0]const u8, offset: u64 = 0, + /// In the program itself, not a library of it. + own: bool = false, elf: ?zt.usdt.Elf = null, usdt: ?zt.usdt.Probe = null, }; @@ -204,7 +223,7 @@ fn place(arena: std.mem.Allocator, p: Probe, program: [:0]const u8) !Place { for (try zt.usdt.probes(arena, elf, 0)) |found| { const colon = std.mem.indexOfScalar(u8, name, ':') orelse fail("--usdt wants [FILE:]PROVIDER:NAME\n", .{}); if (!std.mem.eql(u8, found.provider, name[0..colon]) or !std.mem.eql(u8, found.name, name[colon + 1 ..])) continue; - return .{ .kind = .usdt, .name = name, .target = file, .offset = elf.offset(found.pc) orelse continue, .elf = elf, .usdt = found }; + return .{ .kind = .usdt, .name = name, .target = file, .offset = elf.offset(found.pc) orelse continue, .own = !named, .elf = elf, .usdt = found }; } fail("{s}: no static probe {s} (readelf -n lists them)\n", .{ file, name }); } |
