Skip to content

feat(wasm): bootstrap owned threaded guest instances #35

Closed

Description

@zackees

Child of #32; depends on #34.

Scope

Build on #34 to implement synchronous, owned wasi::thread-spawn(i32) -> i32 for the exact Rust 1.95 wasm32-wasip1-threads guest. Under a short controller lock, reserve a valid nonzero TID; reject configured cap or closing state with a deterministic negative result and facade semantic diagnostic. Drop the lock before native spawn, Store/Instance construction, Wasm execution, and joining.

Each accepted guest spawn creates one native std::thread with a fresh Store, a fresh Instance from the one shared InstancePre, and calls the exported wasi_thread_start(tid, start_arg). start_arg is opaque. All instances share compiled code, the one engine-owned SharedMemory/heap, capability/resource registry, and the one caller-provided RuntimeHandle identity; Store, Instance, Wasm stack, TLS, and execution state are distinct.

Update the source-only real guest to prove ordinary std::thread, Arc, atomics, Mutex, channel, and deterministic concurrent-map behavior. It writes a bounded atomic result record in shared linear memory. The host proves root plus two guest children observe the same allocation and expected synchronization result.

RED → GREEN

  • RED: feat(wasm): add private threaded root execution substrate #34 root execution has a deterministic thread-spawn rejection and no child bootstrap.
  • GREEN: direct real artifact test proves root plus two native child threads; one module/engine/prelink/shared-memory/runtime identity; distinct Store/Instance/TLS identities; expected Arc/atomic/mutex/channel/map result record; and a bounded host read using atomics.
  • Max-thread rejection returns the documented negative value, leaks no slot/handle, and leaves the registry unchanged.
  • Cooperative normal completion joins root and child workers, reports each typed outcome, and leaves zero live registrations/JoinHandles.
  • Characterize nonzero proc_exit and child trap outcomes as typed semantic results. Do not call kernal-api-run twice when root start already reaches guest main.

Platform and safety

Support Linux/macOS/Windows on x86-64 and ARM64 through Wasmtime 45 Cranelift. Native threads own their Stores; no Store/Instance is shared. The host never holds the registry lock during Wasm execution. Shared-memory observation uses only atomic accesses.

Non-goals

No async guest resources/streams/blobs, filesystem/network/process/random authority, broad WASI, public backend types, pool allocator, Tauri, timeout/fuel/epoch policy, cancellation, hostile blocked-atomic teardown, or forced thread termination. Cooperative normal completion only; containment belongs to #27/#28.

Dependencies and related work

Activity

  1. added
    enhancement
    on Aug 27, 2026
  2. zackees commented on Aug 27, 2026

    @zackees
    CollaboratorAuthor

    Lifecycle correction: command root is not Wasm instantiation

    The prior instantiate-only wording is temporary #34 substrate behavior and is superseded for the real Rust command profile.

    Definitive v1 lifecycle

    root:  InstancePre::instantiate(root Store) -> module start initializer
           -> exported _start() once -> Rust command CRT/main
    child: InstancePre::instantiate(fresh child Store) -> same initializer protocol
           -> exported wasi_thread_start(tid, opaque_start_arg) once
    

    Never call _start, __main_void, or kernal-api-run in a child. Never manually invoke the Wasm start section.

    The distinction is material: Wasmtime v45 says instantiation automatically executes the Wasm start function, explicitly not exported _start; its public InstancePre::instantiate uses that path. Wasmtime v45 instance source. Rust 1.95’s wasm32-wasip1-threads target enables imported/exported shared memory and passes --import-memory --export-memory --shared-memory --max-memory=1073741824. Exact target definition. Its bundled LLVM linker emits a synthetic shared-memory start (__wasm_init_memory/__wasm_start) for once-only passive-data initialization; it is not root business entry. Exact Rust 1.95 bundled LLVM source, tool-conventions rationale.

    The command CRT exports _start, which calls constructors and __main_void; that is the root-only user-code path. wasi-libc command CRT. The child entry is instead wasi_thread_start(i32, i32) -> (), which installs per-instance stack/TLS before invoking guest thread work. wasi-libc thread trampoline. Wasmtime’s v45 reference implementation uses fresh Store + instantiate + typed wasi_thread_start for children. Reference implementation.

    Verifier correction/evidence. The direct real-command artifact’s current characterization is instantiate => Started without a guest thread spawn; commit b508732 corrected the earlier expected Trapped assertion accordingly. That is the essential diagnostic: instantiate has not reached Rust main. The checked-in temporary root fixture reports one preparation and two supplied-runtime/kernel-yield observations over two explicit synthetic-root executions; it is not evidence for a real command artifact. No Wasm binary/hash is checked in, so no artifact digest is a stable acceptance value. The direct soldr rustc artifact remains diagnostic-only; soldr#2919 still blocks the Cargo-built acceptance path.

    #35 GREEN must prove: real Rust 1.95 command artifact, instantiate + _start once, root then two std::thread children; each child instantiate + wasi_thread_start once; no duplicate root main; shared-memory atomic result/TLS proof; no second compilation/prelink/memory/runtime identity. Reactor/library output stays deferred: it does not supply command main and Rust’s current reactor-thread initialization remains an upstream problem (rust-lang/rust#146843).

  3. zackees commented on Aug 27, 2026

    @zackees
    CollaboratorAuthor

    Merged threaded bootstrap in #40. Validation covered the Windows Soldr gates, managed Bosn 0.1.3 fmt/lint/test, and the direct Rust 1.95 validation artifact (SHA-256 BA33416332CCCF7F4DA879C6BC04D7BF6A3DDBBBF8D068546ACC3EFC7F157A21). #35 remains open because normal Cargo guest-artifact materialization is still blocked by soldr#2919.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions