wasm-posix-host
    Preparing search index...

    Interface CentralizedKernelCallbacks

    Callbacks for fork/exec/exit handling.

    interface CentralizedKernelCallbacks {
        onClone?: (
            pid: number,
            tid: number,
            fnPtr: number,
            argPtr: number,
            stackPtr: number,
            tlsPtr: number,
            ctidPtr: number,
            memory: Memory,
        ) => Promise<number>;
        onExec?: (
            pid: number,
            path: string,
            argv: string[],
            envp: string[],
        ) => Promise<number>;
        onExit?: (pid: number, exitStatus: number) => void;
        onExitGroup?: (pid: number) => void;
        onFork?: (
            parentPid: number,
            childPid: number,
            parentMemory: Memory,
            threadFork?: ForkFromThreadContext,
        ) => Promise<number[]>;
        onResolveSpawn?: (
            path: string,
            argv: string[],
        ) => Promise<SpawnProgramResolution | null>;
        onSpawn?: (
            childPid: number,
            programBytes: ArrayBuffer,
            argv: string[],
            envp: string[],
        ) => Promise<number>;
        onThreadExit?: (pid: number, tid: number, channelOffset: number) => boolean;
    }
    Index

    Properties

    onClone?: (
        pid: number,
        tid: number,
        fnPtr: number,
        argPtr: number,
        stackPtr: number,
        tlsPtr: number,
        ctidPtr: number,
        memory: Memory,
    ) => Promise<number>

    Called when a process calls clone (thread creation). The callback should spawn a thread Worker sharing the parent's Memory. Returns the TID.

    onExec?: (
        pid: number,
        path: string,
        argv: string[],
        envp: string[],
    ) => Promise<number>

    Called when a process calls execve. The callback should resolve the program path, terminate the old Worker, create a new Worker with the new binary, and call registerProcess with skipKernelCreate. Returns 0 on success, negative errno on error.

    onExit?: (pid: number, exitStatus: number) => void

    Called when a process exits.

    onExitGroup?: (pid: number) => void

    Called when a process calls exit_group (terminate all threads). The callback should forcefully terminate all thread workers for the process. Called BEFORE the process exit is processed.

    onFork?: (
        parentPid: number,
        childPid: number,
        parentMemory: Memory,
        threadFork?: ForkFromThreadContext,
    ) => Promise<number[]>

    Called when a process forks. The kernel has already cloned the Process in its ProcessTable. The callback should spawn a child Worker with a copy of the parent's Memory and register it with the kernel. Returns the channel offsets allocated for the child.

    threadFork is set when the parent issued the fork() syscall from a thread spawned via pthread_create (i.e. on a channel registered through addChannel(pid, offset, tid, fnPtr, argPtr) with tid > 0). The host must:

    • use the thread's forkBufAddr (not the main channel's) for the child's rewind so the saved frames + saved __tls_base / __stack_pointer match what the parent thread populated, and
    • have the child Worker enter the thread function (fnPtr/argPtr) directly instead of _start — _start is not in the thread's fork-path call chain and rewinding through it would never reach the saved fork() call site.

    If threadFork is omitted the callback handles the fork as a fork-from-main-thread (the existing path).

    onResolveSpawn?: (
        path: string,
        argv: string[],
    ) => Promise<SpawnProgramResolution | null>

    Pre-flight resolution step for SYS_SPAWN. Returns the program bytes for path (or { programBytes, argv } when resolution rewrites argv, e.g. a shebang script), { errno } for a located but unlaunchable program, or null for ENOENT. Must NOT have side effectshandleSpawn calls this BEFORE kernel_spawn_process so that file actions never run on a doomed PATH-iteration. POSIX requires file_actions to run "exactly once," and posix_spawnp's PATH-walk issues one posix_spawn per candidate; without this preflight the kernel applies file_actions on every failed iteration (sortix basic/spawn/posix_spawnp exercises an addopen(O_EXCL) "once" file that would conflict on iteration 2).

    Required if onSpawn is set; together they form the spawn surface.

    onSpawn?: (
        childPid: number,
        programBytes: ArrayBuffer,
        argv: string[],
        envp: string[],
    ) => Promise<number>

    Launch a worker for the spawned child with already-resolved bytes and argv (from onResolveSpawn). The kernel has constructed the child Process descriptor under childPid and applied file actions + attrs by the time this is called. The callback instantiates a fresh Worker and registers it via registerProcess({ skipKernelCreate: true }).

    Returns 0 on success, negative errno on failure. On non-zero return the kernel descriptor is rolled back via kernel_remove_process.

    Distinct from onExec (which replaces the calling worker) and onFork (which clones the parent's Memory): onSpawn always creates a fresh Memory and runs the new program from _start.

    onThreadExit?: (pid: number, tid: number, channelOffset: number) => boolean

    Called after a pthread channel reaches SYS_EXIT and the kernel worker has performed the Linux CLONE_CHILD_CLEARTID wake. Return true when the host will terminate the backing Worker, so the syscall channel should not be completed back into guest code.