forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite emscripten unwinding to use libcxx
- Loading branch information
Showing
5 changed files
with
93 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![allow(private_no_mangle_fns)] | ||
|
||
use core::any::Any; | ||
use core::ptr; | ||
use alloc::boxed::Box; | ||
use libc::{self, c_int}; | ||
use unwind as uw; | ||
use core::mem; | ||
|
||
pub fn payload() -> *mut u8 { | ||
ptr::null_mut() | ||
} | ||
|
||
pub unsafe fn cleanup(ptr: *mut u8) -> Box<Any + Send> { | ||
assert!(!ptr.is_null()); | ||
let ex = ptr::read(ptr as *mut _); | ||
__cxa_free_exception(ptr as *mut _); | ||
ex | ||
} | ||
|
||
pub unsafe fn panic(data: Box<Any + Send>) -> u32 { | ||
let sz = mem::size_of_val(&data); | ||
let exception = __cxa_allocate_exception(sz); | ||
if exception == ptr::null_mut() { | ||
return uw::_URC_FATAL_PHASE1_ERROR as u32; | ||
} | ||
let exception = exception as *mut Box<Any + Send>; | ||
ptr::write(exception, data); | ||
__cxa_throw(exception as *mut _, ptr::null_mut(), ptr::null_mut()); | ||
|
||
unreachable!() | ||
} | ||
|
||
#[lang = "eh_personality"] | ||
#[no_mangle] | ||
unsafe extern "C" fn rust_eh_personality(version: c_int, | ||
actions: uw::_Unwind_Action, | ||
exception_class: uw::_Unwind_Exception_Class, | ||
exception_object: *mut uw::_Unwind_Exception, | ||
context: *mut uw::_Unwind_Context) | ||
-> uw::_Unwind_Reason_Code { | ||
__gxx_personality_v0(version, actions, | ||
exception_class, | ||
exception_object, | ||
context) | ||
} | ||
|
||
#[lang = "eh_unwind_resume"] | ||
#[unwind] | ||
unsafe extern "C" fn rust_eh_unwind_resume(panic_ctx: *mut u8) -> ! { | ||
uw::_Unwind_Resume(panic_ctx as *mut uw::_Unwind_Exception); | ||
} | ||
|
||
extern { | ||
fn __cxa_allocate_exception(thrown_size: libc::size_t) -> *mut libc::c_void; | ||
fn __cxa_free_exception(thrown_exception: *mut libc::c_void); | ||
fn __cxa_throw(thrown_exception: *mut libc::c_void, | ||
tinfo: *mut libc::c_void, | ||
dest: *mut libc::c_void); | ||
fn __gxx_personality_v0(version: c_int, | ||
actions: uw::_Unwind_Action, | ||
exception_class: uw::_Unwind_Exception_Class, | ||
exception_object: *mut uw::_Unwind_Exception, | ||
context: *mut uw::_Unwind_Context) | ||
-> uw::_Unwind_Reason_Code; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters