From f3a893342ed3df9eaa41b91489ad8d868470ff53 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sat, 9 Mar 2024 20:48:40 +0000 Subject: [PATCH] Remove 32-bit from dbghelp64 --- src/backtrace/dbghelp64.rs | 146 ------------------------------------- 1 file changed, 146 deletions(-) diff --git a/src/backtrace/dbghelp64.rs b/src/backtrace/dbghelp64.rs index 71058a03..d3ae06df 100644 --- a/src/backtrace/dbghelp64.rs +++ b/src/backtrace/dbghelp64.rs @@ -86,42 +86,6 @@ 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", @@ -172,113 +136,3 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { ); } } - -#[cfg(any(target_arch = "x86", target_arch = "arm"))] -#[inline(always)] -pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { - use core::{mem, ptr}; - - // Allocate necessary structures for doing the stack walk - let process = GetCurrentProcess(); - let thread = GetCurrentThread(); - - let mut context = mem::zeroed::(); - RtlCaptureContext(&mut context.0); - - // Ensure this process's symbols are initialized - let dbghelp = match super::super::dbghelp::init() { - Ok(dbghelp) => dbghelp, - Err(()) => return, // oh well... - }; - - let function_table_access = dbghelp.SymFunctionTableAccess64(); - let get_module_base = dbghelp.SymGetModuleBase64(); - - let process_handle = GetCurrentProcess(); - - #[cfg(target_arch = "x86")] - let image = IMAGE_FILE_MACHINE_I386; - #[cfg(target_arch = "arm")] - let image = IMAGE_FILE_MACHINE_ARMNT; - - // 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() { - Some(StackWalkEx) => { - let mut stack_frame_ex: STACKFRAME_EX = mem::zeroed(); - stack_frame_ex.StackFrameSize = mem::size_of::() as DWORD; - stack_frame_ex.AddrPC.Offset = context.ip() as u64; - stack_frame_ex.AddrPC.Mode = AddrModeFlat; - stack_frame_ex.AddrStack.Offset = context.sp() as u64; - stack_frame_ex.AddrStack.Mode = AddrModeFlat; - stack_frame_ex.AddrFrame.Offset = context.fp() as u64; - stack_frame_ex.AddrFrame.Mode = AddrModeFlat; - - while StackWalkEx( - image as DWORD, - process, - thread, - &mut stack_frame_ex, - ptr::addr_of_mut!(context.0) as PVOID, - None, - Some(function_table_access), - Some(get_module_base), - None, - 0, - ) == TRUE - { - let frame = super::Frame { - inner: Frame { - base_address: get_module_base(process_handle, stack_frame_ex.AddrPC.Offset) - as *mut c_void, - ip: stack_frame_ex.AddrPC.Offset as *mut c_void, - sp: stack_frame_ex.AddrStack.Offset as *mut c_void, - #[cfg(not(target_env = "gnu"))] - inline_context: Some(stack_frame_ex.InlineFrameContext), - }, - }; - - if !cb(&frame) { - break; - } - } - } - None => { - let mut stack_frame64: STACKFRAME64 = mem::zeroed(); - stack_frame64.AddrPC.Offset = context.ip() as u64; - stack_frame64.AddrPC.Mode = AddrModeFlat; - stack_frame64.AddrStack.Offset = context.sp() as u64; - stack_frame64.AddrStack.Mode = AddrModeFlat; - stack_frame64.AddrFrame.Offset = context.fp() as u64; - stack_frame64.AddrFrame.Mode = AddrModeFlat; - - while dbghelp.StackWalk64()( - image as DWORD, - process, - thread, - &mut stack_frame64, - ptr::addr_of_mut!(context.0) as PVOID, - None, - Some(function_table_access), - Some(get_module_base), - None, - ) == TRUE - { - let frame = super::Frame { - inner: Frame { - base_address: get_module_base(process_handle, stack_frame64.AddrPC.Offset) - as *mut c_void, - ip: stack_frame64.AddrPC.Offset as *mut c_void, - sp: stack_frame64.AddrStack.Offset as *mut c_void, - #[cfg(not(target_env = "gnu"))] - inline_context: None, - }, - }; - - if !cb(&frame) { - break; - } - } - } - } -}