mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-27 15:41:33 +00:00
Naming fixes and documentation for trampoline API.
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
//! Trampoline emitter for transforming function calls.
|
||||
|
||||
use std::ffi::c_void;
|
||||
use std::mem;
|
||||
use wasmer_runtime_core::trampoline::*;
|
||||
|
||||
#[repr(C)]
|
||||
@ -10,6 +13,7 @@ pub struct wasmer_trampoline_buffer_t;
|
||||
#[repr(C)]
|
||||
pub struct wasmer_trampoline_callable_t;
|
||||
|
||||
/// Creates a new trampoline builder.
|
||||
#[no_mangle]
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
pub extern "C" fn wasmer_trampoline_buffer_builder_new() -> *mut wasmer_trampoline_buffer_builder_t
|
||||
@ -17,58 +21,62 @@ pub extern "C" fn wasmer_trampoline_buffer_builder_new() -> *mut wasmer_trampoli
|
||||
Box::into_raw(Box::new(TrampolineBufferBuilder::new())) as *mut _
|
||||
}
|
||||
|
||||
/// Adds a context trampoline to the builder.
|
||||
#[no_mangle]
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
pub unsafe extern "C" fn wasmer_trampoline_buffer_builder_add_context_trampoline(
|
||||
b: *mut wasmer_trampoline_buffer_builder_t,
|
||||
f: *const wasmer_trampoline_callable_t,
|
||||
builder: *mut wasmer_trampoline_buffer_builder_t,
|
||||
func: *const wasmer_trampoline_callable_t,
|
||||
ctx: *const c_void,
|
||||
) -> usize {
|
||||
let b = &mut *(b as *mut TrampolineBufferBuilder);
|
||||
b.add_context_trampoline(f as *const CallTarget, ctx as *const CallContext)
|
||||
let builder = &mut *(builder as *mut TrampolineBufferBuilder);
|
||||
builder.add_context_trampoline(func as *const CallTarget, ctx as *const CallContext)
|
||||
}
|
||||
|
||||
/// Adds a callinfo trampoline to the builder.
|
||||
#[no_mangle]
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
pub unsafe extern "C" fn wasmer_trampoline_buffer_builder_add_callinfo_trampoline(
|
||||
b: *mut wasmer_trampoline_buffer_builder_t,
|
||||
f: *const wasmer_trampoline_callable_t,
|
||||
builder: *mut wasmer_trampoline_buffer_builder_t,
|
||||
func: *const wasmer_trampoline_callable_t,
|
||||
ctx: *const c_void,
|
||||
num_params: u32,
|
||||
) -> usize {
|
||||
let b = &mut *(b as *mut TrampolineBufferBuilder);
|
||||
b.add_callinfo_trampoline(
|
||||
::std::mem::transmute(f),
|
||||
ctx as *const CallContext,
|
||||
num_params,
|
||||
)
|
||||
let builder = &mut *(builder as *mut TrampolineBufferBuilder);
|
||||
builder.add_callinfo_trampoline(mem::transmute(func), ctx as *const CallContext, num_params)
|
||||
}
|
||||
|
||||
/// Finalizes the trampoline builder into an executable buffer.
|
||||
#[no_mangle]
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
pub unsafe extern "C" fn wasmer_trampoline_buffer_builder_build(
|
||||
b: *mut wasmer_trampoline_buffer_builder_t,
|
||||
builder: *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 _
|
||||
let builder = Box::from_raw(builder as *mut TrampolineBufferBuilder);
|
||||
Box::into_raw(Box::new(builder.build())) as *mut _
|
||||
}
|
||||
|
||||
/// Destroys the trampoline buffer if not null.
|
||||
#[no_mangle]
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
pub unsafe extern "C" fn wasmer_trampoline_buffer_destroy(b: *mut wasmer_trampoline_buffer_t) {
|
||||
Box::from_raw(b);
|
||||
pub unsafe extern "C" fn wasmer_trampoline_buffer_destroy(buffer: *mut wasmer_trampoline_buffer_t) {
|
||||
if !buffer.is_null() {
|
||||
Box::from_raw(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the callable pointer for the trampoline with index `idx`.
|
||||
#[no_mangle]
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
pub unsafe extern "C" fn wasmer_trampoline_buffer_get_trampoline(
|
||||
b: *const wasmer_trampoline_buffer_t,
|
||||
buffer: *const wasmer_trampoline_buffer_t,
|
||||
idx: usize,
|
||||
) -> *const wasmer_trampoline_callable_t {
|
||||
let b = &*(b as *const TrampolineBuffer);
|
||||
b.get_trampoline(idx) as _
|
||||
let buffer = &*(buffer as *const TrampolineBuffer);
|
||||
buffer.get_trampoline(idx) as _
|
||||
}
|
||||
|
||||
/// Returns the context added by `add_context_trampoline`, from within the callee function.
|
||||
#[no_mangle]
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
pub unsafe extern "C" fn wasmer_trampoline_get_context() -> *mut c_void {
|
||||
|
@ -596,24 +596,45 @@ uint32_t wasmer_table_length(wasmer_table_t *table);
|
||||
*/
|
||||
wasmer_result_t wasmer_table_new(wasmer_table_t **table, wasmer_limits_t limits);
|
||||
|
||||
uintptr_t wasmer_trampoline_buffer_builder_add_callinfo_trampoline(wasmer_trampoline_buffer_builder_t *b,
|
||||
const wasmer_trampoline_callable_t *f,
|
||||
/**
|
||||
* Adds a callinfo trampoline to the builder.
|
||||
*/
|
||||
uintptr_t wasmer_trampoline_buffer_builder_add_callinfo_trampoline(wasmer_trampoline_buffer_builder_t *builder,
|
||||
const wasmer_trampoline_callable_t *func,
|
||||
const void *ctx,
|
||||
uint32_t num_params);
|
||||
|
||||
uintptr_t wasmer_trampoline_buffer_builder_add_context_trampoline(wasmer_trampoline_buffer_builder_t *b,
|
||||
const wasmer_trampoline_callable_t *f,
|
||||
/**
|
||||
* Adds a context trampoline to the builder.
|
||||
*/
|
||||
uintptr_t wasmer_trampoline_buffer_builder_add_context_trampoline(wasmer_trampoline_buffer_builder_t *builder,
|
||||
const wasmer_trampoline_callable_t *func,
|
||||
const void *ctx);
|
||||
|
||||
wasmer_trampoline_buffer_t *wasmer_trampoline_buffer_builder_build(wasmer_trampoline_buffer_builder_t *b);
|
||||
/**
|
||||
* Finalizes the trampoline builder into an executable buffer.
|
||||
*/
|
||||
wasmer_trampoline_buffer_t *wasmer_trampoline_buffer_builder_build(wasmer_trampoline_buffer_builder_t *builder);
|
||||
|
||||
/**
|
||||
* Creates a new trampoline builder.
|
||||
*/
|
||||
wasmer_trampoline_buffer_builder_t *wasmer_trampoline_buffer_builder_new(void);
|
||||
|
||||
void wasmer_trampoline_buffer_destroy(wasmer_trampoline_buffer_t *b);
|
||||
/**
|
||||
* Destroys the trampoline buffer if not null.
|
||||
*/
|
||||
void wasmer_trampoline_buffer_destroy(wasmer_trampoline_buffer_t *buffer);
|
||||
|
||||
const wasmer_trampoline_callable_t *wasmer_trampoline_buffer_get_trampoline(const wasmer_trampoline_buffer_t *b,
|
||||
/**
|
||||
* Returns the callable pointer for the trampoline with index `idx`.
|
||||
*/
|
||||
const wasmer_trampoline_callable_t *wasmer_trampoline_buffer_get_trampoline(const wasmer_trampoline_buffer_t *buffer,
|
||||
uintptr_t idx);
|
||||
|
||||
/**
|
||||
* Returns the context added by `add_context_trampoline`, from within the callee function.
|
||||
*/
|
||||
void *wasmer_trampoline_get_context(void);
|
||||
|
||||
/**
|
||||
|
@ -470,24 +470,31 @@ uint32_t wasmer_table_length(wasmer_table_t *table);
|
||||
/// and `wasmer_last_error_message` to get an error message.
|
||||
wasmer_result_t wasmer_table_new(wasmer_table_t **table, wasmer_limits_t limits);
|
||||
|
||||
uintptr_t wasmer_trampoline_buffer_builder_add_callinfo_trampoline(wasmer_trampoline_buffer_builder_t *b,
|
||||
const wasmer_trampoline_callable_t *f,
|
||||
/// Adds a callinfo trampoline to the builder.
|
||||
uintptr_t wasmer_trampoline_buffer_builder_add_callinfo_trampoline(wasmer_trampoline_buffer_builder_t *builder,
|
||||
const wasmer_trampoline_callable_t *func,
|
||||
const void *ctx,
|
||||
uint32_t num_params);
|
||||
|
||||
uintptr_t wasmer_trampoline_buffer_builder_add_context_trampoline(wasmer_trampoline_buffer_builder_t *b,
|
||||
const wasmer_trampoline_callable_t *f,
|
||||
/// Adds a context trampoline to the builder.
|
||||
uintptr_t wasmer_trampoline_buffer_builder_add_context_trampoline(wasmer_trampoline_buffer_builder_t *builder,
|
||||
const wasmer_trampoline_callable_t *func,
|
||||
const void *ctx);
|
||||
|
||||
wasmer_trampoline_buffer_t *wasmer_trampoline_buffer_builder_build(wasmer_trampoline_buffer_builder_t *b);
|
||||
/// Finalizes the trampoline builder into an executable buffer.
|
||||
wasmer_trampoline_buffer_t *wasmer_trampoline_buffer_builder_build(wasmer_trampoline_buffer_builder_t *builder);
|
||||
|
||||
/// Creates a new trampoline builder.
|
||||
wasmer_trampoline_buffer_builder_t *wasmer_trampoline_buffer_builder_new();
|
||||
|
||||
void wasmer_trampoline_buffer_destroy(wasmer_trampoline_buffer_t *b);
|
||||
/// Destroys the trampoline buffer if not null.
|
||||
void wasmer_trampoline_buffer_destroy(wasmer_trampoline_buffer_t *buffer);
|
||||
|
||||
const wasmer_trampoline_callable_t *wasmer_trampoline_buffer_get_trampoline(const wasmer_trampoline_buffer_t *b,
|
||||
/// Returns the callable pointer for the trampoline with index `idx`.
|
||||
const wasmer_trampoline_callable_t *wasmer_trampoline_buffer_get_trampoline(const wasmer_trampoline_buffer_t *buffer,
|
||||
uintptr_t idx);
|
||||
|
||||
/// Returns the context added by `add_context_trampoline`, from within the callee function.
|
||||
void *wasmer_trampoline_get_context();
|
||||
|
||||
/// Returns true for valid wasm bytes and false for invalid bytes
|
||||
|
Reference in New Issue
Block a user