Skip to content

Commit f5fbf20

Browse files
committed
Fix demo on nightly
Also, inline asm no longer works (segmentation fault).
1 parent 1a0ee47 commit f5fbf20

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

unwind/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ env_logger = "0.6"
1818

1919
[features]
2020
nightly = []
21+
asm = ["nightly"]

unwind/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate gcc;
22
use std::env;
33

44
fn main() {
5-
match env::var("CARGO_FEATURE_NIGHTLY") {
5+
match env::var("CARGO_FEATURE_ASM") {
66
Err(env::VarError::NotPresent) => {
77
gcc::Build::new()
88
.file("src/unwind_helper.c")

unwind/src/glue.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use registers::Registers;
44

55
#[allow(improper_ctypes)] // trampoline just forwards the ptr
66
extern "C" {
7-
#[cfg(not(feature = "nightly"))]
7+
#[cfg(not(feature = "asm"))]
88
pub fn unwind_trampoline(payload: *mut UnwindPayload);
9-
#[cfg(not(feature = "nightly"))]
9+
#[cfg(not(feature = "asm"))]
1010
fn unwind_lander(regs: *const LandingRegisters);
1111
}
1212

13-
#[cfg(feature = "nightly")]
13+
#[cfg(feature = "asm")]
1414
#[naked]
1515
pub unsafe extern fn unwind_trampoline(_payload: *mut UnwindPayload) {
1616
asm!("
@@ -34,7 +34,7 @@ pub unsafe extern fn unwind_trampoline(_payload: *mut UnwindPayload) {
3434
::std::hint::unreachable_unchecked();
3535
}
3636

37-
#[cfg(feature = "nightly")]
37+
#[cfg(feature = "asm")]
3838
#[naked]
3939
unsafe extern fn unwind_lander(_regs: *const LandingRegisters) {
4040
asm!("

unwind/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#![cfg_attr(feature = "nightly", feature(asm, naked_functions))]
1+
#![cfg_attr(feature = "nightly", feature(unwind_attributes))]
2+
#![cfg_attr(feature = "asm", feature(asm, naked_functions))]
23

34
extern crate gimli;
45
extern crate libc;

unwind/src/libunwind_shim.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub type _Unwind_Trace_Fn = extern "C" fn(ctx: *mut _Unwind_Context, arg: *mut c
5454
-> _Unwind_Reason_Code;
5555
type PersonalityRoutine = extern "C" fn(version: c_int, actions: c_int, class: u64, object: *mut _Unwind_Exception, context: *mut _Unwind_Context) -> _Unwind_Reason_Code;
5656

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

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

0 commit comments

Comments
 (0)