From 60e07feef401d9044db3a1c925cb9d1f6d20dac9 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 11 Nov 2026 23:46:02 -0300 Subject: canim: relations as one data-oriented subsystem; aim; the ASan pair; the introduction's chapters From the user. Relations between panes are one subsystem: per-frame tables of places and values in struct-of-arrays, owned by the frame; the kinds one table of data; a resolver of pure passes (join, filter, priority, cut) unit-tested on hand-written tables. Ported kinds draw byte-identical frames; a synthetic map of 4000 places and 6000 values resolves in 0.56 ms against the old table's 5.7. aim, a word holding a code address tied to its row, is the first new kind, off unless a scene turns it on. The ASan pair: one overflow built plain and with ASan, recorded by instruction; the frame as bytes eight a row; the plain run goes on alone in the column, its return address aimed at main's row until the letters reach it; the fault at ret. The introduction's three chapters are built and tested, not yet exported. Annotations, rows and scrolls that changed in one frame now fade; captions stand twelve seconds at most. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa --- anim/build.zig | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'anim/build.zig') diff --git a/anim/build.zig b/anim/build.zig index 6351250..9c7d63e 100644 --- a/anim/build.zig +++ b/anim/build.zig @@ -16,7 +16,7 @@ const std = @import("std"); const sketchbook = @import("sketchbook"); -const scenes = [_][]const u8{ "title", "fib", "list", "sort", "syscalls", "musl", "zoom", "heap", "gallery", "column", "column_sort" }; +const scenes = [_][]const u8{ "title", "fib", "list", "sort", "syscalls", "musl", "zoom", "heap", "gallery", "column", "column_sort", "intro_memory", "intro_stack", "intro_code", "asan" }; pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); @@ -222,6 +222,47 @@ pub fn build(b: *std.Build) void { source_modules.append(b.allocator, .{ .name = b.fmt("{s}-sources", .{r.name}), .module = sources }) catch @panic("OOM"); table.print(b.allocator, "pub const {s}: Program = .{{ .trace = @embedFile(\"{s}\"), .file = \"{s}\", .source = @embedFile(\"{s}\"), .sources = &@import(\"{s}-sources\").list }};\n", .{ r.name, file, r.source, r.source, r.name }) catch @panic("OOM"); } + // The pair (`asan`, design/motion.md "A scene: ASan against a plain + // build"): overflow.c built twice by the system's clang, plain and with + // AddressSanitizer, frame pointers kept and no canary (Arch's clang puts + // one in by default, and the plain run would die in `__stack_chk_fail`, + // not at `ret`). Each run as `./overflow` in a directory of its own, with + // no environment but ASan's leak check off (it fails under a tracer): + // plain by instruction from main to its fault at `ret` (the recorder + // says `exit 139`, SIGSEGV); ASan by instruction from main to the first + // instruction of `__asan_report_store1` (582 stops: the report itself is + // a million more), and the same run again by syscall alone, for the + // report's `write`s to fd 2 as written. + for ([_]struct { name: []const u8, asan: bool, args: []const []const u8, exit: []const u8 }{ + .{ .name = "overflow", .asan = false, .args = &.{ "--by", "insn", "--stack", "1024", "--around", "256", "--disasm", "69", "-s", "64", "--from", "main" }, .exit = "exit 139" }, + .{ .name = "overflow_asan", .asan = true, .args = &.{ "--asan", "--by", "insn", "--stack", "1024", "--around", "256", "--disasm", "69", "-s", "64", "--from", "main", "--steps", "582" }, .exit = "exit 0" }, + .{ .name = "overflow_report", .asan = true, .args = &.{ "--by", "syscall", "--stack", "0", "--telescope", "0", "-s", "4096" }, .exit = "exit 1" }, + }) |r| { + const cc = b.addSystemCommand(&.{ "clang", "-O0", "-g", "-fno-omit-frame-pointer", "-no-pie", "-fno-stack-protector" }); + if (r.asan) cc.addArg("-fsanitize=address"); + cc.addFileArg(b.path("tools/overflow.c")); + cc.addArg("-o"); + const program = cc.addOutputFileArg("overflow"); + const where = b.addWriteFiles(); + _ = where.addCopyFile(program, "overflow"); + const link = "ln -sfn \"" ++ debuginfod_cache ++ "\" debuginfod && exec env -i DEBUGINFOD_CACHE_PATH=debuginfod "; + const run = b.addSystemCommand(&.{ "sh", "-c", if (r.asan) link ++ "ASAN_OPTIONS=detect_leaks=0 setarch -R \"$0\" \"$@\"" else link ++ "setarch -R \"$0\" \"$@\"" }); + run.addArtifactArg(ztrace); + run.addArg("record"); + run.addArgs(r.args); + run.addArg("-o"); + const trace = run.addOutputFileArg(b.fmt("{s}.ztrace", .{r.name})); + run.addArgs(&.{ "--", "./overflow" }); + run.setCwd(where.getDirectory()); + run.expectExitCode(0); + run.expectStdErrMatch(r.exit); + const file = b.fmt("{s}.ztrace", .{r.name}); + record_step.dependOn(&b.addInstallFile(trace, b.fmt("recordings/{s}", .{file})).step); + _ = embedded.addCopyFile(trace, file); + table.print(b.allocator, "pub const {s}: Program = .{{ .trace = @embedFile(\"{s}\"), .file = \"overflow.c\", .source = @embedFile(\"overflow.c\") }};\n", .{ r.name, file }) catch @panic("OOM"); + } + _ = embedded.addCopyFile(b.path("tools/overflow.c"), "overflow.c"); + // SQLite, the next rung: its amalgamation is not ours to copy, so the // scene is made only where it is. Built as the bench builds it (-O2, // frame pointers kept), and as the instrumented ones are (no PIE, bound -- cgit v1.3