Skip to content

Commit 7e8e3d5

Browse files
committed
Apply unsafe_op_in_unsafe_fn
1 parent c047110 commit 7e8e3d5

File tree

10 files changed

+259
-218
lines changed

10 files changed

+259
-218
lines changed

src/backtrace/dbghelp64.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
8787
use core::ptr;
8888

8989
// Capture the initial context to start walking from.
90-
let mut context = core::mem::zeroed::<MyContext>();
91-
RtlCaptureContext(&mut context.0);
90+
let mut context = unsafe { core::mem::zeroed::<MyContext>() };
91+
unsafe { RtlCaptureContext(&mut context.0) };
9292

9393
loop {
9494
let ip = context.ip();
9595

9696
// The base address of the module containing the function will be stored here
9797
// when RtlLookupFunctionEntry returns successfully.
9898
let mut base = 0;
99-
let fn_entry = RtlLookupFunctionEntry(ip, &mut base, ptr::null_mut());
99+
let fn_entry = unsafe { RtlLookupFunctionEntry(ip, &mut base, ptr::null_mut()) };
100100
if fn_entry.is_null() {
101101
// No function entry could be found - this may indicate a corrupt
102102
// stack or that a binary was unloaded (amongst other issues). Stop
@@ -127,16 +127,18 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
127127
let previous_sp = context.sp();
128128
let mut handler_data = 0usize;
129129
let mut establisher_frame = 0;
130-
RtlVirtualUnwind(
131-
0,
132-
base,
133-
ip,
134-
fn_entry,
135-
&mut context.0,
136-
ptr::addr_of_mut!(handler_data).cast::<*mut c_void>(),
137-
&mut establisher_frame,
138-
ptr::null_mut(),
139-
);
130+
unsafe {
131+
RtlVirtualUnwind(
132+
0,
133+
base,
134+
ip,
135+
fn_entry,
136+
&mut context.0,
137+
ptr::addr_of_mut!(handler_data).cast::<*mut c_void>(),
138+
&mut establisher_frame,
139+
ptr::null_mut(),
140+
);
141+
}
140142

141143
// RtlVirtualUnwind indicates the end of the stack in two different ways:
142144
// * On x64, it sets the instruction pointer to 0.

src/backtrace/libunwind.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ impl Drop for Bomb {
113113

114114
#[inline(always)]
115115
pub unsafe fn trace(mut cb: &mut dyn FnMut(&super::Frame) -> bool) {
116-
uw::_Unwind_Backtrace(trace_fn, addr_of_mut!(cb).cast());
116+
unsafe {
117+
uw::_Unwind_Backtrace(trace_fn, addr_of_mut!(cb).cast());
118+
}
117119

118120
extern "C" fn trace_fn(
119121
ctx: *mut uw::_Unwind_Context,
@@ -209,7 +211,7 @@ mod uw {
209211
extern "C" {
210212
pub fn _Unwind_GetGR(ctx: *mut _Unwind_Context, index: libc::c_int) -> libc::uintptr_t;
211213
}
212-
_Unwind_GetGR(ctx, 15)
214+
unsafe { _Unwind_GetGR(ctx, 15) }
213215
}
214216
} else {
215217
use core::ptr::addr_of_mut;
@@ -259,13 +261,15 @@ mod uw {
259261
pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> libc::uintptr_t {
260262
let mut val: _Unwind_Word = 0;
261263
let ptr = addr_of_mut!(val);
262-
let _ = _Unwind_VRS_Get(
263-
ctx,
264-
_Unwind_VRS_RegClass::_UVRSC_CORE,
265-
15,
266-
_Unwind_VRS_DataRepresentation::_UVRSD_UINT32,
267-
ptr.cast::<c_void>(),
268-
);
264+
unsafe {
265+
let _ = _Unwind_VRS_Get(
266+
ctx,
267+
_Unwind_VRS_RegClass::_UVRSC_CORE,
268+
15,
269+
_Unwind_VRS_DataRepresentation::_UVRSD_UINT32,
270+
ptr.cast::<c_void>(),
271+
);
272+
}
269273
(val & !1) as libc::uintptr_t
270274
}
271275

@@ -275,13 +279,15 @@ mod uw {
275279
pub unsafe fn get_sp(ctx: *mut _Unwind_Context) -> libc::uintptr_t {
276280
let mut val: _Unwind_Word = 0;
277281
let ptr = addr_of_mut!(val);
278-
let _ = _Unwind_VRS_Get(
279-
ctx,
280-
_Unwind_VRS_RegClass::_UVRSC_CORE,
281-
SP,
282-
_Unwind_VRS_DataRepresentation::_UVRSD_UINT32,
283-
ptr.cast::<c_void>(),
284-
);
282+
unsafe {
283+
let _ = _Unwind_VRS_Get(
284+
ctx,
285+
_Unwind_VRS_RegClass::_UVRSC_CORE,
286+
SP,
287+
_Unwind_VRS_DataRepresentation::_UVRSD_UINT32,
288+
ptr.cast::<c_void>(),
289+
);
290+
}
285291
val as libc::uintptr_t
286292
}
287293

src/backtrace/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn trace<F: FnMut(&Frame) -> bool>(cb: F) {
6363
///
6464
/// See information on `trace` for caveats on `cb` panicking.
6565
pub unsafe fn trace_unsynchronized<F: FnMut(&Frame) -> bool>(mut cb: F) {
66-
trace_imp(&mut cb)
66+
unsafe { trace_imp(&mut cb) }
6767
}
6868

6969
/// A trait representing one frame of a backtrace, yielded to the `trace`

src/print/fuchsia.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'a> NoteIter<'a> {
148148
// can be anything but the range must be valid for this to be safe.
149149
unsafe fn new(base: *const u8, size: usize) -> Self {
150150
NoteIter {
151-
base: from_raw_parts(base, size),
151+
base: unsafe { from_raw_parts(base, size) },
152152
error: false,
153153
}
154154
}

0 commit comments

Comments
 (0)