From c5f39d61dcc4256f6381a248c5c01265c585060f Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 28 Sep 2024 13:00:53 +0100 Subject: [PATCH] Make use of unsafe attributes --- Cargo.lock | 2 +- Cargo.toml | 4 ++++ src/unwinder/find_fde/registry.rs | 18 ++++++++-------- src/unwinder/mod.rs | 34 +++++++++++++++---------------- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f6b15f5..deb6ad6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,7 +69,7 @@ dependencies = [ [[package]] name = "unwinding" -version = "0.2.2" +version = "0.2.3" dependencies = [ "compiler_builtins", "gimli", diff --git a/Cargo.toml b/Cargo.toml index dc7c364..d3e3161 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,10 @@ panic-handler-dummy = [] system-alloc = [] default = ["unwinder", "dwarf-expr", "hide-trace", "fde-phdr-dl", "fde-registry"] rustc-dep-of-std = ["core", "gimli/rustc-dep-of-std", "compiler_builtins"] +compiler_builtins = ["dep:compiler_builtins"] +core = ["dep:core"] +libc = ["dep:libc"] +spin = ["dep:spin"] [profile.release] debug = true diff --git a/src/unwinder/find_fde/registry.rs b/src/unwinder/find_fde/registry.rs index 1e74650..6933ca4 100644 --- a/src/unwinder/find_fde/registry.rs +++ b/src/unwinder/find_fde/registry.rs @@ -131,7 +131,7 @@ impl super::FDEFinder for Registry { } } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn __register_frame_info_bases( begin: *const c_void, ob: *mut Object, @@ -156,12 +156,12 @@ unsafe extern "C" fn __register_frame_info_bases( } } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn __register_frame_info(begin: *const c_void, ob: *mut Object) { unsafe { __register_frame_info_bases(begin, ob, core::ptr::null_mut(), core::ptr::null_mut()) } } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn __register_frame(begin: *const c_void) { if begin.is_null() { return; @@ -171,7 +171,7 @@ unsafe extern "C" fn __register_frame(begin: *const c_void) { unsafe { __register_frame_info(begin, storage) } } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn __register_frame_info_table_bases( begin: *const c_void, ob: *mut Object, @@ -192,14 +192,14 @@ unsafe extern "C" fn __register_frame_info_table_bases( } } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn __register_frame_info_table(begin: *const c_void, ob: *mut Object) { unsafe { __register_frame_info_table_bases(begin, ob, core::ptr::null_mut(), core::ptr::null_mut()) } } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn __register_frame_table(begin: *const c_void) { if begin.is_null() { return; @@ -209,7 +209,7 @@ unsafe extern "C" fn __register_frame_table(begin: *const c_void) { unsafe { __register_frame_info_table(begin, storage) } } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn __deregister_frame_info_bases(begin: *const c_void) -> *mut Object { if begin.is_null() { return core::ptr::null_mut(); @@ -237,12 +237,12 @@ extern "C" fn __deregister_frame_info_bases(begin: *const c_void) -> *mut Object core::ptr::null_mut() } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn __deregister_frame_info(begin: *const c_void) -> *mut Object { __deregister_frame_info_bases(begin) } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn __deregister_frame(begin: *const c_void) { if begin.is_null() { return; diff --git a/src/unwinder/mod.rs b/src/unwinder/mod.rs index 5bcc383..b6ae438 100644 --- a/src/unwinder/mod.rs +++ b/src/unwinder/mod.rs @@ -58,27 +58,27 @@ pub struct UnwindContext<'a> { signal: bool, } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn _Unwind_GetGR(unwind_ctx: &UnwindContext<'_>, index: c_int) -> usize { unwind_ctx.ctx[Register(index as u16)] } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn _Unwind_GetCFA(unwind_ctx: &UnwindContext<'_>) -> usize { unwind_ctx.ctx[Arch::SP] } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn _Unwind_SetGR(unwind_ctx: &mut UnwindContext<'_>, index: c_int, value: usize) { unwind_ctx.ctx[Register(index as u16)] = value; } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn _Unwind_GetIP(unwind_ctx: &UnwindContext<'_>) -> usize { unwind_ctx.ctx[Arch::RA] } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn _Unwind_GetIPInfo( unwind_ctx: &UnwindContext<'_>, ip_before_insn: &mut c_int, @@ -87,12 +87,12 @@ pub extern "C" fn _Unwind_GetIPInfo( unwind_ctx.ctx[Arch::RA] } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn _Unwind_SetIP(unwind_ctx: &mut UnwindContext<'_>, value: usize) { unwind_ctx.ctx[Arch::RA] = value; } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn _Unwind_GetLanguageSpecificData(unwind_ctx: &UnwindContext<'_>) -> *mut c_void { unwind_ctx .frame @@ -100,12 +100,12 @@ pub extern "C" fn _Unwind_GetLanguageSpecificData(unwind_ctx: &UnwindContext<'_> .unwrap_or(ptr::null_mut()) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn _Unwind_GetRegionStart(unwind_ctx: &UnwindContext<'_>) -> usize { unwind_ctx.frame.map(|f| f.initial_address()).unwrap_or(0) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn _Unwind_GetTextRelBase(unwind_ctx: &UnwindContext<'_>) -> usize { unwind_ctx .frame @@ -113,7 +113,7 @@ pub extern "C" fn _Unwind_GetTextRelBase(unwind_ctx: &UnwindContext<'_>) -> usiz .unwrap_or(0) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn _Unwind_GetDataRelBase(unwind_ctx: &UnwindContext<'_>) -> usize { unwind_ctx .frame @@ -121,7 +121,7 @@ pub extern "C" fn _Unwind_GetDataRelBase(unwind_ctx: &UnwindContext<'_>) -> usiz .unwrap_or(0) } -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn _Unwind_FindEnclosingFunction(pc: *mut c_void) -> *mut c_void { find_fde::get_finder() .find_fde(pc as usize - 1) @@ -148,7 +148,7 @@ macro_rules! try2 { } #[inline(never)] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C-unwind" fn _Unwind_RaiseException( exception: *mut UnwindException, ) -> UnwindReasonCode { @@ -252,7 +252,7 @@ fn raise_exception_phase2( } #[inline(never)] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C-unwind" fn _Unwind_ForcedUnwind( exception: *mut UnwindException, stop: UnwindStopFn, @@ -342,7 +342,7 @@ fn force_unwind_phase2( } #[inline(never)] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C-unwind" fn _Unwind_Resume(exception: *mut UnwindException) -> ! { with_context(|ctx| { let code = match unsafe { (*exception).private_1 } { @@ -362,7 +362,7 @@ pub unsafe extern "C-unwind" fn _Unwind_Resume(exception: *mut UnwindException) } #[inline(never)] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C-unwind" fn _Unwind_Resume_or_Rethrow( exception: *mut UnwindException, ) -> UnwindReasonCode { @@ -380,7 +380,7 @@ pub unsafe extern "C-unwind" fn _Unwind_Resume_or_Rethrow( }) } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn _Unwind_DeleteException(exception: *mut UnwindException) { if let Some(cleanup) = unsafe { (*exception).exception_cleanup } { unsafe { cleanup(UnwindReasonCode::FOREIGN_EXCEPTION_CAUGHT, exception) }; @@ -388,7 +388,7 @@ pub unsafe extern "C" fn _Unwind_DeleteException(exception: *mut UnwindException } #[inline(never)] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C-unwind" fn _Unwind_Backtrace( trace: UnwindTraceFn, trace_argument: *mut c_void,