Skip to content

Commit

Permalink
Make use of unsafe attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Oct 21, 2024
1 parent 41a5258 commit c5f39d6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/unwinder/find_fde/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 17 additions & 17 deletions src/unwinder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -87,41 +87,41 @@ 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
.map(|f| f.lsda() as *mut c_void)
.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
.map(|f| f.bases().eh_frame.text.unwrap() as _)
.unwrap_or(0)
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn _Unwind_GetDataRelBase(unwind_ctx: &UnwindContext<'_>) -> usize {
unwind_ctx
.frame
.map(|f| f.bases().eh_frame.data.unwrap() as _)
.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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 } {
Expand All @@ -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 {
Expand All @@ -380,15 +380,15 @@ 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) };
}
}

#[inline(never)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C-unwind" fn _Unwind_Backtrace(
trace: UnwindTraceFn,
trace_argument: *mut c_void,
Expand Down

0 comments on commit c5f39d6

Please sign in to comment.