From 5922ee911b9a6604f60dc83be36ba9e6c9abac98 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 11 Nov 2026 02:11:12 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa --- anim/src/cursor.zig | 195 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 166 insertions(+), 29 deletions(-) (limited to 'anim/src/cursor.zig') diff --git a/anim/src/cursor.zig b/anim/src/cursor.zig index 6a02948..bbc3cf1 100644 --- a/anim/src/cursor.zig +++ b/anim/src/cursor.zig @@ -16,6 +16,7 @@ const anim = @import("anim"); const zt = @import("ztrace"); const Recording = @import("Recording.zig"); const ui = @import("ui.zig"); +const syscalls = @import("syscalls.zig"); const theme = ui.theme; const time = theme.time; @@ -80,6 +81,9 @@ pub const Plan = struct { total: f32 = time.fire + time.step + time.rest, /// A `continue`: the registers strike in a wave, no arm and no pulse. wave: bool = false, + /// The line fires (not on a step that goes on from the last one's + /// mark: a crossing stepped over, from its call row). + fires: bool = true, /// Once the pattern is known: the levels a stagger apart from the /// first frame, the mark after them, in `seconds`. @@ -93,7 +97,7 @@ pub const Plan = struct { }; /// Registers whose change is no value to read: where execution is, and the flags. -const quiet: u32 = blk: { +pub const quiet: u32 = blk: { var mask: u32 = 0; for (zt.Regs.names, 0..) |name, i| { if (std.mem.eql(u8, name, "rip") or std.mem.eql(u8, name, "eflags")) mask |= 1 << i; @@ -105,10 +109,13 @@ pub const Cursor = struct { rec: *Recording, /// Where it is (or is arriving), where it came from, and before that. stops: [history]anim.Value, + /// The pace each of those steps was taken at (`Gait`): what a run + /// changed is not marked, then or after. + gaits: [history]anim.Value, /// 0 to 1 through the step it is taking; 1 at rest. phase: anim.Value, /// The step's `Plan`, a value a field. - plan: [8]anim.Value, + plan: [9]anim.Value, /// The moment the current mark was on, and the one it is on (or going to). marks: [2]anim.Value, /// 1 while steps are hurried (the head counts them), and while what @@ -119,6 +126,10 @@ pub const Cursor = struct { sprint_veil: anim.Value, /// Steps taken. count: anim.Value, + /// The same values a little behind (`time.minimap_lag`): what the + /// minimap draws from, secondary action that never starts on a primary + /// onset's frame. + lag: Lagged, /// The levels the scene shows: set before the first step. levels: Levels = .{}, /// The scene's whole way, for the head's progress line and counter (`journey`). @@ -133,21 +144,62 @@ pub const Cursor = struct { var c: Cursor = .{ .rec = rec, .stops = undefined, + .gaits = undefined, .phase = s.value(1), - .plan = .{ s.value(0), s.value(plan.at[0]), s.value(plan.at[1]), s.value(plan.at[2]), s.value(plan.advance), s.value(plan.travel), s.value(plan.total), s.value(0) }, + .plan = .{ s.value(0), s.value(plan.at[0]), s.value(plan.at[1]), s.value(plan.at[2]), s.value(plan.advance), s.value(plan.travel), s.value(plan.total), s.value(0), s.value(1) }, .marks = .{ s.value(here), s.value(here) }, .hurried = s.value(0), .veil = s.value(0), .sprint_veil = s.value(0), .count = s.value(0), + .lag = undefined, .first = start, .last = start, }; // shortcut: an f32 holds whole moments up to 16 million; a longer recording needs two values a stop. for (&c.stops) |*stop| stop.* = s.value(here); + for (&c.gaits) |*gait| gait.* = s.value(0); + inline for (@typeInfo(Lagged).@"struct".field_names) |name| { + const from = @field(c, name); + if (@TypeOf(from) == anim.Value) { + @field(c.lag, name) = s.value(s.get(from)); + } else for (&@field(c.lag, name), from) |*to, one| { + to.* = s.value(s.get(one)); + } + } return c; } + /// The cursor's animated values, mirrored for the minimap. + pub const Lagged = struct { + stops: [history]anim.Value, + gaits: [history]anim.Value, + phase: anim.Value, + plan: [9]anim.Value, + marks: [2]anim.Value, + hurried: anim.Value, + veil: anim.Value, + sprint_veil: anim.Value, + count: anim.Value, + }; + + /// Plays `plays(values)` on the cursor's values from here, and on their + /// lagging mirror `time.minimap_lag` later; the cursor ends where the first left it. + fn both(c: Cursor, s: *anim.Frame, plays: anytype) void { + const start = s.cursor; + s.cursor = start + time.minimap_lag; + plays.run(s, lagged(c)); + s.cursor = start; + plays.run(s, c); + } + + /// `c` with its lagging values in place of its own. + fn lagged(c: Cursor) Cursor { + var out = c; + inline for (@typeInfo(Lagged).@"struct".field_names) |name| @field(out, name) = @field(c.lag, name); + return out; + } + /// Where the timeline has taken the cursor so far: for scene code that /// finds the next place from the last. pub fn moment(c: Cursor, s: *const anim.Frame) u64 { @@ -174,18 +226,36 @@ pub const Cursor = struct { /// sentence said faster). pub fn step(c: Cursor, s: *anim.Frame, to: u64, plan: Plan, seconds: f32) void { const from = c.moment(s); - var set: [history + 12]anim.Animation = undefined; - for (1..history) |i| set[i] = c.stops[i].to(settled(s, c.stops[i - 1])); - set[0] = c.stops[0].to(@floatFromInt(to)); - for (c.plan, [_]f32{ @floatFromInt(@intFromEnum(plan.gait)), plan.at[0], plan.at[1], plan.at[2], plan.advance, plan.travel, plan.total, @floatFromInt(@intFromBool(plan.wave)) }, history..) |value, is, n| set[n] = value.to(is); + // Where each value goes, from the cursor's own (the mirror goes the same way, later). + const Step = struct { + stops: [history]f32, + gaits: [history]f32, + plan: [9]f32, + marks: [2]f32, + count: f32, + seconds: f32, + fn run(st: @This(), sf: *anim.Frame, v: Cursor) void { + var set: [2 * history + 13]anim.Animation = undefined; + for (v.stops, st.stops, 0..) |value, is, i| set[i] = value.to(is); + for (v.gaits, st.gaits, 0..) |value, is, i| set[history + 13 + i] = value.to(is); + for (v.plan, st.plan, history..) |value, is, n| set[n] = value.to(is); + set[history + 9] = v.marks[0].to(st.marks[0]); + set[history + 10] = v.marks[1].to(st.marks[1]); + set[history + 11] = v.phase.to(0); + set[history + 12] = v.count.to(st.count); + sf.play(set, .{ .seconds = 0 }); + sf.play(.{v.phase.to(1)}, .{ .seconds = st.seconds, .ease = anim.ease.linear }); + } + }; + var st: Step = .{ .stops = undefined, .gaits = undefined, .plan = .{ @floatFromInt(@intFromEnum(plan.gait)), plan.at[0], plan.at[1], plan.at[2], plan.advance, plan.travel, plan.total, @floatFromInt(@intFromBool(plan.wave)), @floatFromInt(@intFromBool(plan.fires)) }, .marks = undefined, .count = settled(s, c.count) + 1, .seconds = seconds }; + st.stops[0] = @floatFromInt(to); + for (1..history) |i| st.stops[i] = settled(s, c.stops[i - 1]); + st.gaits[0] = @floatFromInt(@intFromEnum(plan.gait)); + for (1..history) |i| st.gaits[i] = settled(s, c.gaits[i - 1]); // At a sprint the mark is seen only where a phrase ends. const was = settled(s, c.marks[1]); - set[history + 8] = c.marks[0].to(was); - set[history + 9] = c.marks[1].to(if (plan.gait == .sprint and !c.phraseEnds(from, to)) was else @floatFromInt(to)); - set[history + 10] = c.phase.to(0); - set[history + 11] = c.count.to(settled(s, c.count) + 1); - s.play(set, .{ .seconds = 0 }); - s.play(.{c.phase.to(1)}, .{ .seconds = seconds, .ease = anim.ease.linear }); + st.marks = .{ was, if (plan.gait == .sprint and !c.phraseEnds(from, to)) was else @floatFromInt(to) }; + c.both(s, st); } /// Steps of `by` up to moment `until`, each shown in full and as long @@ -212,6 +282,11 @@ pub const Cursor = struct { return c.timetable(from, to, false); } + /// The timetable a step from `from` to `to` gets walked (`wave`: as a `continue`), for a scene that adds a beat to it. + pub fn planned(c: Cursor, from: u64, to: u64, wave: bool) Plan { + return c.timetable(from, to, wave); + } + /// `continue`: straight to a stop far from this one (a breakpoint, not /// a step). The line it leaves fires; the registers it changed strike /// in a wave, 2 f apart in pwndbg's order, the fill in over 6 f, no arm @@ -256,8 +331,9 @@ pub const Cursor = struct { const projected = level == 2 and is and levels[1] and (c.levels.idea == .data or deeper); if (projected) slot += time.project.bracket + @as(f32, if (c.levels.idea == .data) time.project.draw else time.project.far) + @as(f32, if (wrote > 0 and c.levels.idea == .data) time.strike.arm else 0) else if (is) slot += time.cascade; strikes.* = @max(slot, time.cascade); - // A wave's last register strikes 2 f a register after its first: the next level is 18 f after that. - if (wave and level == 0 and is) slot += (regs - 1) * time.continue_wave; + // A wave's last register strikes 2 f a register after its first, + // a cascade's 6 f (the fourth and on with the third): the next level is 18 f after that. + if (level == 0 and is) slot += if (wave) (regs - 1) * time.continue_wave else @min(regs - 1, 3) * write_apart; } // The writes of one step strike 6 f apart: the last is later. if (levels[1]) slot += @min(@max(wrote - 1, 0), 3) * write_apart; @@ -327,7 +403,7 @@ pub const Cursor = struct { // What changes faster than it can be read is veiled at a run too. const veiled = options.veil orelse true; const start = s.cursor; - s.play(.{ c.hurried.to(1), c.veil.to(if (veiled) 1 else 0), c.sprint_veil.to(if (options.pace < time.run) 1 else 0) }, .{ .seconds = time.veil, .ease = anim.ease.linear }); + c.both(s, Veils{ .to = .{ 1, if (veiled) 1 else 0, if (options.pace < time.run) 1 else 0 } }); s.cursor = start; var k: f32 = 0; while (here < until) : (k += 1) { @@ -343,22 +419,37 @@ pub const Cursor = struct { here = next; } if (!options.settle) return; - s.play(.{ c.hurried.to(0), c.veil.to(0), c.sprint_veil.to(0) }, .{ .seconds = time.veil, .ease = anim.ease.linear }); + c.both(s, Veils{ .to = .{ 0, 0, 0 } }); s.wait(time.beat); } + /// The hurry's veils going to `to` (hurried, veil, sprint_veil). + const Veils = struct { + to: [3]f32, + fn run(v: Veils, s: *anim.Frame, c: Cursor) void { + s.play(.{ c.hurried.to(v.to[0]), c.veil.to(v.to[1]), c.sprint_veil.to(v.to[2]) }, .{ .seconds = time.veil, .ease = anim.ease.linear }); + } + }; + /// There at once, with nothing struck: a cut. pub fn jump(c: Cursor, s: *anim.Frame, to: u64) void { - var all: [history + 3]anim.Animation = undefined; - for (c.stops, 0..) |stop_value, i| all[i] = stop_value.to(@floatFromInt(to)); - all[history] = c.phase.to(1); - all[history + 1] = c.marks[0].to(@floatFromInt(to)); - all[history + 2] = c.marks[1].to(@floatFromInt(to)); - s.play(all, .{ .seconds = 0 }); + const Jump = struct { + to: u64, + fn run(j: @This(), sf: *anim.Frame, v: Cursor) void { + var all: [history + 3]anim.Animation = undefined; + for (v.stops, 0..) |stop_value, i| all[i] = stop_value.to(@floatFromInt(j.to)); + all[history] = v.phase.to(1); + all[history + 1] = v.marks[0].to(@floatFromInt(j.to)); + all[history + 2] = v.marks[1].to(@floatFromInt(j.to)); + sf.play(all, .{ .seconds = 0 }); + } + }; + c.both(s, Jump{ .to = to }); } - /// For a component, while it draws. - pub fn now(c: Cursor, placed: anim.Placed) Now { + /// For a component, while it draws (on the minimap, `time.minimap_lag` behind). + pub fn now(c_: Cursor, placed: anim.Placed) Now { + const c = if (ui.strokes) lagged(c_) else c_; const rec = c.rec; var n: Now = .{ .rec = rec, @@ -371,6 +462,7 @@ pub const Cursor = struct { .travel = placed.value(c.plan[5]), .total = placed.value(c.plan[6]), .wave = placed.value(c.plan[7]) >= 0.5, + .fires = placed.value(c.plan[8]) >= 0.5, }, .marks = .{ whole(rec, placed.value(c.marks[0])), whole(rec, placed.value(c.marks[1])) }, .hurried = placed.value(c.hurried), @@ -384,6 +476,7 @@ pub const Cursor = struct { .way = .{ c.first, c.last }, }; for (&n.stops, c.stops) |*stop_at, v| stop_at.* = whole(rec, placed.value(v)); + for (&n.gaits, c.gaits) |*gait, v| gait.* = @enumFromInt(@as(u2, @intFromFloat(std.math.clamp(@round(placed.value(v)), 0, 2)))); const phase = placed.value(c.phase); if (phase < 1) n.time = phase * n.plan.total; if (c.last > c.first) { @@ -417,6 +510,8 @@ pub const Now = struct { /// `stops[0]` is the moment shown, `stops[1]` where the step came /// from: the step is every moment after it up to the one shown. stops: [history]u64, + /// The pace each step to them was taken at: `gaits[0]` this one's. + gaits: [history]Gait = @splat(.walk), /// Seconds into the step's plan; infinite at rest. time: f32, plan: Plan, @@ -494,7 +589,7 @@ pub const Now = struct { /// The fire: how far out (in units) the edges of the mark's plaque /// are, on the line about to run. The step's first beat, alone. pub fn fire(n: Now) f32 { - return if (n.walking() and n.time < time.fire) theme.pulse(n.time / time.fire) else 0; + return if (n.walking() and n.plan.fires and n.time < time.fire) theme.pulse(n.time / time.fire) else 0; } /// The same for the view the scene fires in, 0 for the other. @@ -528,6 +623,25 @@ pub const Now = struct { return n.writeAgeFrom(addr, size, 0); } + /// Of the bytes `addr .. addr + len` (16 at most), the first and the last + /// (from `addr`) whose value the step that last wrote them changed: what + /// its strike covers. Null where that is not known. + pub fn changedBytes(n: Now, addr: u64, len: u64) ?[2]u8 { + const age = n.writeAge(addr, len) orelse return null; + const l: usize = @intCast(@min(len, 16)); + var was: [16]u8 = undefined; + var is: [16]u8 = undefined; + var known_was: [16]bool = undefined; + var known_is: [16]bool = undefined; + n.rec.moment(n.stops[age + 1]).read(addr, was[0..l], known_was[0..l]) catch return null; + n.rec.moment(n.stops[age]).read(addr, is[0..l], known_is[0..l]) catch return null; + var out: ?[2]u8 = null; + for (0..l) |i| if (known_was[i] and known_is[i] and was[i] != is[i]) { + out = .{ if (out) |o| o[0] else @intCast(i), @intCast(i) }; + }; + return out; + } + /// The same, not counting the `skip` newest steps. fn writeAgeFrom(n: Now, addr: u64, size: u64, skip: usize) ?u64 { for (skip..history - 1) |age| { @@ -568,6 +682,8 @@ pub const Now = struct { const s = time.strike; const a = age orelse return .none; if (a == 0 or a > s.ember_steps) return .none; + // A run changes values unmarked: it shows them settled. + if (n.gaits[a] == .run) return .none; if (a < s.ember_steps) return .ember; // Linear: a fade, as the mark leaves: secondary action does not // start on the fire's frame, where the step's primary one does. @@ -587,7 +703,8 @@ pub const Now = struct { switch (n.plan.gait) { // Faster than a strike can be seen: embers only. .sprint => return .ember, - .run => return if (was.level >= 1 or n.resting()) .ember else .{ .level = std.math.clamp(since_strike / time.snap, 0, 1) }, + // A run strikes nothing: its values change in place. + .run => return .none, .walk => {}, } if (n.resting()) return .ember; @@ -614,9 +731,27 @@ pub const Now = struct { /// `level`, `delay` seconds after its first, and 6 f after the write of /// this step before theirs. pub fn written(n: Now, addr: u64, size: u64, level: Level, delay: f32) ui.Heat { + // What the kernel fills in a crossing lands as its work does it, unpulsed. + if (level == .memory) if (syscalls.filledAt(n, addr)) |at| { + var h = n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), n.time - at); + h.out = 0; + return h; + }; return n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), n.since(level, delay + n.writeDelay(addr, size))); } + /// `written`, struck `since` seconds ago (a loupe's own times: it strikes once it has opened). + pub fn writtenAt(n: Now, addr: u64, size: u64, struck: f32) ui.Heat { + return n.heat(n.writeAge(addr, size), n.writeAgeFrom(addr, size, 1), struck); + } + + /// The state to draw the memory at `addr` from: `shown(.memory)`, but + /// what the kernel fills in a crossing from when its byte lands. + pub fn shownAt(n: Now, addr: u64) Recording.Moment { + if (syscalls.filledAt(n, addr)) |at| return if (n.time - at >= time.strike.in / 2.0) n.moment() else n.before(); + return n.shown(.memory); + } + /// `written`, on a thing the viewer has watched only through the steps /// `lo` to `hi` ago (a window that faded to its place, a view that came /// in after its step): what changed in any other step is plain. @@ -631,6 +766,8 @@ pub const Now = struct { var last: ?u64 = null; for (n.rec.written(n.stops[1], n.stops[0])) |span| { if (span.addr < addr + size and span.addr + span.len > addr) return @min(order, 3) * write_apart; + // The kernel's own writes have their own times (`filledAt`). + if (syscalls.filledAt(n, span.addr) != null) continue; // Bytes of one write (one store, in pieces) are one strike. if (last == null or span.addr != last.?) order += 1; last = span.addr + span.len; @@ -704,8 +841,8 @@ test "a write is armed, strikes, holds, cools with the advance, and leaves after // Struck again over its ember: armed with the ember still under it. h = instant(0.20, plan).heat(0, 1, -0.10); try expect(h.level == 1 and h.arm == 1 and h.solid == 0); - // Running: an ember and no more. Sprinting: the same, at once. - try expect(instant(0.2, Plan.running(0.3)).heat(0, null, 0.2).solid == 0); + // Running: nothing struck. Sprinting: an ember, at once. + try expectEqual(ui.Heat.none, instant(0.2, Plan.running(0.3)).heat(0, null, 0.2)); try expectEqual(ui.Heat.ember, instant(0.01, Plan.sprinting(0.05)).heat(0, null, 0.01)); } -- cgit v1.3