Add trampoline-related functions to C API.

This commit is contained in:
losfair
2019-06-03 21:59:33 +08:00
committed by Syrus
parent 7808c68cb2
commit d70cb9695e
5 changed files with 134 additions and 1 deletions

View File

@ -95,6 +95,8 @@ pub mod instance;
pub mod memory;
pub mod module;
pub mod table;
#[cfg(all(unix, target_arch = "x86_64"))]
pub mod trampoline;
pub mod value;
#[allow(non_camel_case_types)]

View File

@ -0,0 +1,54 @@
use std::ffi::c_void;
use wasmer_runtime_core::trampoline::*;
#[repr(C)]
pub struct wasmer_trampoline_buffer_builder_t;
#[repr(C)]
pub struct wasmer_trampoline_buffer_t;
#[repr(C)]
pub struct wasmer_trampoline_callable_t;
#[no_mangle]
pub extern "C" fn wasmer_trampoline_buffer_builder_new() -> *mut wasmer_trampoline_buffer_builder_t
{
Box::into_raw(Box::new(TrampolineBufferBuilder::new())) as *mut _
}
#[no_mangle]
pub unsafe extern "C" fn wasmer_trampoline_buffer_builder_add_function(
b: *mut wasmer_trampoline_buffer_builder_t,
f: *const wasmer_trampoline_callable_t,
ctx: *const c_void,
) -> usize {
let b = &mut *(b as *mut TrampolineBufferBuilder);
b.add_function(f as *const CallTarget, ctx as *const CallContext)
}
#[no_mangle]
pub unsafe extern "C" fn wasmer_trampoline_buffer_builder_build(
b: *mut wasmer_trampoline_buffer_builder_t,
) -> *mut wasmer_trampoline_buffer_t {
let b = Box::from_raw(b as *mut TrampolineBufferBuilder);
Box::into_raw(Box::new(b.build())) as *mut _
}
#[no_mangle]
pub unsafe extern "C" fn wasmer_trampoline_buffer_destroy(b: *mut wasmer_trampoline_buffer_t) {
Box::from_raw(b);
}
#[no_mangle]
pub unsafe extern "C" fn wasmer_trampoline_buffer_get_trampoline(
b: *const wasmer_trampoline_buffer_t,
idx: usize,
) -> *const wasmer_trampoline_callable_t {
let b = &*(b as *const TrampolineBuffer);
b.get_trampoline(idx) as _
}
#[no_mangle]
pub unsafe extern "C" fn wasmer_trampoline_get_context() -> *mut c_void {
get_context() as *const c_void as *mut c_void
}