1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
|
//! ASan against a plain build (design/motion.md, "A scene: ASan against a
//! plain build"): `overflow.c`'s loop writes 32 bytes into 16, built plain
//! and with AddressSanitizer, the two runs a `pair` (design/README.md):
//! the shared source, each run's disassembly, registers and frame as bytes
//! on its side of the seam, `buf` facing `buf`. They go together to i = 16,
//! where they part: plain stores into its saved rbp, ASan reads `f3` in the
//! shadow and calls its report, which comes in from the run's own `write`s
//! in place of its registers; plain goes on alone, a letter a turn, through
//! the saved rbp and the return address (the held rest at i = 27 is the
//! poster, mock 38), to `ret` and its fault. Beats A1 to A16, the
//! storyboard's texts as written; A10 to A13 in the pair as captions (see
//! the README: the column holds no frame as bytes).
const std = @import("std");
const anim = @import("anim");
const canim = @import("canim");
const recordings = @import("recordings");
const pair = canim.pair;
pub const background = canim.background;
pub const scene = anim.Live(frame, struct {});
/// The first moment from `from` whose instruction begins with `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 `n`th moment (from 0) from `from` whose pc is `pc`.
fn nth(rec: *canim.Recording, from: u64, pc: u64, n: usize) u64 {
var seen: usize = 0;
var i = from;
while (i < rec.end()) : (i += 1) if (rec.register(i, "rip") == pc) {
if (seen == n) return i;
seen += 1;
};
return rec.end();
}
/// Each moment from here to `until` walked, its whole sentence said in
/// `seconds` (null: as long as it takes).
fn walk(s: *anim.Frame, c: canim.Cursor, until: u64, seconds: ?f32) void {
var here = c.moment(s);
while (here < until) : (here += 1) {
const plan = c.reading(here, here + 1);
c.step(s, here + 1, plan, seconds orelse plan.total);
}
}
/// Straight to `to` at a run: unmarked, values changing in place under 8 f crossfades.
fn run(s: *anim.Frame, c: canim.Cursor, to: u64, seconds: f32) void {
c.step(s, to, canim.Plan.running(seconds), seconds);
}
/// To `until` at a run, `per` moments a step (each step at least 18 f: the
/// mark's 8 f ease and its 8 f advance), the first steps as long as `ramp`
/// says and the rest as long as its last.
fn runTo(s: *anim.Frame, c: canim.Cursor, until: u64, per: u64, ramp: []const f32) void {
var here = c.moment(s);
var k: usize = 0;
while (here < until) : (k += 1) {
const next = @min(here + per, until);
const sec = ramp[@min(k, ramp.len - 1)];
run(s, c, next, sec);
here = next;
}
}
/// The two runs from one instant: the scene goes on when the later is done.
const Together = struct {
start: f32,
end: f32,
fn begin(s: *anim.Frame) Together {
return .{ .start = s.cursor, .end = s.cursor };
}
/// The next run's part, from the same start.
fn next(tg: *Together, s: *anim.Frame) void {
tg.end = @max(tg.end, s.cursor);
s.cursor = tg.start;
}
fn done(tg: *Together, s: *anim.Frame) void {
s.cursor = @max(tg.end, s.cursor);
}
};
/// Of the right run's function, the rows no row of the left faces (`only
/// here`): all but the frame's own instructions, the loop counter's (the
/// memory the loop's `cmp …, 0x20` reads), the branch after that compare,
/// `add eax, 1`, the store of 'A', and the jump back to the compare.
fn onlyHere(a: std.mem.Allocator, rec: *canim.Recording, at: u64, start: u64) []const u64 {
var out: std.ArrayList(u64) = .empty;
var buf: [256]u8 = undefined;
var counter: []const u8 = "";
var head: u64 = 0;
var addr = start;
var after_head = false;
while (rec.instruction(at, addr, &buf)) |one| : (addr += one.len) {
const text = a.dupe(u8, one.text) catch break;
if (std.mem.startsWith(u8, text, "cmp dword ptr [") and std.mem.endsWith(u8, text, ", 0x20")) {
counter = text[std.mem.indexOfScalar(u8, text, '[').? .. std.mem.indexOfScalar(u8, text, ']').? + 1];
head = addr;
}
}
addr = start;
while (rec.instruction(at, addr, &buf)) |one| : (addr += one.len) {
const text = one.text;
const jump_back = std.mem.startsWith(u8, text, "jmp") and std.mem.endsWith(u8, text, a.dupe(u8, std.fmt.bufPrint(buf[200..], "0x{x}", .{head}) catch "") catch "");
const faces = std.mem.eql(u8, text, "push rbp") or std.mem.eql(u8, text, "mov rbp, rsp") or std.mem.eql(u8, text, "pop rbp") or
(counter.len > 0 and std.mem.indexOf(u8, text, counter) != null) or after_head or std.mem.eql(u8, text, "add eax, 1") or
(std.mem.startsWith(u8, text, "mov byte ptr") and std.mem.endsWith(u8, text, ", 0x41")) or jump_back;
after_head = addr == head;
if (!faces) out.append(a, addr) catch break;
if (std.mem.eql(u8, text, "ret")) break;
}
return out.items;
}
/// The signal that stopped the run, if one did: its moment and its name.
fn signal(rec: *canim.Recording) ?struct { at: u64, name: []const u8 } {
var i = rec.end();
while (i > 0) {
i -= 1;
var events = rec.moment(i).events(std.heap.page_allocator) catch continue;
defer events.deinit(std.heap.page_allocator);
while (events.next()) |item| if (item.ev.kind == .signal) {
return .{ .at = i, .name = switch (item.ev.aux) {
4 => "SIGILL",
5 => "SIGTRAP",
6 => "SIGABRT",
7 => "SIGBUS",
8 => "SIGFPE",
11 => "SIGSEGV",
else => "a signal",
} };
};
}
return null;
}
/// A stopped run's tag on the shelf: `stopped:` and its report's first words
/// (the error's kind, and the access: `stack-buffer-overflow, WRITE of size 1`).
fn stopped(a: std.mem.Allocator, said: []const u8) []const u8 {
const kind = blk: {
const at = std.mem.indexOf(u8, said, "AddressSanitizer: ") orelse break :blk "";
const rest = said[at + "AddressSanitizer: ".len ..];
break :blk rest[0 .. std.mem.indexOfAny(u8, rest, " \n") orelse rest.len];
};
const access = blk: {
const at = std.mem.indexOf(u8, said, "WRITE of size") orelse std.mem.indexOf(u8, said, "READ of size") orelse break :blk "";
const rest = said[at..];
break :blk rest[0 .. std.mem.indexOf(u8, rest, " at ") orelse rest.len];
};
return std.fmt.allocPrint(a, "stopped: {s}, {s}", .{ kind, access }) catch "stopped";
}
fn frame(s: *anim.Frame) void {
const plain = canim.open(recordings.overflow);
const asan = canim.open(recordings.overflow_asan);
const report = canim.open(recordings.overflow_report);
const t = canim.theme.time;
// Plain: main's call; fill's line 4; the turns, each from its compare; the store of each; the way out.
const p_call = on(plain, plain.call("main", 0).enter, "call");
const p_line4 = plain.lineMoment(4, p_call + 1);
const p_head = plain.register(on(plain, p_line4, "cmp"), "rip");
var p_turn: [33]u64 = undefined;
var p_store: [32]u64 = undefined;
for (&p_turn, 0..) |*m, i| m.* = nth(plain, p_line4, p_head, i);
for (&p_store, 0..) |*m, i| m.* = on(plain, p_turn[i], "mov byte ptr");
const p_pop = on(plain, p_turn[32], "pop rbp");
const fault = signal(plain);
const p_end = if (fault) |f| f.at else p_pop + 2;
// ASan: the same call; its prologue and `__asan_stack_malloc_0`, stepped over; line 3; the turns.
const q_call = on(asan, asan.call("main", 0).enter, "call");
const q_fill = q_call + 1;
const q_malloc = on(asan, q_fill, "call");
var ibuf: [256]u8 = undefined;
const malloc_pc = asan.register(q_malloc, "rip");
const q_back = nth(asan, q_malloc + 1, malloc_pc + asan.instruction(q_malloc, malloc_pc, &ibuf).?.len, 0);
const q_line3 = asan.lineMoment(3, q_back);
const q_line4 = asan.lineMoment(4, q_line3);
const q_head = asan.register(on(asan, q_line4, "cmp dword ptr"), "rip");
var q_turn: [17]u64 = undefined;
for (&q_turn, 0..) |*m, i| m.* = nth(asan, q_line4, q_head, i);
// The first moment from `from` whose instruction is at the shadow: a check's load, or the prologue's poisoning store.
const q_load = struct {
fn of(rec: *canim.Recording, from: u64) 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.indexOf(u8, here.text, "0x7fff8000]") != null) return i;
return rec.end();
}
}.of;
// The parting turn's check, by what each instruction is: the load, its `je` (not taken), the partial check's
// compare and its branch, the call (the recording ends in it: `--until __asan_report_store1`).
const q_check16 = q_load(asan, q_turn[16]);
const q_je16 = on(asan, q_check16, "je");
const q_partial = on(asan, q_je16 + 1, "cmp");
const q_branch = on(asan, q_partial, "j");
const report_call = on(asan, q_branch, "call");
// The frames: plain's from rbp at line 4 (`i` at rbp-0x14, `buf` at rbp-0x10, then the saved rbp and the
// return address); ASan's fake frame, where `__asan_stack_malloc_0` put it, by its descriptor.
const rbp = plain.register(p_line4, "rbp");
const buf = rbp - 0x10;
const fake = asan.register(q_back, "rax");
const real = asan.register(q_line4, "rbp");
// The descriptor ("1 32 16 5 buf:3"): one variable, at 32, 16 long.
var var_at: u64 = 32;
var var_len: u64 = 16;
if (canim.Recording.word(asan.moment(q_line3), fake + 8, 8) catch null) |descr| {
var text: [32]u8 = undefined;
var known: [32]bool = undefined;
if (asan.moment(q_line3).read(descr, &text, &known)) |_| {
var it = std.mem.tokenizeScalar(u8, text[0 .. std.mem.indexOfScalar(u8, &text, 0) orelse text.len], ' ');
_ = it.next();
if (it.next()) |a| var_at = std.fmt.parseInt(u64, a, 10) catch var_at;
if (it.next()) |a| var_len = std.fmt.parseInt(u64, a, 10) catch var_len;
} else |_| {}
}
const fake_buf = fake + var_at;
var at = canim.cursor(s, plain, p_call);
var as = canim.cursor(s, asan, q_call);
for ([_]*canim.Cursor{ &at, &as }) |c| c.levels = .{ .source_rows = 5, .fire = .disasm };
at.journey(.moment, p_end);
as.journey(.moment, report_call);
const left = canim.Stage.init(s, pair.split(.left, false));
const right = canim.Stage.init(s, pair.split(.right, false));
const fake_in = s.value(0);
const differs = s.value(0);
const attention = s.value(0);
const framed = s.value(0);
const source = canim.add(s, canim.Source{ .cursor = at, .stage = left, .tag = "both builds" });
// Each run's disassembly by its name, aligned by line; ASan's stopped on its report's call once its run stops (A9).
const dis_l = canim.add(s, canim.Disasm{ .cursor = at, .stage = left, .run = "plain", .aligned = true });
const stopped_r = s.value(0);
// In the column (A10 to A13) plain's disassembly is a descent: main's window, the row
// its return address names among them, over fill's whole (motion.md, the column's panes).
const desc_l = canim.add(s, canim.Descent{ .cursor = at, .stage = left });
const dis_r = canim.add(s, canim.Disasm{ .cursor = as, .stage = right, .rows = 9, .run = "asan", .aligned = true, .stopped = stopped_r });
const reg_moves = struct {
fn of(names: []const []const u8) u32 {
var mask: u32 = 0;
for (names) |n| for (canim.ztrace.Regs.names, 0..) |known, i| {
if (std.mem.eql(u8, known, n)) mask |= @as(u32, 1) << @intCast(i);
};
return mask;
}
}.of;
const regs_l = canim.add(s, canim.Registers{ .cursor = at, .stage = left, .moves = reg_moves(&.{ "rax", "rbp", "rsp", "rip" }), .folds = false, .title = "plain \u{00b7} registers" });
const regs_r = canim.add(s, canim.Registers{ .cursor = as, .stage = right, .moves = reg_moves(&.{ "rax", "rbx", "rcx", "rip" }), .folds = false, .title = "asan \u{00b7} registers" });
const offset = pair.shadowOffset(asan) orelse 0x7fff8000;
const frame_l = canim.add(s, pair.Frame{
.cursor = at,
.stage = left,
.title = "plain \u{00b7} stack",
.note = "fill's frame as bytes, eight a row",
.first = buf - 32,
.rows = 10,
.fields = s.arena.dupe(pair.Field, &.{
.{ .at = rbp - 0x14, .len = 4, .name = "i", .from = p_line4 },
.{ .at = buf, .len = 16, .name = "buf", .reads = .text, .from = p_line4 },
.{ .at = rbp, .len = 8, .name = "saved rbp", .reads = .pointer, .from = p_call + 2 },
.{ .at = rbp + 8, .len = 8, .name = "return", .reads = .pointer, .from = p_call + 1 },
}) catch unreachable,
.letters = buf,
.span = .{ rbp - 0x18, rbp + 16 },
.span_from = p_call + 1,
.tall = rbp - 0x18,
.name = "fill",
.side = .left,
.shows = s.value(1),
.differs = differs,
.differ = s.arena.dupe(u64, &.{ rbp, rbp + 8 }) catch unreachable,
});
const frame_r = canim.add(s, pair.Frame{
.cursor = as,
.stage = right,
.title = "asan \u{00b7} fake frame",
.note = std.fmt.allocPrint(s.arena, "its shadow at addr >> 3 + {x} \u{00b7} then the real stack's way back", .{offset}) catch "",
.first = fake,
.rows = 8,
.then = real,
.more = 2,
.fields = s.arena.dupe(pair.Field, &.{
.{ .at = fake, .len = 8, .name = "magic", .reads = .bytes },
.{ .at = fake + 8, .len = 8, .name = "descr", .reads = .pointer },
.{ .at = fake + 16, .len = 8, .name = "pc", .reads = .pointer },
.{ .at = fake + 24, .len = 8, .name = "real stack", .reads = .pointer },
.{ .at = fake_buf, .len = var_len, .name = "buf", .reads = .text },
.{ .at = fake_buf + var_len, .len = 8, .name = "redzone", .reads = .bytes },
.{ .at = fake_buf + var_len + 8, .len = 8, .name = "redzone", .reads = .bytes },
.{ .at = real, .len = 8, .name = "saved rbp", .reads = .pointer, .from = q_fill + 1 },
.{ .at = real + 8, .len = 8, .name = "return", .reads = .pointer, .from = q_fill },
}) catch unreachable,
.letters = fake_buf,
.shadow = true,
.span = .{ fake, real + 16 },
.span_from = q_fill,
.name = "fill",
.side = .right,
.shows = fake_in,
.differs = differs,
.differ = s.arena.dupe(u64, &.{ fake_buf + var_len, fake_buf + var_len + 8 }) catch unreachable,
});
const stderr = canim.add(s, pair.Report{
.rec = report,
.stage = right,
.title = "asan \u{00b7} stderr",
.lines = &.{ "ERROR: AddressSanitizer", "WRITE of size", "is located in stack", "This frame has", "<== Memory access", "=>0x" },
.words = &.{ "stack-buffer-overflow", "WRITE of size 1", "[32, 48) 'buf'", "[f3]" },
.framed = framed,
});
const store_pc = plain.register(p_store[0], "rip");
const load_pc = asan.register(q_load(asan, q_turn[0]), "rip");
const right_shows = s.value(1);
const marks = canim.add(s, pair.Marks{
.left = at,
.right = as,
.stages = .{ left, right },
.name = "asan",
.only = onlyHere(s.arena, asan, q_fill, asan.register(q_fill, "rip")),
.attend = .{ store_pc, load_pc },
.attention = attention,
.right_shows = right_shows,
.fault = if (fault) |f| .{ .at = f.at, .pc = plain.register(f.at, "rip"), .name = f.name } else null,
});
const clock = canim.add(s, pair.Clock{ .left = at, .right = as, .names = .{ "plain", "asan" }, .counter = rbp - 0x14, .counting = p_line4 + 1, .stage = left });
// A10 to A13 in the column (`canim.column`): plain's panes, its frame as bytes the column's height; ASan's
// side folded to one tag on the shelf, its report's first line its note.
const col = canim.column(s, .{ .stage = left, .source = source, .disasm = dis_l, .registers = regs_l, .stack = frame_l, .backtrace = frame_l, .cursor = at }, .{});
const shelf_fold = s.value(0);
const said = pair.Report.stderr(report, s.arena);
const shelf = canim.add(s, pair.Shelf{ .stage = right, .title = "asan", .note = stopped(s.arena, said), .fold = shelf_fold });
// No ties across the seam: this one draws nothing (no thread, no stack words) and clears the frame's places.
const joins = canim.add(s, canim.Ties{ .cursor = at, .stage = left, .threaded = false, .quiet = true });
s.play(.{ marks.fadeIn(), joins.fadeIn(), shelf.fadeIn() }, .{ .seconds = 0 });
var says: canim.Narrator = .{};
canim.establish(s, .{ clock, source, dis_l, dis_r, regs_l, regs_r, frame_l, frame_r });
// A1: fill() called in both, as any call.
says.line(s, "Plain against AddressSanitizer: a loop writes 32 bytes into 16.");
var tg = Together.begin(s);
walk(s, at, p_call + 1, null);
tg.next(s);
walk(s, as, q_fill, null);
tg.done(s);
// A2: line 2, the prologues: plain's two rows walked; ASan's at a run (four rows a step), its
// stack_malloc stepped over, the fake frame's rows coming in as it is made; then the store that
// poisons the shadow walked, its cells struck 2 f apart.
says.line(s, "ASan's prologue moves `buf` to a fake frame\nand poisons its shadow: `f1` before `buf`, `f3` after.");
tg = Together.begin(s);
walk(s, at, p_line4, null);
tg.next(s);
{
const start = s.cursor;
s.play(.{ as.veil.to(1), as.hurried.to(1) }, .{ .seconds = t.veil });
s.cursor = start;
// Ramping in: each step 0.6 of the one before, to a run's 18 f.
runTo(s, as, q_malloc, 4, &.{ 0.5, 0.36, 0.3 });
run(s, as, q_back, 0.4);
// The fake frame is made: its rows come in (12 f).
const made = s.cursor;
s.play(.{fake_in.to(1)}, .{ .seconds = t.quick });
s.cursor = made;
runTo(s, as, q_load(asan, q_back), 5, &.{ 0.3, 0.36, 0.5 });
s.play(.{ as.veil.to(0), as.hurried.to(0) }, .{ .seconds = t.veil });
s.wait(t.beat);
walk(s, as, q_line3, null);
}
tg.done(s);
// A3: line 3, ASan's alone: buf's shadow f8 f8 turns 00 00.
says.line(s, "Line 3 is ASan's alone: `buf`'s shadow `f8 f8` turns `00 00`.");
// One step under a text read for 4.8 s: said slower, so that it covers the reading.
walk(s, as, q_line4, 2.2);
// A4: i = 0, the check: plain at a run to its store, where it waits facing ASan's check; ASan's
// counter and compare at a run, then its address and check rows walked, 30 f a row, the load longer.
says.line(s, "Before each store ASan reads `buf[i]`'s shadow byte,\nat `(addr >> 3) + 7fff8000`.");
const q_check0 = q_load(asan, q_turn[0]);
tg = Together.begin(s);
runTo(s, at, p_store[0], 1, &.{ 0.4, 0.3, 0.3 });
tg.next(s);
runTo(s, as, q_turn[0] + 2, 1, &.{ 0.4, 0.3, 0.3 });
walk(s, as, q_check0, 0.5);
walk(s, as, q_check0 + 1, 0.9);
walk(s, as, on(asan, q_check0, "je"), 0.5);
tg.done(s);
// A5: i = 0, the stores: ASan's rows after the check, then both stores, plain first, and each side's i++.
says.line(s, "It is `00`: the store may go. Both write `'A'`;\nplain in one instruction, ASan in seventeen.");
const q_store0 = on(asan, q_check0, "mov byte ptr");
walk(s, as, q_store0, 0.5);
tg = Together.begin(s);
walk(s, at, p_store[0] + 1, null);
tg.next(s);
s.wait(6.0 / 60.0);
walk(s, as, q_store0 + 1, null);
tg.done(s);
tg = Together.begin(s);
runTo(s, at, p_turn[1], 1, &.{ 0.3, 0.3, 0.36 });
tg.next(s);
runTo(s, as, q_turn[1], 1, &.{ 0.3, 0.3, 0.36 });
tg.done(s);
// A6: i = 1 to 14 at a run, a turn a step on each side, ramping in and out.
says.line(s, "Fourteen more turns, at a run: `buf` fills on both sides.");
{
const start = s.cursor;
s.play(.{ at.veil.to(1), at.hurried.to(1), as.veil.to(1), as.hurried.to(1) }, .{ .seconds = t.veil });
s.cursor = start;
const paces = [_]f32{ 0.6, 0.36, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.36, 0.6 };
for (paces, 1..) |sec, i| {
tg = Together.begin(s);
run(s, at, p_turn[i + 1], sec);
tg.next(s);
run(s, as, q_turn[i + 1], sec);
tg.done(s);
}
s.play(.{ at.veil.to(0), at.hurried.to(0), as.veil.to(0), as.hurried.to(0) }, .{ .seconds = t.veil });
s.wait(t.beat);
}
// A7: i = 15: the rows to each side's store at a run, ASan's load walked (the last 00 read), both stores
// walked, plain first; then each side's i++ at a run, to the turn's first row.
says.line(s, "i = 15, `buf`'s last byte:\nstill `00` on ASan's side, still `buf` on plain's.");
const q_check15 = q_load(asan, q_turn[15]);
const q_store15 = on(asan, q_check15, "mov byte ptr");
tg = Together.begin(s);
runTo(s, at, p_store[15], 2, &.{ 0.4, 0.4 });
tg.next(s);
runTo(s, as, q_check15, 2, &.{ 0.4, 0.3, 0.3 });
walk(s, as, q_check15 + 1, 1.0);
runTo(s, as, q_store15, 3, &.{0.3});
tg.done(s);
tg = Together.begin(s);
walk(s, at, p_store[15] + 1, 1.4);
run(s, at, p_turn[16], 0.4);
tg.next(s);
s.wait(6.0 / 60.0);
walk(s, as, q_store15 + 1, 1.4);
run(s, as, q_turn[16], 0.4);
tg.done(s);
// A8: i = 16, they part (the storyboard's chart): plain to its store at a run over the time ASan takes
// to reach its check; the two first different rows framed `attention`; plain's store into the saved
// rbp, its `differs` bar 12 f after; ASan's load reads f3, its compare, its `je` not taken.
says.line(s, "i = 16, one past `buf`: plain writes an A into the saved rbp;\nASan reads `f3`, a redzone.");
tg = Together.begin(s);
runTo(s, at, p_store[16], 1, &.{ 0.4, 0.4, 0.4 });
tg.next(s);
runTo(s, as, q_check16, 4, &.{ 0.6, 0.6 });
tg.done(s);
s.play(.{attention.to(1)}, .{ .seconds = 6.0 / 60.0 });
s.wait(6.0 / 60.0);
tg = Together.begin(s);
{
const plan = at.reading(p_store[16], p_store[16] + 1);
at.step(s, p_store[16] + 1, plan, plan.total);
const after = s.cursor;
s.cursor = tg.start + plan.at[1] + 12.0 / 60.0;
s.play(.{differs.to(1)}, .{ .seconds = t.quick });
s.cursor = after;
}
tg.next(s);
s.wait(30.0 / 60.0);
for (q_check16..q_je16) |m| {
const plan = as.reading(m, m + 1);
as.step(s, m + 1, plan, plan.total * 0.75);
}
tg.done(s);
s.play(.{attention.to(0)}, .{ .seconds = t.quick });
// A9: ASan's partial check and its call walked; its run stops: its registers give way to its stderr.
says.line(s, "ASan does not store: it calls its report,\nwhich names `buf` and the write.");
// The partial check's compare and branch walked; the loads round them at a run.
runTo(s, as, q_partial, 1, &.{0.3});
walk(s, as, q_branch + 1, 0.9);
runTo(s, as, report_call, 1, &.{0.3});
s.wait(t.beat);
s.play(.{ regs_r.fadeOut(), stopped_r.to(1) }, .{ .seconds = t.quick, .ease = anim.ease.linear });
right.glide(s, pair.split(.right, true), 0.4);
s.play(.{stderr.fadeIn()}, .{ .seconds = t.quick, .ease = anim.ease.linear });
s.play(.{framed.to(3)}, .{ .seconds = 18.0 / 60.0, .ease = anim.ease.linear });
// A10 to A13: plain goes on alone, a store a turn, into the saved rbp and then the return address,
// in the column: the caption leaves; ASan's side folds to one tag on the shelf; plain's panes glide left
// and its frame's bytes open to the column's height; each text level with the field the turn's letter lands in.
const Store = struct {
/// Turn `i`: its rows up to the store at a run, then the store walked.
fn turn(sf: *anim.Frame, c: canim.Cursor, store: u64) void {
turnIn(sf, c, store, 78.0 / 60.0);
}
/// The same, the store's step `seconds` long (the aim's glide or fray in it, its text read within the beat).
fn turnIn(sf: *anim.Frame, c: canim.Cursor, store: u64, seconds: f32) void {
run(sf, c, store, 18.0 / 60.0);
walk(sf, c, store + 1, seconds);
}
};
s.wait(@max(says.read_by - s.cursor, 0));
if (says.current) |caption| {
const out = s.cursor;
s.play(.{caption.fadeOut()}, .{ .seconds = t.caption_out, .ease = canim.ease.exit });
s.cursor = out;
}
s.play(.{ dis_r.fadeOut(), stderr.fadeOut(), frame_r.fadeOut(), right_shows.to(0), differs.to(0), shelf_fold.to(1), dis_l.fadeOut(), desc_l.fadeIn() }, .{ .seconds = t.quick, .ease = anim.ease.linear });
s.play(.{shelf_fold.to(2)}, .{ .seconds = 18.0 / 60.0, .ease = anim.ease.linear });
col.beat(s, .{ .panes = &.{ .{ .source, 3 }, .{ .disasm, 18 }, .{ .stack, canim.column_rest } }, .say = "Plain goes on alone, an A a turn, into the saved rbp.", .level = .{ .row = rbp } });
{
// `aim = .standing` for these four beats: once the bubble has arrived, the return
// address's field aims at the row it names (18 f), in the lead before the first store.
const fires = s.cursor;
s.cursor = fires - 0.7;
at.aim(s, .standing);
s.cursor = fires;
}
for (17..21) |i| Store.turn(s, at, p_store[i]);
col.beat(s, .{ .panes = &.{ .{ .source, 3 }, .{ .disasm, 18 }, .{ .stack, canim.column_rest } }, .say = "The saved rbp fills: `4141414141414141`, no longer an address.", .level = .{ .row = rbp } });
for (21..24) |i| Store.turn(s, at, p_store[i]);
col.beat(s, .{ .panes = &.{ .{ .source, 3 }, .{ .disasm, 18 }, .{ .stack, canim.column_rest } }, .say = "i = 24, the return address: it reads `fill+1`, still code.", .level = .{ .row = rbp + 8 } });
Store.turnIn(s, at, p_store[24], 132.0 / 60.0);
col.beat(s, .{ .panes = &.{ .{ .source, 3 }, .{ .disasm, 18 }, .{ .stack, canim.column_rest } }, .say = "Each turn makes it stranger: `404141` is data, `414141` is nowhere.", .level = .{ .row = rbp + 8 } });
for (25..27) |i| Store.turnIn(s, at, p_store[i], 128.0 / 60.0);
// Back to the pair: the aim goes with the column; the texts leave together, plain's panes glide back to their side, ASan's unfolds from the shelf.
at.aim(s, .off);
col.beat(s, .{ .at = .below, .say = "" });
s.play(.{ desc_l.fadeOut(), dis_l.fadeIn() }, .{ .seconds = t.quick, .ease = anim.ease.linear });
s.play(.{shelf_fold.to(1)}, .{ .seconds = 18.0 / 60.0, .ease = anim.ease.linear });
s.play(.{ dis_r.fadeIn(), stderr.fadeIn(), frame_r.fadeIn(), right_shows.to(1), differs.to(1), shelf_fold.to(0) }, .{ .seconds = t.quick, .ease = anim.ease.linear });
says.read_by = 0;
// A14: i = 27 walked, then the held rest (the poster: mock 38), ASan standing on its report.
says.line(s, "Half written: `41414141`, no longer an address.\nOn the right, ASan stopped at the first byte past `buf`.");
run(s, at, p_store[27], 18.0 / 60.0);
{
// Its hold runs on under its own text (4.9 s): the struck byte solid, the plaque on the store.
var plan = at.reading(p_store[27], p_store[27] + 1);
const held = 4.9;
plan.advance += held;
plan.total += held;
const start = s.cursor;
at.step(s, p_store[27] + 1, plan, plan.total);
const after = s.cursor;
// ASan's side, read meanwhile: the shadow byte its check stopped on, framed in its report.
s.cursor = start + plan.at[1] + 1.0;
s.play(.{framed.to(4)}, .{ .seconds = t.quick, .ease = anim.ease.linear });
s.cursor = after;
}
// A15: i = 28 to 31.
says.line(s, "Four more turns: the last A lands,\nand it reads `4141414141414141`.");
for (28..32) |i| Store.turn(s, at, p_store[i]);
// A16: the loop's exit, pop rbp, ret, and the fault.
says.line(s, "The loop ends: `pop rbp`, then `ret` to `4141414141414141`:\nthe CPU faults. SIGSEGV.");
run(s, at, p_turn[32], 18.0 / 60.0);
runTo(s, at, p_pop, 1, &.{ 0.4, 0.4 });
for (p_pop..p_end) |m| {
const plan = at.reading(m, m + 1);
at.step(s, m + 1, plan, if (m + 1 == p_end) plan.total else plan.total * 0.8);
}
says.close(s);
}
|