1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Unwinding for emscripten
13 //! Whereas Rust's usual unwinding implementation for Unix platforms
14 //! calls into the libunwind APIs directly, on emscripten we instead
15 //! call into the C++ unwinding APIs. This is just an expedience since
16 //! emscripten's runtime always implements those APIs and does not
17 //! implement libunwind.
19 #![allow(private_no_mangle_fns)]
23 use alloc::boxed::Box;
24 use libc::{self, c_int};
28 pub fn payload() -> *mut u8 {
32 pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> {
33 assert!(!ptr.is_null());
34 let ex = ptr::read(ptr as *mut _);
35 __cxa_free_exception(ptr as *mut _);
39 pub unsafe fn panic(data: Box<Any + Send>) -> u32 {
40 let sz = mem::size_of_val(&data);
41 let exception = __cxa_allocate_exception(sz);
42 if exception == ptr::null_mut() {
43 return uw::_URC_FATAL_PHASE1_ERROR as u32;
45 let exception = exception as *mut Box<Any + Send>;
46 ptr::write(exception, data);
47 __cxa_throw(exception as *mut _, ptr::null_mut(), ptr::null_mut());
52 #[lang = "eh_personality"]
54 unsafe extern "C" fn rust_eh_personality(version: c_int,
55 actions: uw::_Unwind_Action,
56 exception_class: uw::_Unwind_Exception_Class,
57 exception_object: *mut uw::_Unwind_Exception,
58 context: *mut uw::_Unwind_Context)
59 -> uw::_Unwind_Reason_Code {
60 __gxx_personality_v0(version, actions, exception_class, exception_object, context)
64 fn __cxa_allocate_exception(thrown_size: libc::size_t) -> *mut libc::c_void;
65 fn __cxa_free_exception(thrown_exception: *mut libc::c_void);
66 fn __cxa_throw(thrown_exception: *mut libc::c_void,
67 tinfo: *mut libc::c_void,
68 dest: *mut libc::c_void);
69 fn __gxx_personality_v0(version: c_int,
70 actions: uw::_Unwind_Action,
71 exception_class: uw::_Unwind_Exception_Class,
72 exception_object: *mut uw::_Unwind_Exception,
73 context: *mut uw::_Unwind_Context)
74 -> uw::_Unwind_Reason_Code;