1 use crate::types::{LucetFunctionSignature, LucetSandboxInstance, SizedBuffer};
2 
3 use lucet_module::Signature;
4 use lucet_runtime_internals::instance::InstanceInternal;
5 
6 use std::convert::TryFrom;
7 use std::ffi::c_void;
8 
9 #[no_mangle]
lucet_get_reserved_callback_slot_val( inst_ptr: *mut c_void, slot_number: u32, ) -> usize10 pub extern "C" fn lucet_get_reserved_callback_slot_val(
11     inst_ptr: *mut c_void,
12     slot_number: u32,
13 ) -> usize {
14     let inst = unsafe { &mut *(inst_ptr as *mut LucetSandboxInstance) };
15 
16     let name = format!("sandboxReservedCallbackSlot{}", slot_number);
17     let func = inst
18         .instance_handle
19         .module()
20         .get_export_func(&name)
21         .unwrap();
22     return func.ptr.as_usize();
23 }
24 
25 #[no_mangle]
lucet_get_function_pointer_table(inst_ptr: *mut c_void) -> SizedBuffer26 pub extern "C" fn lucet_get_function_pointer_table(inst_ptr: *mut c_void) -> SizedBuffer {
27     let inst = unsafe { &mut *(inst_ptr as *mut LucetSandboxInstance) };
28 
29     let elems = inst.instance_handle.module().table_elements().unwrap();
30 
31     SizedBuffer {
32         data: elems.as_ptr() as *mut c_void,
33         length: elems.len(),
34     }
35 }
36 
37 #[no_mangle]
lucet_get_function_type_index( inst_ptr: *mut c_void, csig: LucetFunctionSignature, ) -> i3238 pub extern "C" fn lucet_get_function_type_index(
39     inst_ptr: *mut c_void,
40     csig: LucetFunctionSignature,
41 ) -> i32 {
42     let inst = unsafe { &mut *(inst_ptr as *mut LucetSandboxInstance) };
43 
44     let conv_sig: Signature = csig.into();
45     let index = inst.signatures.iter().position(|r| *r == conv_sig);
46 
47     match index {
48         Some(x) => i32::try_from(x).unwrap_or(-1),
49         _ => -1,
50     }
51 }
52