summaryrefslogtreecommitdiff
path: root/anim/src/syscalls.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/src/syscalls.zig')
-rw-r--r--anim/src/syscalls.zig252
1 files changed, 77 insertions, 175 deletions
diff --git a/anim/src/syscalls.zig b/anim/src/syscalls.zig
index e184990..4a46170 100644
--- a/anim/src/syscalls.zig
+++ b/anim/src/syscalls.zig
@@ -20,7 +20,6 @@ const Stage = @import("stage.zig").Stage;
const theme = ui.theme;
const time = theme.time;
const Rect = ui.Rect;
-const k = theme.color.on_kernel;
/// A crossing's timetable, in seconds into its step (design/motion.md, "A
/// system call"). Staging, one thing at a time and no effect before its
@@ -156,11 +155,12 @@ pub fn fills(call: Recording.Syscall) ?Recording.Span {
return if (call.nr == @intFromEnum(std.os.linux.SYS.read) and got > 0) .{ .addr = call.args[1], .len = @intCast(got) } else null;
}
-/// The kernel as a lens: solid vellum, and nothing else on the frame is.
-/// The call the step made, decoded (its name, a row an argument by the
-/// argument's own name, what came back), the calls before it, the bytes it
-/// was given; and the arrow that crosses into it from the registers'
-/// side and returns.
+/// The `syscalls` lens: the program's conversation with the kernel. Its
+/// drawing is the calls so far as strace writes them, a row each, oldest
+/// on top and the newest at the bottom (its row comes in once the call is
+/// back, with the turned corner); not the kernel, and not on vellum: the
+/// kernel is under the program, the floor of the disassembly's `descent`.
+/// Its view, the bytes the newest call was given or filled.
pub const Crossing = struct {
cursor: cursors.Cursor,
stage: *const Stage,
@@ -182,45 +182,78 @@ pub const Crossing = struct {
defer u.unclip();
const now = c.cursor.now(placed);
const rec = c.cursor.rec;
- const body = u.panel(box.w, box.h, "kernel", .{ .focus = c.focus, .note = "the other side of a system call" });
- u.fill(.{ .x = theme.stroke.rule, .y = body.y, .w = body.w - 2 * theme.stroke.rule, .h = body.h - theme.stroke.rule }, theme.color.kernel);
+ const room = context.rowsOf(box);
+ // The calls from the scene's first moment: the program's, not its loader's.
+ var first: usize = 0;
+ while (first < rec.syscalls.len and rec.syscalls[first].enter < c.cursor.first) first += 1;
+ var newest = latest(rec, now.stops[0]);
+ // A crossing's own row comes in once it is back (rax struck), 12 f.
+ var arrives: f32 = 1;
+ if (newest) |n| if (inStep(now) != null and now.walking()) {
+ const p = Plan.of(rec.syscalls[n]);
+ arrives = std.math.clamp((now.time - p.struck - 6.0 / 60.0) / theme.time.quick, 0, 1);
+ };
+ if (newest) |n| if (n < first) {
+ newest = null;
+ };
+ const count = if (newest) |n| n + 1 - first else 0;
+ const body = u.panel(box.w, box.h, "system calls", .{ .focus = c.focus, .note = if (count > room) u.print("as strace writes them \u{00b7} newest at the bottom \u{00b7} {d} more above", .{count - room}) else "as strace writes them \u{00b7} newest at the bottom" });
context.clipBody(u, box);
defer u.unclip();
- u.text(.sans, theme.size.sans.micro, 12, body.y + 22, "calls so far", k.dim);
- const newest = latest(rec, now.stops[0]) orelse return;
- const live = inStep(now) != null and now.walking();
- const p = Plan.of(rec.syscalls[newest]);
- const t: f32 = if (live) now.time else std.math.inf(f32);
- if (t >= p.enters) arrows(u, body, t, p, rec.syscalls[newest]);
- // No effect before its cause: until the arrow is through the
- // line the kernel knows nothing of this call, and shows the last.
- if (t < p.name) {
- if (newest > 0) c.call(u.faded(1 - theme.ease(.exit, std.math.clamp((t - p.leaves) / (p.name - p.leaves), 0, 1))), body, rec.syscalls[newest - 1], .{}, std.math.inf(f32));
- } else c.call(u, body, rec.syscalls[newest], p, t);
+ const n = newest orelse return;
+ const top = body.y + theme.metric.context.pad;
+ const shown = @min(count, room);
+ for (0..shown) |j| {
+ const i = n + 1 - shown + j;
+ const v = if (i == n) u.faded(arrives) else u;
+ const y = top + @as(f32, @floatFromInt(j)) * row_h;
+ logRow(v, rec, rec.syscalls[i], y, box.w - theme.metric.context.side);
+ if (i == n) v.corner(theme.metric.context.side, y + 2, theme.metric.context.corner, 1);
+ }
+ }
- // The calls so far, newest on top. This one's row pushes in when
- // the kernel has taken the call: the others make room first.
- const pushed = cursors.standard(std.math.clamp((t - p.card) / theme.time.quick, 0, 1));
- const arrived = std.math.clamp((t - p.card - theme.time.snap) / theme.time.quick, 0, 1);
- const top = body.y + 32;
- var i = newest + 1;
- while (i > 0) {
- i -= 1;
- const place = @as(f32, @floatFromInt(newest - i)) - (if (i == newest) 0 else 1 - pushed);
- const y = top + place * (row_h + 4) - (if (i == newest) (1 - arrived) * 8 else 0);
- if (y + row_h > body.y + body.h - 6) continue;
- const v = if (i == newest) u.faded(arrived) else u;
- const card: Rect = .{ .x = 12, .y = y, .w = 196, .h = row_h };
- const done = rec.syscalls[i];
- const gold = if (i == newest) arrived >= 1 else i + 1 == newest and arrived < 1;
- if (gold) v.fill(card, theme.mark(.current).solid);
- v.frame(card, k.ink, theme.stroke.rule);
- const name = zt.syscalls.name(done.nr) orelse "?";
- // The result ranged right, when it is short; the name has the rest, and is cut only there.
- const words = if ((i != newest or t >= p.returns) and done.exit != null) result(u, done) else "";
- const said = if (words.len > 0 and words.len <= 4) words else "";
- if (said.len > 0) v.text(.mono, size, card.x + card.w - 8 - u.width(.mono, size, said), theme.baseline(card.y, card.h, size), said, k.dim);
- v.text(if (gold) .mono_bold else .mono, size, card.x + 8, theme.baseline(card.y, card.h, size), rows.fitted(u, name, card.w - 16 - (if (said.len > 0) u.width(.mono, size, said) + 12 else 0)), k.ink);
+ /// A call as strace writes it, its arguments by name: `read fd 3
+ /// "note" buf 7fffffffecd0 count 32 = 15`, cut at `room` with `…`.
+ fn logRow(u: ui.Ui, rec: *const Recording, made: Recording.Syscall, y: f32, room: f32) void {
+ const base = theme.baseline(y, row_h, size);
+ const adv = ui.advance(size);
+ var x: f32 = theme.metric.context.side;
+ const name = zt.syscalls.name(made.nr) orelse "syscall";
+ u.text(.mono_bold, size, x, base, name, theme.color.text.bright);
+ x += u.width(.mono_bold, size, name) + adv;
+ const names = zt.syscalls.names(made.nr);
+ const n = @min(zt.syscalls.signature(made.nr).len, 6);
+ const Part = struct { text: []const u8, ink: u24 };
+ var parts: [32]Part = undefined;
+ var np: usize = 0;
+ for (0..n) |j| {
+ const what = if (j < names.len) names[j] else "";
+ if (what.len > 0) {
+ parts[np] = .{ .text = what, .ink = theme.color.text.dim };
+ np += 1;
+ }
+ parts[np] = .{ .text = @import("disasm.zig").argument(u, rec, made.enter, what, made.args[j]), .ink = theme.color.text.primary };
+ np += 1;
+ if (std.mem.endsWith(u8, what, "fd")) {
+ const on = rec.openOn(u.f.scratch, made.args[j], made.enter);
+ if (on.len > 0) {
+ parts[np] = .{ .text = on, .ink = theme.color.text.faint };
+ np += 1;
+ }
+ }
+ }
+ parts[np] = .{ .text = "=", .ink = theme.color.text.faint };
+ np += 1;
+ parts[np] = .{ .text = if (made.exit != null) result(u, made) else "?", .ink = theme.color.text.primary };
+ np += 1;
+ for (parts[0..np]) |part| {
+ const w = u.width(.mono, size, part.text);
+ if (x + w > room) {
+ u.text(.mono, size, x, base, "\u{2026}", theme.color.text.faint);
+ return;
+ }
+ u.text(.mono, size, x, base, part.text, part.ink);
+ x += w + adv;
}
}
@@ -236,7 +269,8 @@ pub const Crossing = struct {
newest = if (n > 0) n - 1 else null;
};
const made: ?Recording.Syscall = if (newest) |n| rec.syscalls[n] else null;
- const span: ?Recording.Span = if (made) |given| bufferRead(given) orelse fills(given) orelse if (given.text.len > 0 and std.mem.indexOfScalar(u8, zt.syscalls.signature(given.nr), 's') != null) .{ .addr = given.args[0], .len = given.text.len + 1 } else null else null;
+ const path_at: ?usize = if (made) |given| std.mem.indexOfScalar(u8, zt.syscalls.signature(given.nr), 's') else null;
+ const span: ?Recording.Span = if (made) |given| bufferRead(given) orelse fills(given) orelse if (given.text.len > 0 and path_at != null) .{ .addr = given.args[path_at.?], .len = given.text.len + 1 } else null else null;
const scratch = context.at(f, placed, c.stage.box(placed, .view));
const about = if (span) |sp| scratch.print("the {s}, {x} to {x}", .{ if (bufferRead(made.?) != null) "buffer given" else if (fills(made.?) != null) "buffer filled" else "path given", sp.addr, sp.addr + sp.len - 1 }) else "the call names no bytes";
const v = hexdump.panel(f, placed, c.stage, about, &.{});
@@ -259,140 +293,8 @@ pub const Crossing = struct {
});
v.veil(now);
}
-
- /// A call, decoded: its name, a row for each argument, what came
- /// back; and to the right the bytes it was given, as the kernel
- /// copies them.
- fn call(c: *const Crossing, u: ui.Ui, body: Rect, made: Recording.Syscall, p: Plan, t: f32) void {
- const rec = c.cursor.rec;
- const x = 236;
- const name = zt.syscalls.name(made.nr) orelse "syscall";
- // The name arrives rising, as a caption does.
- const named = theme.ease(.enter, std.math.clamp((t - p.name) / theme.time.quick, 0, 1));
- const title = u.faded(named);
- const rise = (1 - named) * theme.time.caption_rise;
- title.text(.mono_bold, theme.size.mono.value, x, body.y + 46 + rise, name, k.ink);
- title.text(.sans, theme.size.sans.micro, x + u.width(.mono_bold, theme.size.mono.value, name) + 16, body.y + 44 + rise, u.print("system call {d}", .{made.nr}), k.dim);
- const signature = zt.syscalls.signature(made.nr);
- var row_y: f32 = body.y + 62;
- var text_used = false;
- const row = struct {
- /// `note`: faint after the words, what a descriptor is open on (the `value` class `fd`).
- fn draw(v: ui.Ui, y: f32, register: []const u8, meaning: []const u8, words: []const u8, note: []const u8) void {
- v.fill(.{ .x = x, .y = y, .w = 300, .h = theme.stroke.rule }, k.rule);
- const base = theme.baseline(y, row_h + 4, size);
- v.text(.mono, size, x, base, register, k.dim);
- v.text(.sans_medium, theme.size.sans.tag, x + 52, base, meaning, k.ink);
- v.text(.mono, size, x + 130, base, words, k.ink);
- v.text(.mono, size, x + 130 + v.width(.mono, size, words) + 8, base, note, k.dim);
- }
- }.draw;
- for (signature, 0..) |kind, arg| {
- if (arg >= 4) break;
- const shows = std.math.clamp((t - p.rows - @as(f32, @floatFromInt(arg)) * Plan.row) / Plan.row, 0, 1);
- const meaning = what(made.nr, kind, arg);
- const note = if (std.mem.eql(u8, meaning, "fd")) rec.openOn(u.f.scratch, made.args[arg], made.enter) else "";
- row(u.faded(shows), row_y, carriers[arg], meaning, value(u, made, kind, arg, &text_used), note);
- row_y += row_h + 4;
- }
- const back = t >= p.returns and made.exit != null;
- // What `open` returns is a descriptor: open on the path it was given.
- const opened = back and std.mem.eql(u8, zt.syscalls.name(made.nr) orelse "", "open") and @as(i64, @bitCast(made.result)) >= 0;
- row(u.faded(std.math.clamp((t - p.rows - @as(f32, @floatFromInt(@min(signature.len, 4))) * Plan.row) / Plan.row, 0, 1)), row_y, "rax", "returns", if (back) result(u, made) else "\u{2014}", if (opened) rec.openOn(u.f.scratch, made.result, made.exit.? + 1) else "");
-
- if (made.text.len == 0) return;
- const bytes_x = 564;
- const framed = u.faded(std.math.clamp((t - p.work) / Plan.row, 0, 1));
- framed.text(.sans, theme.size.sans.micro, bytes_x, body.y + 22, if (std.mem.indexOfScalar(u8, signature, 's') != null) "the path it was given" else "the bytes it was given", k.dim);
- const shown = @min(made.text.len, shown_bytes);
- const text = for (made.text[0..shown]) |byte| {
- if (!std.ascii.isPrint(byte) and byte != '\n') break false;
- } else true;
- for (made.text[0..shown], 0..) |byte, j| {
- const cell: Rect = .{ .x = bytes_x + @as(f32, @floatFromInt(j % per_row)) * 28, .y = body.y + 32 + @as(f32, @floatFromInt(j / per_row)) * 30, .w = 26, .h = 26 };
- // Each fills as it is copied, two frames a byte: struck, then held.
- const since = t - p.fills - @as(f32, @floatFromInt(j)) * Plan.byte;
- if (since < 0) {
- framed.frame(cell, k.rule, theme.stroke.rule);
- continue;
- }
- const in = std.math.clamp(since / theme.time.strike.in, 0, 1);
- u.fill(cell, ui.mix(theme.color.kernel, ui.mix(theme.mark(.write).solid, k.held, std.math.clamp((since - theme.time.quick) / theme.time.strike.cool, 0, 1)), in));
- u.frame(cell, k.ink, theme.stroke.rule);
- if (in < 0.5) continue;
- // Text as its characters; anything else (a page of a file) as hex.
- if (!text) {
- u.label(.mono, size, cell, .center, u.print("{x:0>2}", .{byte}), k.ink);
- } else if (std.ascii.isPrint(byte) and byte != ' ') u.label(.mono, size, cell, .center, &.{byte}, k.ink) else if (byte == '\n') u.label(.mono, size, cell, .center, "\\n", k.dim);
- }
- }
-
- /// The crossing itself: in from the side the registers are on as the
- /// call enters, and back out as it returns. Vellum outside the
- /// kernel, ink inside it. Machines do not lob: straight.
- /// The crossing itself: up out of the registers below the band (the
- /// ones that carried it), into the kernel, as the call enters; and back
- /// down as it returns. Machines do not lob: straight.
- fn arrows(u: ui.Ui, body: Rect, t: f32, p: Plan, made: Recording.Syscall) void {
- // At the drawing's right, where it meets the state column the call leaves from.
- const x = body.w - 56;
- const bottom = body.y + body.h;
- const reach = 64;
- // Off promptly, and settling in the kernel.
- const up = cursors.standard(std.math.clamp((t - p.enters) / Plan.cross, 0, 1));
- const gone = std.math.clamp((t - p.struck - theme.time.quick) / theme.time.read.out, 0, 1);
- const v = u.faded(1 - gone);
- if (t < p.back) along(v, x, bottom, bottom - up * reach);
- if (made.exit != null and t > p.back) along(v, x + 40, bottom - reach, bottom - reach + cursors.standard(std.math.clamp((t - p.back) / Plan.cross, 0, 1)) * reach);
- }
-
- /// An arrow down the column at `x` from `from` to `to`, in ink: it is inside the kernel.
- fn along(u: ui.Ui, x: f32, from: f32, to: f32) void {
- if (@abs(to - from) < 1) return;
- const w = theme.stroke.arrow;
- const head = theme.stroke.flow_head;
- const dir: f32 = if (to > from) 1 else -1;
- const neck = to - dir * (head[0] - 2);
- if ((neck - from) * dir > 0) u.fill(.{ .x = x - w / 2, .y = @min(from, neck), .w = w, .h = @abs(neck - from) }, k.ink);
- if (@abs(to - from) < head[0]) return;
- sk.draw.polygon(u.f, &.{ .{ x, to }, .{ x - head[1] / 2, to - dir * head[0] }, .{ x + head[1] / 2, to - dir * head[0] } }, u.at.pen(.{ .fill = ui.rgb(k.ink) }));
- }
};
-/// What an argument is called: by the call's own names where the tracer's
-/// table has them, else from its letter in `zt.syscalls.signature`.
-fn what(nr: u16, kind: u8, arg: usize) []const u8 {
- const names = zt.syscalls.names(nr);
- if (arg < names.len) return names[arg];
- return switch (kind) {
- 'i' => "number",
- 'd' => "size",
- 's' => "path",
- 'b' => "buffer",
- else => "pointer",
- };
-}
-
-fn value(u: ui.Ui, made: Recording.Syscall, kind: u8, arg: usize, text_used: *bool) []const u8 {
- // Flags and a mode are bits: hex, said so.
- const meaning = what(made.nr, kind, arg);
- if (std.mem.eql(u8, meaning, "flags") or std.mem.eql(u8, meaning, "mode")) return u.print("0x{x}", .{made.args[arg]});
- const a = made.args[arg];
- switch (kind) {
- 'i' => return u.print("{d}", .{@as(i32, @bitCast(@as(u32, @truncate(a))))}),
- 'd' => return u.print("{d}", .{a}),
- 's' => if (made.text.len > 0 and !text_used.*) {
- text_used.* = true;
- const base = std.fs.path.basename(made.text);
- // A string cut says so: `…` and no closing quote.
- return if (base.len <= 14) u.print("\"{s}\"", .{base}) else u.print("\"{s}\u{2026}", .{base[0..13]});
- },
- else => {},
- }
- return u.print("{x}", .{a});
-}
-
-
/// What came back: a count, an address, or an error by name.
fn result(u: ui.Ui, made: Recording.Syscall) []const u8 {
const ret: i64 = @bitCast(made.result);