Skip to content

Commit

Permalink
unwind: Apply unsafe_op_in_unsafe_fn
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss authored and gitbot committed Mar 4, 2025
1 parent 43f085c commit c49e782
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)]
#![allow(internal_features)]
#![cfg_attr(not(bootstrap), feature(cfg_emscripten_wasm_eh))]
#![deny(unsafe_op_in_unsafe_fn)]

// Force libc to be included even if unused. This is required by many platforms.
#[cfg(not(all(windows, target_env = "msvc")))]
Expand Down
20 changes: 11 additions & 9 deletions unwind/src/libunwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,36 +218,38 @@ if #[cfg(any(target_vendor = "apple", target_os = "netbsd", not(target_arch = "a

pub unsafe fn _Unwind_GetGR(ctx: *mut _Unwind_Context, reg_index: c_int) -> _Unwind_Word {
let mut val: _Unwind_Word = core::ptr::null();
_Unwind_VRS_Get(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
(&raw mut val) as *mut c_void);
unsafe { _Unwind_VRS_Get(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
(&raw mut val) as *mut c_void); }
val
}

pub unsafe fn _Unwind_SetGR(ctx: *mut _Unwind_Context, reg_index: c_int, value: _Unwind_Word) {
let mut value = value;
_Unwind_VRS_Set(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
(&raw mut value) as *mut c_void);
unsafe { _Unwind_VRS_Set(ctx, _UVRSC_CORE, reg_index as _Unwind_Word, _UVRSD_UINT32,
(&raw mut value) as *mut c_void); }
}

pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context)
-> _Unwind_Word {
let val = _Unwind_GetGR(ctx, UNWIND_IP_REG);
let val = unsafe { _Unwind_GetGR(ctx, UNWIND_IP_REG) };
val.map_addr(|v| v & !1)
}

pub unsafe fn _Unwind_SetIP(ctx: *mut _Unwind_Context,
value: _Unwind_Word) {
// Propagate thumb bit to instruction pointer
let thumb_state = _Unwind_GetGR(ctx, UNWIND_IP_REG).addr() & 1;
let thumb_state = unsafe { _Unwind_GetGR(ctx, UNWIND_IP_REG).addr() & 1 };
let value = value.map_addr(|v| v | thumb_state);
_Unwind_SetGR(ctx, UNWIND_IP_REG, value);
unsafe { _Unwind_SetGR(ctx, UNWIND_IP_REG, value); }
}

pub unsafe fn _Unwind_GetIPInfo(ctx: *mut _Unwind_Context,
ip_before_insn: *mut c_int)
-> _Unwind_Word {
*ip_before_insn = 0;
_Unwind_GetIP(ctx)
unsafe {
*ip_before_insn = 0;
_Unwind_GetIP(ctx)
}
}

// This function also doesn't exist on Android or ARM/Linux, so make it a no-op
Expand Down

0 comments on commit c49e782

Please sign in to comment.