gmux - v0.1.0
    Preparing search index...

    Class Machine

    A Linux machine on one host thread.

    Every kernel task and every CPU is one vmlinux instance over one shared memory, as in linux-wasm. Blocking host imports are JSPI Suspending functions and every call into wasm that can block goes through WebAssembly.promising, so a pump can run exactly one task at a time and switch by resolving the task the kernel names next.

    Index
    • a machine that has not booted; run boots it. Its memory starts at initialPages 64 KiB pages

      Parameters

      • options: MachineOptions
      • initialPages: number = 15
      • keep: boolean = false

      Returns Machine

    crashed: unknown = null

    the error that stopped the machine, if one did

    halted: boolean = false

    whether the kernel halted (reboot, poweroff)

    memory: Memory

    the one memory the kernel and every process share

    restoredStreams: IngressStream[] = []

    the streams of the snapshot this machine was restored from, parked as their owner left them

    stats: MachineStats = ...

    counters, updated as the machine runs

    • get clockNs(): bigint

      the kernel clock, in nanoseconds; deadline is on it

      Returns bigint

    • get coreScheduling(): boolean

      whether the C scheduler core picks the tasks (else the TypeScript tables do)

      Returns boolean

    • get deadline(): bigint | null

      the earliest Linux timer an idle task waits for, in kernel-clock nanoseconds, or null

      Returns bigint | null

    • get netActivity(): number

      changes whenever a stream gains something to read or its guest end closes, which a pump waiting on a stream can end its turn at

      Returns number

    • get openStreams(): number

      streams opened to the machine's listeners that are not finished with

      Returns number

    • get runnable(): boolean

      whether a task is ready to run, which a machine with no timer to wait on can still have

      Returns boolean

    • turns every parked stack into bytes and returns the machine as data. The machine cannot run afterwards; continue from Machine.restore(options, snapshot). memory is a view over this machine's memory, not a copy, so a caller persists it before dropping the machine

      Returns Promise<Snapshot>

    • opens a stream to the program listening on port: the kernel connects a socket to it and the program accepts an ordinary connection. Throws when nothing listens there. borrows lets the kernel lend its buffers to the reader (kernel patch 0041) on the terms of IngressStream.recycle

      Parameters

      • port: number
      • borrows: boolean = false

      Returns IngressStream

    • whether a program in the machine listens on port (kernel patch 0031)

      Parameters

      • port: number

      Returns boolean

    • raises the relay's interrupt for any stream that has room again; the site calls it between steps

      Returns void

    • Runs the machine until until says stop, or nothing can run and no timer is armed. sleep(ms) is how the host waits for a timer; budget caps pump steps for one call.

      Parameters

      • until: () => boolean
      • sleep: (ms: number) => Promise<void>
      • budget: number = Infinity

      Returns Promise<string>

    • keyboard input; raises the console interrupt, or waits for the driver's poll on an older kernel

      Parameters

      • text: string

      Returns void

    • rebuilds a machine from a snapshot in fresh instances and rewinds every stack into its park. image, when given, writes the memory straight into the machine instead of snapshot.memory, so a large machine never needs a second full copy of itself to restore

      Parameters

      • options: MachineOptions
      • snapshot: Snapshot
      • Optionalimage: { byteLength: number; write(into: Uint8Array): void }
      • Optionallazy: {
            byteLength: number;
            read(
                start: number,
                end: number,
            ): Uint8Array<ArrayBufferLike> | Promise<Uint8Array<ArrayBufferLike>>;
        }

      Returns Promise<Machine>

    • continues a machine that has just checkpointed, in the memory it checkpointed from, which options.memory must be: that memory already is the snapshot's image, so nothing is copied or read back

      Parameters

      Returns Promise<Machine>