Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind Trap::i32_exit_status in C API #1912

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/c-api/include/wasmtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ WASM_API_EXTERN own wasmtime_interrupt_handle_t *wasmtime_interrupt_handle_new(w

WASM_API_EXTERN void wasmtime_interrupt_handle_interrupt(wasmtime_interrupt_handle_t *handle);

///////////////////////////////////////////////////////////////////////////////
//
// Extensions to `wasm_trap_t`

// Returns `true` if the trap is a WASI "exit" trap and has a return status. If
// `true` is returned then the exit status is returned through the `status`
// pointer. If `false` is returned then this is not a wasi exit trap.
WASM_API_EXTERN bool wasmtime_trap_exit_status(const wasm_trap_t*, int *status);

///////////////////////////////////////////////////////////////////////////////
//
// Extensions to `wasm_frame_t`
Expand Down
12 changes: 12 additions & 0 deletions crates/c-api/src/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ pub extern "C" fn wasm_trap_trace(raw: &wasm_trap_t, out: &mut wasm_frame_vec_t)
out.set_buffer(vec);
}

#[no_mangle]
pub extern "C" fn wasmtime_trap_exit_status(raw: &wasm_trap_t, status: &mut i32) -> bool {
let trap = raw.trap.borrow();
match trap.i32_exit_status() {
Some(i) => {
*status = i;
true
}
None => false,
}
}

#[no_mangle]
pub extern "C" fn wasm_frame_func_index(frame: &wasm_frame_t) -> u32 {
frame.trap.borrow().trace()[frame.idx].func_index()
Expand Down