lunatic_sys/
lib.rs

1#[export_name = "lunatic_alloc"]
2pub extern "C" fn lunatic_alloc(len: u32) -> *mut u8 {
3    let buf = Vec::with_capacity(len as usize);
4    let mut buf = std::mem::ManuallyDrop::new(buf);
5    buf.as_mut_ptr()
6}
7
8/// This export is used by the host as a trampoline to re-enter the Wasm
9/// instance. Every re-entrance can be used as a point to catch a Wasm trap.
10#[export_name = "_lunatic_catch_trap"]
11extern "C" fn lunatic_catch_trap(function: usize, pointer: usize) -> usize {
12    let function: fn(usize) -> usize = unsafe { std::mem::transmute(function) };
13    function(pointer)
14}