diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-18 23:12:37 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 01:07:19 -0300 |
| commit | e567aadc19f58b1e36098388483294321f3502dd (patch) | |
| tree | c3a9f3430f3cad2e4d9ba7d21be0e88eae16bbeb /core/term/TerminalImages.zig | |
| parent | 250d34c1b942cd6e3726e96f6d80a9cf98d6e20e (diff) | |
| download | pardes-e567aadc19f58b1e36098388483294321f3502dd.tar.gz pardes-e567aadc19f58b1e36098388483294321f3502dd.zip | |
core: the rollback's two faults read by the probe (pardes-probes P4 b), each shown by a test that fails on the base, and fixed: (a) a terminal's kitty-image cache (TerminalImages.converted, RGBA made of an RGB or grey image) was made with the drawing core's allocator, so on a far client, whose emulator is outside its rollback epoch, a frame drawn under a speculation left the emulator holding epoch-born memory that the rollback freed (reachable since a closed terminal brought back loads the session's dump of it, its images with it): the next frame read the freed map (SIGSEGV in TerminalImages.draw on the base), so the caches are now the emulator's own allocator's and a terminal's close takes none; (b) a far client's slot of a kind whose state is not plain was on the C heap (initDump's image_allocator), so its own Del of such a pane freed the slot outside the epoch, and the rollback by another client's unit put back a pane pointing at it (a general protection fault in Jump.trackJump on the base), so a far client's image_allocator is now its epoch, as every other of its allocators: the free is put off and the Del stays instant; two tests at the end of core/replica.zig; tui core-test 824/966 (142 skipped), shell-test 1001/1004, pane-test 183/184, behaviour-test 274/274 and --replay 274/274, process-test 2 of 144 failed (lspcomplete, lspcompletemoved; winch failed once under load and passed alone), replicas --clients 5 diverged 0 unequal 0 deltas wrong 0 quiet differ 0 at 30/80/207 ms, gui unit-test 1598/1602 with its perf check passing, daemon.py plain, --far and --games pass (--games once timed out at its teardown and passed again; --window-clients failed on the gate's own TMPDIR, a socket path past 108 bytes, and passed on the next change)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/term/TerminalImages.zig')
| -rw-r--r-- | core/term/TerminalImages.zig | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/core/term/TerminalImages.zig b/core/term/TerminalImages.zig index 1420d9e3..feba5ddc 100644 --- a/core/term/TerminalImages.zig +++ b/core/term/TerminalImages.zig @@ -29,6 +29,8 @@ pub const storage_limit = 64 * 1024 * 1024; petscii: bool = false, /// Pixels in RGBA for images ghostty-vt holds in another format (RGB, /// grey): only for images on screen, dropped the frame they are not. +/// The emulator's own allocator's, as the emulator is (`draw`'s `own`): +/// never a client core's, whose rollback would free it under the emulator. converted: std.AutoHashMapUnmanaged(u32, Converted) = .empty, /// When the next frame of a playing animation (a=a) is due, in ms on the /// core's clock (`Pardes.stepped_ns`): the core wakes for it (nextWake). @@ -160,9 +162,11 @@ fn decodePng(gpa: std.mem.Allocator, bytes: []const u8) ghostty_vt.sys.DecodeErr /// Draw the active screen's images. `rows_of[v]` is the body row the /// viewport's row `v` is shown on, if it is shown; `cols` how many of its -/// columns the body shows, from `tx`. +/// columns the body shows, from `tx`. The caches are `own`'s (the +/// emulator's), `out` is `gpa`'s. pub fn draw( ti: *TerminalImages, + own: std.mem.Allocator, gpa: std.mem.Allocator, vt: *ghostty_vt.Terminal, where: plain.term.ImagesAt, @@ -173,7 +177,7 @@ pub fn draw( ) void { var conv = ti.converted.valueIterator(); while (conv.next()) |c| c.used = false; - defer ti.prune(gpa); + defer ti.prune(own); const screen = vt.screens.active; const storage = &screen.kitty_images; @@ -187,7 +191,7 @@ pub fn draw( const bottom = pages.getBottomRight(.viewport) orelse return; const cw: u32 = @max(1, where.cell_w); const ch: u32 = @max(1, where.cell_h); - const ctx: Ctx = .{ .ti = ti, .gpa = gpa, .out = out, .pane = where.pane, .serial = where.serial, .tx = where.tx, .body_y = where.body_y, .cols = where.cols, .rows_of = rows_of, .cw = cw, .ch = ch }; + const ctx: Ctx = .{ .ti = ti, .own = own, .gpa = gpa, .out = out, .pane = where.pane, .serial = where.serial, .tx = where.tx, .body_y = where.body_y, .cols = where.cols, .rows_of = rows_of, .cw = cw, .ch = ch }; // Handed on lowest z first (the storage's order is a hash map's), the // order a shell draws them in; equal z keeps the order they came in. const first = out.items.len; @@ -268,6 +272,7 @@ pub fn draw( const Ctx = struct { ti: *TerminalImages, + own: std.mem.Allocator, gpa: std.mem.Allocator, out: *std.ArrayList(plain.Placement), pane: u8, @@ -287,7 +292,7 @@ const Ctx = struct { const x0 = @max(dst.x, 0); const x1 = @min(dst.x + dst.w, @as(i64, ctx.cols) * cw); if (x1 <= x0) return; - const rgba = ctx.ti.pixelsOf(ctx.gpa, img) orelse return; + const rgba = ctx.ti.pixelsOf(ctx.own, img) orelse return; const first_row = @divFloor(@max(dst.y, 0), ch); const last_row = @min(@divFloor(dst.y + dst.h - 1, ch), @as(i64, @intCast(ctx.rows_of.len)) - 1); var v = first_row; |
