Files
sausage/userland/cwd-init/init.rs
T
surma 57a47b069e host: process table, shell, coreutils and harness (T8, T9)
T8: sausage:process WIT (spawn, wait, kill), one store per process over the
shared root, /proc/processes, /run, pipeline and cancellation groups, Exec.
brush and 78 uutils commands; the shared cwd-init object sets the cwd from PWD
and keeps numeric exit codes. The corpus matches native bash.

T9: V8 (deno_core) runs pi-durable, pi-ai and chord; SQLite storage in
<dir>/host/harness.sqlite (WAL, synchronous=FULL); file tools on the VFS, bash
through Exec; resumes after SIGKILL.
2026-11-06 16:34:34 +00:00

47 lines
1.2 KiB
Rust

//! Initialize wasi-libc's cwd for every program that the world toolchain builds.
#![no_std]
#[used]
#[unsafe(link_section = "component-type:sausage-exit")]
static EXIT_INTERFACE: [u8; include_bytes!("exit-meta.bin").len()] =
*include_bytes!("exit-meta.bin");
unsafe extern "C" {
fn getenv(name: *const u8) -> *const u8;
fn chdir(path: *const u8) -> i32;
}
#[link(wasm_import_module = "wasi:cli/exit@0.2.12")]
unsafe extern "C" {
#[link_name = "exit-with-code"]
fn exit_with_code(code: u32);
}
/// Replace wasi-libc's success/failure conversion with the standard numeric exit interface.
#[unsafe(no_mangle)]
unsafe extern "C" fn _Exit(code: i32) -> ! {
unsafe {
exit_with_code((code as u32) & 255);
}
core::arch::wasm32::unreachable()
}
#[unsafe(no_mangle)]
unsafe extern "C" fn _exit(code: i32) -> ! {
unsafe { _Exit(code) }
}
extern "C" fn initialize() {
// PWD is supplied by the process table, never inferred from a host directory.
unsafe {
let cwd = getenv(c"PWD".as_ptr().cast());
if !cwd.is_null() && chdir(cwd) != 0 {
_exit(1);
}
}
}
#[used]
#[unsafe(link_section = ".init_array")]
static INITIALIZE: extern "C" fn() = initialize;