Skip to content

Commit

Permalink
Fix demo on nightly
Browse files Browse the repository at this point in the history
Also, inline asm no longer works (segmentation fault).
  • Loading branch information
philipc committed Feb 25, 2019
1 parent 1a0ee47 commit f5fbf20
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions unwind/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ env_logger = "0.6"

[features]
nightly = []
asm = ["nightly"]
2 changes: 1 addition & 1 deletion unwind/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate gcc;
use std::env;

fn main() {
match env::var("CARGO_FEATURE_NIGHTLY") {
match env::var("CARGO_FEATURE_ASM") {
Err(env::VarError::NotPresent) => {
gcc::Build::new()
.file("src/unwind_helper.c")
Expand Down
8 changes: 4 additions & 4 deletions unwind/src/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use registers::Registers;

#[allow(improper_ctypes)] // trampoline just forwards the ptr
extern "C" {
#[cfg(not(feature = "nightly"))]
#[cfg(not(feature = "asm"))]
pub fn unwind_trampoline(payload: *mut UnwindPayload);
#[cfg(not(feature = "nightly"))]
#[cfg(not(feature = "asm"))]
fn unwind_lander(regs: *const LandingRegisters);
}

#[cfg(feature = "nightly")]
#[cfg(feature = "asm")]
#[naked]
pub unsafe extern fn unwind_trampoline(_payload: *mut UnwindPayload) {
asm!("
Expand All @@ -34,7 +34,7 @@ pub unsafe extern fn unwind_trampoline(_payload: *mut UnwindPayload) {
::std::hint::unreachable_unchecked();
}

#[cfg(feature = "nightly")]
#[cfg(feature = "asm")]
#[naked]
unsafe extern fn unwind_lander(_regs: *const LandingRegisters) {
asm!("
Expand Down
3 changes: 2 additions & 1 deletion unwind/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(feature = "nightly", feature(asm, naked_functions))]
#![cfg_attr(feature = "nightly", feature(unwind_attributes))]
#![cfg_attr(feature = "asm", feature(asm, naked_functions))]

extern crate gimli;
extern crate libc;
Expand Down
9 changes: 9 additions & 0 deletions unwind/src/libunwind_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub type _Unwind_Trace_Fn = extern "C" fn(ctx: *mut _Unwind_Context, arg: *mut c
-> _Unwind_Reason_Code;
type PersonalityRoutine = extern "C" fn(version: c_int, actions: c_int, class: u64, object: *mut _Unwind_Exception, context: *mut _Unwind_Context) -> _Unwind_Reason_Code;

// FIXME: we skip over this function when unwinding, so we should ensure
// it never needs any cleanup. Currently this is not true.
#[no_mangle]
pub unsafe extern "C" fn _Unwind_Resume(exception: *mut _Unwind_Exception) -> ! {
DwarfUnwinder::default().trace(|frames| unwind_tracer(frames, exception));
Expand Down Expand Up @@ -108,6 +110,13 @@ pub unsafe extern "C" fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut
pc // FIXME: implement this
}

// FIXME: Set `unwind(allowed)` because we need to be able to unwind this function as
// part of its operation. But this means any panics in this function are undefined
// behaviour, and we don't currently ensure it doesn't panic.
//
// On stable (1.32), `unwind(allowed)` is the default, but this will change in 1.33, with
// no stable way of setting `unwind(allowed)`, so this function will always abort in 1.33.
#[cfg_attr(feature = "nightly", unwind(allowed))]
#[no_mangle]
pub unsafe extern "C" fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code {
(*exception).private_contptr = None;
Expand Down

0 comments on commit f5fbf20

Please sign in to comment.