1
2
3
4
5
6
7
8
9
10
11
12
13
14
#[export_name = "lunatic_alloc"]
pub extern "C" fn lunatic_alloc(len: u32) -> *mut u8 {
    let buf = Vec::with_capacity(len as usize);
    let mut buf = std::mem::ManuallyDrop::new(buf);
    buf.as_mut_ptr()
}

/// This export is used by the host as a trampoline to re-enter the Wasm
/// instance. Every re-entrance can be used as a point to catch a Wasm trap.
#[export_name = "_lunatic_catch_trap"]
extern "C" fn lunatic_catch_trap(function: usize, pointer: usize) -> usize {
    let function: fn(usize) -> usize = unsafe { std::mem::transmute(function) };
    function(pointer)
}