diff --git a/src/arch/aarch64.rs b/src/arch/aarch64.rs index daf529c8..d2c623ac 100644 --- a/src/arch/aarch64.rs +++ b/src/arch/aarch64.rs @@ -222,7 +222,7 @@ pub unsafe fn swap_link(arg: usize, new_sp: StackPointer, : "={x0}" (ret) "={x1}" (ret_sp) : "{x0}" (arg) - "{x2}" (*new_sp.0) + "{x2}" (new_sp.offset(0)) "{x3}" (new_stack_base) :/*"x0", "x1",*/"x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", @@ -260,7 +260,7 @@ pub unsafe fn swap(arg: usize, new_sp: StackPointer) -> (usize, StackPointer) { : "={x0}" (ret) "={x1}" (ret_sp) : "{x0}" (arg) - "{x2}" (*new_sp.0) + "{x2}" (new_sp.offset(0)) :/*"x0", "x1",*/"x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", @@ -299,7 +299,7 @@ pub unsafe fn unwind(new_sp: StackPointer, new_stack_base: *mut u8) { : : "s" (unwind::start_unwind as usize) "{x0}" (arg) - "{x2}" (*new_sp.0) + "{x2}" (new_sp.offset(0)) "{x3}" (new_stack_base) : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", diff --git a/src/arch/arm.rs b/src/arch/arm.rs index a9d24db0..b40c293e 100644 --- a/src/arch/arm.rs +++ b/src/arch/arm.rs @@ -208,7 +208,7 @@ pub unsafe fn swap_link(arg: usize, new_sp: StackPointer, : "={r0}" (ret) "={r1}" (ret_sp) : "{r0}" (arg) - "{r2}" (*new_sp.0) + "{r2}" (new_sp.offset(0)) "{r3}" (new_stack_base) :/*r0, r1,*/ "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",/*r11,*/"r12",/*sp,*/ "lr", /*pc,*/ @@ -239,7 +239,7 @@ pub unsafe fn swap(arg: usize, new_sp: StackPointer) -> (usize, StackPointer) { : "={r0}" (ret) "={r1}" (ret_sp) : "{r0}" (arg) - "{r2}" (*new_sp.0) + "{r2}" (new_sp.offset(0)) :/*r0, r1,*/ "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",/*r11,*/"r12",/*sp,*/ "lr", /*pc,*/ "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", @@ -279,7 +279,7 @@ pub unsafe fn unwind(new_sp: StackPointer, new_stack_base: *mut u8) { : : "s" (unwind::start_unwind as usize) "{r0}" (arg) - "{r2}" (*new_sp.0) + "{r2}" (new_sp.offset(0)) "{r3}" (new_stack_base) : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",/*r11,*/"r12",/*sp,*/ "lr", /*pc,*/ diff --git a/src/arch/mod.rs b/src/arch/mod.rs index 2357277d..f603980b 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -7,7 +7,7 @@ // copied, modified, or distributed except according to those terms. pub use self::imp::*; -use core::nonzero::NonZero; +use core::ptr::NonNull; #[allow(unused_attributes)] // rust-lang/rust#35584 #[cfg_attr(target_arch = "x86", path = "x86.rs")] @@ -18,23 +18,23 @@ use core::nonzero::NonZero; mod imp; #[derive(Debug, Clone, Copy)] -pub struct StackPointer(NonZero<*mut usize>); +pub struct StackPointer(NonNull); impl StackPointer { #[inline(always)] pub unsafe fn push(&mut self, val: usize) { - self.0 = NonZero::new(self.0.offset(-1)); - **self.0 = val; + self.0 = NonNull::new_unchecked(self.0.as_ptr().offset(-1)); + *self.0.as_mut() = val; } #[inline(always)] pub unsafe fn new(sp: *mut u8) -> StackPointer { - StackPointer(NonZero::new(sp as *mut usize)) + StackPointer(NonNull::new_unchecked(sp as *mut usize)) } #[inline(always)] pub unsafe fn offset(&self, count: isize) -> *mut usize { - self.0.offset(count) + self.0.as_ptr().offset(count) } } diff --git a/src/arch/or1k.rs b/src/arch/or1k.rs index 0d0310fb..b5b42aa0 100644 --- a/src/arch/or1k.rs +++ b/src/arch/or1k.rs @@ -212,7 +212,7 @@ pub unsafe fn swap_link(arg: usize, new_sp: StackPointer, "={r4}" (ret_sp) : "s" (trampoline as usize) "{r3}" (arg) - "{r5}" (*new_sp.0) + "{r5}" (new_sp.offset(0)) "{r6}" (new_stack_base) :/*"r0", "r1", "r2", "r3", "r4",*/"r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", @@ -255,7 +255,7 @@ pub unsafe fn swap(arg: usize, new_sp: StackPointer) -> (usize, StackPointer) { "={r4}" (ret_sp) : "s" (trampoline as usize) "{r3}" (arg) - "{r5}" (*new_sp.0) + "{r5}" (new_sp.offset(0)) :/*"r0", "r1", "r2", "r3", "r4",*/"r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", @@ -306,7 +306,7 @@ pub unsafe fn unwind(new_sp: StackPointer, new_stack_base: *mut u8) { : : "s" (trampoline as usize) "{r3}" (arg) - "{r5}" (*new_sp.0) + "{r5}" (new_sp.offset(0)) "{r6}" (new_stack_base) :/*"r0", "r1", "r2",*/"r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", diff --git a/src/arch/x86.rs b/src/arch/x86.rs index 830a9670..65cf30cf 100644 --- a/src/arch/x86.rs +++ b/src/arch/x86.rs @@ -256,7 +256,7 @@ pub unsafe fn swap_link(arg: usize, new_sp: StackPointer, "={esi}" (ret_sp) : "s" (trampoline as usize) "{edi}" (arg) - "{edx}" (*new_sp.0) + "{edx}" (new_sp.offset(0)) "{ecx}" (new_stack_base) : "eax", "ebx", "ecx", "edx",/*"esi", "edi", "ebp", "esp",*/ "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", @@ -299,7 +299,7 @@ pub unsafe fn swap(arg: usize, new_sp: StackPointer) -> (usize, StackPointer) { "={esi}" (ret_sp) : "s" (trampoline as usize) "{edi}" (arg) - "{edx}" (*new_sp.0) + "{edx}" (new_sp.offset(0)) : "eax", "ebx", "ecx", "edx",/*"esi", "edi", "ebp", "esp",*/ "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", @@ -348,7 +348,7 @@ pub unsafe fn unwind(new_sp: StackPointer, new_stack_base: *mut u8) { : : "s" (trampoline as usize) "{edi}" (arg) - "{edx}" (*new_sp.0) + "{edx}" (new_sp.offset(0)) "{ecx}" (new_stack_base) : "eax", "ebx", "ecx", "edx", "esi", "edi",/*"ebp", "esp",*/ "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs index 48effe85..c69ac61b 100644 --- a/src/arch/x86_64.rs +++ b/src/arch/x86_64.rs @@ -230,7 +230,7 @@ pub unsafe fn swap_link(arg: usize, new_sp: StackPointer, : "={rdi}" (ret) "={rsi}" (ret_sp) : "{rdi}" (arg) - "{rdx}" (*new_sp.0) + "{rdx}" (new_sp.offset(0)) "{rcx}" (new_stack_base) : "rax", "rbx", "rcx", "rdx", /*"rsi", "rdi", "rbp", "rsp",*/ "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", @@ -269,7 +269,7 @@ pub unsafe fn swap(arg: usize, new_sp: StackPointer) -> (usize, StackPointer) { : "={rdi}" (ret) "={rsi}" (ret_sp) : "{rdi}" (arg) - "{rdx}" (*new_sp.0) + "{rdx}" (new_sp.offset(0)) : "rax", "rbx", "rcx", "rdx", /*"rsi", "rdi", "rbp", "rsp",*/ "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7", @@ -307,7 +307,7 @@ pub unsafe fn unwind(new_sp: StackPointer, new_stack_base: *mut u8) { : : "s" (unwind::start_unwind as usize) "{rdi}" (arg) - "{rdx}" (*new_sp.0) + "{rdx}" (new_sp.offset(0)) "{rcx}" (new_stack_base) : "rax", "rbx", "rcx", "rdx", "rsi", "rdi", /*"rbp", "rsp",*/ "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", diff --git a/src/lib.rs b/src/lib.rs index d7beb110..c24dac00 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms. -#![feature(asm, naked_functions, cfg_target_vendor, nonzero, untagged_unions)] +#![feature(asm, naked_functions, cfg_target_vendor, untagged_unions, unwind_attributes)] #![cfg_attr(feature = "alloc", feature(alloc, heap_api, allocator_api))] #![cfg_attr(test, feature(test))] #![no_std] diff --git a/src/unwind.rs b/src/unwind.rs index ebe4a30c..0d018f3d 100644 --- a/src/unwind.rs +++ b/src/unwind.rs @@ -34,6 +34,7 @@ fn have_cross_stack_unwind() -> bool { } // Wrapper around the root function of a generator which handles unwinding. +#[unwind(allowed)] pub unsafe extern "C" fn unwind_wrapper(arg: usize, sp: StackPointer, stack_base: *mut u8, f: unsafe fn(usize, StackPointer)) -> Option>> { // Catch any attempts to unwind out of the context. @@ -63,6 +64,7 @@ pub unsafe extern "C" fn unwind_wrapper(arg: usize, sp: StackPointer, stack_base // Called by asm to start unwinding in the current context with the given // exception object. +#[unwind(allowed)] pub unsafe extern "C" fn start_unwind(panic: Box>) -> ! { // Use resume_unwind instead of panic! to avoid printing a message. panic::resume_unwind(*panic)