Skip to content

Commit

Permalink
Merge pull request #573 from kleisauke/thumbv7a-win-compat
Browse files Browse the repository at this point in the history
Fix build errors on `thumbv7a-*-windows-msvc` targets
  • Loading branch information
ChrisDenton committed Nov 6, 2023
2 parents e9da96e + 3f9d175 commit aa0a5e2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
48 changes: 42 additions & 6 deletions src/backtrace/dbghelp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,42 @@ impl MyContext {
}
}

#[cfg(target_arch = "x86")]
impl MyContext {
#[inline(always)]
fn ip(&self) -> DWORD {
self.0.Eip
}

#[inline(always)]
fn sp(&self) -> DWORD {
self.0.Esp
}

#[inline(always)]
fn fp(&self) -> DWORD {
self.0.Ebp
}
}

#[cfg(target_arch = "arm")]
impl MyContext {
#[inline(always)]
fn ip(&self) -> DWORD {
self.0.Pc
}

#[inline(always)]
fn sp(&self) -> DWORD {
self.0.Sp
}

#[inline(always)]
fn fp(&self) -> DWORD {
self.0.R11
}
}

#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
#[inline(always)]
pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
Expand Down Expand Up @@ -167,11 +203,11 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
Some(StackWalkEx) => {
let mut stack_frame_ex: STACKFRAME_EX = mem::zeroed();
stack_frame_ex.StackFrameSize = mem::size_of::<STACKFRAME_EX>() as DWORD;
stack_frame_ex.AddrPC.Offset = context.0.Eip as u64;
stack_frame_ex.AddrPC.Offset = context.ip() as u64;
stack_frame_ex.AddrPC.Mode = AddrModeFlat;
stack_frame_ex.AddrStack.Offset = context.0.Esp as u64;
stack_frame_ex.AddrStack.Offset = context.sp() as u64;
stack_frame_ex.AddrStack.Mode = AddrModeFlat;
stack_frame_ex.AddrFrame.Offset = context.0.Ebp as u64;
stack_frame_ex.AddrFrame.Offset = context.fp() as u64;
stack_frame_ex.AddrFrame.Mode = AddrModeFlat;

while StackWalkEx(
Expand Down Expand Up @@ -205,11 +241,11 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
}
None => {
let mut stack_frame64: STACKFRAME64 = mem::zeroed();
stack_frame64.AddrPC.Offset = context.0.Eip as u64;
stack_frame64.AddrPC.Offset = context.ip() as u64;
stack_frame64.AddrPC.Mode = AddrModeFlat;
stack_frame64.AddrStack.Offset = context.0.Esp as u64;
stack_frame64.AddrStack.Offset = context.sp() as u64;
stack_frame64.AddrStack.Mode = AddrModeFlat;
stack_frame64.AddrFrame.Offset = context.0.Ebp as u64;
stack_frame64.AddrFrame.Offset = context.fp() as u64;
stack_frame64.AddrFrame.Mode = AddrModeFlat;

while dbghelp.StackWalk64()(
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ mod lock {

#[cfg(all(
windows,
any(target_env = "msvc", all(target_env = "gnu", target_arch = "x86")),
any(
target_env = "msvc",
all(target_env = "gnu", any(target_arch = "x86", target_arch = "arm"))
),
not(target_vendor = "uwp")
))]
mod dbghelp;
Expand Down

0 comments on commit aa0a5e2

Please sign in to comment.