Skip to content

hyperlight-wasm capi - #564

Draft
ludfjig wants to merge 4 commits into
mainfrom
hyperlight-0.18-capi
Draft

ludfjig wants to merge 4 commits into
mainfrom
hyperlight-0.18-capi

Conversation

@ludfjig

@ludfjig ludfjig commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

No description provided.

// SAFETY: guaranteed by the caller.
let name = try_c!(unsafe { str(name, name_len) });
// SAFETY: guaranteed by the caller.
let State::Proto(proto) = &mut unsafe { &mut *sandbox }.state else {
// SAFETY: guaranteed by the caller.
let path = try_c!(unsafe { str(path, len) });
// SAFETY: guaranteed by the caller.
load(unsafe { &mut *sandbox }, |s| s.load_module(path))
// SAFETY: guaranteed by the caller.
let data = unsafe { slice(data, len) };
// SAFETY: guaranteed by the caller.
load(unsafe { &mut *sandbox }, |s| {
.map(|a| unsafe { slice(a.data, a.len) }.to_vec())
.collect();
// SAFETY: guaranteed by the caller.
let sandbox = unsafe { &mut *sandbox };
out: *mut *mut hlw_snapshot,
) -> *mut hlw_error {
// SAFETY: guaranteed by the caller.
let loaded = try_c!(loaded(unsafe { &mut *sandbox }));
snapshot: *const hlw_snapshot,
) -> *mut hlw_error {
// SAFETY: guaranteed by the caller.
let loaded = try_c!(loaded(unsafe { &mut *sandbox }));
// SAFETY: guaranteed by the caller.
let loaded = try_c!(loaded(unsafe { &mut *sandbox }));
// SAFETY: guaranteed by the caller.
let snapshot = unsafe { &*snapshot }.snapshot.clone();
out: *mut *mut hlw_interrupt_handle,
) -> *mut hlw_error {
// SAFETY: guaranteed by the caller.
let loaded = try_c!(loaded(unsafe { &mut *sandbox }));
#[unsafe(no_mangle)]
pub unsafe extern "C" fn hlw_interrupt_handle_kill(handle: *const hlw_interrupt_handle) -> bool {
// SAFETY: guaranteed by the caller.
unsafe { &*handle }.handle.kill()
@ludfjig
ludfjig force-pushed the hyperlight-0.18-capi branch 2 times, most recently from 5783d57 to bda3ce3 Compare October 30, 2026 20:01
Build against the hyperlight branch with the component wire format, which
names component functions <instance>#<function> and encodes numbers
little-endian. Hosts and guests built with earlier versions cannot call
each other.

Wasm traps go through the undefined instruction hook, which turns a trap
into a guest call error instead of a general protection fault.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
SandboxBuilder::with_runtime_file loads the guest runtime from a file
instead of the one built into the crate. A host built once can then run
components of any world whose runtime was built separately.

SandboxBuilder::with_interrupt_vcpu_sigrtmin_offset changes the signal
that interrupts a running guest on Linux. Hosts such as .NET use SIGRTMIN
themselves.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
Add hyperlight-wasm-capi, a C library declared in
include/hyperlight_wasm.h. It registers host functions, loads
components, calls guest functions, and snapshots, restores and
interrupts sandboxes.

Arguments and results are byte buffers in hyperlight's component wire
format, so the library needs no knowledge of a component's WIT. Host
functions take up to 32 parameters. A panic in a guest call becomes an
error and leaves the sandbox unusable.

just examples-components runs its tests against the component_sample
example world.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
Hyperlight.Wasm runs components from .NET through the C API. WasmSandbox
registers host functions, loads components and calls them, with
snapshots, interrupts and CancellationToken support. Host exceptions
become the InnerException of the failed call. The interrupt signal
defaults to SIGRTMIN + 1, because the .NET runtime suspends threads for
garbage collection with SIGRTMIN. With offset 0 a collection can hang.

Hyperlight.Wasm.Build generates C# bindings from HyperlightWit items at
build time. Its MSBuild task loads hyperlight-wasm-bindgen, a native
library around hyperlight's C# generator, so builds need no Rust.

just dotnet-test runs the tests against the component_sample example
world. just dotnet-pack packs both packages for the build machine's
runtime identifier.

Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
@ludfjig
ludfjig force-pushed the hyperlight-0.18-capi branch from bda3ce3 to fbcf9c8 Compare October 30, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants