mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-16 10:21:22 +00:00
feat(runtime-c-api) Add an API to update vm::Ctx.data
.
This patch adds 2 functions for the runtime C API, respectively `wasmer_instance_context_data_set` and `wasmer_instance_context_data_get`. The goal is to modify the `vm::Ctx.data` field in the `runtime-core` library. This is required to pass dynamic data to imported functions for instance.
This commit is contained in:
@ -947,6 +947,17 @@ pub unsafe extern "C" fn wasmer_instance_exports(
|
||||
*exports = Box::into_raw(named_exports) as *mut wasmer_exports_t;
|
||||
}
|
||||
|
||||
/// Sets the `data` field of the instance context. This context will be
|
||||
/// passed to all imported function for instance.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmer_instance_context_data_set(
|
||||
instance: *mut wasmer_instance_t,
|
||||
data_ptr: *mut c_void,
|
||||
) {
|
||||
let instance_ref = unsafe { &mut *(instance as *mut Instance) };
|
||||
instance_ref.context_mut().data = data_ptr;
|
||||
}
|
||||
|
||||
pub struct NamedExports(Vec<NamedExport>);
|
||||
|
||||
/// Frees the memory for the given exports
|
||||
@ -1350,6 +1361,15 @@ pub extern "C" fn wasmer_instance_context_memory(
|
||||
memory as *const Memory as *const wasmer_memory_t
|
||||
}
|
||||
|
||||
/// Gets the `data` field within the context.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmer_instance_context_data_get(
|
||||
ctx: *const wasmer_instance_context_t,
|
||||
) -> *mut c_void {
|
||||
let ctx = unsafe { &*(ctx as *const Ctx) };
|
||||
ctx.data
|
||||
}
|
||||
|
||||
/// Gets the start pointer to the bytes within a Memory
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
#[no_mangle]
|
||||
|
Reference in New Issue
Block a user