summaryrefslogtreecommitdiff
path: root/src/tty
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-23 17:10:58 -0300
committerGabriel Schneider <[email protected]>2026-10-23 17:10:58 -0300
commit0073d05329335dbb0eb85f5c3044e42805d144e5 (patch)
tree744edfc317719b2018b1c3a8657c223aec058d47 /src/tty
parenta8b457a306a4442975210bcac3f04b56513c61c3 (diff)
downloadpardes-0073d05329335dbb0eb85f5c3044e42805d144e5.tar.gz
pardes-0073d05329335dbb0eb85f5c3044e42805d144e5.zip
Callstack lists every caller and pages a tree too big for one query; memory bounds and resident-size fixes
Callstack walks while the server answers, counts on the message row past a second, puts test callers last at each level, and ends a tree past one query's memory (memory.limits.arena.lsp_query, a 256 MiB region taken and given back per query) in a row whose Callstack shows the next page. Grep reads whole files. New hard limits: undo text per file, image decode pixels, the LSP snapshot of other open files, one paste. Safe builds no longer fill worst-case buffers with 0xAA (memory.unfilled), big regions are kept off transparent huge pages, and malloc_trim runs after big results. Also: Look's git show pages into a +Diff, and dropped marks in File. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/tty')
-rw-r--r--src/tty/tty.zig51
1 files changed, 36 insertions, 15 deletions
diff --git a/src/tty/tty.zig b/src/tty/tty.zig
index 4cd1bc9a..afc0dbf0 100644
--- a/src/tty/tty.zig
+++ b/src/tty/tty.zig
@@ -34,6 +34,8 @@ var kitty_shm = std.atomic.Value(bool).init(false);
var kitty_shm_probing = std.atomic.Value(bool).init(false);
const kitty_shm_probe_id = 0x7fff_fff1;
var kitty_shm_serial: u32 = 0;
+/// Transmissions an unread shm segment outlives before it is removed.
+const kitty_shm_window = 64;
fn kittyShmName(buf: []u8, n: u32) ![:0]const u8 {
return std.fmt.bufPrintSentinel(buf, "/pardes-{d}-{d}", .{ libc.getpid(), n }, 0);
@@ -1787,6 +1789,13 @@ const Shell = struct {
if (!s.kitty.contains(key) and vx.caps.kitty_graphics and kitty_shm.load(.acquire)) shm: {
var buf: [64]u8 = undefined;
kitty_shm_serial +%= 1;
+ // Bounded: a segment this many transmissions old was never
+ // read (a terminal reads one as its command arrives), and a
+ // tmpfs holds it in memory until it goes.
+ if (kitty_shm_serial > kitty_shm_window) {
+ var old_buf: [64]u8 = undefined;
+ if (kittyShmName(&old_buf, kitty_shm_serial - kitty_shm_window)) |old| _ = libc.shm_unlink(old) else |_| {}
+ }
const name = kittyShmName(&buf, kitty_shm_serial) catch break :shm;
if (!kittyShmWrite(name, place.rgba)) break :shm;
if (vx.transmitLocalImagePath(s.gpa, s.tty.writer(), name, @intCast(place.iw), @intCast(place.ih), .shared_mem, .rgba) catch null) |handle|
@@ -2010,7 +2019,7 @@ const Shell = struct {
old.future.cancel(s.io) catch {};
s.lsp_task = null;
}
- const future = s.io.concurrent(lspWorker, .{ s.lsp_gpa, job, s.loop }) catch |err| {
+ const future = s.io.concurrent(lspWorker, .{ s.io, s.lsp_gpa, job, s.loop }) catch |err| {
job.free(s.lsp_gpa);
s.core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } });
return s.core.reportError(req.pane, "lsp", err);
@@ -2144,9 +2153,9 @@ fn requestClipboard(vx: *vaxis.Vaxis, tty: *vaxis.Tty) void {
vx.requestSystemClipboard(tty.writer()) catch {};
}
-fn lspWorker(allocator: std.mem.Allocator, job: *host_io.Lsp.Job, loop: *Loop) anyerror!void {
+fn lspWorker(io: std.Io, allocator: std.mem.Allocator, job: *host_io.Lsp.Job, loop: *Loop) anyerror!void {
var sink: LspRowSink = .{ .allocator = allocator, .loop = loop };
- host_io.Lsp.work(allocator, job, &sink, LspRowSink.take);
+ host_io.Lsp.work(io, allocator, job, &sink, LspRowSink.take);
}
const LspRowSink = struct {
@@ -2185,23 +2194,30 @@ fn watchFiles(io: std.Io, fd: c_int, loop: *Loop) anyerror!void {
return;
}
const file: std.Io.File = .{ .handle = fd, .flags = .{ .nonblocking = false } };
- var read_buf: [4096]u8 = undefined;
- var reader = file.readerStreaming(io, &read_buf);
+ // One buffer, read into directly: a Reader around it only added a second
+ // (and in a safe build, filled both as `undefined` on every start).
+ var buf: [4096]u8 = undefined;
while (true) {
- var buf: [4096]u8 = undefined;
- var vec = [_][]u8{&buf};
- const n = reader.interface.readVec(&vec) catch break;
+ const n = file.readStreaming(io, &.{&buf}) catch break;
if (n == 0) break;
loop.postEvent(.files_changed) catch break;
}
}
fn winchWatch(loop: *Loop, vx: *vaxis.Vaxis, tty: *vaxis.Tty) void {
+ winchWatchUntil(loop, vx, tty, null);
+}
+
+/// A SIGWINCH watcher that ends: `stop` set, then a SIGWINCH sent to its
+/// thread, wakes its sigwait and it returns, so whoever owns `loop` can join
+/// it before the loop goes (attachSession's loop is on its stack).
+fn winchWatchUntil(loop: *Loop, vx: *vaxis.Vaxis, tty: *vaxis.Tty, stop: ?*const std.atomic.Value(bool)) void {
var set = posix.sigemptyset();
posix.sigaddset(&set, posix.SIG.WINCH);
while (true) {
var sig: c_int = 0;
if (libc.sigwait(&set, &sig) != 0) continue;
+ if (stop) |flag| if (flag.load(.acquire)) return;
if (vx.state.in_band_resize) continue; // terminal reports via CSI 48
const ws = tty.getWinsize() catch continue;
loop.postEvent(.{ .winsize = ws }) catch {};
@@ -2285,12 +2301,11 @@ fn wakeFs(ctx: ?*anyopaque) void {
}
fn readPty(io: std.Io, gpa: std.mem.Allocator, pty: std.Io.File, id: usize, gen: u32, loop: *Loop) anyerror!void {
- var read_buf: [0x10000]u8 = undefined;
- var reader = pty.readerStreaming(io, &read_buf);
+ // One buffer, read into directly: a Reader around it only added a second
+ // (and in a safe build, filled both as `undefined` on every start).
+ var buf: [0x10000]u8 = undefined;
while (true) {
- var buf: [0x10000]u8 = undefined;
- var vec = [_][]u8{&buf};
- const n = reader.interface.readVec(&vec) catch break;
+ const n = pty.readStreaming(io, &.{&buf}) catch break;
if (n == 0) break;
const bytes = try gpa.dupe(u8, buf[0..n]);
loop.postEvent(.{ .pty_read = .{ .id = id, .gen = gen, .bytes = bytes } }) catch {
@@ -2301,7 +2316,7 @@ fn readPty(io: std.Io, gpa: std.mem.Allocator, pty: std.Io.File, id: usize, gen:
_ = loop.tryPostEvent(.{ .pty_eof = .{ .id = id, .gen = gen } }) catch {};
}
-const max_paste_bytes: usize = 4 << 20;
+const max_paste_bytes: usize = pardes.memory.limits.max_paste_bytes;
fn pasteBytes(key: vaxis.Key) []const u8 {
const text = key.text orelse "";
@@ -3023,7 +3038,13 @@ fn attachSession(init: std.process.Init, name: []const u8, tty: *vaxis.Tty, vx:
startInput(&loop, &input_cache) catch |err| return .{ .lost = err };
defer stopInput(&loop);
- (std.Thread.spawn(.{}, winchWatch, .{ &loop, vx, tty }) catch |err| return .{ .lost = err }).detach();
+ var winch_stop: std.atomic.Value(bool) = .init(false);
+ const winch = std.Thread.spawn(.{}, winchWatchUntil, .{ &loop, vx, tty, &winch_stop }) catch |err| return .{ .lost = err };
+ defer {
+ winch_stop.store(true, .release);
+ _ = libc.pthread_kill(winch.getHandle(), posix.SIG.WINCH);
+ winch.join();
+ }
vx.queryTerminalSend(tty.writer()) catch {};
return attachLoop(&a);