mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-15 23:25:41 +00:00
55 lines
1.5 KiB
Rust
55 lines
1.5 KiB
Rust
|
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
|
||
|
}
|