summaryrefslogtreecommitdiff
path: root/anim/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-11 00:06:30 -0300
committerGabriel Schneider <[email protected]>2026-11-11 01:16:48 -0300
commitc3d9f7ba5effd615374b1359ad98ecf801559f83 (patch)
tree07f85932abc1df23c722bcd1bd1b3b65bca28f2e /anim/build.zig
parentc94ade9e77a811d3ff75ffc2889a65375262ab1f (diff)
downloadcomputeranim-c3d9f7ba5effd615374b1359ad98ecf801559f83.tar.gz
computeranim-c3d9f7ba5effd615374b1359ad98ecf801559f83.zip
canim: a call followed down to the kernel; rows that say what they do; the heap from the inside
From the user. The disassembly can descend: the syscalls scene is glibc's hello by instruction, and open is followed from main through its PLT stub, whose jmp reads the GOT, into libc's wrapper to the syscall row, which crosses to the kernel's window under it, and back up. The band keeps the calls so far as strace writes them. Operands lose their size words and show a width as byte cells only where nothing else says it. A compare shows its values and the flags it leaves, a jump the flags it reads, lea its result, an indirect jump its target and the slot it read, a call that has run its C form. The backtrace has its newest frame at the bottom. A new scene shows glibc 2.44's heap from blocks that exist: chunks read by fields (a size with its bits, a protected pointer), the free list as arcs, the tcache in a loupe, the program's list over malloc's own. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/build.zig')
-rw-r--r--anim/build.zig37
1 files changed, 28 insertions, 9 deletions
diff --git a/anim/build.zig b/anim/build.zig
index 21abbce..d12912d 100644
--- a/anim/build.zig
+++ b/anim/build.zig
@@ -16,7 +16,7 @@
const std = @import("std");
const sketchbook = @import("sketchbook");
-const scenes = [_][]const u8{ "title", "fib", "list", "sort", "syscalls", "zoom", "gallery" };
+const scenes = [_][]const u8{ "title", "fib", "list", "sort", "syscalls", "zoom", "heap", "gallery" };
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
@@ -74,23 +74,34 @@ pub fn build(b: *std.Build) void {
alloc: bool = false,
/// A file of tools/ it reads, by its bare name.
reads: ?[]const u8 = null,
- /// Bytes of stack above rsp each stop records. An instrumented
- /// program's runtime reads the clock through the vDSO, whose retry
- /// loop is stepped: with 512 or more the loop seldom gets through
- /// (`list` took 27 000 to 42 000 moments at 512, and 0.3 to 1.6
- /// million at 1024, against 3 900 at 256), so those take 256.
+ /// Bytes of stack above rsp each stop records. (A call into the
+ /// vDSO, the runtime's clock, is one moment: its retry loop is not stepped.)
stack: []const u8 = "1024",
+ /// Built by the system's clang against its glibc and linked
+ /// dynamically, as a C programmer's program is (a PLT, libc's own
+ /// code to follow down): `-no-pie` for short addresses, bound at
+ /// load (`-z now`: no resolver), with the canary the compiler puts in.
+ glibc: bool = false,
+ /// Stops after `from` before the recording ends: main's return, not the exit's.
+ steps: ?[]const u8 = null,
+ /// Also glibc's heap at every stop (`--heap`), and memory watched (`-w`).
+ heap: bool = false,
+ watch: []const []const u8 = &.{},
};
for ([_]Recording{
.{ .name = "steps", .source = "fib.c", .by = "insn" },
- .{ .name = "hello", .source = "hello.c", .by = "line", .reads = "note" },
+ // By instruction from main, through the PLT and libc's wrappers to
+ // the kernel and back: the descent; to main's return.
+ .{ .name = "hello", .source = "hello.c", .by = "insn", .from = "main", .steps = "132", .glibc = true, .reads = "note" },
+ // A line a stop, malloc and free run through; glibc's heap at each.
+ .{ .name = "heap", .source = "heap.c", .by = "line", .from = "main", .glibc = true, .heap = true, .watch = &.{ "0x405000,1024", "head" } },
// By instruction, as `steps` is: the registers are the program's
// own, so they strike and link. Only the variables the scenes name
// are told by the instrumentation (each a call into its runtime,
// stepped like any other); `list` starts at `reverse`, its pushes
// (the agent's and the runtime's first calls) run through.
- .{ .name = "sort", .source = "sort.c", .by = "insn", .instr = "vars", .only = "sort,a", .from = "main", .stack = "256" },
- .{ .name = "list", .source = "list.c", .by = "insn", .instr = "vars", .only = "push,reverse,head", .from = "reverse", .alloc = true, .stack = "256" },
+ .{ .name = "sort", .source = "sort.c", .by = "insn", .instr = "vars", .only = "sort,a", .from = "main" },
+ .{ .name = "list", .source = "list.c", .by = "insn", .instr = "vars", .only = "push,reverse,head", .from = "reverse", .alloc = true },
}) |r| {
const source = b.path(b.fmt("tools/{s}", .{r.source}));
var program: std.Build.LazyPath = undefined;
@@ -108,6 +119,11 @@ pub fn build(b: *std.Build) void {
cc.addFileArg(source);
cc.addArg("-o");
program = cc.addOutputFileArg(r.name);
+ } else if (r.glibc) {
+ const cc = b.addSystemCommand(&.{ "clang", "-O0", "-g", "-no-pie", "-fstack-protector-strong", "-Wl,-z,now" });
+ cc.addFileArg(source);
+ cc.addArg("-o");
+ program = cc.addOutputFileArg(r.name);
} else {
const mod = b.createModule(.{ .target = musl, .optimize = .Debug, .link_libc = true, .omit_frame_pointer = false, .sanitize_c = .off, .stack_protector = false });
mod.addCSourceFile(.{ .file = source, .flags = &.{ "-O0", "-g" } });
@@ -127,6 +143,9 @@ pub fn build(b: *std.Build) void {
// instructions round the pc.
run.addArgs(&.{ "record", "--by", r.by, "--stack", r.stack, "--around", "256", "--disasm", "69", "-s", "64" });
if (r.from) |place| run.addArgs(&.{ "--from", place });
+ if (r.steps) |n| run.addArgs(&.{ "--steps", n });
+ if (r.heap) run.addArg("--heap");
+ for (r.watch) |what| run.addArgs(&.{ "-w", what });
// What an instrumented program tells of itself comes through a ring.
if (r.instr != null) run.addArg("--ring");
if (r.alloc) {