Skip to content

Commit b6ccbd9

Browse files
authored
Merge pull request #697 from ChrisDenton/cleanup-win
Cleanup Windows trace modules
2 parents e33eaac + b1bc2e8 commit b6ccbd9

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

src/backtrace/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,15 @@ cfg_if::cfg_if! {
189189
} else if #[cfg(all(windows, not(target_vendor = "uwp")))] {
190190
cfg_if::cfg_if! {
191191
if #[cfg(any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "arm64ec"))] {
192-
mod dbghelp64;
193-
use dbghelp64 as dbghelp;
192+
mod win64;
193+
use self::win64::trace as trace_imp;
194+
pub(crate) use self::win64::Frame as FrameImp;
194195
} else if #[cfg(any(target_arch = "x86", target_arch = "arm"))] {
195-
mod dbghelp32;
196-
use dbghelp32 as dbghelp;
196+
mod win32;
197+
use self::win32::trace as trace_imp;
198+
pub(crate) use self::win32::Frame as FrameImp;
197199
}
198200
}
199-
use self::dbghelp::trace as trace_imp;
200-
pub(crate) use self::dbghelp::Frame as FrameImp;
201201
} else {
202202
mod noop;
203203
use self::noop::trace as trace_imp;

src/backtrace/dbghelp32.rs src/backtrace/win32.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
//! Note that all dbghelp support is loaded dynamically, see `src/dbghelp.rs`
1010
//! for more information about that.
1111
12-
#![allow(bad_style)]
13-
1412
use super::super::{dbghelp, windows_sys::*};
1513
use core::ffi::c_void;
1614
use core::mem;
@@ -111,14 +109,6 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
111109
Err(()) => return, // oh well...
112110
};
113111

114-
// On x86_64 and ARM64 we opt to not use the default `Sym*` functions from
115-
// dbghelp for getting the function table and module base. Instead we use
116-
// the `RtlLookupFunctionEntry` function in kernel32 which will account for
117-
// JIT compiler frames as well. These should be equivalent, but using
118-
// `Rtl*` allows us to backtrace through JIT frames.
119-
//
120-
// Note that `RtlLookupFunctionEntry` only works for in-process backtraces,
121-
// but that's all we support anyway, so it all lines up well.
122112
let function_table_access = dbghelp.SymFunctionTableAccess64();
123113
let get_module_base = dbghelp.SymGetModuleBase64();
124114

@@ -127,6 +117,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
127117
// Attempt to use `StackWalkEx` if we can, but fall back to `StackWalk64`
128118
// since it's in theory supported on more systems.
129119
match (*dbghelp.dbghelp()).StackWalkEx() {
120+
#[allow(non_snake_case)]
130121
Some(StackWalkEx) => {
131122
let mut inner: STACKFRAME_EX = mem::zeroed();
132123
inner.StackFrameSize = mem::size_of::<STACKFRAME_EX>() as u32;

src/backtrace/dbghelp64.rs src/backtrace/win64.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//! We still report inlined frames during symbolization by consulting the appropriate
77
//! `dbghelp` functions.
88
9-
#![allow(bad_style)]
10-
119
use super::super::windows_sys::*;
1210
use core::ffi::c_void;
1311

@@ -77,11 +75,6 @@ impl MyContext {
7775
}
7876
}
7977

80-
#[cfg(any(
81-
target_arch = "x86_64",
82-
target_arch = "aarch64",
83-
target_arch = "arm64ec"
84-
))]
8578
#[inline(always)]
8679
pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
8780
use core::ptr;
@@ -96,6 +89,10 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
9689
// The base address of the module containing the function will be stored here
9790
// when RtlLookupFunctionEntry returns successfully.
9891
let mut base = 0;
92+
// We use the `RtlLookupFunctionEntry` function in kernel32 which allows
93+
// us to backtrace through JIT frames.
94+
// Note that `RtlLookupFunctionEntry` only works for in-process backtraces,
95+
// but that's all we support anyway, so it all lines up well.
9996
let fn_entry = RtlLookupFunctionEntry(ip, &mut base, ptr::null_mut());
10097
if fn_entry.is_null() {
10198
// No function entry could be found - this may indicate a corrupt

0 commit comments

Comments
 (0)