diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-11 14:43:13 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-11 16:17:33 -0300 |
| commit | 3093eb55ac4a7054f51f06ea2786b5f9c9ec73f6 (patch) | |
| tree | f1bc91879a447f178dfaba39d0df107d01e557bd /anim/scenes | |
| parent | a72831d5c322078260314c305ddd940e4967947d (diff) | |
| download | computeranim-3093eb55ac4a7054f51f06ea2786b5f9c9ec73f6.tar.gz computeranim-3093eb55ac4a7054f51f06ea2786b5f9c9ec73f6.zip | |
canim: a minimap in each pane; source wherever it can be had, libc's included
From the user. Each pane with more than it shows carries a strip of its
whole column at its right edge, the pane's window outlined and what
happens off it marked there; the corner minimap is gone and the dive
folds each column of the map into its pane's strip. The source panel
follows the pc into any file the build has: glibc's own, from the
distro's debuginfod by an optional step that caches them by build id
(zig build sources; nothing else touches the network), and musl's, from
Zig's lib directory. The syscalls scene shows open64.c on the way down,
and a new scene follows the same call through a Zig-built musl. A
graph's counts and inks are as of the moment shown.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/scenes')
| -rw-r--r-- | anim/scenes/gallery.zig | 4 | ||||
| -rw-r--r-- | anim/scenes/musl.zig | 84 | ||||
| -rw-r--r-- | anim/scenes/syscalls.zig | 5 |
3 files changed, 89 insertions, 4 deletions
diff --git a/anim/scenes/gallery.zig b/anim/scenes/gallery.zig index 48fba99..f8964bd 100644 --- a/anim/scenes/gallery.zig +++ b/anim/scenes/gallery.zig @@ -14,7 +14,7 @@ //! an edge never taken), `leave` mid-way, `turn` landing, folds //! 24 s the graph with its rows, as the map draws it (here at half size): //! sort's (panned to its loop, the pc's block annotated) and libc's -//! `open` at its syscall (the blocks never reached folded) +//! `open` at its syscall (the blocks not reached folded) const std = @import("std"); const sk = @import("sketch"); const anim = @import("anim"); @@ -319,7 +319,7 @@ const GraphPages = struct { const u: ui.Ui = .{ .f = f, .at = at }; if (at.t >= 21 and at.t < 24) { title(u, 64, 40, "graph: the blocks lens"); - for ([_][2]f32{ .{ 64, 72 }, .{ 976, 72 }, .{ 64, 488 }, .{ 976, 488 } }, [_][]const u8{ "at rest: reached, not yet, the trail, never taken", "leave: the edge drawn gold, the mark on it", "turn: landed, the lane's count and the header's struck", "folds: libc's open, the blocks never reached" }) |p, words| note(u, p[0], p[1], words); + for ([_][2]f32{ .{ 64, 72 }, .{ 976, 72 }, .{ 64, 488 }, .{ 976, 488 } }, [_][]const u8{ "at rest: reached, not yet, the trail, not taken so far", "leave: the edge drawn gold, the mark on it", "turn: landed, the lane's count and the header's struck", "folds: libc's open, the blocks not reached" }) |p, words| note(u, p[0], p[1], words); } else if (at.t >= 24 and at.t < 27) { title(u, 64, 40, "graph: with its rows, as on the map (half size)"); } diff --git a/anim/scenes/musl.zig b/anim/scenes/musl.zig new file mode 100644 index 0000000..3112a27 --- /dev/null +++ b/anim/scenes/musl.zig @@ -0,0 +1,84 @@ +//! The `syscalls` scene's `open`, built by Zig against musl, static: no +//! PLT and no GOT, and musl compiled from its source with the program, so +//! the source panel follows the pc all the way down: `main`'s line, musl's +//! `open.c`, `__syscall_cp.c`, and the one line of `syscall_arch.h` that +//! is the `syscall`; the kernel's window at the floor, and back up. +//! +//! How it moves: as `syscalls` (design/motion.md, "A call followed down", +//! "A system call"); each window opened by `descend`, the source fading +//! through to each file it comes to. +const std = @import("std"); +const anim = @import("anim"); +const canim = @import("canim"); +const recordings = @import("recordings"); + +pub const background = canim.background; +pub const scene = anim.Live(frame, struct {}); + +/// The first moment from `from` whose instruction is `text`. +fn on(rec: *canim.Recording, from: u64, text: []const u8) u64 { + var buf: [256]u8 = undefined; + var i = from; + while (i < rec.end()) : (i += 1) if (rec.instruction(i, rec.register(i, "rip"), &buf)) |here| if (std.mem.startsWith(u8, here.text, text)) return i; + return rec.end(); +} + +/// The first moment from `from` on line `line` of a file not the program's own. +fn libLine(rec: *canim.Recording, from: u64, line: u32) u64 { + var i = from; + while (i < rec.end()) : (i += 1) if (rec.shown[i].here and rec.shown[i].src != 0 and rec.shown[i].line == line) return i; + return rec.end(); +} + +fn frame(s: *anim.Frame) void { + const rec = canim.open(recordings.musl); + const main = rec.call("main", 0); + var cur = canim.cursor(s, rec, main.enter); + const call_open = on(rec, main.enter, "call"); + const call_cp = on(rec, call_open + 1, "call"); + const jump = on(rec, call_cp, "jmp"); + const crossing = on(rec, jump, "syscall"); + const ret_cp = on(rec, crossing, "ret"); + const ret_open = on(rec, ret_cp + 1, "ret"); + const done = ret_open + 1; + cur.journey(.moment, done); + cur.levels = .{ .source_rows = 8, .fire = .disasm }; + const ctx = canim.context(s, cur, .{ .split = canim.layout.split.beside, .syscalls = true, .descent = true }); + const log = canim.crossing(s, .{ .cursor = cur, .stage = ctx.stage, .focus = true }); + ctx.map.add(s, canim.Crossing{ .cursor = cur, .stage = ctx.map.stage }); + var says: canim.Narrator = .{}; + const t = canim.theme.time; + const joins = ctx.ties(s); + canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, log, joins }); + + says.line(s, "The same `hello`, built by Zig against musl, static."); + cur.walk(s, .line, rec.lineMoment(6, main.enter)); + says.line(s, "`main` calls `open` itself: no PLT stub, no GOT.\nmusl is compiled from its source with the program."); + cur.walk(s, .moment, call_open); + canim.descent.step(cur, s, .moment); + s.wait(t.phrase_rest); + says.line(s, "musl's `open` is open.c: the source follows it."); + cur.hurry(s, .moment, libLine(rec, call_open, 9), .{}); + says.line(s, "Its line 16 calls `__syscall_cp`,\nin __syscall_cp.c."); + cur.hurry(s, .moment, call_cp, .{}); + canim.descent.step(cur, s, .moment); + s.wait(t.phrase_rest); + says.line(s, "Which jumps on to `__syscall_cp_c`, in the same file."); + // __syscall_cp's few rows, and its jump on. + while (cur.moment(s) <= jump) canim.descent.step(cur, s, .moment); + s.wait(t.phrase_rest); + says.line(s, "The `syscall` is one line of C, in syscall_arch.h:\nrax holds 2, open's number, and rdi the path."); + cur.hurry(s, .moment, crossing - 2, .{}); + cur.walk(s, .moment, crossing); + says.line(s, "The kernel opens the file and answers in rax: 3."); + canim.descent.step(cur, s, .moment); + s.wait(t.phrase_rest); + cur.hurry(s, .moment, ret_cp, .{}); + canim.descent.step(cur, s, .moment); + s.wait(t.phrase_rest); + says.line(s, "Back in open.c, which returns the 3 to `main`."); + cur.hurry(s, .moment, ret_open, .{}); + canim.descent.step(cur, s, .moment); + s.wait(t.phrase_rest); + says.close(s); +} diff --git a/anim/scenes/syscalls.zig b/anim/scenes/syscalls.zig index e9f0ae5..b795116 100644 --- a/anim/scenes/syscalls.zig +++ b/anim/scenes/syscalls.zig @@ -1,7 +1,8 @@ //! A program that needs the kernel four times: open, read, close, write. //! glibc's `hello`, by instruction from main: `open` followed down (the //! disassembly a `descent`: main's call, the PLT's stub, libc's wrapper, -//! the kernel's window at the floor, and back up), then the other three +//! its source, open64.c, beside it where the build has it (`zig build +//! sources`), the kernel's window at the floor, and back up), then the other three //! stepped over, each crossing under its call. The band is the calls so //! far, as strace writes them. //! @@ -66,7 +67,7 @@ fn frame(s: *anim.Frame) void { canim.descent.step(cur, s, .moment); s.wait(t.phrase_rest); // The wrapper at a run, veiled; its last three instructions walked, named as they run. - says.line(s, "libc's `open` is a wrapper: no source, its own code,\nup to the instruction that calls the kernel."); + says.line(s, "libc's `open` is a wrapper: a few lines of C, open64.c,\nup to the instruction that calls the kernel."); cur.hurry(s, .moment, crossing - 3, .{}); says.line(s, "Its last three set r8 to 0, rdi to AT_FDCWD (-100)\nand rax to 257: openat's number."); cur.walk(s, .moment, crossing); |
