mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-27 15:41:33 +00:00
Add trampoline-related functions to C API.
This commit is contained in:
@ -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)]
|
||||
|
54
lib/runtime-c-api/src/trampoline.rs
Normal file
54
lib/runtime-c-api/src/trampoline.rs
Normal 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
|
||||
}
|
Reference in New Issue
Block a user