Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Windows trace modules #697

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/backtrace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ cfg_if::cfg_if! {
} else if #[cfg(all(windows, not(target_vendor = "uwp")))] {
cfg_if::cfg_if! {
if #[cfg(any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "arm64ec"))] {
mod dbghelp64;
use dbghelp64 as dbghelp;
mod win64;
use self::win64::trace as trace_imp;
pub(crate) use self::win64::Frame as FrameImp;
} else if #[cfg(any(target_arch = "x86", target_arch = "arm"))] {
mod dbghelp32;
use dbghelp32 as dbghelp;
mod win32;
use self::win32::trace as trace_imp;
pub(crate) use self::win32::Frame as FrameImp;
}
}
use self::dbghelp::trace as trace_imp;
pub(crate) use self::dbghelp::Frame as FrameImp;
} else {
mod noop;
use self::noop::trace as trace_imp;
Expand Down
11 changes: 1 addition & 10 deletions src/backtrace/dbghelp32.rs → src/backtrace/win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
//! Note that all dbghelp support is loaded dynamically, see `src/dbghelp.rs`
//! for more information about that.

#![allow(bad_style)]

use super::super::{dbghelp, windows_sys::*};
use core::ffi::c_void;
use core::mem;
Expand Down Expand Up @@ -111,14 +109,6 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
Err(()) => return, // oh well...
};

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

Expand All @@ -127,6 +117,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
// Attempt to use `StackWalkEx` if we can, but fall back to `StackWalk64`
// since it's in theory supported on more systems.
match (*dbghelp.dbghelp()).StackWalkEx() {
#[allow(non_snake_case)]
Some(StackWalkEx) => {
let mut inner: STACKFRAME_EX = mem::zeroed();
inner.StackFrameSize = mem::size_of::<STACKFRAME_EX>() as u32;
Expand Down
11 changes: 4 additions & 7 deletions src/backtrace/dbghelp64.rs → src/backtrace/win64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
//! We still report inlined frames during symbolization by consulting the appropriate
//! `dbghelp` functions.

#![allow(bad_style)]

use super::super::windows_sys::*;
use core::ffi::c_void;

Expand Down Expand Up @@ -77,11 +75,6 @@ impl MyContext {
}
}

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