Skip to content

Commit

Permalink
Correct base address and update dbghelp64 comment (#604)
Browse files Browse the repository at this point in the history
I've been staring at the code a lot lately but somehow missed that
we're returning the wrong thing for the module base. It *probably*
works out ok because
a) most things only care that the pointer points to something
  within the right module and
b) backtrace doesn't use it.

I added a comment because apparently I need the obvious pointed out
to me.

Also while I'm at it I updated a 64-bit comment to remove the stuff
commenting on 32-bit code (which is now in another file).
  • Loading branch information
ChrisDenton authored Mar 28, 2024
1 parent eabeb5e commit adc9f5c
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/backtrace/dbghelp64.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
//! Backtrace strategy for MSVC platforms.
//! Backtrace strategy for MSVC `x86_64` and `aarch64` platforms.
//!
//! This module contains the ability to capture a backtrace on MSVC using one
//! of three possible methods. For `x86_64` and `aarch64`, we use `RtlVirtualUnwind`
//! to walk the stack one frame at a time. This function is much faster than using
//! This module contains the ability to capture a backtrace on MSVC using
//! `RtlVirtualUnwind` to walk the stack one frame at a time. This function is much faster than using
//! `dbghelp!StackWalk*` because it does not load debug info to report inlined frames.
//! We still report inlined frames during symbolization by consulting the appropriate
//! `dbghelp` functions.
//!
//! For all other platforms, primarily `i686`, the `StackWalkEx` function is used if
//! possible, but not all systems have that. Failing that the `StackWalk64` function
//! is used instead. Note that `StackWalkEx` is favored because it handles debuginfo
//! internally and returns inline frame information.
//!
//! Note that all dbghelp support is loaded dynamically, see `src/dbghelp.rs`
//! for more information about that.

#![allow(bad_style)]

Expand Down Expand Up @@ -100,6 +91,8 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {

// Call `RtlVirtualUnwind` to find the previous stack frame, walking until we hit ip = 0.
while context.ip() != 0 {
// The base address of the module containing the function will be stored here
// when RtlLookupFunctionEntry returns successfully.
let mut base = 0;

let fn_entry = RtlLookupFunctionEntry(context.ip(), &mut base, ptr::null_mut());
Expand All @@ -109,7 +102,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {

let frame = super::Frame {
inner: Frame {
base_address: fn_entry.cast::<c_void>(),
base_address: base as *mut c_void,
ip: context.ip() as *mut c_void,
sp: context.sp() as *mut c_void,
#[cfg(not(target_env = "gnu"))]
Expand Down

0 comments on commit adc9f5c

Please sign in to comment.