diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-11 02:11:12 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-11 04:20:25 -0300 |
| commit | 5922ee911b9a6604f60dc83be36ba9e6c9abac98 (patch) | |
| tree | 310b983f5205709e5db173f9f1bc8e8d499d24fe /anim/scenes | |
| parent | 64e64c74be6a3e46abeae8a30dd42efff91aaf91 (diff) | |
| download | computeranim-5922ee911b9a6604f60dc83be36ba9e6c9abac98.tar.gz computeranim-5922ee911b9a6604f60dc83be36ba9e6c9abac98.zip | |
canim: what the second review found, fixed
A system call stepped over plays in order: the registers set, the
crossing from the call row with the kernel's window under it, the stores
after rax. A strike covers the bytes that changed. The band's view
changes with the argument framing. In the descent a callee sits under
its caller's return row, and rows fade before others glide. The heap
scene follows the storyboard's nine captions: pushes at a run without
marks, each free and the malloc that takes the head back walked, the
tcache's loupe over the stack and closed with each advance, a chunk in
neither list drawn, the freed node travelling to malloc's row. In the
dive the map falls into the corner and becomes the minimap; on the map
boxes are as long as their rows. A narrow read is shown at its width.
The chart checks captions and one-frame changes.
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/heap.zig | 249 | ||||
| -rw-r--r-- | anim/scenes/syscalls.zig | 10 |
2 files changed, 191 insertions, 68 deletions
diff --git a/anim/scenes/heap.zig b/anim/scenes/heap.zig index e227f17..e7f70f7 100644 --- a/anim/scenes/heap.zig +++ b/anim/scenes/heap.zig @@ -66,15 +66,44 @@ fn programList(a: std.mem.Allocator, rec: *canim.Recording, i: u64, head_at: u64 /// the free list's) and its index in that row. const Spot = struct { row: u8, k: usize }; +/// The program's row at a moment: the chunks of 0x20 in neither list (the +/// one malloc has just returned, the one pop has just taken off), then the +/// list from `head`. User addresses. +fn programRow(a: std.mem.Allocator, rec: *canim.Recording, i: u64, head_at: u64, hp: ?zt.heap.Heap) []const u64 { + const list = programList(a, rec, i, head_at); + var out: std.ArrayList(u64) = .empty; + if (hp) |h| for (h.chunks, 0..) |c, k| { + if (k + 1 == h.chunks.len or c.size() != 0x20 or c.free or c.in != .none) continue; + if (std.mem.indexOfScalar(u64, list, c.addr + 16) != null) continue; + out.append(a, c.addr + 16) catch {}; + }; + out.appendSlice(a, list) catch {}; + return out.items; +} + fn spotOf(program: []const u64, free: []const zt.heap.Entry, node: u64) ?Spot { for (program, 0..) |p, k| if (p == node) return .{ .row = 0, .k = k }; for (free, 0..) |e, k| if (e.chunk + 16 == node) return .{ .row = 1, .k = k }; return null; } +/// The value of the stack local `name` of the newest frame, where the debug info places it. +fn local(a: std.mem.Allocator, m: canim.Recording.Moment, regs: zt.Regs, name: []const u8) ?u64 { + if (regs.rbp <= regs.rsp or regs.rbp - regs.rsp > 512) return null; + const out = a.alloc(zt.telescope.Slot, (regs.rbp + 16 - regs.rsp) / 8) catch return null; + const slots = zt.telescope.slots(m, ®s, regs.rsp, out) catch return null; + for (slots, 0..) |sl, k| if (sl.role == .local and sl.frame == 0 and sl.role.local.offset == 0 and std.mem.eql(u8, sl.role.local.name, name)) { + return canim.Recording.word(m, regs.rsp + 8 * k, 8) catch null; + }; + return null; +} + /// The drawing: `nodes` in two rows, the program's list over malloc's free /// list, the `bin` heading the second; a node travels between the rows -/// when it is freed or taken back (36 f, `glide`, with the idea's slot). +/// when it is freed or taken back (36 f, `glide`, in the idea's slot). +/// Nothing changes in one frame: the bin's box and the top's crossfade +/// (12 f), the top's size and the bin's count are struck, the count fading +/// in first (design/motion.md, "The first free"). const Lists = struct { cursor: canim.Cursor, stage: *const canim.Stage, @@ -85,12 +114,22 @@ const Lists = struct { const apart = 28; const well = theme.metric.node.pointer_w; const rows_y = [2]f32{ 72, 182 }; - const row_x = [2]f32{ 160, 12 + 160 + 28 }; + /// Both rows from the free list's first node, under the program's head. + const row_x = [2]f32{ 12 + 160 + 28, 12 + 160 + 28 }; fn at(s: Spot) ui.Vec { return .{ row_x[s.row] + @as(f32, @floatFromInt(s.k)) * (w + apart), rows_y[s.row] }; } + /// How far through `len` frames from `from` frames after the idea's slot. + fn after(now: canim.Now, from: f32, len: f32) f32 { + return switch (now.plan.gait) { + .walk => if (now.resting()) 1 else std.math.clamp((now.since(.idea, 0) - from / 60.0) / (len / 60.0), 0, 1), + .run => std.math.clamp(now.since(.idea, 0) / theme.time.run_ease, 0, 1), + .sprint => 1, + }; + } + pub fn draw(l: *const Lists, f: *sk.Frame, placed: anim.Placed) void { const box = l.stage.box(placed, .band); if (box.h < cm.tag + 24) return; @@ -108,49 +147,78 @@ const Lists = struct { var heaps: [2]?zt.heap.Heap = undefined; for (stops, 0..) |i, side| { heaps[side] = heapAt(a, rec, i); - program[side] = programList(a, rec, i, l.head_at); + program[side] = programRow(a, rec, i, l.head_at, heaps[side]); free[side] = if (heaps[side]) |hp| freeList(hp) else &.{}; } - // The idea reacts after the bytes: a node travels with the idea's slot. - const p = canim.ease.glide(now.moving(.idea, 0, 36.0 / 60.0)); + // The idea reacts after the bytes: the boxes crossfade (12 f), then a node lifts and travels (36 f). + const fade = after(now, 0, 12); + const p = canim.ease.glide(after(now, 12, 36)); const shown: usize = if (p >= 0.5) 1 else 0; v.text(.sans, theme.size.sans.micro, 12, rows_y[0] + 28, "the program's", t.faint); - // The bin: dashed and faint while the thread's tcache is glibc's dummy. + // The bin: dashed and faint while the thread's tcache is glibc's dummy; raised once it has one. const bin: canim.Rect = .{ .x = 12, .y = rows_y[1], .w = 160, .h = h }; - const hp = heaps[shown]; - if (hp == null or hp.?.tcache == null) { - v.dashedFrame(bin, t.faint, theme.stroke.rule); - v.label(.mono, theme.size.mono.context, bin, .center, "dummy tcache", t.faint); - } else { - v.fill(bin, theme.color.raised); - v.label(.mono, theme.size.mono.context, bin, .center, "tcache 0x20", t.primary); - // How many it holds, on its shoulder. + const real = [2]bool{ heaps[0] != null and heaps[0].?.tcache != null, heaps[1] != null and heaps[1].?.tcache != null }; + for (real, 0..) |is, side| { + const shows = if (real[0] == real[1]) @as(f32, if (side == 1) 1 else 0) else if (side == 1) fade else 1 - fade; + if (shows <= 0) continue; + const bv = v.faded(shows); + if (!is) { + bv.dashedFrame(bin, t.faint, theme.stroke.rule); + bv.label(.mono, theme.size.mono.context, bin, .center, "dummy tcache", t.faint); + } else { + bv.fill(bin, theme.color.raised); + bv.label(.mono, theme.size.mono.context, bin, .center, "tcache 0x20", t.primary); + } + } + // How many it holds, on its shoulder: it fades in (6 f), then is armed and struck as the node lands. + const counts = [2]?u16{ if (heaps[0]) |hp| holds(hp) else null, if (heaps[1]) |hp| holds(hp) else null }; + if (counts[1] != null and real[1]) { const badge: canim.Rect = .{ .x = bin.x + bin.w - 24, .y = bin.y - 34, .w = 30, .h = 30 }; - v.fill(badge, theme.color.page); - v.frame(badge, t.faint, theme.stroke.rule); - v.label(.mono, theme.size.mono.small, badge, .center, v.print("{d}", .{holds(hp.?) orelse 0}), t.primary); - if (free[shown].len > 0) v.route(&.{ .{ bin.x + bin.w, bin.y + h / 2 }, .{ row_x[1] - 2, bin.y + h / 2 } }, theme.color.region.heap, .{ .width = theme.stroke.line, .head = theme.metric.node.arrow_head }); + const changed = counts[0] == null or !real[0] or counts[0].? != counts[1].?; + const comes = !real[0] or counts[0] == null; + const bv = v.faded(if (comes) after(now, 42, 6) else 1); + const heat = if (changed and now.walking()) now.heat(0, null, now.since(.idea, 0) - 60.0 / 60.0) else if (changed) canim.ui.Heat.ember else canim.ui.Heat.none; + bv.fill(badge, theme.color.page); + const ink = bv.cellWritten(badge, heat, theme.color.page); + // Framed, but while the strike's paper is on it. + bv.faded(if (heat.level < 1) 1 else 1 - heat.solid * heat.in).frame(badge, t.faint, theme.stroke.rule); + const landed = !changed or now.resting() or !now.walking() or now.since(.idea, 0) >= 60.0 / 60.0 + theme.time.strike.in / 2.0; + const count = if (landed or comes) counts[1].? else counts[0].?; + bv.label(ink.face, theme.size.mono.small, badge, .center, bv.print("{d}", .{count}), if (heat.level >= 1) ink.ink else ui.rgb(t.primary)); } - // The top: what is left of the arena, its size. - if (hp) |hh| if (hh.chunks.len > 0) { - const top = hh.chunks[hh.chunks.len - 1]; - const r: canim.Rect = .{ .x = box.w - 12 - 160, .y = rows_y[1], .w = 160, .h = h }; - v.dashedFrame(r, t.faint, theme.stroke.rule); - v.label(.mono, theme.size.mono.context, r, .center, v.print("top 0x{x}", .{top.size()}), t.dim); - _ = v.address(r.x + 16, r.y - 8, top.addr, .{ .ink = ui.rgb(theme.color.region.heap) }); + if (real[shown] and free[shown].len > 0) v.route(&.{ .{ bin.x + bin.w, bin.y + h / 2 }, .{ row_x[1] - 2, bin.y + h / 2 } }, theme.color.region.heap, .{ .width = theme.stroke.line, .head = theme.metric.node.arrow_head }); + // The top: what is left of the arena, its place and size; crossfading where the step moved it, its size struck. + const tops = [2]?zt.heap.Chunk{ if (heaps[0]) |hp| (if (hp.chunks.len > 0) hp.chunks[hp.chunks.len - 1] else null) else null, if (heaps[1]) |hp| (if (hp.chunks.len > 0) hp.chunks[hp.chunks.len - 1] else null) else null }; + const top_r: canim.Rect = .{ .x = box.w - 12 - 160, .y = rows_y[1], .w = 160, .h = h }; + const moved = if (tops[0] != null and tops[1] != null) tops[0].?.addr != tops[1].?.addr or tops[0].?.size() != tops[1].?.size() else tops[0] != null or tops[1] != null; + for (tops, 0..) |maybe, side| if (maybe) |top| { + const shows = if (!moved) @as(f32, if (side == 1) 1 else 0) else if (side == 1) fade else 1 - fade; + if (shows <= 0) continue; + const tv = v.faded(shows); + tv.dashedFrame(top_r, t.faint, theme.stroke.rule); + const size_text = tv.print("0x{x}", .{top.size()}); + const sx = top_r.x + top_r.w - 16 - tv.width(.mono, theme.size.mono.context, size_text); + tv.text(.mono, theme.size.mono.context, top_r.x + 16, theme.baseline(top_r.y, h, theme.size.mono.context), "top", t.dim); + var ink: canim.ui.Ink = .{ .ink = ui.rgb(t.dim) }; + if (side == 1 and moved and tops[0] != null and now.walking()) ink = tv.cellWritten(.{ .x = sx - 4, .y = top_r.y + 10, .w = tv.width(.mono, theme.size.mono.context, size_text) + 8, .h = 24 }, now.heat(0, null, now.since(.idea, 0) - 12.0 / 60.0), null); + tv.text(ink.face, theme.size.mono.context, sx, theme.baseline(top_r.y, h, theme.size.mono.context), size_text, ink.ink); + _ = tv.address(top_r.x + 16, top_r.y - 8, top.addr, .{ .ink = ui.rgb(theme.color.region.heap) }); }; // Every node of either moment, where it was and where it goes. var nodes: std.ArrayList(u64) = .empty; for (program) |list| for (list) |n| if (std.mem.indexOfScalar(u64, nodes.items, n) == null) nodes.append(a, n) catch {}; for (free) |list| for (list) |e| if (std.mem.indexOfScalar(u64, nodes.items, e.chunk + 16) == null) nodes.append(a, e.chunk + 16) catch {}; - const regs = (now.moment().regs(rec.tid) catch null) orelse zt.Regs{}; + // Who points at each node, before the step and after it: its pin's names crossfade (12 f, with the idea). + const regs = [2]zt.Regs{ (now.before().regs(rec.tid) catch null) orelse zt.Regs{}, (now.moment().regs(rec.tid) catch null) orelse zt.Regs{} }; + const locals = [2]?u64{ local(a, now.before(), regs[0], "n"), local(a, now.moment(), regs[1], "n") }; + const heads = [2]?u64{ canim.Recording.word(now.before(), l.head_at, 8) catch null, canim.Recording.word(now.moment(), l.head_at, 8) catch null }; for (nodes.items) |node| { const from = spotOf(program[0], free[0], node); const to = spotOf(program[1], free[1], node); const s0 = from orelse to.?; const s1 = to orelse from.?; const xy = canim.ui.Vec{ std.math.lerp(at(s0)[0], at(s1)[0], p), std.math.lerp(at(s0)[1], at(s1)[1], p) }; - const shows: f32 = if (from == null) p else if (to == null) 1 - p else 1; + const shows: f32 = if (from == null) after(now, 0, 12) else if (to == null) 1 - after(now, 0, 12) else 1; const nv = v.faded(shows); const freed = (if (p >= 0.5) s1 else s0).row == 1; const r: canim.Rect = .{ .x = xy[0], .y = xy[1], .w = w, .h = h }; @@ -169,9 +237,13 @@ const Lists = struct { nv.fill(.{ .x = r.x, .y = r.y, .w = w - well, .h = h }, theme.color.raised); nv.fill(.{ .x = r.x + w - well, .y = r.y, .w = well, .h = h }, theme.color.well); const value = (canim.Recording.word(m, node, 8) catch null) orelse 0; - const heat = now.written(node, 8, .idea, 0); - const ink = nv.cellWritten(.{ .x = r.x, .y = r.y, .w = w - well, .h = h }, heat, theme.color.raised); - nv.label(ink.face, theme.size.mono.small, .{ .x = r.x, .y = r.y, .w = w - well, .h = h }, .center, nv.print("{d}", .{@as(i64, @bitCast(value))}), if (heat.level >= 1) ink.ink else ui.rgb(t.primary)); + // A node changing hands is not struck: its words are the other list's now (the dump strikes them). + const heat = if (s0.row == s1.row) now.written(node, 8, .idea, 0) else canim.ui.Heat.none; + const cell: canim.Rect = .{ .x = r.x, .y = r.y, .w = w - well, .h = h }; + const ink = nv.cellWritten(cell, heat, theme.color.raised); + // Taken back before the program writes it: the old link, faint, as stored. + const stale = value != 0 and value >> 12 == node >> 12; + if (stale) nv.label(.mono, theme.size.mono.context, cell, .center, nv.print("{x}", .{value}), t.faint) else nv.label(ink.face, theme.size.mono.small, cell, .center, nv.print("{d}", .{@as(i64, @bitCast(value))}), if (heat.level >= 1) ink.ink else ui.rgb(t.primary)); } // Its link: the next node in its row, as the pointer protects or holds it. const sq: canim.Rect = .{ .x = if (freed) r.x + 18 else r.x + w - well / 2 - 5, .y = r.y + h / 2 - 5, .w = 10, .h = 10 }; @@ -182,20 +254,33 @@ const Lists = struct { } else if (spotOf(program[shown], free[shown], next)) |ns| { nv.fill(sq, theme.color.region.heap); const nx = at(ns); - if (nx[1] == r.y and nx[0] > r.x) nv.route(&.{ .{ sq.x + 10, r.y + h / 2 }, .{ nx[0] - 2, r.y + h / 2 } }, theme.color.region.heap, .{ .width = theme.stroke.line, .head = theme.metric.node.arrow_head }); + if (@abs(nx[1] - r.y) < 1 and nx[0] > r.x) nv.route(&.{ .{ sq.x + 10, r.y + h / 2 }, .{ nx[0] - 2, r.y + h / 2 } }, theme.color.region.heap, .{ .width = theme.stroke.line, .head = theme.metric.node.arrow_head }); } - // Who points here: `head`, and the registers. - var names: [4][]const u8 = undefined; - var n: usize = 0; - if ((canim.Recording.word(m, l.head_at, 8) catch null) == node) { - names[n] = "head"; - n += 1; + // Who points here: `head`, the local `n`, and the registers. + var names: [2][4][]const u8 = undefined; + var count = [2]usize{ 0, 0 }; + for (0..2) |side| { + if (heads[side] == node) { + names[side][count[side]] = "head"; + count[side] += 1; + } + if (locals[side] == node) { + names[side][count[side]] = "n"; + count[side] += 1; + } + for ([_][]const u8{ "rax", "rdi" }) |reg| if (regs[side].named(reg) == node and count[side] < 4) { + names[side][count[side]] = reg; + count[side] += 1; + }; + } + const same = count[0] == count[1] and for (names[0][0..count[0]], names[1][0..count[1]]) |x, y| { + if (!std.mem.eql(u8, x, y)) break false; + } else true; + const turn = if (same) 1 else after(now, 0, 12); + for (0..2) |side| { + const pin = if (same) @as(f32, if (side == 1) 1 else 0) else if (side == 1) turn else 1 - turn; + if (pin > 0 and count[side] > 0) nv.faded(pin).pinUnder(r.x + 40, r.y + h + 2, names[side][0..count[side]], theme.color.region.heap, theme.size.mono.context); } - for ([_][]const u8{ "rax", "rdi" }) |reg| if (regs.named(reg) == node and n < names.len) { - names[n] = reg; - n += 1; - }; - if (n > 0) nv.pinUnder(r.x + 40, r.y + h + 2, names[0..n], theme.color.region.heap, theme.size.mono.context); } } }; @@ -236,7 +321,10 @@ const Chunks = struct { defer v.u.unclip(); if (v.rows == 0) return; const now = c.cursor.now(placed); - canim.hexdump.fielded(v, now, cm.tag + cm.pad, .{ .base = view_base, .len = view_len, .fields = fieldsAt(f.scratch, c.cursor.rec, now.stop(.memory)) }); + // The heap new in this step (the first malloc's): its rows come in, unmarked, over 12 f with memory's slot. + const new = !now.resting() and heapAt(f.scratch, c.cursor.rec, now.stops[1]) == null; + const comes: f32 = if (new) std.math.clamp(now.since(.memory, 0) / (12.0 / 60.0), 0, 1) else 1; + canim.hexdump.fielded(.{ .u = v.u.faded(comes), .rows = v.rows, .box = v.box }, now, cm.tag + cm.pad, .{ .base = view_base, .len = view_len, .fields = fieldsAt(f.scratch, c.cursor.rec, now.stop(.memory)), .watched = if (new) 0 else std.math.maxInt(usize) }); v.veil(now); } }; @@ -273,10 +361,37 @@ fn lineIn(rec: *canim.Recording, function: []const u8, n: usize, line: u32) u64 return rec.lineMoment(line, rec.call(function, n).enter); } +/// A step that changes the tcache, walked (`wave`: as a continue, free +/// having been stepped over): after memory has struck, the loupe opens over +/// the stack (36 f), its fields strike in it (6 f after, 6 f apart), then +/// the idea; it closes with the advance. Never open over a step it does not concern. +fn tcacheStep(at: canim.Cursor, s: *anim.Frame, tcache: *const canim.Loupe, wave: bool) void { + const tm = theme.time; + const from = at.moment(s); + const to = at.rec.next(.line, from); + var plan = at.planned(from, to, wave); + const opens = plan.at[1] + 3 * 6.0 / 60.0 + 12.0 / 60.0; + const idea = opens + tm.loupe.open + 24.0 / 60.0; + const later = @max(idea - plan.at[2], 0); + plan.at[2] += later; + plan.advance += later; + plan.total += later; + const start = s.cursor; + at.step(s, to, plan, plan.total); + const end = s.cursor; + s.cursor = start + opens; + tcache.open(s); + s.cursor = start + plan.advance; + tcache.close(s); + s.cursor = end; + if (at.phraseEnds(from, to)) s.wait(tm.phrase_rest); +} + fn frame(s: *anim.Frame) void { const rec = canim.open(recordings.heap); const main = rec.call("main", 0); - var at = canim.cursor(s, rec, main.enter); + // From main's first line, `push(7)`. + var at = canim.cursor(s, rec, rec.lineMoment(24, main.enter)); at.journey(.line, rec.lineMoment(30, main.enter)); at.levels = .{ .idea = .data, .source_rows = 10 }; const ctx = canim.context(s, at, .{ .split = canim.layout.split.subject }); @@ -284,40 +399,44 @@ fn frame(s: *anim.Frame) void { const head_at = globalOf(rec, lineIn(rec, "push", 0, 13)); const lists = canim.add(s, Lists{ .cursor = at, .stage = ctx.stage, .head_at = head_at }); const chunks = canim.add(s, Chunks{ .cursor = at, .stage = ctx.stage }); - // The tcache, once there is one: a loupe from the row of the chunk it lives in. + // The tcache, once there is one: a loupe from the row of the chunk it lives in, over the stack. const tc = tcacheOf(rec); const tcache = canim.loupe(s, .{ .cursor = at, .stage = ctx.stage, .from = .{ .row = .{ .at = tc.addr - 8, .name = "tcache", - .note = "tcache_perthread_struct \u{00b7} 0x2f0 bytes", - .fields = .{ .base = tc.addr, .len = 0x2f0, .fields = &.{ + // 76 two-byte counts and 76 pointers (glibc 2.44): 760 bytes. + .note = "tcache_perthread_struct \u{00b7} 0x2f8 bytes", + .fields = .{ .base = tc.addr, .len = 0x2f8, .fields = &.{ .{ .at = 0, .len = 2, .note = "slots left" }, .{ .at = 0x98, .len = 8, .reads = .pointer, .note = "the head of 0x20" }, } }, } } }); var says: canim.Narrator = .{}; - const tm = theme.time; const joins = ctx.ties(s); canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, chunks, lists, joins }); - says.line(s, "A list of three, pushed and popped: what malloc and free\ndo to the heap under it, a stop after each."); - at.walk(s, .line, lineIn(rec, "push", 0, 12)); - says.line(s, "malloc(16) cut a chunk of 0x20 off the top: its size word,\n0x21, then the 16 bytes rax points at."); - at.walk(s, .line, lineIn(rec, "push", 1, 10)); - at.hurry(s, .line, rec.lineMoment(26, main.enter), .{}); - says.line(s, "Three pushes, three chunks in a row, each with P: the chunk\nbefore it is in use. The next pointers are arcs in the bytes."); - at.walk(s, .line, lineIn(rec, "pop", 0, 21)); - says.line(s, "free gives 9's chunk to the tcache, malloc's bin for 0x20.\nIts first word is the link now: 405, NULL safe-linked."); - at.walk(s, .line, rec.lineMoment(27, main.enter)); - tcache.open(s); - s.wait(tm.phrase_rest); - at.hurry(s, .line, lineIn(rec, "pop", 1, 21), .{}); - says.line(s, "The second chains to the first: 405455 is 405050 xor 405,\nthe chunk's own address shifted 12."); + // design/motion.md, "A scene: libc's heap from the inside": each caption + // leads the steps it is about, and changes only in a rest. + says.line(s, "Three pushes and two pops: what malloc and free\ndo to the heap."); + at.walk(s, .line, lineIn(rec, "push", 0, 11)); + says.line(s, "malloc(16) cut a chunk of 0x20 off the top: its size word,\n0x21, then the 16 bytes rax points at. The top is 0x20 smaller."); + at.walk(s, .line, rec.lineMoment(25, main.enter)); + says.line(s, "Two more pushes, at a run: three chunks in a row, each\nwith P set, the chunk before it in use."); + at.hurry(s, .line, rec.lineMoment(27, main.enter), .{}); + says.line(s, "pop takes the head off the list: head = n->next."); + at.walk(s, .line, lineIn(rec, "pop", 0, 20)); + says.line(s, "free gave 9's chunk to the tcache, malloc's bin for 0x20.\nIts first word is the link now: 405, which is NULL, safe-linked."); + tcacheStep(at, s, tcache, true); at.walk(s, .line, rec.lineMoment(28, main.enter)); - s.wait(tm.phrase_rest); - says.line(s, "malloc(16) takes the bin's head back: the tcache points\nat 405050 again, the key is wiped, the old link stays."); - at.walk(s, .line, lineIn(rec, "push", 3, 12)); + says.line(s, "The second pop: head moves on, to 7's node."); + at.walk(s, .line, lineIn(rec, "pop", 1, 20)); + says.line(s, "The second free chains to the first: 405455 is 405050 xor 405,\nthe chunk's own address shifted 12. The arc is the pointer it hides."); + tcacheStep(at, s, tcache, true); + at.walk(s, .line, rec.lineMoment(29, main.enter)); + says.line(s, "malloc(16) took the bin's head, 405030: the tcache points\nat 405050 again, the key is wiped, the old link stays."); + at.walk(s, .line, lineIn(rec, "push", 3, 11)); + tcacheStep(at, s, tcache, false); + says.line(s, "push writes 25 over the old link: the list is 25, then 7."); at.walk(s, .line, rec.lineMoment(30, main.enter)); - tcache.close(s); says.close(s); } diff --git a/anim/scenes/syscalls.zig b/anim/scenes/syscalls.zig index db67045..0d39089 100644 --- a/anim/scenes/syscalls.zig +++ b/anim/scenes/syscalls.zig @@ -58,11 +58,15 @@ fn frame(s: *anim.Frame) void { says.line(s, "`main` calls `open` by its stub in the PLT. The arguments\nare in rdi and rsi: \"note\" and O_RDONLY."); canim.descent.step(cur, s, .moment); s.wait(t.phrase_rest); - says.line(s, "The call went down: main's window keeps its call, ringed;\nthe stub's jmp reads the GOT, and goes on to libc."); + says.line(s, "The call went down: main's window keeps its call, ringed,\nand the stub's three rows open under it."); + says.line(s, "The stub's jmp reads open@got, the GOT's slot,\nand goes on to libc's `open`."); canim.descent.step(cur, s, .moment); s.wait(t.phrase_rest); - says.line(s, "libc's `open` is a wrapper: it puts openat's number in rax\nand its arguments in rdi, rsi, rdx and r10."); - cur.hurry(s, .moment, crossing, .{}); + // 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."); + 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); says.line(s, "`syscall` crosses down. The kernel opens the file\nand answers in rax: 3, the descriptor."); canim.descent.step(cur, s, .moment); s.wait(t.phrase_rest); |
