From 64e64c74be6a3e46abeae8a30dd42efff91aaf91 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 11 Nov 2026 02:11:12 -0300 Subject: design: what the second review found, placed A caller keeps one row after its call and its callee sits under it; opening and closing fade what is given up before what is kept glides, and nothing changes in one frame. A system call stepped over is three parts: the registers set, the crossing from the call row, the stores after it. A loupe never covers a row its step changes, hangs over the stack when opened from a view, and closes with the advance. A run draws no strikes and no arcs, and a caption never names what the pace veils; the heap scene's captions have landing and leaving frames. The map's boxes are as tall as their rows. The veiled map travels into the minimap. The motion instrument checks captions and fires POP on any one-frame change after stillness. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa --- design/mock/09-context-480.png | Bin 36022 -> 36033 bytes design/mock/09-context.png | Bin 232404 -> 232320 bytes design/mock/09-context.svg | 20 +- design/mock/10-context-step-480.png | Bin 36905 -> 36917 bytes design/mock/10-context-step.png | Bin 236408 -> 236387 bytes design/mock/10-context-step.svg | 20 +- design/mock/11-context-lens-480.png | Bin 36592 -> 36603 bytes design/mock/11-context-lens.png | Bin 225223 -> 225200 bytes design/mock/11-context-lens.svg | 20 +- design/mock/16-descent.png | Bin 288435 -> 288956 bytes design/mock/16-descent.svg | 147 +++++---- design/mock/18-heap-480.png | Bin 75720 -> 65376 bytes design/mock/18-heap-free-480.png | Bin 0 -> 33997 bytes design/mock/18-heap-free.png | Bin 0 -> 205456 bytes design/mock/18-heap-free.svg | 639 ++++++++++++++++++++++++++++++++++++ design/mock/18-heap.png | Bin 450494 -> 393020 bytes design/mock/18-heap.svg | 293 +---------------- design/mock/19-map-1080.png | Bin 392428 -> 392740 bytes design/mock/19-map-480.png | Bin 45447 -> 45599 bytes design/mock/19-map.png | Bin 896620 -> 896682 bytes design/mock/19-map.svg | 24 +- design/mock/20-dive.png | Bin 1320934 -> 1321188 bytes design/mock/21-loupe-480.png | Bin 38096 -> 38102 bytes design/mock/21-loupe.png | Bin 243732 -> 243789 bytes design/mock/21-loupe.svg | 20 +- design/mock/context.py | 12 +- design/mock/heap.py | 75 ++++- design/mock/map.py | 4 +- 28 files changed, 843 insertions(+), 431 deletions(-) create mode 100644 design/mock/18-heap-free-480.png create mode 100644 design/mock/18-heap-free.png create mode 100644 design/mock/18-heap-free.svg (limited to 'design/mock') diff --git a/design/mock/09-context-480.png b/design/mock/09-context-480.png index d20bfa0..52edc14 100644 Binary files a/design/mock/09-context-480.png and b/design/mock/09-context-480.png differ diff --git a/design/mock/09-context.png b/design/mock/09-context.png index d7ad775..b262b5b 100644 Binary files a/design/mock/09-context.png and b/design/mock/09-context.png differ diff --git a/design/mock/09-context.svg b/design/mock/09-context.svg index a67fd37..c867889 100644 --- a/design/mock/09-context.svg +++ b/design/mock/09-context.svg @@ -874,16 +874,16 @@ - + - - - - - - + + + + + + @@ -2000,9 +2000,9 @@ - - - + + + diff --git a/design/mock/10-context-step-480.png b/design/mock/10-context-step-480.png index 8f92f8d..2a9eaad 100644 Binary files a/design/mock/10-context-step-480.png and b/design/mock/10-context-step-480.png differ diff --git a/design/mock/10-context-step.png b/design/mock/10-context-step.png index 59d3169..7290e91 100644 Binary files a/design/mock/10-context-step.png and b/design/mock/10-context-step.png differ diff --git a/design/mock/10-context-step.svg b/design/mock/10-context-step.svg index b33a4d0..c788864 100644 --- a/design/mock/10-context-step.svg +++ b/design/mock/10-context-step.svg @@ -886,16 +886,16 @@ - + - - - - - - + + + + + + @@ -2013,9 +2013,9 @@ - - - + + + diff --git a/design/mock/11-context-lens-480.png b/design/mock/11-context-lens-480.png index c5e6c0b..6285b81 100644 Binary files a/design/mock/11-context-lens-480.png and b/design/mock/11-context-lens-480.png differ diff --git a/design/mock/11-context-lens.png b/design/mock/11-context-lens.png index c070e3e..6e17b47 100644 Binary files a/design/mock/11-context-lens.png and b/design/mock/11-context-lens.png differ diff --git a/design/mock/11-context-lens.svg b/design/mock/11-context-lens.svg index 1190b7c..b8188b3 100644 --- a/design/mock/11-context-lens.svg +++ b/design/mock/11-context-lens.svg @@ -901,16 +901,16 @@ - + - - - - - - + + + + + + @@ -2028,9 +2028,9 @@ - - - + + + diff --git a/design/mock/16-descent.png b/design/mock/16-descent.png index 36ff670..1c26cd7 100644 Binary files a/design/mock/16-descent.png and b/design/mock/16-descent.png differ diff --git a/design/mock/16-descent.svg b/design/mock/16-descent.svg index c0af532..d0fcadb 100644 --- a/design/mock/16-descent.svg +++ b/design/mock/16-descent.svg @@ -263,102 +263,103 @@ disassembly open@plt · the PLT 4011 -87 +76 4 -mov -[rbp - 8], rax +push +rbp 4011 -8b -xor -eax, eax +77 +mov +rbp, rsp 4011 -8d -6 -lea -rax, [rip + 0xe70] -= -402004 - "note" +7a +sub +rsp, 0x40 4011 -94 +7e mov -esi, 0 - +rax, fs:[0x28] +the stack's canary 4011 -99 +87 mov -rdi, rax - +[rbp - 8], rax 4011 -9c -mov -eax, 0 - - +8b +xor +eax, eax 4011 -a1 -call -401070 -open@plt -open -("note", O_RDONLY) +8d +6 +lea +rax, [rip + 0xe70] += +402004 + "note" 4011 -a6 +94 mov -[rbp - 0x38], eax +esi, 0 + 4011 -a9 -7 -lea -rcx, [rbp - 0x30] +99 +mov +rdi, rax + 4011 -ad +9c mov -eax, [rbp - 0x38] +eax, 0 + + 4011 -b0 -mov -edx, 0x20 +a1 +call +401070 +open@plt +open +("note", O_RDONLY) 4011 -b5 +a6 mov -rsi, rcx -4011 -b8 -mov -edi, eax - -open@plt -the PLT · its jmp reads open@got, 403fd8 - - - - - +[rbp - 0x38], eax + +open@plt +the PLT · its jmp reads open@got, 403fd8 + + + + + +4010 +70 +jmp +[rip + 0x2f62] + + +7ffff7d10ec0 + open 4010 -70 -jmp -[rip + 0x2f62] - - -7ffff7d10ec0 - open +76 +push +4 +lazy binding: unused 4010 -76 -push -4 -lazy binding: unused +7b +jmp +401020 + 4010 -7b -jmp -401020 +80 +endbr64 +_start - - - - + + + + The call pushed main+48 and went down: main's window keeps its call, ringed; the stub's opens under it, and its jmp reads the GOT. diff --git a/design/mock/18-heap-480.png b/design/mock/18-heap-480.png index 2ba9c76..078ee3e 100644 Binary files a/design/mock/18-heap-480.png and b/design/mock/18-heap-480.png differ diff --git a/design/mock/18-heap-free-480.png b/design/mock/18-heap-free-480.png new file mode 100644 index 0000000..1041f68 Binary files /dev/null and b/design/mock/18-heap-free-480.png differ diff --git a/design/mock/18-heap-free.png b/design/mock/18-heap-free.png new file mode 100644 index 0000000..ae1fe01 Binary files /dev/null and b/design/mock/18-heap-free.png differ diff --git a/design/mock/18-heap-free.svg b/design/mock/18-heap-free.svg new file mode 100644 index 0000000..b3a2076 --- /dev/null +++ b/design/mock/18-heap-free.svg @@ -0,0 +1,639 @@ + + + + + + +heap.c +lines 14 to 23 of 31 +14 +head += +n +; +15 +} +16 +17 +void +pop +( +void +) +{ + +18 +node +* +n += +head +; + +19 +head += +n +- +> +next +; + + +20 +free +( +n +) +; +21 +} +22 +23 +int +main +( +void +) +{ + + + +disassembly +pop +4011 +9b +19 +mov +rax, [rbp - 8] +4011 +9f +mov +rax, [rax + 8] +4011 +a3 +mov +[rip + 0x2e7e], rax +head + +4011 +aa +20 +mov +rax, [rbp - 8] + +4011 +ae +mov +rdi, rax + + + +4011 +b1 +call +401030 +free@plt +free + in libc, stepped over +4011 +b6 +21 +nop +rdi +405050 + + +0x405 +1029 +4011 +b7 +leave +4011 +b8 +ret + + + + + + + + + + +registers +stack +heap +code +data +rwx + +read-only +rax + +0 +rbx +0 +rcx + +0x405 +rdx + +0xf +rsi + +0xe2263c1be1246b56 +rdi +405050 + + +0x405 +1029 +rbp +7fffffffecf0 + + +7fffffffed00 + + +7fffffffedb0 + + +7fffffffee10 + + +0 +rsp +7fffffffece0 + + +0 +r8 + +405070 + + +0x10001000100f +r9 +0x20 +32 +r10 + +0x21 +r11 +7ffff7e19ac8 +r12 +7fffffffee38 + + +7fffffffefea + + +"./heap" +r13 +1 +r14 +7ffff7ffd000 + + +7ffff7ffe3c0 + + +0 +r15 +403df0 + + +401110 +__do_global_dtors_aux + + +rip +4011b6 +pop+46 +cf + +PF +af +zf +sf + +IF +df +of + + + +stack +six words from rsp · the frames they belong to +rsp + ++0 +7fffffffe +ce0 + + +0 ++8 +n +7fffffffe +ce8 + + +405050 + + +0x405 +1029 +rbp + ++10 +saved rbp +7fffffffe +cf0 + + +7fffffffed00 + + + + + ++18 +7fffffffe +cf8 + + +4011e0 +main+39 ++20 +saved rbp +7fffffffe +d00 + + +7fffffffedb0 + + + + + ++28 +7fffffffe +d08 + + +7ffff7c27781 +libc+27781 + + + +pop + + + +main + + + +the chunks of 0x20 +the program's list · malloc's free list +the program's +405030 +405010 + +12 + + + + + +7 + + + +tcache 0x20 + + +1 + + +405050 + + +key + + + + +top +0x20ca0 +405360 + + +head +head + + +rdi + + + +its bytes +the heap, 405000 to 40506f + + + +4050 +00 +00 +00 +00 +00 +00 +00 +00 +00 + +21 +00 +00 +00 +00 +00 +00 +00 +0x20 +a +m + +P + + + +4050 +10 + +07 +00 +00 +00 +00 +00 +00 +00 +7 + +00 +00 +00 +00 +00 +00 +00 +00 +NULL + + + +4050 +20 +00 +00 +00 +00 +00 +00 +00 +00 + +21 +00 +00 +00 +00 +00 +00 +00 +0x20 +a +m + +P + + + +4050 +30 + +0c +00 +00 +00 +00 +00 +00 +00 +12 + +10 +50 +40 +00 +00 +00 +00 +00 + + +405010 + + + +4050 +40 +00 +00 +00 +00 +00 +00 +00 +00 + +21 +00 +00 +00 +00 +00 +00 +00 +0x20 +a +m + +P + + + +4050 +50 + + +05 +04 +00 +00 +00 +00 +00 +00 +NULL +^ 405 + + +53 +89 +03 +0a +cf +c5 +9f +6b +key + + + +4050 +60 +00 +00 +00 +00 +00 +00 +00 +00 + + +01 +03 +00 +00 +00 +00 +00 +00 +0x300 +a +m + +P +tcache + + + + + + +tcache + → +405070 +tcache_perthread_struct · 0x2f8 bytes + + + +405 +070 + + + +0f +00 +15 +slots left · 1 in the bin +10 +00 +10 +00 +10 +00 +10 +00 +10 +00 +10 +00 +10 +00 + + + + + +8 rows + + + +405 +100 +10 +00 +10 +00 +10 +00 +10 +00 + + + +50 +50 +40 +00 +00 +00 +00 +00 + + +405050 + + + +405 +110 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 + + + + + +37 rows + + + + + +moment 7 of 12 +free gave 9's chunk to the tcache, malloc's bin for 0x20. Its first +word is the link now: 405, which is NULL, safe-linked. + diff --git a/design/mock/18-heap.png b/design/mock/18-heap.png index 17789ad..f7b90d9 100644 Binary files a/design/mock/18-heap.png and b/design/mock/18-heap.png differ diff --git a/design/mock/18-heap.svg b/design/mock/18-heap.svg index cf60bb3..3445a01 100644 --- a/design/mock/18-heap.svg +++ b/design/mock/18-heap.svg @@ -381,7 +381,6 @@ 4050 50 - 09 00 00 @@ -392,7 +391,6 @@ 00 9 - 30 50 40 @@ -436,8 +434,8 @@ -Three pushes, three chunks in a row, each with P: the chunk -before it is in use. The list's next pointers are arcs in the bytes. +Two more pushes, at a run: three chunks in a row, each with P +set, the chunk before it in use. Settled: no marks, the arcs standing. 3 @@ -683,101 +681,6 @@ tcache - - - - -tcache - → -405070 -tcache_perthread_struct · 0x2f0 bytes - - - -405 -070 - - - -0f -00 -15 -slots left · 1 in the bin -10 -00 -10 -00 -10 -00 -10 -00 -10 -00 -10 -00 -10 -00 - - - - - -8 rows - - - -405 -100 -10 -00 -10 -00 -10 -00 -10 -00 - - - -50 -50 -40 -00 -00 -00 -00 -00 - - -405050 - - - -405 -110 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 - - - - - -36 rows - free gave 9's chunk to the tcache, malloc's bin for 0x20. Its first word is the link now: 405, which is NULL, safe-linked. @@ -1026,101 +929,6 @@ tcache - - - - -tcache - → -405070 -tcache_perthread_struct · 0x2f0 bytes - - - -405 -070 - - - -0e -00 -14 -slots left · 2 in the bin -10 -00 -10 -00 -10 -00 -10 -00 -10 -00 -10 -00 -10 -00 - - - - - -8 rows - - - -405 -100 -10 -00 -10 -00 -10 -00 -10 -00 - - - -30 -50 -40 -00 -00 -00 -00 -00 - - -405030 - - - -405 -110 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 - - - - - -36 rows - The second chains to the first: 405455 is 405050 xor 405, the chunk's own address shifted 12. The arc is the pointer it hides. @@ -1359,102 +1167,7 @@ P tcache - - - - -tcache - → -405070 -tcache_perthread_struct · 0x2f0 bytes - - - -405 -070 - - - -0f -00 -15 -slots left · 1 in the bin -10 -00 -10 -00 -10 -00 -10 -00 -10 -00 -10 -00 -10 -00 - - - - - -8 rows - - - -405 -100 -10 -00 -10 -00 -10 -00 -10 -00 - - - -50 -50 -40 -00 -00 -00 -00 -00 - - -405050 - - - -405 -110 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 -00 - - - - - -36 rows - malloc(16) took the bin's head, 405030: the tcache points at 405050 -again, the key is wiped, and the old link stays until push writes. +again, the key is wiped, the old link stays. diff --git a/design/mock/19-map-1080.png b/design/mock/19-map-1080.png index 65ae927..7fe6d63 100644 Binary files a/design/mock/19-map-1080.png and b/design/mock/19-map-1080.png differ diff --git a/design/mock/19-map-480.png b/design/mock/19-map-480.png index 1dabf72..bb0404f 100644 Binary files a/design/mock/19-map-480.png and b/design/mock/19-map-480.png differ diff --git a/design/mock/19-map.png b/design/mock/19-map.png index 3c5d6d9..a20d85e 100644 Binary files a/design/mock/19-map.png and b/design/mock/19-map.png differ diff --git a/design/mock/19-map.svg b/design/mock/19-map.svg index 8dc8779..613dd14 100644 --- a/design/mock/19-map.svg +++ b/design/mock/19-map.svg @@ -374,22 +374,22 @@ #4 _start+37 - + the map targets/list · moment 3 of 4 every panel whole; the working frame's windows outlined - - -current - -struck - -read - -held - -window + + +current + +struck + +read + +held + +window diff --git a/design/mock/20-dive.png b/design/mock/20-dive.png index b389ac2..5efba9c 100644 Binary files a/design/mock/20-dive.png and b/design/mock/20-dive.png differ diff --git a/design/mock/21-loupe-480.png b/design/mock/21-loupe-480.png index 684fc1a..383c7f2 100644 Binary files a/design/mock/21-loupe-480.png and b/design/mock/21-loupe-480.png differ diff --git a/design/mock/21-loupe.png b/design/mock/21-loupe.png index 1633127..ed97f20 100644 Binary files a/design/mock/21-loupe.png and b/design/mock/21-loupe.png differ diff --git a/design/mock/21-loupe.svg b/design/mock/21-loupe.svg index 7a40916..5a3e837 100644 --- a/design/mock/21-loupe.svg +++ b/design/mock/21-loupe.svg @@ -1017,16 +1017,16 @@ - + - - - - - - + + + + + + @@ -2286,9 +2286,9 @@ - - - + + + diff --git a/design/mock/context.py b/design/mock/context.py index efae74c..a040109 100644 --- a/design/mock/context.py +++ b/design/mock/context.py @@ -1403,7 +1403,7 @@ def frame_sqlite(name, late): # 2 (in the stub), 4 (at libc's `syscall`), 5 (after it) and 6 (back in main). HELLO = open(__file__.replace("design/mock/context.py", "anim/tools/hello.c")).read().split("\n") R_ = VELLUM # read-only data: the string, and the GOT once relro has sealed it -HM = [(0x40117a, 4, "sub", "rsp, 0x40"), (0x40117e, 4, "mov", "rax, qword ptr fs:[0x28]"), +HM = [(0x401176, 4, "push", "rbp"), (0x401177, 4, "mov", "rbp, rsp"), (0x40117a, 4, "sub", "rsp, 0x40"), (0x40117e, 4, "mov", "rax, qword ptr fs:[0x28]"), (0x401187, 4, "mov", "qword ptr [rbp - 8], rax"), (0x40118b, 4, "xor", "eax, eax"), (0x40118d, 6, "lea", "rax, [rip + 0xe70]"), (0x401194, 6, "mov", "esi, 0"), (0x401199, 6, "mov", "rdi, rax"), (0x40119c, 6, "mov", "eax, 0"), (0x4011a1, 6, "call", (0x401070, "open@plt")), @@ -1443,7 +1443,7 @@ def frame_descent(name): call_c = ("runs", [("open", BRIGHT), ('("note", O_RDONLY)', VELLUM)]) instants = [ ("1", "at the call", "moment 1", None, "main", - [("main", None, main_rows(0, 17, {0x401194: "trail2", 0x401199: "trail1", 0x40119c: "trail0", 0x4011a1: "cur"}, + [("main", None, main_rows(0x40117a, 17, {0x401194: "trail2", 0x401199: "trail1", 0x40119c: "trail0", 0x4011a1: "cur"}, {0x401194: ("set", "rsi", [], ("int", 0)), 0x401199: ("set", "rdi", [(0x402004, R_)], ("str", "note")), 0x40119c: ("set", "rax", [], ("int", 0)), @@ -1452,13 +1452,15 @@ def frame_descent(name): ["main calls open by its stub in the PLT. The arguments", 'are in rdi and rsi: "note" and O_RDONLY.']), ("2", "in the stub", "moment 2", "main waits at line 6 · the pc is in the PLT", "open@plt · the PLT", - [("main", None, main_rows(0x401187, 13, {0x401199: "trail2", 0x40119c: "trail1", 0x4011a1: "wait"}, + # main keeps one row after its call and gives the rest above it: the stub's head is under its return row + [("main", None, main_rows(0x401176, 12, {0x401199: "trail2", 0x40119c: "trail1", 0x4011a1: "wait"}, {0x4011a1: call_c})), ("open@plt", "the PLT · its jmp reads open@got, 403fd8", [(0x401070, None, "jmp", [("qword ptr [rip + 0x2f62]", P)], "cur", ("runs", [("", "arrow"), (0x7ffff7d10ec0, CODE), (" open", VELLUM)])), (0x401076, None, "push", [("4", P)], None, ("text", "lazy binding: unused", FAINT)), - (0x40107b, None, "jmp", [(0x401020, CODE)], None, None)])], + (0x40107b, None, "jmp", [(0x401020, CODE)], None, None), + (0x401080, None, "endbr64", [], "other_first", ("text", "_start", DIM))])], ["The call pushed main+48 and went down: main's window keeps", "its call, ringed; the stub's opens under it, and its jmp reads the GOT."]), ("3", "the crossing", "moments 4 and 5", "main waits at line 6 · the pc is in libc's open", @@ -1482,7 +1484,7 @@ def frame_descent(name): ["libc's open is a wrapper: it puts openat's number in rax", "and its arguments in rdi, rsi, rdx, r10; syscall crosses down."]), ("4", "back up", "moment 6", None, "main", - [("main", None, main_rows(0, 17, {0x401199: "trail2", 0x40119c: "trail1", 0x4011a1: "trail0", 0x4011a6: "cur"}, + [("main", None, main_rows(0x40117a, 17, {0x401199: "trail2", 0x40119c: "trail1", 0x4011a1: "trail0", 0x4011a6: "cur"}, {0x4011a1: ("runs", [("open", VELLUM), ('("note", O_RDONLY) = ', DIM), ("3", VELLUM)]), 0x4011a6: ("chain", [(0x7fffffffecc8, S_)], ("int", 0), None)}))], ["open's ret came straight back to main+48: the stub was a jump,", diff --git a/design/mock/heap.py b/design/mock/heap.py index e4c3e3a..57cd7e3 100644 --- a/design/mock/heap.py +++ b/design/mock/heap.py @@ -165,7 +165,7 @@ def loupe(g, x, y, inst, changed): for s_, ink in [("tcache", DIM), (" → ", FAINT), ("405070", HEAP)]: g.t(xx, y + 18, s_, S, ink, MONO) xx += len(s_) * A - g.t(x + CW - 10, y + 18, "tcache_perthread_struct · 0x2f0 bytes", 18, DIM, "sans", "end") + g.t(x + CW - 10, y + 18, "tcache_perthread_struct · 0x2f8 bytes", 18, DIM, "sans", "end") slots, head = TC[inst] base = 0x405070 mem = {base + i: v for i, v in enumerate(bytes([slots, 0] + [0x10, 0] * 7))} @@ -173,9 +173,8 @@ def loupe(g, x, y, inst, changed): mem.update({base + 0xa0 + i: 0 for i in range(16)}) fl = [(0, 2, "number", False, None, "slots left · %d in the bin" % (16 - slots)), (0x98, 8, "pointer", False, None, "the head of 0x20")] - C.fields(g, y, h, "", base, 0x2f0, fl, mem, HEAP, region, framed=[(0, 2), (0x98, 8)], bare=True, x=x, + C.fields(g, y, h, "", base, 0x2f8, fl, mem, HEAP, region, framed=[(0, 2), (0x98, 8)], bare=True, x=x, rows_shown=[0, 9, 10], changed=changed) - g.rect(RX + 34 - 2, y - 4, 6 * A + 4, 4, HEAP) # the stem: a bracket under the row's address, on the tag INSTANTS = [ @@ -183,8 +182,8 @@ INSTANTS = [ ["malloc(16) cut a chunk of 0x20 off the top: its size word, 0x21,", "then the 16 bytes rax points at. The top is 0x20 smaller."]), ("B", "2", "three chunks", "stop 6, after push(9)", - ["Three pushes, three chunks in a row, each with P: the chunk", - "before it is in use. The list's next pointers are arcs in the bytes."]), + ["Two more pushes, at a run: three chunks in a row, each with P", + "set, the chunk before it in use. Settled: no marks, the arcs standing."]), ("C", "3", "a free", "stop 7, back from free in the first pop", ["free gave 9's chunk to the tcache, malloc's bin for 0x20. Its first", "word is the link now: 405, which is NULL, safe-linked."]), @@ -193,7 +192,7 @@ INSTANTS = [ "chunk's own address shifted 12. The arc is the pointer it hides."]), ("E", "5", "malloc takes it back", "stop 9, back from malloc in push(25)", ["malloc(16) took the bin's head, 405030: the tcache points at 405050", - "again, the key is wiped, and the old link stays until push writes."]), + "again, the key is wiped, the old link stays."]), ] CHANGED = { # the bytes each stop changed, of those on screen: struck "C": {0x405050, 0x405051} | set(range(0x405058, 0x405060)) | {0x405068, 0x405069, 0x40506a}, @@ -215,15 +214,73 @@ def storyboard(name): drawing(g, 48, 296, inst) C.fields(g, 48, 200, "the heap, 405000 to 40506f", BASE, 0x70, chunk_fields(inst), MEM[inst], HEAP, region, rows_shown=list(range(7)), more_rows=False, changed=CHANGED.get(inst, ()), - held_at={0x405050, 0x405058} if inst == "B" else (), touched={0x405030} if inst == "D" else ()) - if inst in TC: # hung from the view's last row: the chunk that is the tcache - loupe(g, RX + 34 - 92, 48 + TAG + PAD + 7 * ROW + 2, inst, LOUPE_CHANGED[inst]) + touched={0x405030} if inst == "D" else ()) # 2 is a run's end: settled, no marks + # the tcache's loupe lies over the stack, never over the registers: in 18-heap-free, not on this sheet for i, line in enumerate(cap): g.t(LX, 440 + i * 44, line, 32, VELLUM, "sans") g.o.append("") g.save(name) +# ---- beat 3 whole: the first free, mid-step, in the working frame (`subject`) --------------------------------- +H_, S_, C_, D_ = HEAP, C.STACK, C.CODE, DATA +SRC = open(__file__.replace("heap.py", "heap.c")).read().split("\n") +RBP = [(0x7fffffffed00, S_), (0x7fffffffedb0, S_), (0x7fffffffee10, S_)] +REGS = [("rax", [], ("int", 0)), ("rbx", [], ("int", 0)), ("rcx", [], ("int", 0x405)), ("rdx", [], ("int", 0xf)), + ("rsi", [], ("int", 0xe2263c1be1246b56)), ("rdi", [(0x405050, H_)], ("int", 0x405)), + ("rbp", [(0x7fffffffecf0, S_)] + RBP, ("int", 0)), ("rsp", [(0x7fffffffece0, S_)], ("int", 0)), + ("r8", [(0x405070, H_)], ("int", 0x10001000100f)), ("r9", [], ("int", 0x20)), ("r10", [], ("int", 0x21)), + ("r11", [(0x7ffff7e19ac8, D_)], None), ("r12", [(0x7fffffffee38, S_), (0x7fffffffefea, S_)], ("str", "./heap")), + ("r13", [], ("int", 1)), ("r14", [(0x7ffff7ffd000, D_), (0x7ffff7ffe3c0, D_)], ("int", 0)), + ("r15", [(0x403df0, D_), (0x401110, C_, "__do_global_dtors_aux")], None), + ("rip", [(0x4011b6, C_, "pop+46")], None)] +FLAGS = [("CF", 0, 0), ("PF", 1, 0), ("AF", 0, 0), ("ZF", 0, 0), ("SF", 0, 0), ("IF", 1, 0), ("DF", 0, 0), ("OF", 0, 0)] +STACK = [(0x7fffffffece0, ["rsp"], [], ("int", 0)), (0x7fffffffece8, [], [(0x405050, H_)], ("int", 0x405)), + (0x7fffffffecf0, ["rbp"], RBP, ("int", 0)), (0x7fffffffecf8, [], [(0x4011e0, C_, "main+39")], None), + (0x7fffffffed00, [], RBP[1:], ("int", 0)), (0x7fffffffed08, [], [(0x7ffff7c27781, C_, "libc+27781")], None)] +P = VELLUM +DIS = [(0x40119b, 19, "mov", "rax, qword ptr [rbp - 8]", None, None), + (0x40119f, 19, "mov", "rax, qword ptr [rax + 8]", None, None), + (0x4011a3, 19, "mov", "qword ptr [rip + 0x2e7e], rax", None, ("text", "head", DATA)), + (0x4011aa, 20, "mov", "rax, qword ptr [rbp - 8]", "trail1", None), + (0x4011ae, 20, "mov", "rdi, rax", "trail0", None), + (0x4011b1, 20, "call", (0x401030, "free@plt"), "cur", ("runs", [("free", BRIGHT), (" in libc, stepped over", FAINT)])), + (0x4011b6, 21, "nop", "", None, ("set", "rdi", [(0x405050, H_)], ("int", 0x405))), + (0x4011b7, 21, "leave", "", None, None), (0x4011b8, 21, "ret", "", None, None)] + + +def frame_free(name): + """The first free in the working frame: the register wave struck, the chunk's words struck on the bytes that + changed, the node gone down to the bin's row, and the loupe on the tcache over the stack, never the registers.""" + gen.W, gen.H = 1920, 1080 + g = Svg() + sp = C.SUBJECT + y = 48 + sp["band"] + 12 + ys = C.source(g, y, sp["src"], SRC, 14, 20, [19, 18], "heap.c", 31) + at = C.disasm(g, y + ph(sp["src"]) + 12, + [(a, ln, mn, [(ops, C.CODE)] if isinstance(ops, tuple) else ([(ops, P)] if ops else []), st, note) + for a, ln, mn, ops, st, note in DIS], "pop", 20) + C.thread(g, ys, [(at[0x4011aa], at[0x4011b1] + ROW)]) + yr = 48 + sp["view"] + 12 + C.registers(g, yr, REGS, FLAGS, {r: {0: "strike"} for r in ("rax", "rcx", "rdx", "rsi", "r8", "r10")}) + C.stack(g, yr + ph(17) + 12, STACK, [("pop", 0, 3), ("main", 4, 5)], rsp=0x7fffffffece0, + roles={1: ("n", VELLUM), 2: ("saved rbp", DIM), 4: ("saved rbp", DIM)}) + drawing(g, 48, sp["band"], "C") + rows_y = C.fields(g, 48, sp["view"], "the heap, 405000 to 40506f", BASE, 0x70, chunk_fields("C"), MEM["C"], HEAP, + region, rows_shown=list(range(7)), more_rows=False, changed=CHANGED["C"]) + ly = 888 - ph(5) # over the stack, clamped to the stage + loupe(g, RX, ly, "C", LOUPE_CHANGED["C"]) + foot = rows_y[0x405060] + ROW + 2 # the stem: from under the row's address, down the gutter's right lane + g.rect(RX + 34 - 2, foot - 2, 6 * A + 4, 4, HEAP) + gen.arrow(g, [(RX + 32, foot), (962, foot), (962, ly + 12), (RX - 1, ly + 12)], HEAP, 3, r=8, + hl=10, hw=10) + C.clock(g, 7, 12) + gen.caption(g, [[("free gave 9's chunk to the tcache, malloc's bin for ",), ("0x20", "mono"), (". Its first",)], + [("word is the link now: ",), ("405", "mono"), (", which is NULL, safe-linked.",)]]) + g.save(name) + + if __name__ == "__main__": assert 0x405455 ^ (0x405030 >> 12) == 0x405050 and 0x405 ^ (0x405050 >> 12) == 0 # safe-linking, as stored storyboard("18-heap") + frame_free("18-heap-free") diff --git a/design/mock/map.py b/design/mock/map.py index aaf90e6..1b4287b 100644 --- a/design/mock/map.py +++ b/design/mock/map.py @@ -148,13 +148,13 @@ def draw_map(g, step, loupe, subject=False): def key(g, x, y, step): """The map's key, at the foot of a column it leaves: what this is, and its marks.""" - y0 = C.panel(g, x, y, D.CW, 5, "the map", note="targets/list · moment %d of 4" % (3 if step else 2)) + y0 = C.panel(g, x, y, D.CW, 3, "the map", note="targets/list · moment %d of 4" % (3 if step else 2)) # its rows, no more g.t(x + 12, b(y0), "every panel whole; the working frame's windows outlined", 18, DIM, "sans") items = [("current", lambda xx, yy: C.current_row(g, xx, yy, 120, 24)), ("struck", lambda xx, yy: C.struck(g, xx, yy, 60)), ("read", lambda xx, yy: g.frame(xx, yy, 60, ROW, READ, 2)), ("held", lambda xx, yy: C.held(g, xx + 8, yy, 40)), ("window", lambda xx, yy: g.frame(xx, yy, 60, ROW, DIM, 2))] for i, (name, draw) in enumerate(items): - xx, yy = x + 12 + (i % 3) * 290, y0 + (1 + i // 3) * ROW + 8 + xx, yy = x + 12 + (i % 3) * 290, y0 + (1 + i // 3) * ROW draw(xx, yy) g.t(xx + 136, b(yy), name, 18, DIM, "sans") -- cgit v1.3