Skip to content

Commit aa0a5e2

Browse files
authored
Merge pull request #573 from kleisauke/thumbv7a-win-compat
Fix build errors on `thumbv7a-*-windows-msvc` targets
2 parents e9da96e + 3f9d175 commit aa0a5e2

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

src/backtrace/dbghelp.rs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,42 @@ impl MyContext {
8686
}
8787
}
8888

89+
#[cfg(target_arch = "x86")]
90+
impl MyContext {
91+
#[inline(always)]
92+
fn ip(&self) -> DWORD {
93+
self.0.Eip
94+
}
95+
96+
#[inline(always)]
97+
fn sp(&self) -> DWORD {
98+
self.0.Esp
99+
}
100+
101+
#[inline(always)]
102+
fn fp(&self) -> DWORD {
103+
self.0.Ebp
104+
}
105+
}
106+
107+
#[cfg(target_arch = "arm")]
108+
impl MyContext {
109+
#[inline(always)]
110+
fn ip(&self) -> DWORD {
111+
self.0.Pc
112+
}
113+
114+
#[inline(always)]
115+
fn sp(&self) -> DWORD {
116+
self.0.Sp
117+
}
118+
119+
#[inline(always)]
120+
fn fp(&self) -> DWORD {
121+
self.0.R11
122+
}
123+
}
124+
89125
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
90126
#[inline(always)]
91127
pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
@@ -167,11 +203,11 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
167203
Some(StackWalkEx) => {
168204
let mut stack_frame_ex: STACKFRAME_EX = mem::zeroed();
169205
stack_frame_ex.StackFrameSize = mem::size_of::<STACKFRAME_EX>() as DWORD;
170-
stack_frame_ex.AddrPC.Offset = context.0.Eip as u64;
206+
stack_frame_ex.AddrPC.Offset = context.ip() as u64;
171207
stack_frame_ex.AddrPC.Mode = AddrModeFlat;
172-
stack_frame_ex.AddrStack.Offset = context.0.Esp as u64;
208+
stack_frame_ex.AddrStack.Offset = context.sp() as u64;
173209
stack_frame_ex.AddrStack.Mode = AddrModeFlat;
174-
stack_frame_ex.AddrFrame.Offset = context.0.Ebp as u64;
210+
stack_frame_ex.AddrFrame.Offset = context.fp() as u64;
175211
stack_frame_ex.AddrFrame.Mode = AddrModeFlat;
176212

177213
while StackWalkEx(
@@ -205,11 +241,11 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) {
205241
}
206242
None => {
207243
let mut stack_frame64: STACKFRAME64 = mem::zeroed();
208-
stack_frame64.AddrPC.Offset = context.0.Eip as u64;
244+
stack_frame64.AddrPC.Offset = context.ip() as u64;
209245
stack_frame64.AddrPC.Mode = AddrModeFlat;
210-
stack_frame64.AddrStack.Offset = context.0.Esp as u64;
246+
stack_frame64.AddrStack.Offset = context.sp() as u64;
211247
stack_frame64.AddrStack.Mode = AddrModeFlat;
212-
stack_frame64.AddrFrame.Offset = context.0.Ebp as u64;
248+
stack_frame64.AddrFrame.Offset = context.fp() as u64;
213249
stack_frame64.AddrFrame.Mode = AddrModeFlat;
214250

215251
while dbghelp.StackWalk64()(

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ mod lock {
194194

195195
#[cfg(all(
196196
windows,
197-
any(target_env = "msvc", all(target_env = "gnu", target_arch = "x86")),
197+
any(
198+
target_env = "msvc",
199+
all(target_env = "gnu", any(target_arch = "x86", target_arch = "arm"))
200+
),
198201
not(target_vendor = "uwp")
199202
))]
200203
mod dbghelp;

0 commit comments

Comments
 (0)