Skip to content

Commit 505d93f

Browse files
authored
fix(execution): provide host_tty.isatty/get_size + wire set_raw_mode for wasm-c TTY guests (#167)
wasm-runner.mjs's host_tty import only provided read() + a stubbed set_raw_mode, missing isatty/get_size — so any wasm-c program importing host_tty.{isatty,get_size} (pty_probe, vim) failed to instantiate (LinkError) and produced no output. Wire all three to the existing kernel sync-RPCs (__kernel_isatty / __kernel_tty_size / __pty_set_raw_mode) already served on the same dispatch as __kernel_stdin_read.
1 parent 2e90d52 commit 505d93f

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

crates/execution/assets/runners/wasm-runner.mjs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5046,9 +5046,26 @@ const hostTtyImport = {
50465046
Atomics.wait(syntheticWaitArray, 0, 0, 10);
50475047
}
50485048
},
5049-
// Toggle terminal raw mode on the guest's PTY. crossterm calls this instead of
5050-
// tcsetattr; route it to the kernel so reedline gets raw \r keystrokes and submits.
5051-
set_raw_mode(_enabled) {
5049+
// `host_tty.isatty(fd)` -> 1 if the guest fd is a kernel PTY, else 0.
5050+
isatty(fd) {
5051+
return callSyncRpc('__kernel_isatty', [fd >>> 0]) === true ? 1 : 0;
5052+
},
5053+
// `host_tty.get_size(fd, colsPtr, rowsPtr)` -> writes the PTY window size as two
5054+
// little-endian u16s and returns 0; non-zero (ENOTTY) if fd is not a PTY.
5055+
get_size(fd, colsPtr, rowsPtr) {
5056+
const size = callSyncRpc('__kernel_tty_size', [fd >>> 0]);
5057+
if (!size || typeof size.cols !== 'number' || typeof size.rows !== 'number') {
5058+
return 25; // ENOTTY
5059+
}
5060+
const view = new DataView(instanceMemory.buffer);
5061+
view.setUint16(colsPtr >>> 0, size.cols & 0xffff, true);
5062+
view.setUint16(rowsPtr >>> 0, size.rows & 0xffff, true);
5063+
return 0;
5064+
},
5065+
// Toggle terminal raw mode on the guest's PTY. crossterm/pty_probe/vim call this
5066+
// instead of tcsetattr; route it to the kernel so the guest gets raw keystrokes.
5067+
set_raw_mode(enabled) {
5068+
callSyncRpc('__pty_set_raw_mode', [(enabled >>> 0) !== 0]);
50525069
return 0;
50535070
},
50545071
};

0 commit comments

Comments
 (0)