wasmer_vm/libcalls/eh/mod.rs
1// Part of the logic, here, is borrowed as-is from rust's stdlib.
2
3use crate::{InternalStoreHandle, VMContext, VMExceptionObj};
4
5mod dwarf;
6
7cfg_if::cfg_if! {
8 if #[cfg(any(target_env = "msvc", target_family = "wasm"))] {
9 /// The implementation of Wasmer's personality function.
10 ///
11 /// # Safety
12 ///
13 /// Performs libunwind unwinding magic.
14 pub unsafe fn wasmer_eh_personality() {
15 panic!()
16 }
17
18 /// The second stage of the personality function. See module level documentation
19 /// for an explanation of the exact procedure used during unwinding.
20 ///
21 /// # Safety
22 ///
23 /// Does pointer accesses, which must be valid.
24 pub unsafe fn wasmer_eh_personality2() {
25 panic!()
26 }
27
28 pub unsafe fn read_exnref(_exception: *mut std::ffi::c_void) -> u32 {
29 panic!()
30 }
31
32 /// # Safety
33 ///
34 /// Performs libunwind unwinding magic. Highly unsafe.
35 pub unsafe fn throw(_ctx: &crate::StoreObjects, _exnref: u32) -> ! {
36 panic!()
37 }
38
39 /// Given a pointer to a caught exception, return the exnref contained within.
40 ///
41 /// # Safety
42 ///
43 /// `exception` must be a pointer the platform-specific exception type; this is
44 /// `UwExceptionWrapper` for gcc.
45 pub unsafe fn delete_exception(_exception: *mut std::ffi::c_void) {
46 panic!()
47 }
48 } else if #[cfg(any(
49 all(target_family = "windows", target_env = "gnu"),
50 target_family = "unix",
51 ))] {
52 // gcc-like eh-personality mechanisms.
53 mod gcc;
54 pub use gcc::*;
55 } else {
56 // Targets that don't support unwinding.
57 // - os=none ("bare metal" targets)
58 // - os=uefi
59 // - os=espidf
60 // - os=hermit
61 // - nvptx64-nvidia-cuda
62 // - arch=avr
63 }
64}
65
66pub(crate) fn exn_obj_from_exnref(vmctx: *mut VMContext, exnref: u32) -> *mut VMExceptionObj {
67 let instance = unsafe { (*vmctx).instance_mut() };
68 let exnref = InternalStoreHandle::<VMExceptionObj>::from_index(exnref as usize).unwrap();
69 let exn = exnref.get_mut(instance.context_mut());
70 exn as *mut VMExceptionObj
71}