From c16ac407120d6fc6d039fe87f95419a455018960 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Fri, 18 Nov 2022 15:43:48 -0600 Subject: [PATCH 01/13] port --- .github/workflows/main.yml | 4 +- Cargo.toml | 29 +- src/backtrace/dbghelp32.rs | 21 +- src/dbghelp.rs | 179 +++---- src/lib.rs | 2 - src/symbolize/dbghelp.rs | 24 +- src/symbolize/gimli/libs_windows.rs | 6 +- src/symbolize/mod.rs | 4 +- src/windows.rs | 749 ---------------------------- 9 files changed, 118 insertions(+), 900 deletions(-) delete mode 100644 src/windows.rs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 55e2d126f..c2439d136 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,7 +63,7 @@ jobs: - run: cargo build - run: cargo test - run: cargo test --features "serialize-serde" - - run: cargo test --features "verify-winapi" + - run: cargo test --features "verify-windows-sys" - run: cargo test --features "cpp_demangle" - run: cargo test --no-default-features - run: cargo test --no-default-features --features "std" @@ -144,7 +144,7 @@ jobs: shell: bash - run: rustup target add aarch64-pc-windows-msvc - run: cargo test --no-run --target aarch64-pc-windows-msvc - - run: cargo test --no-run --target aarch64-pc-windows-msvc --features verify-winapi + - run: cargo test --no-run --target aarch64-pc-windows-msvc --features verify-windows-sys ios: name: iOS diff --git a/Cargo.toml b/Cargo.toml index 3c7102407..b3fdc8527 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,8 +49,18 @@ version = "0.36.0" default-features = false features = ['read_core', 'elf', 'macho', 'pe', 'xcoff', 'unaligned', 'archive'] -[target.'cfg(windows)'.dependencies] -winapi = { version = "0.3.9", optional = true } +[target.'cfg(windows)'.dependencies.windows-sys] +version = "0.42.0" +features = [ + "Win32_Foundation", + "Win32_Security", + "Win32_System_Diagnostics_Debug", + "Win32_System_Kernel", + "Win32_System_LibraryLoader", + "Win32_System_SystemInformation", + "Win32_System_Threading", + "Win32_System_WindowsProgramming", +] [build-dependencies] # Only needed for Android, but cannot be target dependent @@ -82,20 +92,7 @@ dladdr = [] kernel32 = [] libunwind = [] unix-backtrace = [] -verify-winapi = [ - 'winapi/dbghelp', - 'winapi/handleapi', - 'winapi/libloaderapi', - 'winapi/memoryapi', - 'winapi/minwindef', - 'winapi/processthreadsapi', - 'winapi/synchapi', - 'winapi/tlhelp32', - 'winapi/winbase', - 'winapi/winnt', - 'winapi/winnls', - 'winapi/stringapiset', -] +verify-windows-sys = [] [[example]] name = "backtrace" diff --git a/src/backtrace/dbghelp32.rs b/src/backtrace/dbghelp32.rs index 940638a99..e130963a1 100644 --- a/src/backtrace/dbghelp32.rs +++ b/src/backtrace/dbghelp32.rs @@ -11,7 +11,12 @@ #![allow(bad_style)] -use super::super::{dbghelp, windows::*}; +use windows_sys::{ + Win32::Foundation::*, Win32::System::Diagnostics::Debug::*, + Win32::System::SystemInformation::*, Win32::System::Threading::*, +}; + +use super::super::dbghelp; use core::ffi::c_void; use core::mem; @@ -129,7 +134,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { match (*dbghelp.dbghelp()).StackWalkEx() { Some(StackWalkEx) => { let mut inner: STACKFRAME_EX = mem::zeroed(); - inner.StackFrameSize = mem::size_of::() as DWORD; + inner.StackFrameSize = mem::size_of::() as u32; let mut frame = super::Frame { inner: Frame { stack_frame: StackFrame::New(inner), @@ -143,7 +148,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { }; while StackWalkEx( - image as DWORD, + image as u32, process, thread, frame_ptr, @@ -153,7 +158,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { Some(get_module_base), None, 0, - ) == TRUE + ) == 1 { frame.inner.base_address = get_module_base(process_handle, frame.ip() as _) as _; @@ -176,7 +181,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { }; while dbghelp.StackWalk64()( - image as DWORD, + image as _, process, thread, frame_ptr, @@ -185,7 +190,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { Some(function_table_access), Some(get_module_base), None, - ) == TRUE + ) == 1 { frame.inner.base_address = get_module_base(process_handle, frame.ip() as _) as _; @@ -198,7 +203,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { } #[cfg(target_arch = "x86")] -fn init_frame(frame: &mut Frame, ctx: &CONTEXT) -> WORD { +fn init_frame(frame: &mut Frame, ctx: &CONTEXT) -> u16 { frame.addr_pc_mut().Offset = ctx.Eip as u64; frame.addr_pc_mut().Mode = AddrModeFlat; frame.addr_stack_mut().Offset = ctx.Esp as u64; @@ -210,7 +215,7 @@ fn init_frame(frame: &mut Frame, ctx: &CONTEXT) -> WORD { } #[cfg(target_arch = "arm")] -fn init_frame(frame: &mut Frame, ctx: &CONTEXT) -> WORD { +fn init_frame(frame: &mut Frame, ctx: &CONTEXT) -> u16 { frame.addr_pc_mut().Offset = ctx.Pc as u64; frame.addr_pc_mut().Mode = AddrModeFlat; frame.addr_stack_mut().Offset = ctx.Sp as u64; diff --git a/src/dbghelp.rs b/src/dbghelp.rs index e7c45e2e8..58724029d 100644 --- a/src/dbghelp.rs +++ b/src/dbghelp.rs @@ -12,7 +12,7 @@ //! actually use the raw definitions in `winapi`, but rather we need to define //! the function pointer types ourselves and use that. We don't really want to //! be in the business of duplicating winapi, so we have a Cargo feature -//! `verify-winapi` which asserts that all bindings match those in winapi and +//! `verify-windows-sys` which asserts that all bindings match those in winapi and //! this feature is enabled on CI. //! //! Finally, you'll note here that the dll for `dbghelp.dll` is never unloaded, @@ -25,65 +25,21 @@ use alloc::vec::Vec; -use super::windows::*; +use windows_sys::{ + core::*, Win32::Foundation::*, Win32::System::Diagnostics::Debug::*, + Win32::System::LibraryLoader::*, Win32::System::Threading::*, + Win32::System::WindowsProgramming::*, +}; + +use core::ffi::c_void; use core::mem; use core::ptr; use core::slice; -// Work around `SymGetOptions` and `SymSetOptions` not being present in winapi -// itself. Otherwise this is only used when we're double-checking types against -// winapi. -#[cfg(feature = "verify-winapi")] -mod dbghelp { - use crate::windows::*; - pub use winapi::um::dbghelp::{ - StackWalk64, StackWalkEx, SymFromAddrW, SymFunctionTableAccess64, SymGetLineFromAddrW64, - SymGetModuleBase64, SymGetOptions, SymInitializeW, SymSetOptions, - }; - - extern "system" { - // Not defined in winapi yet - pub fn SymFromInlineContextW( - hProcess: HANDLE, - Address: DWORD64, - InlineContext: ULONG, - Displacement: PDWORD64, - Symbol: PSYMBOL_INFOW, - ) -> BOOL; - pub fn SymGetLineFromInlineContextW( - hProcess: HANDLE, - dwAddr: DWORD64, - InlineContext: ULONG, - qwModuleBaseAddress: DWORD64, - pdwDisplacement: PDWORD, - Line: PIMAGEHLP_LINEW64, - ) -> BOOL; - pub fn SymAddrIncludeInlineTrace(hProcess: HANDLE, Address: DWORD64) -> DWORD; - pub fn SymQueryInlineTrace( - hProcess: HANDLE, - StartAddress: DWORD64, - StartContext: DWORD, - StartRetAddress: DWORD64, - CurAddress: DWORD64, - CurContext: LPDWORD, - CurFrameIndex: LPDWORD, - ) -> BOOL; - pub fn SymGetSearchPathW( - hprocess: HANDLE, - searchpatha: PWSTR, - searchpathlength: DWORD, - ) -> BOOL; - pub fn SymSetSearchPathW(hprocess: HANDLE, searchpatha: PCWSTR) -> BOOL; - pub fn EnumerateLoadedModulesW64( - hprocess: HANDLE, - enumloadedmodulescallback: PENUMLOADED_MODULES_CALLBACKW64, - usercontext: PVOID, - ) -> BOOL; - } - - pub fn assert_equal_types(a: T, _b: T) -> T { - a - } +// This is only used when we're double-checking function signatures against windows-sys. +#[cfg(feature = "verify-windows-sys")] +fn assert_equal_types(a: T, _b: T) -> T { + a } // This macro is used to define a `Dbghelp` structure which internally contains @@ -94,7 +50,7 @@ macro_rules! dbghelp { }) => ( pub struct Dbghelp { /// The loaded DLL for `dbghelp.dll` - dll: HMODULE, + dll: HINSTANCE, // Each function pointer for each function we might use $($name: usize,)* @@ -102,7 +58,7 @@ macro_rules! dbghelp { static mut DBGHELP: Dbghelp = Dbghelp { // Initially we haven't loaded the DLL - dll: ptr::null_mut(), + dll: 0, // Initially all functions are set to zero to say they need to be // dynamically loaded. $($name: 0,)* @@ -117,13 +73,13 @@ macro_rules! dbghelp { /// /// Panics if library is already loaded. fn ensure_open(&mut self) -> Result<(), ()> { - if !self.dll.is_null() { + if self.dll != 0 { return Ok(()) } let lib = b"dbghelp.dll\0"; unsafe { - self.dll = LoadLibraryA(lib.as_ptr().cast::()); - if self.dll.is_null() { + self.dll = LoadLibraryA(lib.as_ptr()); + if self.dll == 0 { Err(()) } else { Ok(()) @@ -141,18 +97,15 @@ macro_rules! dbghelp { self.$name = self.symbol(name.as_bytes())?; } let ret = mem::transmute::(self.$name); - #[cfg(feature = "verify-winapi")] - dbghelp::assert_equal_types(ret, dbghelp::$name); + #[cfg(feature = "verify-windows-sys")] + assert_equal_types(ret, $name); Some(ret) } })* fn symbol(&self, symbol: &[u8]) -> Option { unsafe { - match GetProcAddress(self.dll, symbol.as_ptr().cast()) as usize { - 0 => None, - n => Some(n), - } + GetProcAddress(self.dll, symbol.as_ptr()).map(|address|address as usize) } } } @@ -177,12 +130,10 @@ macro_rules! dbghelp { } -const SYMOPT_DEFERRED_LOADS: DWORD = 0x00000004; - dbghelp! { extern "system" { - fn SymGetOptions() -> DWORD; - fn SymSetOptions(options: DWORD) -> DWORD; + fn SymGetOptions() -> u32; + fn SymSetOptions(options: u32) -> u32; fn SymInitializeW( handle: HANDLE, path: PCWSTR, @@ -191,7 +142,7 @@ dbghelp! { fn SymGetSearchPathW( hprocess: HANDLE, searchpatha: PWSTR, - searchpathlength: DWORD + searchpathlength: u32 ) -> BOOL; fn SymSetSearchPathW( hprocess: HANDLE, @@ -203,11 +154,11 @@ dbghelp! { usercontext: PVOID ) -> BOOL; fn StackWalk64( - MachineType: DWORD, + MachineType: u32, hProcess: HANDLE, hThread: HANDLE, - StackFrame: LPSTACKFRAME64, - ContextRecord: PVOID, + StackFrame: *mut STACKFRAME64, + ContextRecord: *mut c_void, ReadMemoryRoutine: PREAD_PROCESS_MEMORY_ROUTINE64, FunctionTableAccessRoutine: PFUNCTION_TABLE_ACCESS_ROUTINE64, GetModuleBaseRoutine: PGET_MODULE_BASE_ROUTINE64, @@ -215,62 +166,74 @@ dbghelp! { ) -> BOOL; fn SymFunctionTableAccess64( hProcess: HANDLE, - AddrBase: DWORD64 - ) -> PVOID; + AddrBase: u64 + ) -> *mut c_void; fn SymGetModuleBase64( hProcess: HANDLE, - AddrBase: DWORD64 - ) -> DWORD64; + AddrBase: u64 + ) -> u64; + fn SymFromAddrW( + hProcess: HANDLE, + Address: u64, + Displacement: *mut u64, + Symbol: *mut SYMBOL_INFOW + ) -> BOOL; + fn SymGetLineFromAddrW64( + hProcess: HANDLE, + dwAddr: u64, + pdwDisplacement: *mut u32, + Line: *mut IMAGEHLP_LINEW64 + ) -> BOOL; fn StackWalkEx( - MachineType: DWORD, + MachineType: u32, hProcess: HANDLE, hThread: HANDLE, - StackFrame: LPSTACKFRAME_EX, - ContextRecord: PVOID, + StackFrame: *mut STACKFRAME_EX, + ContextRecord: *mut c_void, ReadMemoryRoutine: PREAD_PROCESS_MEMORY_ROUTINE64, FunctionTableAccessRoutine: PFUNCTION_TABLE_ACCESS_ROUTINE64, GetModuleBaseRoutine: PGET_MODULE_BASE_ROUTINE64, TranslateAddress: PTRANSLATE_ADDRESS_ROUTINE64, - Flags: DWORD + Flags: u32 ) -> BOOL; fn SymFromInlineContextW( hProcess: HANDLE, - Address: DWORD64, - InlineContext: ULONG, - Displacement: PDWORD64, - Symbol: PSYMBOL_INFOW + Address: u64, + InlineContext: u32, + Displacement: *mut u64, + Symbol: *mut SYMBOL_INFOW ) -> BOOL; fn SymGetLineFromInlineContextW( hProcess: HANDLE, - dwAddr: DWORD64, - InlineContext: ULONG, - qwModuleBaseAddress: DWORD64, - pdwDisplacement: PDWORD, - Line: PIMAGEHLP_LINEW64 + dwAddr: u64, + InlineContext: u32, + qwModuleBaseAddress: u64, + pdwDisplacement: *mut u32, + Line: *mut IMAGEHLP_LINEW64 ) -> BOOL; fn SymAddrIncludeInlineTrace( hProcess: HANDLE, - Address: DWORD64 - ) -> DWORD; + Address: u64 + ) -> u32; fn SymQueryInlineTrace( hProcess: HANDLE, - StartAddress: DWORD64, - StartContext: DWORD, - StartRetAddress: DWORD64, - CurAddress: DWORD64, - CurContext: LPDWORD, - CurFrameIndex: LPDWORD + StartAddress: u64, + StartContext: u32, + StartRetAddress: u64, + CurAddress: u64, + CurContext: *mut u32, + CurFrameIndex: *mut u32 ) -> BOOL; fn SymFromAddrW( hProcess: HANDLE, - Address: DWORD64, - Displacement: PDWORD64, + Address: u64, + Displacement: *mut u64, Symbol: PSYMBOL_INFOW ) -> BOOL; fn SymGetLineFromAddrW64( hProcess: HANDLE, - dwAddr: DWORD64, - pdwDisplacement: PDWORD, + dwAddr: u64, + pdwDisplacement: *mut u32, Line: PIMAGEHLP_LINEW64 ) -> BOOL; } @@ -356,7 +319,7 @@ pub fn init() -> Result { } } debug_assert!(!lock.is_null()); - let r = WaitForSingleObjectEx(lock, INFINITE, FALSE); + let r = WaitForSingleObjectEx(lock, INFINITE, 0); debug_assert_eq!(r, 0); let ret = Init { lock }; @@ -403,7 +366,7 @@ fn set_optional_options() -> Option<()> { // the time, but now that it's using this crate it means that someone will // get to initialization first and the other will pick up that // initialization. - DBGHELP.SymInitializeW()?(GetCurrentProcess(), ptr::null_mut(), TRUE); + DBGHELP.SymInitializeW()?(GetCurrentProcess(), ptr::null_mut(), 1); // The default search path for dbghelp will only look in the current working // directory and (possibly) `_NT_SYMBOL_PATH` and `_NT_ALT_SYMBOL_PATH`. @@ -421,7 +384,7 @@ fn set_optional_options() -> Option<()> { GetCurrentProcess(), search_path_buf.as_mut_ptr(), search_path_buf.len() as _, - ) == TRUE + ) == 1 { // Trim the buffer to the actual length of the string. let len = lstrlenW(search_path_buf.as_mut_ptr()); @@ -497,7 +460,7 @@ impl SearchPath { extern "system" fn enum_loaded_modules_callback( module_name: PCWSTR, - _: DWORD64, + _: u64, _: ULONG, user_context: PVOID, ) -> BOOL { diff --git a/src/lib.rs b/src/lib.rs index 20e9ecb80..6b549723e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -248,5 +248,3 @@ mod lock { not(target_vendor = "uwp") ))] mod dbghelp; -#[cfg(windows)] -mod windows; diff --git a/src/symbolize/dbghelp.rs b/src/symbolize/dbghelp.rs index 718120a31..cacf371d0 100644 --- a/src/symbolize/dbghelp.rs +++ b/src/symbolize/dbghelp.rs @@ -17,7 +17,11 @@ #![allow(bad_style)] -use super::super::{dbghelp, windows::*}; +use windows_sys::{ + Win32::Foundation::*, Win32::System::Diagnostics::Debug::*, Win32::System::Threading::*, +}; + +use super::super::dbghelp; use super::{BytesOrWideString, ResolveWhat, SymbolName}; use core::ffi::c_void; use core::marker; @@ -126,10 +130,10 @@ pub unsafe fn resolve(what: ResolveWhat<'_>, cb: &mut dyn FnMut(&super::Symbol)) unsafe fn resolve_legacy( dbghelp: &dbghelp::Init, addr: *mut c_void, - _inline_context: Option, + _inline_context: Option, cb: &mut dyn FnMut(&super::Symbol), ) -> Option<()> { - let addr = super::adjust_ip(addr) as DWORD64; + let addr = super::adjust_ip(addr) as u64; do_resolve( |info| dbghelp.SymFromAddrW()(GetCurrentProcess(), addr, &mut 0, info), |line| dbghelp.SymGetLineFromAddrW64()(GetCurrentProcess(), addr, &mut 0, line), @@ -145,7 +149,7 @@ unsafe fn resolve_legacy( unsafe fn resolve_with_inline( dbghelp: &dbghelp::Init, addr: *mut c_void, - inline_context: Option, + inline_context: Option, cb: &mut dyn FnMut(&super::Symbol), ) -> Option<()> { let current_process = GetCurrentProcess(); @@ -153,7 +157,7 @@ unsafe fn resolve_with_inline( let SymFromInlineContextW = (*dbghelp.dbghelp()).SymFromInlineContextW()?; let SymGetLineFromInlineContextW = (*dbghelp.dbghelp()).SymGetLineFromInlineContextW()?; - let addr = super::adjust_ip(addr) as DWORD64; + let addr = super::adjust_ip(addr) as u64; let (inlined_frame_count, inline_context) = if let Some(ic) = inline_context { (0, ic) @@ -205,7 +209,7 @@ unsafe fn do_resolve( get_line_from_addr: impl FnOnce(&mut IMAGEHLP_LINEW64) -> BOOL, cb: &mut dyn FnMut(&super::Symbol), ) { - const SIZE: usize = 2 * MAX_SYM_NAME + mem::size_of::(); + const SIZE: usize = 2 * MAX_SYM_NAME as usize + mem::size_of::(); let mut data = Aligned8([0u8; SIZE]); let info = &mut *data.0.as_mut_ptr().cast::(); info.MaxNameLen = MAX_SYM_NAME as ULONG; @@ -214,7 +218,7 @@ unsafe fn do_resolve( // due to struct alignment. info.SizeOfStruct = 88; - if sym_from_addr(info) != TRUE { + if sym_from_addr(info) != 1 { return; } @@ -248,12 +252,12 @@ unsafe fn do_resolve( let name = ptr::addr_of!(name_buffer[..name_len]); let mut line = mem::zeroed::(); - line.SizeOfStruct = mem::size_of::() as DWORD; + line.SizeOfStruct = mem::size_of::() as u32; let mut filename = None; let mut lineno = None; - if get_line_from_addr(&mut line) == TRUE { - lineno = Some(line.LineNumber as u32); + if get_line_from_addr(&mut line) == 1 { + lineno = Some(line.LineNumber); let base = line.FileName; let mut len = 0; diff --git a/src/symbolize/gimli/libs_windows.rs b/src/symbolize/gimli/libs_windows.rs index b47ed4245..04e0d5325 100644 --- a/src/symbolize/gimli/libs_windows.rs +++ b/src/symbolize/gimli/libs_windows.rs @@ -23,14 +23,14 @@ unsafe fn add_loaded_images(ret: &mut Vec) { } let mut me = MaybeUninit::::zeroed().assume_init(); - me.dwSize = mem::size_of_val(&me) as DWORD; - if Module32FirstW(snap, &mut me) == TRUE { + me.dwSize = mem::size_of_val(&me) as u32; + if Module32FirstW(snap, &mut me) == 1 { loop { if let Some(lib) = load_library(&me) { ret.push(lib); } - if Module32NextW(snap, &mut me) != TRUE { + if Module32NextW(snap, &mut me) != 1 { break; } } diff --git a/src/symbolize/mod.rs b/src/symbolize/mod.rs index 9706835e6..64542bdd0 100644 --- a/src/symbolize/mod.rs +++ b/src/symbolize/mod.rs @@ -318,8 +318,8 @@ impl<'a> SymbolName<'a> { }; SymbolName { - bytes: bytes, - demangled: demangled, + bytes, + demangled, #[cfg(feature = "cpp_demangle")] cpp_demangled: cpp, } diff --git a/src/windows.rs b/src/windows.rs deleted file mode 100644 index 305da0570..000000000 --- a/src/windows.rs +++ /dev/null @@ -1,749 +0,0 @@ -//! A module to define the FFI definitions we use on Windows for `dbghelp.dll` -//! -//! This module uses a custom macro, `ffi!`, to wrap all definitions to -//! automatically generate tests to assert that our definitions here are the -//! same as `winapi`. -//! -//! This module largely exists to integrate into libstd itself where winapi is -//! not currently available. - -#![allow(bad_style, dead_code, unused)] - -cfg_if::cfg_if! { - if #[cfg(feature = "verify-winapi")] { - pub use self::winapi::c_void; - pub use self::winapi::HINSTANCE; - pub use self::winapi::FARPROC; - pub use self::winapi::LPSECURITY_ATTRIBUTES; - #[cfg(target_pointer_width = "64")] - pub use self::winapi::PUNWIND_HISTORY_TABLE; - #[cfg(target_pointer_width = "64")] - pub use self::winapi::PRUNTIME_FUNCTION; - pub use self::winapi::PEXCEPTION_ROUTINE; - #[cfg(target_pointer_width = "64")] - pub use self::winapi::PKNONVOLATILE_CONTEXT_POINTERS; - - mod winapi { - pub use winapi::ctypes::*; - pub use winapi::shared::basetsd::*; - pub use winapi::shared::minwindef::*; - pub use winapi::um::dbghelp::*; - pub use winapi::um::fileapi::*; - pub use winapi::um::handleapi::*; - pub use winapi::um::libloaderapi::*; - pub use winapi::um::memoryapi::*; - pub use winapi::um::minwinbase::*; - pub use winapi::um::processthreadsapi::*; - pub use winapi::um::synchapi::*; - pub use winapi::um::tlhelp32::*; - pub use winapi::um::winbase::*; - pub use winapi::um::winnt::*; - pub use winapi::um::winnls::*; - pub use winapi::um::stringapiset::*; - - // Work around winapi not having this function on aarch64. - #[cfg(target_arch = "aarch64")] - #[link(name = "kernel32")] - extern "system" { - pub fn RtlVirtualUnwind( - HandlerType: ULONG, - ImageBase: ULONG64, - ControlPc: ULONG64, - FunctionEntry: PRUNTIME_FUNCTION, - ContextRecord: PCONTEXT, - HandlerData: *mut PVOID, - EstablisherFrame: PULONG64, - ContextPointers: PKNONVOLATILE_CONTEXT_POINTERS - ) -> PEXCEPTION_ROUTINE; - } - - // winapi doesn't have this type - pub type PENUMLOADED_MODULES_CALLBACKW64 = Option< - unsafe extern "system" fn( - modulename: PCWSTR, - modulebase: DWORD64, - modulesize: ULONG, - usercontext: PVOID, - ) -> BOOL, - >; - } - } else { - pub use core::ffi::c_void; - pub type HINSTANCE = *mut c_void; - pub type FARPROC = *mut c_void; - pub type LPSECURITY_ATTRIBUTES = *mut c_void; - #[cfg(target_pointer_width = "64")] - pub type PRUNTIME_FUNCTION = *mut c_void; - #[cfg(target_pointer_width = "64")] - pub type PUNWIND_HISTORY_TABLE = *mut c_void; - pub type PEXCEPTION_ROUTINE = *mut c_void; - #[cfg(target_pointer_width = "64")] - pub type PKNONVOLATILE_CONTEXT_POINTERS = *mut c_void; - } -} - -macro_rules! ffi { - () => (); - - (#[repr($($r:tt)*)] pub struct $name:ident { $(pub $field:ident: $ty:ty,)* } $($rest:tt)*) => ( - #[repr($($r)*)] - #[cfg(not(feature = "verify-winapi"))] - #[derive(Copy, Clone)] - pub struct $name { - $(pub $field: $ty,)* - } - - #[cfg(feature = "verify-winapi")] - pub use self::winapi::$name; - - #[test] - #[cfg(feature = "verify-winapi")] - fn $name() { - use core::mem; - - #[repr($($r)*)] - pub struct $name { - $(pub $field: $ty,)* - } - - assert_eq!( - mem::size_of::<$name>(), - mem::size_of::(), - concat!("size of ", stringify!($name), " is wrong"), - ); - assert_eq!( - mem::align_of::<$name>(), - mem::align_of::(), - concat!("align of ", stringify!($name), " is wrong"), - ); - - type Winapi = winapi::$name; - - fn assert_same(_: T, _: T) {} - - unsafe { - let a = &*(mem::align_of::<$name>() as *const $name); - let b = &*(mem::align_of::() as *const Winapi); - - $( - ffi!(@test_fields a b $field $ty); - )* - } - } - - ffi!($($rest)*); - ); - - // Handling verification against unions in winapi requires some special care - (@test_fields $a:ident $b:ident FltSave $ty:ty) => ( - // Skip this field on x86_64 `CONTEXT` since it's a union and a bit funny - ); - (@test_fields $a:ident $b:ident D $ty:ty) => ({ - let a = &$a.D; - let b = $b.D(); - assert_same(a, b); - assert_eq!(a as *const $ty, b as *const $ty, "misplaced field D"); - }); - (@test_fields $a:ident $b:ident s $ty:ty) => ({ - let a = &$a.s; - let b = $b.s(); - assert_same(a, b); - assert_eq!(a as *const $ty, b as *const $ty, "misplaced field s"); - }); - - // Otherwise test all fields normally. - (@test_fields $a:ident $b:ident $field:ident $ty:ty) => ({ - let a = &$a.$field; - let b = &$b.$field; - assert_same(a, b); - assert_eq!(a as *const $ty, b as *const $ty, - concat!("misplaced field ", stringify!($field))); - }); - - (pub type $name:ident = $ty:ty; $($rest:tt)*) => ( - pub type $name = $ty; - - #[cfg(feature = "verify-winapi")] - #[allow(dead_code)] - const $name: () = { - fn _foo() { - trait SameType {} - impl SameType for (T, T) {} - fn assert_same() {} - - assert_same::<($name, winapi::$name)>(); - } - }; - - ffi!($($rest)*); - ); - - (pub const $name:ident: $ty:ty = $val:expr; $($rest:tt)*) => ( - pub const $name: $ty = $val; - - #[cfg(feature = "verify-winapi")] - #[allow(unused_imports)] - mod $name { - use super::*; - #[test] - fn assert_valid() { - let x: $ty = winapi::$name; - assert_eq!(x, $val); - } - } - - - ffi!($($rest)*); - ); - - ($(#[$meta:meta])* extern "system" { $(pub fn $name:ident($($args:tt)*) -> $ret:ty;)* } $($rest:tt)*) => ( - $(#[$meta])* extern "system" { - $(pub fn $name($($args)*) -> $ret;)* - } - - $( - #[cfg(feature = "verify-winapi")] - mod $name { - #[test] - fn assert_same() { - use super::*; - - assert_eq!($name as usize, winapi::$name as usize); - let mut x: unsafe extern "system" fn($($args)*) -> $ret; - x = $name; - let _ = x; - x = winapi::$name; - let _ = x; - } - } - )* - - ffi!($($rest)*); - ); - - (impl $name:ident { $($i:tt)* } $($rest:tt)*) => ( - #[cfg(not(feature = "verify-winapi"))] - impl $name { - $($i)* - } - - ffi!($($rest)*); - ); -} - -ffi! { - #[repr(C)] - pub struct STACKFRAME64 { - pub AddrPC: ADDRESS64, - pub AddrReturn: ADDRESS64, - pub AddrFrame: ADDRESS64, - pub AddrStack: ADDRESS64, - pub AddrBStore: ADDRESS64, - pub FuncTableEntry: PVOID, - pub Params: [DWORD64; 4], - pub Far: BOOL, - pub Virtual: BOOL, - pub Reserved: [DWORD64; 3], - pub KdHelp: KDHELP64, - } - - pub type LPSTACKFRAME64 = *mut STACKFRAME64; - - #[repr(C)] - pub struct STACKFRAME_EX { - pub AddrPC: ADDRESS64, - pub AddrReturn: ADDRESS64, - pub AddrFrame: ADDRESS64, - pub AddrStack: ADDRESS64, - pub AddrBStore: ADDRESS64, - pub FuncTableEntry: PVOID, - pub Params: [DWORD64; 4], - pub Far: BOOL, - pub Virtual: BOOL, - pub Reserved: [DWORD64; 3], - pub KdHelp: KDHELP64, - pub StackFrameSize: DWORD, - pub InlineFrameContext: DWORD, - } - - pub type LPSTACKFRAME_EX = *mut STACKFRAME_EX; - - #[repr(C)] - pub struct IMAGEHLP_LINEW64 { - pub SizeOfStruct: DWORD, - pub Key: PVOID, - pub LineNumber: DWORD, - pub FileName: PWSTR, - pub Address: DWORD64, - } - - pub type PIMAGEHLP_LINEW64 = *mut IMAGEHLP_LINEW64; - - #[repr(C)] - pub struct SYMBOL_INFOW { - pub SizeOfStruct: ULONG, - pub TypeIndex: ULONG, - pub Reserved: [ULONG64; 2], - pub Index: ULONG, - pub Size: ULONG, - pub ModBase: ULONG64, - pub Flags: ULONG, - pub Value: ULONG64, - pub Address: ULONG64, - pub Register: ULONG, - pub Scope: ULONG, - pub Tag: ULONG, - pub NameLen: ULONG, - pub MaxNameLen: ULONG, - pub Name: [WCHAR; 1], - } - - pub type PSYMBOL_INFOW = *mut SYMBOL_INFOW; - - pub type PTRANSLATE_ADDRESS_ROUTINE64 = Option< - unsafe extern "system" fn(hProcess: HANDLE, hThread: HANDLE, lpaddr: LPADDRESS64) -> DWORD64, - >; - pub type PENUMLOADED_MODULES_CALLBACKW64 = Option BOOL>; - pub type PGET_MODULE_BASE_ROUTINE64 = - Option DWORD64>; - pub type PFUNCTION_TABLE_ACCESS_ROUTINE64 = - Option PVOID>; - pub type PREAD_PROCESS_MEMORY_ROUTINE64 = Option< - unsafe extern "system" fn( - hProcess: HANDLE, - qwBaseAddress: DWORD64, - lpBuffer: PVOID, - nSize: DWORD, - lpNumberOfBytesRead: LPDWORD, - ) -> BOOL, - >; - - #[repr(C)] - pub struct ADDRESS64 { - pub Offset: DWORD64, - pub Segment: WORD, - pub Mode: ADDRESS_MODE, - } - - pub type LPADDRESS64 = *mut ADDRESS64; - - pub type ADDRESS_MODE = u32; - - #[repr(C)] - pub struct KDHELP64 { - pub Thread: DWORD64, - pub ThCallbackStack: DWORD, - pub ThCallbackBStore: DWORD, - pub NextCallback: DWORD, - pub FramePointer: DWORD, - pub KiCallUserMode: DWORD64, - pub KeUserCallbackDispatcher: DWORD64, - pub SystemRangeStart: DWORD64, - pub KiUserExceptionDispatcher: DWORD64, - pub StackBase: DWORD64, - pub StackLimit: DWORD64, - pub BuildVersion: DWORD, - pub Reserved0: DWORD, - pub Reserved1: [DWORD64; 4], - } - - #[repr(C)] - pub struct MODULEENTRY32W { - pub dwSize: DWORD, - pub th32ModuleID: DWORD, - pub th32ProcessID: DWORD, - pub GlblcntUsage: DWORD, - pub ProccntUsage: DWORD, - pub modBaseAddr: *mut u8, - pub modBaseSize: DWORD, - pub hModule: HMODULE, - pub szModule: [WCHAR; MAX_MODULE_NAME32 + 1], - pub szExePath: [WCHAR; MAX_PATH], - } - - pub const MAX_SYM_NAME: usize = 2000; - pub const AddrModeFlat: ADDRESS_MODE = 3; - pub const TRUE: BOOL = 1; - pub const FALSE: BOOL = 0; - pub const PROCESS_QUERY_INFORMATION: DWORD = 0x400; - pub const IMAGE_FILE_MACHINE_ARM64: u16 = 43620; - pub const IMAGE_FILE_MACHINE_AMD64: u16 = 34404; - pub const IMAGE_FILE_MACHINE_I386: u16 = 332; - pub const IMAGE_FILE_MACHINE_ARMNT: u16 = 452; - pub const FILE_SHARE_READ: DWORD = 0x1; - pub const FILE_SHARE_WRITE: DWORD = 0x2; - pub const OPEN_EXISTING: DWORD = 0x3; - pub const GENERIC_READ: DWORD = 0x80000000; - pub const INFINITE: DWORD = !0; - pub const PAGE_READONLY: DWORD = 2; - pub const FILE_MAP_READ: DWORD = 4; - pub const TH32CS_SNAPMODULE: DWORD = 0x00000008; - pub const INVALID_HANDLE_VALUE: HANDLE = -1isize as HANDLE; - pub const MAX_MODULE_NAME32: usize = 255; - pub const MAX_PATH: usize = 260; - pub const CP_UTF8: u32 = 65001; - - pub type DWORD = u32; - pub type PDWORD = *mut u32; - pub type BOOL = i32; - pub type DWORD64 = u64; - pub type PDWORD64 = *mut u64; - pub type HANDLE = *mut c_void; - pub type PVOID = HANDLE; - pub type PCWSTR = *const u16; - pub type LPSTR = *mut i8; - pub type LPCSTR = *const i8; - pub type PWSTR = *mut u16; - pub type WORD = u16; - pub type USHORT = u16; - pub type ULONG = u32; - pub type ULONG64 = u64; - pub type WCHAR = u16; - pub type PCONTEXT = *mut CONTEXT; - pub type LPDWORD = *mut DWORD; - pub type DWORDLONG = u64; - pub type HMODULE = HINSTANCE; - pub type SIZE_T = usize; - pub type LPVOID = *mut c_void; - pub type LPCVOID = *const c_void; - pub type LPMODULEENTRY32W = *mut MODULEENTRY32W; - pub type PULONG = *mut ULONG; - pub type PULONG64 = *mut ULONG64; - - #[link(name = "kernel32")] - extern "system" { - pub fn GetCurrentProcess() -> HANDLE; - pub fn GetCurrentThread() -> HANDLE; - pub fn RtlCaptureContext(ContextRecord: PCONTEXT) -> (); - pub fn LoadLibraryA(a: *const i8) -> HMODULE; - pub fn GetProcAddress(h: HMODULE, name: *const i8) -> FARPROC; - pub fn GetCurrentProcessId() -> DWORD; - pub fn CloseHandle(h: HANDLE) -> BOOL; - pub fn CreateMutexA( - attrs: LPSECURITY_ATTRIBUTES, - initial: BOOL, - name: LPCSTR, - ) -> HANDLE; - pub fn ReleaseMutex(hMutex: HANDLE) -> BOOL; - pub fn WaitForSingleObjectEx( - hHandle: HANDLE, - dwMilliseconds: DWORD, - bAlertable: BOOL, - ) -> DWORD; - pub fn CreateFileMappingA( - hFile: HANDLE, - lpFileMappingAttributes: LPSECURITY_ATTRIBUTES, - flProtect: DWORD, - dwMaximumSizeHigh: DWORD, - dwMaximumSizeLow: DWORD, - lpName: LPCSTR, - ) -> HANDLE; - pub fn MapViewOfFile( - hFileMappingObject: HANDLE, - dwDesiredAccess: DWORD, - dwFileOffsetHigh: DWORD, - dwFileOffsetLow: DWORD, - dwNumberOfBytesToMap: SIZE_T, - ) -> LPVOID; - pub fn UnmapViewOfFile(lpBaseAddress: LPCVOID) -> BOOL; - pub fn CreateToolhelp32Snapshot( - dwFlags: DWORD, - th32ProcessID: DWORD, - ) -> HANDLE; - pub fn Module32FirstW( - hSnapshot: HANDLE, - lpme: LPMODULEENTRY32W, - ) -> BOOL; - pub fn Module32NextW( - hSnapshot: HANDLE, - lpme: LPMODULEENTRY32W, - ) -> BOOL; - pub fn lstrlenW(lpstring: PCWSTR) -> i32; - pub fn WideCharToMultiByte( - codepage: u32, - dwflags: u32, - lpwidecharstr: PCWSTR, - cchwidechar: i32, - lpmultibytestr: *mut i8, - cbmultibyte: i32, - lpdefaultchar: *const i8, - lpuseddefaultchar: *mut BOOL - ) -> i32; - } -} - -#[cfg(any( - target_arch = "x86_64", - target_arch = "aarch64", - target_arch = "arm64ec" -))] -ffi! { - #[link(name = "kernel32")] - extern "system" { - pub fn RtlVirtualUnwind( - HandlerType: ULONG, - ImageBase: ULONG64, - ControlPc: ULONG64, - FunctionEntry: PRUNTIME_FUNCTION, - ContextRecord: PCONTEXT, - HandlerData: *mut PVOID, - EstablisherFrame: PULONG64, - ContextPointers: PKNONVOLATILE_CONTEXT_POINTERS - ) -> PEXCEPTION_ROUTINE; - } -} - -#[cfg(target_pointer_width = "64")] -ffi! { - #[link(name = "kernel32")] - extern "system" { - pub fn RtlLookupFunctionEntry( - ControlPc: DWORD64, - ImageBase: PDWORD64, - HistoryTable: PUNWIND_HISTORY_TABLE, - ) -> PRUNTIME_FUNCTION; - } -} - -#[cfg(target_arch = "aarch64")] -ffi! { - #[repr(C, align(16))] - pub struct CONTEXT { - pub ContextFlags: DWORD, - pub Cpsr: DWORD, - pub u: CONTEXT_u, - pub Sp: u64, - pub Pc: u64, - pub V: [ARM64_NT_NEON128; 32], - pub Fpcr: DWORD, - pub Fpsr: DWORD, - pub Bcr: [DWORD; ARM64_MAX_BREAKPOINTS], - pub Bvr: [DWORD64; ARM64_MAX_BREAKPOINTS], - pub Wcr: [DWORD; ARM64_MAX_WATCHPOINTS], - pub Wvr: [DWORD64; ARM64_MAX_WATCHPOINTS], - } - - #[repr(C)] - pub struct CONTEXT_u { - pub s: CONTEXT_u_s, - } - - impl CONTEXT_u { - pub unsafe fn s(&self) -> &CONTEXT_u_s { - &self.s - } - } - - #[repr(C)] - pub struct CONTEXT_u_s { - pub X0: u64, - pub X1: u64, - pub X2: u64, - pub X3: u64, - pub X4: u64, - pub X5: u64, - pub X6: u64, - pub X7: u64, - pub X8: u64, - pub X9: u64, - pub X10: u64, - pub X11: u64, - pub X12: u64, - pub X13: u64, - pub X14: u64, - pub X15: u64, - pub X16: u64, - pub X17: u64, - pub X18: u64, - pub X19: u64, - pub X20: u64, - pub X21: u64, - pub X22: u64, - pub X23: u64, - pub X24: u64, - pub X25: u64, - pub X26: u64, - pub X27: u64, - pub X28: u64, - pub Fp: u64, - pub Lr: u64, - } - - pub const ARM64_MAX_BREAKPOINTS: usize = 8; - pub const ARM64_MAX_WATCHPOINTS: usize = 2; - - #[repr(C)] - pub struct ARM64_NT_NEON128 { - pub D: [f64; 2], - } -} - -#[cfg(target_arch = "x86")] -ffi! { - #[repr(C)] - pub struct CONTEXT { - pub ContextFlags: DWORD, - pub Dr0: DWORD, - pub Dr1: DWORD, - pub Dr2: DWORD, - pub Dr3: DWORD, - pub Dr6: DWORD, - pub Dr7: DWORD, - pub FloatSave: FLOATING_SAVE_AREA, - pub SegGs: DWORD, - pub SegFs: DWORD, - pub SegEs: DWORD, - pub SegDs: DWORD, - pub Edi: DWORD, - pub Esi: DWORD, - pub Ebx: DWORD, - pub Edx: DWORD, - pub Ecx: DWORD, - pub Eax: DWORD, - pub Ebp: DWORD, - pub Eip: DWORD, - pub SegCs: DWORD, - pub EFlags: DWORD, - pub Esp: DWORD, - pub SegSs: DWORD, - pub ExtendedRegisters: [u8; 512], - } - - #[repr(C)] - pub struct FLOATING_SAVE_AREA { - pub ControlWord: DWORD, - pub StatusWord: DWORD, - pub TagWord: DWORD, - pub ErrorOffset: DWORD, - pub ErrorSelector: DWORD, - pub DataOffset: DWORD, - pub DataSelector: DWORD, - pub RegisterArea: [u8; 80], - pub Spare0: DWORD, - } -} - -#[cfg(any(target_arch = "x86_64", target_arch = "arm64ec"))] -ffi! { - #[repr(C, align(8))] - pub struct CONTEXT { - pub P1Home: DWORDLONG, - pub P2Home: DWORDLONG, - pub P3Home: DWORDLONG, - pub P4Home: DWORDLONG, - pub P5Home: DWORDLONG, - pub P6Home: DWORDLONG, - - pub ContextFlags: DWORD, - pub MxCsr: DWORD, - - pub SegCs: WORD, - pub SegDs: WORD, - pub SegEs: WORD, - pub SegFs: WORD, - pub SegGs: WORD, - pub SegSs: WORD, - pub EFlags: DWORD, - - pub Dr0: DWORDLONG, - pub Dr1: DWORDLONG, - pub Dr2: DWORDLONG, - pub Dr3: DWORDLONG, - pub Dr6: DWORDLONG, - pub Dr7: DWORDLONG, - - pub Rax: DWORDLONG, - pub Rcx: DWORDLONG, - pub Rdx: DWORDLONG, - pub Rbx: DWORDLONG, - pub Rsp: DWORDLONG, - pub Rbp: DWORDLONG, - pub Rsi: DWORDLONG, - pub Rdi: DWORDLONG, - pub R8: DWORDLONG, - pub R9: DWORDLONG, - pub R10: DWORDLONG, - pub R11: DWORDLONG, - pub R12: DWORDLONG, - pub R13: DWORDLONG, - pub R14: DWORDLONG, - pub R15: DWORDLONG, - - pub Rip: DWORDLONG, - - pub FltSave: FLOATING_SAVE_AREA, - - pub VectorRegister: [M128A; 26], - pub VectorControl: DWORDLONG, - - pub DebugControl: DWORDLONG, - pub LastBranchToRip: DWORDLONG, - pub LastBranchFromRip: DWORDLONG, - pub LastExceptionToRip: DWORDLONG, - pub LastExceptionFromRip: DWORDLONG, - } - - #[repr(C)] - pub struct M128A { - pub Low: u64, - pub High: i64, - } -} - -#[repr(C)] -#[cfg(any(target_arch = "x86_64", target_arch = "arm64ec"))] -#[derive(Copy, Clone)] -pub struct FLOATING_SAVE_AREA { - _Dummy: [u8; 512], -} - -#[cfg(target_arch = "arm")] -ffi! { - // #[repr(C)] - // pub struct NEON128 { - // pub Low: ULONG64, - // pub High: LONG64, - // } - - // pub type PNEON128 = *mut NEON128; - - #[repr(C)] - pub struct CONTEXT_u { - // pub Q: [NEON128; 16], - pub D: [ULONG64; 32], - // pub S: [DWORD; 32], - } - - pub const ARM_MAX_BREAKPOINTS: usize = 8; - pub const ARM_MAX_WATCHPOINTS: usize = 1; - - #[repr(C)] - pub struct CONTEXT { - pub ContextFlags: DWORD, - pub R0: DWORD, - pub R1: DWORD, - pub R2: DWORD, - pub R3: DWORD, - pub R4: DWORD, - pub R5: DWORD, - pub R6: DWORD, - pub R7: DWORD, - pub R8: DWORD, - pub R9: DWORD, - pub R10: DWORD, - pub R11: DWORD, - pub R12: DWORD, - pub Sp: DWORD, - pub Lr: DWORD, - pub Pc: DWORD, - pub Cpsr: DWORD, - pub Fpsrc: DWORD, - pub Padding: DWORD, - pub u: CONTEXT_u, - pub Bvr: [DWORD; ARM_MAX_BREAKPOINTS], - pub Bcr: [DWORD; ARM_MAX_BREAKPOINTS], - pub Wvr: [DWORD; ARM_MAX_WATCHPOINTS], - pub Wcr: [DWORD; ARM_MAX_WATCHPOINTS], - pub Padding2: [DWORD; 2], - } -} // IFDEF(arm) From b69f1c4341326c0bfb8af7306c468dbed18da5ea Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 7 Jun 2024 19:00:03 -0700 Subject: [PATCH 02/13] Fix errors --- Cargo.lock | 59 +++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/backtrace/dbghelp64.rs | 12 ++++---- src/dbghelp.rs | 30 ++++++------------- src/symbolize/dbghelp.rs | 7 +++-- 5 files changed, 78 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 308e0e9da..dd76b46cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,7 +45,7 @@ dependencies = [ "object", "rustc-demangle", "serde", - "winapi", + "windows-sys", ] [[package]] @@ -209,3 +209,60 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" diff --git a/Cargo.toml b/Cargo.toml index b3fdc8527..e8dff728e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,6 +60,7 @@ features = [ "Win32_System_SystemInformation", "Win32_System_Threading", "Win32_System_WindowsProgramming", + "Win32_Globalization", ] [build-dependencies] diff --git a/src/backtrace/dbghelp64.rs b/src/backtrace/dbghelp64.rs index acf977c22..6dbc4198d 100644 --- a/src/backtrace/dbghelp64.rs +++ b/src/backtrace/dbghelp64.rs @@ -8,7 +8,7 @@ #![allow(bad_style)] -use super::super::windows::*; +use windows_sys::Win32::System::Diagnostics::Debug::*; use core::ffi::c_void; #[derive(Clone, Copy)] @@ -17,7 +17,7 @@ pub struct Frame { ip: *mut c_void, sp: *mut c_void, #[cfg(not(target_env = "gnu"))] - inline_context: Option, + inline_context: Option, } // we're just sending around raw pointers and reading them, never interpreting @@ -43,7 +43,7 @@ impl Frame { } #[cfg(not(target_env = "gnu"))] - pub fn inline_context(&self) -> Option { + pub fn inline_context(&self) -> Option { self.inline_context } } @@ -54,12 +54,12 @@ struct MyContext(CONTEXT); #[cfg(any(target_arch = "x86_64", target_arch = "arm64ec"))] impl MyContext { #[inline(always)] - fn ip(&self) -> DWORD64 { + fn ip(&self) -> u64 { self.0.Rip } #[inline(always)] - fn sp(&self) -> DWORD64 { + fn sp(&self) -> u64 { self.0.Rsp } } @@ -133,7 +133,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { ip, fn_entry, &mut context.0, - ptr::addr_of_mut!(handler_data).cast::(), + ptr::addr_of_mut!(handler_data).cast::<*mut c_void>(), &mut establisher_frame, ptr::null_mut(), ); diff --git a/src/dbghelp.rs b/src/dbghelp.rs index 58724029d..e04b376f4 100644 --- a/src/dbghelp.rs +++ b/src/dbghelp.rs @@ -28,7 +28,7 @@ use alloc::vec::Vec; use windows_sys::{ core::*, Win32::Foundation::*, Win32::System::Diagnostics::Debug::*, Win32::System::LibraryLoader::*, Win32::System::Threading::*, - Win32::System::WindowsProgramming::*, + Win32::System::WindowsProgramming::*, Win32::Globalization::*, }; use core::ffi::c_void; @@ -151,7 +151,7 @@ dbghelp! { fn EnumerateLoadedModulesW64( hprocess: HANDLE, enumloadedmodulescallback: PENUMLOADED_MODULES_CALLBACKW64, - usercontext: PVOID + usercontext: *const c_void ) -> BOOL; fn StackWalk64( MachineType: u32, @@ -224,18 +224,6 @@ dbghelp! { CurContext: *mut u32, CurFrameIndex: *mut u32 ) -> BOOL; - fn SymFromAddrW( - hProcess: HANDLE, - Address: u64, - Displacement: *mut u64, - Symbol: PSYMBOL_INFOW - ) -> BOOL; - fn SymGetLineFromAddrW64( - hProcess: HANDLE, - dwAddr: u64, - pdwDisplacement: *mut u32, - Line: PIMAGEHLP_LINEW64 - ) -> BOOL; } } @@ -308,7 +296,7 @@ pub fn init() -> Result { let mut lock = LOCK.load(SeqCst); if lock.is_null() { let name = mutex_name(); - lock = CreateMutexA(ptr::null_mut(), 0, name.as_ptr().cast::()); + lock = CreateMutexA(ptr::null_mut(), 0, name.as_ptr()); if lock.is_null() { return Err(()); } @@ -387,7 +375,7 @@ fn set_optional_options() -> Option<()> { ) == 1 { // Trim the buffer to the actual length of the string. - let len = lstrlenW(search_path_buf.as_mut_ptr()); + let len = lstrlenW(search_path_buf.as_mut_ptr()); assert!(len >= 0); search_path_buf.truncate(len as usize); } else { @@ -461,8 +449,8 @@ impl SearchPath { extern "system" fn enum_loaded_modules_callback( module_name: PCWSTR, _: u64, - _: ULONG, - user_context: PVOID, + _: u32, + user_context: *const c_void, ) -> BOOL { // `module_name` is an absolute path like `C:\path\to\module.dll` // or `C:\path\to\module.exe` @@ -470,7 +458,7 @@ extern "system" fn enum_loaded_modules_callback( if len == 0 { // This should not happen, but if it does, we can just ignore it. - return TRUE; + return 1; } let module_name = unsafe { slice::from_raw_parts(module_name, len) }; @@ -483,13 +471,13 @@ extern "system" fn enum_loaded_modules_callback( else { // `module_name` being an absolute path, it should always contain at least one // path separator. If not, there is nothing we can do. - return TRUE; + return 1; }; let search_path = unsafe { &mut *(user_context as *mut SearchPath) }; search_path.add(&module_name[..end_of_directory]); - TRUE + 1 } impl Drop for Init { diff --git a/src/symbolize/dbghelp.rs b/src/symbolize/dbghelp.rs index cacf371d0..46f04283e 100644 --- a/src/symbolize/dbghelp.rs +++ b/src/symbolize/dbghelp.rs @@ -19,6 +19,7 @@ use windows_sys::{ Win32::Foundation::*, Win32::System::Diagnostics::Debug::*, Win32::System::Threading::*, + Win32::Globalization::*, }; use super::super::dbghelp; @@ -180,7 +181,7 @@ unsafe fn resolve_with_inline( addr, &mut inline_context, &mut 0, - ) != TRUE) + ) != 1) || inlined_frame_count == 0 { inlined_frame_count = 0; @@ -212,7 +213,7 @@ unsafe fn do_resolve( const SIZE: usize = 2 * MAX_SYM_NAME as usize + mem::size_of::(); let mut data = Aligned8([0u8; SIZE]); let info = &mut *data.0.as_mut_ptr().cast::(); - info.MaxNameLen = MAX_SYM_NAME as ULONG; + info.MaxNameLen = MAX_SYM_NAME as u32; // the struct size in C. the value is different to // `size_of::() - MAX_SYM_NAME + 1` (== 81) // due to struct alignment. @@ -236,7 +237,7 @@ unsafe fn do_resolve( 0, name_ptr, name_len as i32, - name_buffer.as_mut_ptr().cast::(), + name_buffer.as_mut_ptr(), name_buffer.len() as i32, core::ptr::null_mut(), core::ptr::null_mut(), From df89fe1991eee94b079c81c6973bc2f5263031d3 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 7 Jun 2024 19:21:14 -0700 Subject: [PATCH 03/13] Use meaningful TRUE constant --- src/backtrace/dbghelp32.rs | 4 ++-- src/dbghelp.rs | 14 ++++++++------ src/lib.rs | 2 ++ src/symbolize/dbghelp.rs | 8 ++++---- src/symbolize/gimli/libs_windows.rs | 4 ++-- src/windows.rs | 4 ++++ 6 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 src/windows.rs diff --git a/src/backtrace/dbghelp32.rs b/src/backtrace/dbghelp32.rs index e130963a1..ed4331d5f 100644 --- a/src/backtrace/dbghelp32.rs +++ b/src/backtrace/dbghelp32.rs @@ -158,7 +158,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { Some(get_module_base), None, 0, - ) == 1 + ) == TRUE { frame.inner.base_address = get_module_base(process_handle, frame.ip() as _) as _; @@ -190,7 +190,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { Some(function_table_access), Some(get_module_base), None, - ) == 1 + ) == TRUE { frame.inner.base_address = get_module_base(process_handle, frame.ip() as _) as _; diff --git a/src/dbghelp.rs b/src/dbghelp.rs index e04b376f4..7f239a845 100644 --- a/src/dbghelp.rs +++ b/src/dbghelp.rs @@ -26,11 +26,13 @@ use alloc::vec::Vec; use windows_sys::{ - core::*, Win32::Foundation::*, Win32::System::Diagnostics::Debug::*, + core::*, + Win32::Foundation::*, Win32::System::Diagnostics::Debug::*, Win32::System::LibraryLoader::*, Win32::System::Threading::*, Win32::System::WindowsProgramming::*, Win32::Globalization::*, }; +use super::windows::*; use core::ffi::c_void; use core::mem; use core::ptr; @@ -354,7 +356,7 @@ fn set_optional_options() -> Option<()> { // the time, but now that it's using this crate it means that someone will // get to initialization first and the other will pick up that // initialization. - DBGHELP.SymInitializeW()?(GetCurrentProcess(), ptr::null_mut(), 1); + DBGHELP.SymInitializeW()?(GetCurrentProcess(), ptr::null_mut(), TRUE); // The default search path for dbghelp will only look in the current working // directory and (possibly) `_NT_SYMBOL_PATH` and `_NT_ALT_SYMBOL_PATH`. @@ -372,7 +374,7 @@ fn set_optional_options() -> Option<()> { GetCurrentProcess(), search_path_buf.as_mut_ptr(), search_path_buf.len() as _, - ) == 1 + ) == TRUE { // Trim the buffer to the actual length of the string. let len = lstrlenW(search_path_buf.as_mut_ptr()); @@ -458,7 +460,7 @@ extern "system" fn enum_loaded_modules_callback( if len == 0 { // This should not happen, but if it does, we can just ignore it. - return 1; + return TRUE; } let module_name = unsafe { slice::from_raw_parts(module_name, len) }; @@ -471,13 +473,13 @@ extern "system" fn enum_loaded_modules_callback( else { // `module_name` being an absolute path, it should always contain at least one // path separator. If not, there is nothing we can do. - return 1; + return TRUE; }; let search_path = unsafe { &mut *(user_context as *mut SearchPath) }; search_path.add(&module_name[..end_of_directory]); - 1 + TRUE } impl Drop for Init { diff --git a/src/lib.rs b/src/lib.rs index 6b549723e..20e9ecb80 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -248,3 +248,5 @@ mod lock { not(target_vendor = "uwp") ))] mod dbghelp; +#[cfg(windows)] +mod windows; diff --git a/src/symbolize/dbghelp.rs b/src/symbolize/dbghelp.rs index 46f04283e..4c6e1847a 100644 --- a/src/symbolize/dbghelp.rs +++ b/src/symbolize/dbghelp.rs @@ -22,7 +22,7 @@ use windows_sys::{ Win32::Globalization::*, }; -use super::super::dbghelp; +use super::super::{dbghelp, windows::*}; use super::{BytesOrWideString, ResolveWhat, SymbolName}; use core::ffi::c_void; use core::marker; @@ -181,7 +181,7 @@ unsafe fn resolve_with_inline( addr, &mut inline_context, &mut 0, - ) != 1) + ) != TRUE) || inlined_frame_count == 0 { inlined_frame_count = 0; @@ -219,7 +219,7 @@ unsafe fn do_resolve( // due to struct alignment. info.SizeOfStruct = 88; - if sym_from_addr(info) != 1 { + if sym_from_addr(info) != TRUE { return; } @@ -257,7 +257,7 @@ unsafe fn do_resolve( let mut filename = None; let mut lineno = None; - if get_line_from_addr(&mut line) == 1 { + if get_line_from_addr(&mut line) == TRUE { lineno = Some(line.LineNumber); let base = line.FileName; diff --git a/src/symbolize/gimli/libs_windows.rs b/src/symbolize/gimli/libs_windows.rs index 04e0d5325..05efd5a22 100644 --- a/src/symbolize/gimli/libs_windows.rs +++ b/src/symbolize/gimli/libs_windows.rs @@ -24,13 +24,13 @@ unsafe fn add_loaded_images(ret: &mut Vec) { let mut me = MaybeUninit::::zeroed().assume_init(); me.dwSize = mem::size_of_val(&me) as u32; - if Module32FirstW(snap, &mut me) == 1 { + if Module32FirstW(snap, &mut me) == TRUE { loop { if let Some(lib) = load_library(&me) { ret.push(lib); } - if Module32NextW(snap, &mut me) != 1 { + if Module32NextW(snap, &mut me) != TRUE { break; } } diff --git a/src/windows.rs b/src/windows.rs new file mode 100644 index 000000000..45a237cb2 --- /dev/null +++ b/src/windows.rs @@ -0,0 +1,4 @@ + +use windows_sys::Win32::Foundation::*; + +pub const TRUE: BOOL = 1; From c91dde3bc508883a395e93d28f8296ee095532c9 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 7 Jun 2024 19:27:24 -0700 Subject: [PATCH 04/13] Format --- src/dbghelp.rs | 7 +++---- src/symbolize/dbghelp.rs | 4 ++-- src/windows.rs | 1 - 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/dbghelp.rs b/src/dbghelp.rs index 7f239a845..36fe2a8d9 100644 --- a/src/dbghelp.rs +++ b/src/dbghelp.rs @@ -26,10 +26,9 @@ use alloc::vec::Vec; use windows_sys::{ - core::*, - Win32::Foundation::*, Win32::System::Diagnostics::Debug::*, + core::*, Win32::Foundation::*, Win32::Globalization::*, Win32::System::Diagnostics::Debug::*, Win32::System::LibraryLoader::*, Win32::System::Threading::*, - Win32::System::WindowsProgramming::*, Win32::Globalization::*, + Win32::System::WindowsProgramming::*, }; use super::windows::*; @@ -377,7 +376,7 @@ fn set_optional_options() -> Option<()> { ) == TRUE { // Trim the buffer to the actual length of the string. - let len = lstrlenW(search_path_buf.as_mut_ptr()); + let len = lstrlenW(search_path_buf.as_mut_ptr()); assert!(len >= 0); search_path_buf.truncate(len as usize); } else { diff --git a/src/symbolize/dbghelp.rs b/src/symbolize/dbghelp.rs index 4c6e1847a..9ab465951 100644 --- a/src/symbolize/dbghelp.rs +++ b/src/symbolize/dbghelp.rs @@ -18,8 +18,8 @@ #![allow(bad_style)] use windows_sys::{ - Win32::Foundation::*, Win32::System::Diagnostics::Debug::*, Win32::System::Threading::*, - Win32::Globalization::*, + Win32::Foundation::*, Win32::Globalization::*, Win32::System::Diagnostics::Debug::*, + Win32::System::Threading::*, }; use super::super::{dbghelp, windows::*}; diff --git a/src/windows.rs b/src/windows.rs index 45a237cb2..7f155c910 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -1,4 +1,3 @@ - use windows_sys::Win32::Foundation::*; pub const TRUE: BOOL = 1; From df02d84520c2e115926b8d6382991d1de9395ede Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 7 Jun 2024 19:32:11 -0700 Subject: [PATCH 05/13] Fix pc-windows-gnu builds --- Cargo.toml | 12 +++++++----- src/backtrace/dbghelp32.rs | 6 +++--- src/symbolize/gimli/libs_windows.rs | 2 ++ src/symbolize/gimli/mmap_windows.rs | 8 +++++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e8dff728e..cbf4e4bd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,10 +20,10 @@ rust-version = "1.65.0" [workspace] members = ['crates/cpp_smoke_test', 'crates/as-if-std'] exclude = [ - 'crates/without_debuginfo', - 'crates/macos_frames_test', - 'crates/line-tables-only', - 'crates/debuglink', + 'crates/without_debuginfo', + 'crates/macos_frames_test', + 'crates/line-tables-only', + 'crates/debuglink', ] [dependencies] @@ -36,7 +36,7 @@ serde = { version = "1.0", optional = true, features = ['derive'] } # Optionally demangle C++ frames' symbols in backtraces. cpp_demangle = { default-features = false, version = "0.4.0", optional = true, features = [ - "alloc", + "alloc", ] } [target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies] @@ -55,12 +55,14 @@ features = [ "Win32_Foundation", "Win32_Security", "Win32_System_Diagnostics_Debug", + "Win32_System_Diagnostics_ToolHelp", "Win32_System_Kernel", "Win32_System_LibraryLoader", "Win32_System_SystemInformation", "Win32_System_Threading", "Win32_System_WindowsProgramming", "Win32_Globalization", + "Win32_System_Memory" ] [build-dependencies] diff --git a/src/backtrace/dbghelp32.rs b/src/backtrace/dbghelp32.rs index ed4331d5f..e4c4ca34a 100644 --- a/src/backtrace/dbghelp32.rs +++ b/src/backtrace/dbghelp32.rs @@ -12,11 +12,11 @@ #![allow(bad_style)] use windows_sys::{ - Win32::Foundation::*, Win32::System::Diagnostics::Debug::*, - Win32::System::SystemInformation::*, Win32::System::Threading::*, + Win32::System::Diagnostics::Debug::*, Win32::System::SystemInformation::*, + Win32::System::Threading::*, }; -use super::super::dbghelp; +use super::super::{dbghelp, windows::*}; use core::ffi::c_void; use core::mem; diff --git a/src/symbolize/gimli/libs_windows.rs b/src/symbolize/gimli/libs_windows.rs index 05efd5a22..899ca9579 100644 --- a/src/symbolize/gimli/libs_windows.rs +++ b/src/symbolize/gimli/libs_windows.rs @@ -1,3 +1,5 @@ +use windows_sys::{Win32::Foundation::*, Win32::System::Diagnostics::ToolHelp::*}; + use super::super::super::windows::*; use super::mystd::os::windows::prelude::*; use super::{coff, mmap, Library, LibrarySegment, OsString}; diff --git a/src/symbolize/gimli/mmap_windows.rs b/src/symbolize/gimli/mmap_windows.rs index c49ab083c..4940112af 100644 --- a/src/symbolize/gimli/mmap_windows.rs +++ b/src/symbolize/gimli/mmap_windows.rs @@ -1,6 +1,8 @@ -use super::super::super::windows::*; +use windows_sys::{Win32::Foundation::*, Win32::System::Memory::*}; + use super::mystd::fs::File; use super::mystd::os::windows::prelude::*; +use core::ffi::c_void; use core::ops::Deref; use core::ptr; use core::slice; @@ -17,14 +19,14 @@ impl Mmap { pub unsafe fn map(file: &File, len: usize) -> Option { let file = file.try_clone().ok()?; let mapping = CreateFileMappingA( - file.as_raw_handle().cast(), + file.as_raw_handle() as isize, ptr::null_mut(), PAGE_READONLY, 0, 0, ptr::null(), ); - if mapping.is_null() { + if mapping == 0 { return None; } let ptr = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, len); From 372c9c7aaf5389759af9f5bd4d08c08d618a0970 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Sun, 9 Jun 2024 23:08:39 -0700 Subject: [PATCH 06/13] Switch to using windows-bindgen in build.rs --- .gitignore | 1 + Cargo.lock | 186 ++++++++++++++++++---------- Cargo.toml | 18 +-- bindings.txt | 62 ++++++++++ build.rs | 6 + crates/as-if-std/Cargo.toml | 1 + src/backtrace/dbghelp32.rs | 9 +- src/backtrace/dbghelp64.rs | 2 +- src/dbghelp.rs | 14 +-- src/lib.rs | 3 +- src/symbolize/dbghelp.rs | 7 +- src/symbolize/gimli/libs_windows.rs | 3 +- src/symbolize/gimli/mmap_windows.rs | 12 +- src/windows.rs | 3 - 14 files changed, 211 insertions(+), 116 deletions(-) create mode 100644 bindings.txt delete mode 100644 src/windows.rs diff --git a/.gitignore b/.gitignore index eb5a316cb..15827d2fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ target +src/windows_sys.rs diff --git a/Cargo.lock b/Cargo.lock index dd76b46cc..5cfcb0993 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,6 +28,7 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", + "windows-bindgen 0.56.0", ] [[package]] @@ -45,14 +46,14 @@ dependencies = [ "object", "rustc-demangle", "serde", - "windows-sys", + "windows-bindgen 0.57.0", ] [[package]] name = "cc" -version = "1.0.97" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" [[package]] name = "cfg-if" @@ -77,21 +78,58 @@ dependencies = [ "cc", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + [[package]] name = "dylib-dep" version = "0.1.0" +[[package]] +name = "either" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" + [[package]] name = "gimli" version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + [[package]] name = "libc" -version = "0.2.147" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libloading" @@ -105,15 +143,15 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", ] @@ -129,53 +167,90 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + [[package]] name = "serde" -version = "1.0.188" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "serde_json" +version = "1.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "syn" -version = "2.0.29" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -184,9 +259,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "winapi" @@ -211,58 +286,41 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "windows-sys" -version = "0.42.0" +name = "windows-bindgen" +version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +checksum = "a28e3ea6330cf17fdcdce8bf08d0549ce93769dca9bedc6c39c36c8c0e17db46" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "proc-macro2", + "rayon", + "serde", + "serde_json", + "syn", + "windows-metadata 0.56.0", ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" +name = "windows-bindgen" +version = "0.57.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +checksum = "1ccb96113d6277ba543c0f77e1c5494af8094bf9daf9b85acdc3f1b620e7c7b4" +dependencies = [ + "proc-macro2", + "rayon", + "serde", + "serde_json", + "syn", + "windows-metadata 0.57.0", +] [[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" +name = "windows-metadata" +version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "3993f7827fff10c454e3a24847075598c7c08108304b8b07943c2c73d78f3b34" [[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" +name = "windows-metadata" +version = "0.57.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "8308d076825b9d9e5abc64f8113e96d02b2aeeba869b20fdd65c7e70cda13dfc" diff --git a/Cargo.toml b/Cargo.toml index cbf4e4bd7..4508ca042 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,26 +49,12 @@ version = "0.36.0" default-features = false features = ['read_core', 'elf', 'macho', 'pe', 'xcoff', 'unaligned', 'archive'] -[target.'cfg(windows)'.dependencies.windows-sys] -version = "0.42.0" -features = [ - "Win32_Foundation", - "Win32_Security", - "Win32_System_Diagnostics_Debug", - "Win32_System_Diagnostics_ToolHelp", - "Win32_System_Kernel", - "Win32_System_LibraryLoader", - "Win32_System_SystemInformation", - "Win32_System_Threading", - "Win32_System_WindowsProgramming", - "Win32_Globalization", - "Win32_System_Memory" -] - [build-dependencies] # Only needed for Android, but cannot be target dependent # https://github.com/rust-lang/cargo/issues/4932 cc = "1.0.97" +# Same as above but for Windows +windows-bindgen = "0.57" [dev-dependencies] dylib-dep = { path = "crates/dylib-dep" } diff --git a/bindings.txt b/bindings.txt new file mode 100644 index 000000000..6ec077b89 --- /dev/null +++ b/bindings.txt @@ -0,0 +1,62 @@ +--out src/windows_sys.rs +--config std flatten +--filter +Windows.Win32.Foundation.CloseHandle +Windows.Win32.Foundation.HINSTANCE +Windows.Win32.Foundation.INVALID_HANDLE_VALUE +Windows.Win32.Foundation.TRUE +Windows.Win32.Globalization.CP_UTF8 +Windows.Win32.Globalization.lstrlenW +Windows.Win32.Globalization.WideCharToMultiByte +Windows.Win32.System.Diagnostics.Debug.AddrModeFlat +Windows.Win32.System.Diagnostics.Debug.CONTEXT +Windows.Win32.System.Diagnostics.Debug.EnumerateLoadedModulesW64 +Windows.Win32.System.Diagnostics.Debug.IMAGEHLP_LINEW64 +Windows.Win32.System.Diagnostics.Debug.MAX_SYM_NAME +Windows.Win32.System.Diagnostics.Debug.PENUMLOADED_MODULES_CALLBACKW64 +Windows.Win32.System.Diagnostics.Debug.PFUNCTION_TABLE_ACCESS_ROUTINE64 +Windows.Win32.System.Diagnostics.Debug.PGET_MODULE_BASE_ROUTINE64 +Windows.Win32.System.Diagnostics.Debug.PREAD_PROCESS_MEMORY_ROUTINE64 +Windows.Win32.System.Diagnostics.Debug.PTRANSLATE_ADDRESS_ROUTINE64 +Windows.Win32.System.Diagnostics.Debug.RtlCaptureContext +Windows.Win32.System.Diagnostics.Debug.RtlLookupFunctionEntry +Windows.Win32.System.Diagnostics.Debug.RtlVirtualUnwind +Windows.Win32.System.Diagnostics.Debug.STACKFRAME64 +Windows.Win32.System.Diagnostics.Debug.STACKFRAME_EX +Windows.Win32.System.Diagnostics.Debug.StackWalk64 +Windows.Win32.System.Diagnostics.Debug.StackWalkEx +Windows.Win32.System.Diagnostics.Debug.SymAddrIncludeInlineTrace +Windows.Win32.System.Diagnostics.Debug.SYMBOL_INFOW +Windows.Win32.System.Diagnostics.Debug.SymFromAddrW +Windows.Win32.System.Diagnostics.Debug.SymFromInlineContextW +Windows.Win32.System.Diagnostics.Debug.SymFunctionTableAccess64 +Windows.Win32.System.Diagnostics.Debug.SymGetLineFromAddrW64 +Windows.Win32.System.Diagnostics.Debug.SymGetLineFromInlineContextW +Windows.Win32.System.Diagnostics.Debug.SymGetModuleBase64 +Windows.Win32.System.Diagnostics.Debug.SymGetOptions +Windows.Win32.System.Diagnostics.Debug.SymGetSearchPathW +Windows.Win32.System.Diagnostics.Debug.SymInitializeW +Windows.Win32.System.Diagnostics.Debug.SYMOPT_DEFERRED_LOADS +Windows.Win32.System.Diagnostics.Debug.SymQueryInlineTrace +Windows.Win32.System.Diagnostics.Debug.SymSetOptions +Windows.Win32.System.Diagnostics.Debug.SymSetSearchPathW +Windows.Win32.System.Diagnostics.ToolHelp.CreateToolhelp32Snapshot +Windows.Win32.System.Diagnostics.ToolHelp.Module32FirstW +Windows.Win32.System.Diagnostics.ToolHelp.Module32NextW +Windows.Win32.System.Diagnostics.ToolHelp.MODULEENTRY32W +Windows.Win32.System.Diagnostics.ToolHelp.TH32CS_SNAPMODULE +Windows.Win32.System.LibraryLoader.GetProcAddress +Windows.Win32.System.LibraryLoader.LoadLibraryA +Windows.Win32.System.Memory.CreateFileMappingA +Windows.Win32.System.Memory.FILE_MAP_READ +Windows.Win32.System.Memory.MapViewOfFile +Windows.Win32.System.Memory.PAGE_READONLY +Windows.Win32.System.Memory.UnmapViewOfFile +Windows.Win32.System.SystemInformation.IMAGE_FILE_MACHINE_I386 +Windows.Win32.System.Threading.CreateMutexA +Windows.Win32.System.Threading.GetCurrentProcess +Windows.Win32.System.Threading.GetCurrentProcessId +Windows.Win32.System.Threading.GetCurrentThread +Windows.Win32.System.Threading.INFINITE +Windows.Win32.System.Threading.ReleaseMutex +Windows.Win32.System.Threading.WaitForSingleObjectEx \ No newline at end of file diff --git a/build.rs b/build.rs index 2a3da849f..0a61764b5 100644 --- a/build.rs +++ b/build.rs @@ -7,6 +7,7 @@ use std::path::Path; pub fn main() { match env::var("CARGO_CFG_TARGET_OS").unwrap_or_default().as_str() { "android" => build_android(), + "windows" => build_windows(), _ => {} } } @@ -53,3 +54,8 @@ fn build_android() { println!("cargo:rustc-cfg=feature=\"dl_iterate_phdr\""); } } + +fn build_windows() { + let args = ["--etc", "bindings.txt"]; + windows_bindgen::bindgen(args).unwrap(); +} diff --git a/crates/as-if-std/Cargo.toml b/crates/as-if-std/Cargo.toml index c18e379f1..71001666c 100644 --- a/crates/as-if-std/Cargo.toml +++ b/crates/as-if-std/Cargo.toml @@ -29,6 +29,7 @@ features = ['read_core', 'elf', 'macho', 'pe', 'xcoff', 'unaligned', 'archive'] [build-dependencies] # Dependency of the `backtrace` crate cc = "1.0.97" +windows-bindgen = "0.56" [features] default = ['backtrace'] diff --git a/src/backtrace/dbghelp32.rs b/src/backtrace/dbghelp32.rs index e4c4ca34a..4b9ca8166 100644 --- a/src/backtrace/dbghelp32.rs +++ b/src/backtrace/dbghelp32.rs @@ -11,12 +11,7 @@ #![allow(bad_style)] -use windows_sys::{ - Win32::System::Diagnostics::Debug::*, Win32::System::SystemInformation::*, - Win32::System::Threading::*, -}; - -use super::super::{dbghelp, windows::*}; +use super::super::{dbghelp, windows::*, windows_sys::*}; use core::ffi::c_void; use core::mem; @@ -55,7 +50,7 @@ impl Frame { } #[cfg(not(target_env = "gnu"))] - pub fn inline_context(&self) -> Option { + pub fn inline_context(&self) -> Option { match self.stack_frame { StackFrame::New(ref new) => Some(new.InlineFrameContext), StackFrame::Old(_) => None, diff --git a/src/backtrace/dbghelp64.rs b/src/backtrace/dbghelp64.rs index 6dbc4198d..6d0dab623 100644 --- a/src/backtrace/dbghelp64.rs +++ b/src/backtrace/dbghelp64.rs @@ -8,7 +8,7 @@ #![allow(bad_style)] -use windows_sys::Win32::System::Diagnostics::Debug::*; +use super::super::windows_sys::*; use core::ffi::c_void; #[derive(Clone, Copy)] diff --git a/src/dbghelp.rs b/src/dbghelp.rs index 36fe2a8d9..a6250255c 100644 --- a/src/dbghelp.rs +++ b/src/dbghelp.rs @@ -25,13 +25,7 @@ use alloc::vec::Vec; -use windows_sys::{ - core::*, Win32::Foundation::*, Win32::Globalization::*, Win32::System::Diagnostics::Debug::*, - Win32::System::LibraryLoader::*, Win32::System::Threading::*, - Win32::System::WindowsProgramming::*, -}; - -use super::windows::*; +use super::windows_sys::*; use core::ffi::c_void; use core::mem; use core::ptr; @@ -59,7 +53,7 @@ macro_rules! dbghelp { static mut DBGHELP: Dbghelp = Dbghelp { // Initially we haven't loaded the DLL - dll: 0, + dll: ptr::null_mut(), // Initially all functions are set to zero to say they need to be // dynamically loaded. $($name: 0,)* @@ -74,13 +68,13 @@ macro_rules! dbghelp { /// /// Panics if library is already loaded. fn ensure_open(&mut self) -> Result<(), ()> { - if self.dll != 0 { + if !self.dll.is_null() { return Ok(()) } let lib = b"dbghelp.dll\0"; unsafe { self.dll = LoadLibraryA(lib.as_ptr()); - if self.dll == 0 { + if self.dll.is_null() { Err(()) } else { Ok(()) diff --git a/src/lib.rs b/src/lib.rs index 20e9ecb80..7f02405ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -248,5 +248,6 @@ mod lock { not(target_vendor = "uwp") ))] mod dbghelp; +// Auto-generated by windows_bindgen in build.rs #[cfg(windows)] -mod windows; +mod windows_sys; diff --git a/src/symbolize/dbghelp.rs b/src/symbolize/dbghelp.rs index 9ab465951..d4c887ddd 100644 --- a/src/symbolize/dbghelp.rs +++ b/src/symbolize/dbghelp.rs @@ -17,12 +17,7 @@ #![allow(bad_style)] -use windows_sys::{ - Win32::Foundation::*, Win32::Globalization::*, Win32::System::Diagnostics::Debug::*, - Win32::System::Threading::*, -}; - -use super::super::{dbghelp, windows::*}; +use super::super::{dbghelp, windows_sys::*}; use super::{BytesOrWideString, ResolveWhat, SymbolName}; use core::ffi::c_void; use core::marker; diff --git a/src/symbolize/gimli/libs_windows.rs b/src/symbolize/gimli/libs_windows.rs index 899ca9579..9d69f8e48 100644 --- a/src/symbolize/gimli/libs_windows.rs +++ b/src/symbolize/gimli/libs_windows.rs @@ -1,6 +1,5 @@ -use windows_sys::{Win32::Foundation::*, Win32::System::Diagnostics::ToolHelp::*}; - use super::super::super::windows::*; +use super::super::super::windows_sys::*; use super::mystd::os::windows::prelude::*; use super::{coff, mmap, Library, LibrarySegment, OsString}; use alloc::vec; diff --git a/src/symbolize/gimli/mmap_windows.rs b/src/symbolize/gimli/mmap_windows.rs index 4940112af..787eccf91 100644 --- a/src/symbolize/gimli/mmap_windows.rs +++ b/src/symbolize/gimli/mmap_windows.rs @@ -1,4 +1,4 @@ -use windows_sys::{Win32::Foundation::*, Win32::System::Memory::*}; +use super::super::super::windows_sys::*; use super::mystd::fs::File; use super::mystd::os::windows::prelude::*; @@ -19,24 +19,24 @@ impl Mmap { pub unsafe fn map(file: &File, len: usize) -> Option { let file = file.try_clone().ok()?; let mapping = CreateFileMappingA( - file.as_raw_handle() as isize, + file.as_raw_handle(), ptr::null_mut(), PAGE_READONLY, 0, 0, ptr::null(), ); - if mapping == 0 { + if mapping.is_null() { return None; } let ptr = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, len); CloseHandle(mapping); - if ptr.is_null() { + if ptr.Value.is_null() { return None; } Some(Mmap { _file: file, - ptr, + ptr: ptr.Value, len, }) } @@ -52,7 +52,7 @@ impl Deref for Mmap { impl Drop for Mmap { fn drop(&mut self) { unsafe { - let r = UnmapViewOfFile(self.ptr); + let r = UnmapViewOfFile(MEMORY_MAPPED_VIEW_ADDRESS { Value: self.ptr }); debug_assert!(r != 0); } } diff --git a/src/windows.rs b/src/windows.rs deleted file mode 100644 index 7f155c910..000000000 --- a/src/windows.rs +++ /dev/null @@ -1,3 +0,0 @@ -use windows_sys::Win32::Foundation::*; - -pub const TRUE: BOOL = 1; From e89bcf65a67e5d3ab26b7e0a91e3a98a283f1596 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Sun, 9 Jun 2024 23:11:26 -0700 Subject: [PATCH 07/13] Commit generated bindings --- .gitignore | 1 - build.rs | 6 - src/windows_sys.rs | 892 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 892 insertions(+), 7 deletions(-) create mode 100644 src/windows_sys.rs diff --git a/.gitignore b/.gitignore index 15827d2fa..eb5a316cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ target -src/windows_sys.rs diff --git a/build.rs b/build.rs index 0a61764b5..2a3da849f 100644 --- a/build.rs +++ b/build.rs @@ -7,7 +7,6 @@ use std::path::Path; pub fn main() { match env::var("CARGO_CFG_TARGET_OS").unwrap_or_default().as_str() { "android" => build_android(), - "windows" => build_windows(), _ => {} } } @@ -54,8 +53,3 @@ fn build_android() { println!("cargo:rustc-cfg=feature=\"dl_iterate_phdr\""); } } - -fn build_windows() { - let args = ["--etc", "bindings.txt"]; - windows_bindgen::bindgen(args).unwrap(); -} diff --git a/src/windows_sys.rs b/src/windows_sys.rs new file mode 100644 index 000000000..f54f1a657 --- /dev/null +++ b/src/windows_sys.rs @@ -0,0 +1,892 @@ +// Bindings generated by `windows-bindgen` 0.57.0 + +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] +#[link(name = "dbghelp")] +extern "system" { + pub fn EnumerateLoadedModulesW64( + hprocess: HANDLE, + enumloadedmodulescallback: PENUMLOADED_MODULES_CALLBACKW64, + usercontext: *const core::ffi::c_void, + ) -> BOOL; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn StackWalk64( + machinetype: u32, + hprocess: HANDLE, + hthread: HANDLE, + stackframe: *mut STACKFRAME64, + contextrecord: *mut core::ffi::c_void, + readmemoryroutine: PREAD_PROCESS_MEMORY_ROUTINE64, + functiontableaccessroutine: PFUNCTION_TABLE_ACCESS_ROUTINE64, + getmodulebaseroutine: PGET_MODULE_BASE_ROUTINE64, + translateaddress: PTRANSLATE_ADDRESS_ROUTINE64, + ) -> BOOL; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn StackWalkEx( + machinetype: u32, + hprocess: HANDLE, + hthread: HANDLE, + stackframe: *mut STACKFRAME_EX, + contextrecord: *mut core::ffi::c_void, + readmemoryroutine: PREAD_PROCESS_MEMORY_ROUTINE64, + functiontableaccessroutine: PFUNCTION_TABLE_ACCESS_ROUTINE64, + getmodulebaseroutine: PGET_MODULE_BASE_ROUTINE64, + translateaddress: PTRANSLATE_ADDRESS_ROUTINE64, + flags: u32, + ) -> BOOL; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn SymAddrIncludeInlineTrace(hprocess: HANDLE, address: u64) -> u32; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn SymFromAddrW( + hprocess: HANDLE, + address: u64, + displacement: *mut u64, + symbol: *mut SYMBOL_INFOW, + ) -> BOOL; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn SymFromInlineContextW( + hprocess: HANDLE, + address: u64, + inlinecontext: u32, + displacement: *mut u64, + symbol: *mut SYMBOL_INFOW, + ) -> BOOL; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn SymFunctionTableAccess64(hprocess: HANDLE, addrbase: u64) -> *mut core::ffi::c_void; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn SymGetLineFromAddrW64( + hprocess: HANDLE, + dwaddr: u64, + pdwdisplacement: *mut u32, + line: *mut IMAGEHLP_LINEW64, + ) -> BOOL; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn SymGetLineFromInlineContextW( + hprocess: HANDLE, + dwaddr: u64, + inlinecontext: u32, + qwmodulebaseaddress: u64, + pdwdisplacement: *mut u32, + line: *mut IMAGEHLP_LINEW64, + ) -> BOOL; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn SymGetModuleBase64(hprocess: HANDLE, qwaddr: u64) -> u64; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn SymGetOptions() -> u32; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn SymGetSearchPathW(hprocess: HANDLE, searchpatha: PWSTR, searchpathlength: u32) -> BOOL; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn SymInitializeW(hprocess: HANDLE, usersearchpath: PCWSTR, finvadeprocess: BOOL) -> BOOL; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn SymQueryInlineTrace( + hprocess: HANDLE, + startaddress: u64, + startcontext: u32, + startretaddress: u64, + curaddress: u64, + curcontext: *mut u32, + curframeindex: *mut u32, + ) -> BOOL; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn SymSetOptions(symoptions: u32) -> u32; +} +#[link(name = "dbghelp")] +extern "system" { + pub fn SymSetSearchPathW(hprocess: HANDLE, searchpatha: PCWSTR) -> BOOL; +} +#[link(name = "kernel32")] +extern "system" { + pub fn CloseHandle(hobject: HANDLE) -> BOOL; +} +#[link(name = "kernel32")] +extern "system" { + pub fn CreateFileMappingA( + hfile: HANDLE, + lpfilemappingattributes: *const SECURITY_ATTRIBUTES, + flprotect: PAGE_PROTECTION_FLAGS, + dwmaximumsizehigh: u32, + dwmaximumsizelow: u32, + lpname: PCSTR, + ) -> HANDLE; +} +#[link(name = "kernel32")] +extern "system" { + pub fn CreateMutexA( + lpmutexattributes: *const SECURITY_ATTRIBUTES, + binitialowner: BOOL, + lpname: PCSTR, + ) -> HANDLE; +} +#[link(name = "kernel32")] +extern "system" { + pub fn CreateToolhelp32Snapshot( + dwflags: CREATE_TOOLHELP_SNAPSHOT_FLAGS, + th32processid: u32, + ) -> HANDLE; +} +#[link(name = "kernel32")] +extern "system" { + pub fn GetCurrentProcess() -> HANDLE; +} +#[link(name = "kernel32")] +extern "system" { + pub fn GetCurrentProcessId() -> u32; +} +#[link(name = "kernel32")] +extern "system" { + pub fn GetCurrentThread() -> HANDLE; +} +#[link(name = "kernel32")] +extern "system" { + pub fn GetProcAddress(hmodule: HMODULE, lpprocname: PCSTR) -> FARPROC; +} +#[link(name = "kernel32")] +extern "system" { + pub fn LoadLibraryA(lplibfilename: PCSTR) -> HMODULE; +} +#[link(name = "kernel32")] +extern "system" { + pub fn MapViewOfFile( + hfilemappingobject: HANDLE, + dwdesiredaccess: FILE_MAP, + dwfileoffsethigh: u32, + dwfileoffsetlow: u32, + dwnumberofbytestomap: usize, + ) -> MEMORY_MAPPED_VIEW_ADDRESS; +} +#[link(name = "kernel32")] +extern "system" { + pub fn Module32FirstW(hsnapshot: HANDLE, lpme: *mut MODULEENTRY32W) -> BOOL; +} +#[link(name = "kernel32")] +extern "system" { + pub fn Module32NextW(hsnapshot: HANDLE, lpme: *mut MODULEENTRY32W) -> BOOL; +} +#[link(name = "kernel32")] +extern "system" { + pub fn ReleaseMutex(hmutex: HANDLE) -> BOOL; +} +#[link(name = "kernel32")] +extern "system" { + pub fn RtlCaptureContext(contextrecord: *mut CONTEXT); +} +#[cfg(target_arch = "aarch64")] +#[link(name = "kernel32")] +extern "system" { + pub fn RtlLookupFunctionEntry( + controlpc: usize, + imagebase: *mut usize, + historytable: *mut UNWIND_HISTORY_TABLE, + ) -> *mut IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY; +} +#[cfg(any(target_arch = "arm64ec", target_arch = "x86_64"))] +#[link(name = "kernel32")] +extern "system" { + pub fn RtlLookupFunctionEntry( + controlpc: u64, + imagebase: *mut u64, + historytable: *mut UNWIND_HISTORY_TABLE, + ) -> *mut IMAGE_RUNTIME_FUNCTION_ENTRY; +} +#[cfg(target_arch = "aarch64")] +#[link(name = "kernel32")] +extern "system" { + pub fn RtlVirtualUnwind( + handlertype: RTL_VIRTUAL_UNWIND_HANDLER_TYPE, + imagebase: usize, + controlpc: usize, + functionentry: *const IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY, + contextrecord: *mut CONTEXT, + handlerdata: *mut *mut core::ffi::c_void, + establisherframe: *mut usize, + contextpointers: *mut KNONVOLATILE_CONTEXT_POINTERS_ARM64, + ) -> EXCEPTION_ROUTINE; +} +#[cfg(any(target_arch = "arm64ec", target_arch = "x86_64"))] +#[link(name = "kernel32")] +extern "system" { + pub fn RtlVirtualUnwind( + handlertype: RTL_VIRTUAL_UNWIND_HANDLER_TYPE, + imagebase: u64, + controlpc: u64, + functionentry: *const IMAGE_RUNTIME_FUNCTION_ENTRY, + contextrecord: *mut CONTEXT, + handlerdata: *mut *mut core::ffi::c_void, + establisherframe: *mut u64, + contextpointers: *mut KNONVOLATILE_CONTEXT_POINTERS, + ) -> EXCEPTION_ROUTINE; +} +#[link(name = "kernel32")] +extern "system" { + pub fn UnmapViewOfFile(lpbaseaddress: MEMORY_MAPPED_VIEW_ADDRESS) -> BOOL; +} +#[link(name = "kernel32")] +extern "system" { + pub fn WaitForSingleObjectEx( + hhandle: HANDLE, + dwmilliseconds: u32, + balertable: BOOL, + ) -> WAIT_EVENT; +} +#[link(name = "kernel32")] +extern "system" { + pub fn WideCharToMultiByte( + codepage: u32, + dwflags: u32, + lpwidecharstr: PCWSTR, + cchwidechar: i32, + lpmultibytestr: PSTR, + cbmultibyte: i32, + lpdefaultchar: PCSTR, + lpuseddefaultchar: *mut BOOL, + ) -> i32; +} +#[link(name = "kernel32")] +extern "system" { + pub fn lstrlenW(lpstring: PCWSTR) -> i32; +} +#[repr(C)] +#[derive(Clone, Copy)] +pub struct ADDRESS64 { + pub Offset: u64, + pub Segment: u16, + pub Mode: ADDRESS_MODE, +} +pub type ADDRESS_MODE = i32; +#[repr(C)] +#[derive(Clone, Copy)] +pub union ARM64_NT_NEON128 { + pub Anonymous: ARM64_NT_NEON128_0, + pub D: [f64; 2], + pub S: [f32; 4], + pub H: [u16; 8], + pub B: [u8; 16], +} +#[repr(C)] +#[derive(Clone, Copy)] +pub struct ARM64_NT_NEON128_0 { + pub Low: u64, + pub High: i64, +} +pub const AddrModeFlat: ADDRESS_MODE = 3i32; +pub type BOOL = i32; +#[repr(C)] +#[cfg(target_arch = "aarch64")] +#[derive(Clone, Copy)] +pub struct CONTEXT { + pub ContextFlags: CONTEXT_FLAGS, + pub Cpsr: u32, + pub Anonymous: CONTEXT_0, + pub Sp: u64, + pub Pc: u64, + pub V: [ARM64_NT_NEON128; 32], + pub Fpcr: u32, + pub Fpsr: u32, + pub Bcr: [u32; 8], + pub Bvr: [u64; 8], + pub Wcr: [u32; 2], + pub Wvr: [u64; 2], +} +#[repr(C)] +#[cfg(target_arch = "aarch64")] +#[derive(Clone, Copy)] +pub union CONTEXT_0 { + pub Anonymous: CONTEXT_0_0, + pub X: [u64; 31], +} +#[repr(C)] +#[cfg(target_arch = "aarch64")] +#[derive(Clone, Copy)] +pub struct CONTEXT_0_0 { + pub X0: u64, + pub X1: u64, + pub X2: u64, + pub X3: u64, + pub X4: u64, + pub X5: u64, + pub X6: u64, + pub X7: u64, + pub X8: u64, + pub X9: u64, + pub X10: u64, + pub X11: u64, + pub X12: u64, + pub X13: u64, + pub X14: u64, + pub X15: u64, + pub X16: u64, + pub X17: u64, + pub X18: u64, + pub X19: u64, + pub X20: u64, + pub X21: u64, + pub X22: u64, + pub X23: u64, + pub X24: u64, + pub X25: u64, + pub X26: u64, + pub X27: u64, + pub X28: u64, + pub Fp: u64, + pub Lr: u64, +} +#[repr(C)] +#[cfg(any(target_arch = "arm64ec", target_arch = "x86_64"))] +#[derive(Clone, Copy)] +pub struct CONTEXT { + pub P1Home: u64, + pub P2Home: u64, + pub P3Home: u64, + pub P4Home: u64, + pub P5Home: u64, + pub P6Home: u64, + pub ContextFlags: CONTEXT_FLAGS, + pub MxCsr: u32, + pub SegCs: u16, + pub SegDs: u16, + pub SegEs: u16, + pub SegFs: u16, + pub SegGs: u16, + pub SegSs: u16, + pub EFlags: u32, + pub Dr0: u64, + pub Dr1: u64, + pub Dr2: u64, + pub Dr3: u64, + pub Dr6: u64, + pub Dr7: u64, + pub Rax: u64, + pub Rcx: u64, + pub Rdx: u64, + pub Rbx: u64, + pub Rsp: u64, + pub Rbp: u64, + pub Rsi: u64, + pub Rdi: u64, + pub R8: u64, + pub R9: u64, + pub R10: u64, + pub R11: u64, + pub R12: u64, + pub R13: u64, + pub R14: u64, + pub R15: u64, + pub Rip: u64, + pub Anonymous: CONTEXT_0, + pub VectorRegister: [M128A; 26], + pub VectorControl: u64, + pub DebugControl: u64, + pub LastBranchToRip: u64, + pub LastBranchFromRip: u64, + pub LastExceptionToRip: u64, + pub LastExceptionFromRip: u64, +} +#[repr(C)] +#[cfg(any(target_arch = "arm64ec", target_arch = "x86_64"))] +#[derive(Clone, Copy)] +pub union CONTEXT_0 { + pub FltSave: XSAVE_FORMAT, + pub Anonymous: CONTEXT_0_0, +} +#[repr(C)] +#[cfg(any(target_arch = "arm64ec", target_arch = "x86_64"))] +#[derive(Clone, Copy)] +pub struct CONTEXT_0_0 { + pub Header: [M128A; 2], + pub Legacy: [M128A; 8], + pub Xmm0: M128A, + pub Xmm1: M128A, + pub Xmm2: M128A, + pub Xmm3: M128A, + pub Xmm4: M128A, + pub Xmm5: M128A, + pub Xmm6: M128A, + pub Xmm7: M128A, + pub Xmm8: M128A, + pub Xmm9: M128A, + pub Xmm10: M128A, + pub Xmm11: M128A, + pub Xmm12: M128A, + pub Xmm13: M128A, + pub Xmm14: M128A, + pub Xmm15: M128A, +} +#[repr(C)] +#[cfg(target_arch = "x86")] +#[derive(Clone, Copy)] +pub struct CONTEXT { + pub ContextFlags: CONTEXT_FLAGS, + pub Dr0: u32, + pub Dr1: u32, + pub Dr2: u32, + pub Dr3: u32, + pub Dr6: u32, + pub Dr7: u32, + pub FloatSave: FLOATING_SAVE_AREA, + pub SegGs: u32, + pub SegFs: u32, + pub SegEs: u32, + pub SegDs: u32, + pub Edi: u32, + pub Esi: u32, + pub Ebx: u32, + pub Edx: u32, + pub Ecx: u32, + pub Eax: u32, + pub Ebp: u32, + pub Eip: u32, + pub SegCs: u32, + pub EFlags: u32, + pub Esp: u32, + pub SegSs: u32, + pub ExtendedRegisters: [u8; 512], +} +pub type CONTEXT_FLAGS = u32; +pub const CP_UTF8: u32 = 65001u32; +pub type CREATE_TOOLHELP_SNAPSHOT_FLAGS = u32; +pub type EXCEPTION_DISPOSITION = i32; +#[repr(C)] +#[derive(Clone, Copy)] +pub struct EXCEPTION_RECORD { + pub ExceptionCode: NTSTATUS, + pub ExceptionFlags: u32, + pub ExceptionRecord: *mut EXCEPTION_RECORD, + pub ExceptionAddress: *mut core::ffi::c_void, + pub NumberParameters: u32, + pub ExceptionInformation: [usize; 15], +} +pub type EXCEPTION_ROUTINE = Option< + unsafe extern "system" fn( + exceptionrecord: *mut EXCEPTION_RECORD, + establisherframe: *const core::ffi::c_void, + contextrecord: *mut CONTEXT, + dispatchercontext: *const core::ffi::c_void, + ) -> EXCEPTION_DISPOSITION, +>; +pub type FARPROC = Option isize>; +pub type FILE_MAP = u32; +pub const FILE_MAP_READ: FILE_MAP = 4u32; +#[repr(C)] +#[cfg(any( + target_arch = "aarch64", + target_arch = "arm64ec", + target_arch = "x86_64" +))] +#[derive(Clone, Copy)] +pub struct FLOATING_SAVE_AREA { + pub ControlWord: u32, + pub StatusWord: u32, + pub TagWord: u32, + pub ErrorOffset: u32, + pub ErrorSelector: u32, + pub DataOffset: u32, + pub DataSelector: u32, + pub RegisterArea: [u8; 80], + pub Cr0NpxState: u32, +} +#[repr(C)] +#[cfg(target_arch = "x86")] +#[derive(Clone, Copy)] +pub struct FLOATING_SAVE_AREA { + pub ControlWord: u32, + pub StatusWord: u32, + pub TagWord: u32, + pub ErrorOffset: u32, + pub ErrorSelector: u32, + pub DataOffset: u32, + pub DataSelector: u32, + pub RegisterArea: [u8; 80], + pub Spare0: u32, +} +pub type HANDLE = *mut core::ffi::c_void; +pub type HINSTANCE = *mut core::ffi::c_void; +pub type HMODULE = *mut core::ffi::c_void; +#[repr(C)] +#[derive(Clone, Copy)] +pub struct IMAGEHLP_LINEW64 { + pub SizeOfStruct: u32, + pub Key: *mut core::ffi::c_void, + pub LineNumber: u32, + pub FileName: PWSTR, + pub Address: u64, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub struct IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY { + pub BeginAddress: u32, + pub Anonymous: IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY_0, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub union IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY_0 { + pub UnwindData: u32, + pub Anonymous: IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY_0_0, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub struct IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY_0_0 { + pub _bitfield: u32, +} +pub type IMAGE_FILE_MACHINE = u16; +pub const IMAGE_FILE_MACHINE_I386: IMAGE_FILE_MACHINE = 332u16; +#[repr(C)] +#[derive(Clone, Copy)] +pub struct IMAGE_RUNTIME_FUNCTION_ENTRY { + pub BeginAddress: u32, + pub EndAddress: u32, + pub Anonymous: IMAGE_RUNTIME_FUNCTION_ENTRY_0, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub union IMAGE_RUNTIME_FUNCTION_ENTRY_0 { + pub UnwindInfoAddress: u32, + pub UnwindData: u32, +} +pub const INFINITE: u32 = 4294967295u32; +pub const INVALID_HANDLE_VALUE: HANDLE = -1i32 as _; +#[repr(C)] +#[derive(Clone, Copy)] +pub struct KDHELP64 { + pub Thread: u64, + pub ThCallbackStack: u32, + pub ThCallbackBStore: u32, + pub NextCallback: u32, + pub FramePointer: u32, + pub KiCallUserMode: u64, + pub KeUserCallbackDispatcher: u64, + pub SystemRangeStart: u64, + pub KiUserExceptionDispatcher: u64, + pub StackBase: u64, + pub StackLimit: u64, + pub BuildVersion: u32, + pub RetpolineStubFunctionTableSize: u32, + pub RetpolineStubFunctionTable: u64, + pub RetpolineStubOffset: u32, + pub RetpolineStubSize: u32, + pub Reserved0: [u64; 2], +} +#[repr(C)] +#[cfg(any(target_arch = "arm64ec", target_arch = "x86_64"))] +#[derive(Clone, Copy)] +pub struct KNONVOLATILE_CONTEXT_POINTERS { + pub Anonymous1: KNONVOLATILE_CONTEXT_POINTERS_0, + pub Anonymous2: KNONVOLATILE_CONTEXT_POINTERS_1, +} +#[repr(C)] +#[cfg(any(target_arch = "arm64ec", target_arch = "x86_64"))] +#[derive(Clone, Copy)] +pub union KNONVOLATILE_CONTEXT_POINTERS_0 { + pub FloatingContext: [*mut M128A; 16], + pub Anonymous: KNONVOLATILE_CONTEXT_POINTERS_0_0, +} +#[repr(C)] +#[cfg(any(target_arch = "arm64ec", target_arch = "x86_64"))] +#[derive(Clone, Copy)] +pub struct KNONVOLATILE_CONTEXT_POINTERS_0_0 { + pub Xmm0: *mut M128A, + pub Xmm1: *mut M128A, + pub Xmm2: *mut M128A, + pub Xmm3: *mut M128A, + pub Xmm4: *mut M128A, + pub Xmm5: *mut M128A, + pub Xmm6: *mut M128A, + pub Xmm7: *mut M128A, + pub Xmm8: *mut M128A, + pub Xmm9: *mut M128A, + pub Xmm10: *mut M128A, + pub Xmm11: *mut M128A, + pub Xmm12: *mut M128A, + pub Xmm13: *mut M128A, + pub Xmm14: *mut M128A, + pub Xmm15: *mut M128A, +} +#[repr(C)] +#[cfg(any(target_arch = "arm64ec", target_arch = "x86_64"))] +#[derive(Clone, Copy)] +pub union KNONVOLATILE_CONTEXT_POINTERS_1 { + pub IntegerContext: [*mut u64; 16], + pub Anonymous: KNONVOLATILE_CONTEXT_POINTERS_1_0, +} +#[repr(C)] +#[cfg(any(target_arch = "arm64ec", target_arch = "x86_64"))] +#[derive(Clone, Copy)] +pub struct KNONVOLATILE_CONTEXT_POINTERS_1_0 { + pub Rax: *mut u64, + pub Rcx: *mut u64, + pub Rdx: *mut u64, + pub Rbx: *mut u64, + pub Rsp: *mut u64, + pub Rbp: *mut u64, + pub Rsi: *mut u64, + pub Rdi: *mut u64, + pub R8: *mut u64, + pub R9: *mut u64, + pub R10: *mut u64, + pub R11: *mut u64, + pub R12: *mut u64, + pub R13: *mut u64, + pub R14: *mut u64, + pub R15: *mut u64, +} +#[repr(C)] +#[cfg(target_arch = "x86")] +#[derive(Clone, Copy)] +pub struct KNONVOLATILE_CONTEXT_POINTERS { + pub Dummy: u32, +} +#[repr(C)] +#[cfg(target_arch = "aarch64")] +#[derive(Clone, Copy)] +pub struct KNONVOLATILE_CONTEXT_POINTERS_ARM64 { + pub X19: *mut u64, + pub X20: *mut u64, + pub X21: *mut u64, + pub X22: *mut u64, + pub X23: *mut u64, + pub X24: *mut u64, + pub X25: *mut u64, + pub X26: *mut u64, + pub X27: *mut u64, + pub X28: *mut u64, + pub Fp: *mut u64, + pub Lr: *mut u64, + pub D8: *mut u64, + pub D9: *mut u64, + pub D10: *mut u64, + pub D11: *mut u64, + pub D12: *mut u64, + pub D13: *mut u64, + pub D14: *mut u64, + pub D15: *mut u64, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub struct M128A { + pub Low: u64, + pub High: i64, +} +pub const MAX_SYM_NAME: u32 = 2000u32; +#[repr(C)] +#[derive(Clone, Copy)] +pub struct MEMORY_MAPPED_VIEW_ADDRESS { + pub Value: *mut core::ffi::c_void, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub struct MODULEENTRY32W { + pub dwSize: u32, + pub th32ModuleID: u32, + pub th32ProcessID: u32, + pub GlblcntUsage: u32, + pub ProccntUsage: u32, + pub modBaseAddr: *mut u8, + pub modBaseSize: u32, + pub hModule: HMODULE, + pub szModule: [u16; 256], + pub szExePath: [u16; 260], +} +pub type NTSTATUS = i32; +pub type PAGE_PROTECTION_FLAGS = u32; +pub const PAGE_READONLY: PAGE_PROTECTION_FLAGS = 2u32; +pub type PCSTR = *const u8; +pub type PCWSTR = *const u16; +pub type PENUMLOADED_MODULES_CALLBACKW64 = Option< + unsafe extern "system" fn( + modulename: PCWSTR, + modulebase: u64, + modulesize: u32, + usercontext: *const core::ffi::c_void, + ) -> BOOL, +>; +pub type PFUNCTION_TABLE_ACCESS_ROUTINE64 = + Option *mut core::ffi::c_void>; +pub type PGET_MODULE_BASE_ROUTINE64 = + Option u64>; +pub type PREAD_PROCESS_MEMORY_ROUTINE64 = Option< + unsafe extern "system" fn( + hprocess: HANDLE, + qwbaseaddress: u64, + lpbuffer: *mut core::ffi::c_void, + nsize: u32, + lpnumberofbytesread: *mut u32, + ) -> BOOL, +>; +pub type PSTR = *mut u8; +pub type PTRANSLATE_ADDRESS_ROUTINE64 = Option< + unsafe extern "system" fn(hprocess: HANDLE, hthread: HANDLE, lpaddr: *const ADDRESS64) -> u64, +>; +pub type PWSTR = *mut u16; +pub type RTL_VIRTUAL_UNWIND_HANDLER_TYPE = u32; +#[repr(C)] +#[derive(Clone, Copy)] +pub struct SECURITY_ATTRIBUTES { + pub nLength: u32, + pub lpSecurityDescriptor: *mut core::ffi::c_void, + pub bInheritHandle: BOOL, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub struct STACKFRAME64 { + pub AddrPC: ADDRESS64, + pub AddrReturn: ADDRESS64, + pub AddrFrame: ADDRESS64, + pub AddrStack: ADDRESS64, + pub AddrBStore: ADDRESS64, + pub FuncTableEntry: *mut core::ffi::c_void, + pub Params: [u64; 4], + pub Far: BOOL, + pub Virtual: BOOL, + pub Reserved: [u64; 3], + pub KdHelp: KDHELP64, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub struct STACKFRAME_EX { + pub AddrPC: ADDRESS64, + pub AddrReturn: ADDRESS64, + pub AddrFrame: ADDRESS64, + pub AddrStack: ADDRESS64, + pub AddrBStore: ADDRESS64, + pub FuncTableEntry: *mut core::ffi::c_void, + pub Params: [u64; 4], + pub Far: BOOL, + pub Virtual: BOOL, + pub Reserved: [u64; 3], + pub KdHelp: KDHELP64, + pub StackFrameSize: u32, + pub InlineFrameContext: u32, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub struct SYMBOL_INFOW { + pub SizeOfStruct: u32, + pub TypeIndex: u32, + pub Reserved: [u64; 2], + pub Index: u32, + pub Size: u32, + pub ModBase: u64, + pub Flags: SYMBOL_INFO_FLAGS, + pub Value: u64, + pub Address: u64, + pub Register: u32, + pub Scope: u32, + pub Tag: u32, + pub NameLen: u32, + pub MaxNameLen: u32, + pub Name: [u16; 1], +} +pub type SYMBOL_INFO_FLAGS = u32; +pub const SYMOPT_DEFERRED_LOADS: u32 = 4u32; +pub const TH32CS_SNAPMODULE: CREATE_TOOLHELP_SNAPSHOT_FLAGS = 8u32; +pub const TRUE: BOOL = 1i32; +#[repr(C)] +#[cfg(any( + target_arch = "aarch64", + target_arch = "arm64ec", + target_arch = "x86_64" +))] +#[derive(Clone, Copy)] +pub struct UNWIND_HISTORY_TABLE { + pub Count: u32, + pub LocalHint: u8, + pub GlobalHint: u8, + pub Search: u8, + pub Once: u8, + pub LowAddress: usize, + pub HighAddress: usize, + pub Entry: [UNWIND_HISTORY_TABLE_ENTRY; 12], +} +#[repr(C)] +#[cfg(target_arch = "aarch64")] +#[derive(Clone, Copy)] +pub struct UNWIND_HISTORY_TABLE_ENTRY { + pub ImageBase: usize, + pub FunctionEntry: *mut IMAGE_ARM64_RUNTIME_FUNCTION_ENTRY, +} +#[repr(C)] +#[cfg(any(target_arch = "arm64ec", target_arch = "x86_64"))] +#[derive(Clone, Copy)] +pub struct UNWIND_HISTORY_TABLE_ENTRY { + pub ImageBase: usize, + pub FunctionEntry: *mut IMAGE_RUNTIME_FUNCTION_ENTRY, +} +pub type WAIT_EVENT = u32; +#[repr(C)] +#[cfg(any( + target_arch = "aarch64", + target_arch = "arm64ec", + target_arch = "x86_64" +))] +#[derive(Clone, Copy)] +pub struct XSAVE_FORMAT { + pub ControlWord: u16, + pub StatusWord: u16, + pub TagWord: u8, + pub Reserved1: u8, + pub ErrorOpcode: u16, + pub ErrorOffset: u32, + pub ErrorSelector: u16, + pub Reserved2: u16, + pub DataOffset: u32, + pub DataSelector: u16, + pub Reserved3: u16, + pub MxCsr: u32, + pub MxCsr_Mask: u32, + pub FloatRegisters: [M128A; 8], + pub XmmRegisters: [M128A; 16], + pub Reserved4: [u8; 96], +} +#[repr(C)] +#[cfg(target_arch = "x86")] +#[derive(Clone, Copy)] +pub struct XSAVE_FORMAT { + pub ControlWord: u16, + pub StatusWord: u16, + pub TagWord: u8, + pub Reserved1: u8, + pub ErrorOpcode: u16, + pub ErrorOffset: u32, + pub ErrorSelector: u16, + pub Reserved2: u16, + pub DataOffset: u32, + pub DataSelector: u16, + pub Reserved3: u16, + pub MxCsr: u32, + pub MxCsr_Mask: u32, + pub FloatRegisters: [M128A; 8], + pub XmmRegisters: [M128A; 8], + pub Reserved4: [u8; 224], +} From 8168c6c832ef23974e5b4e0125e5a9bc35f1b69d Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Sun, 9 Jun 2024 23:13:02 -0700 Subject: [PATCH 08/13] Remove remaining references to `windows::*` --- src/backtrace/dbghelp32.rs | 2 +- src/symbolize/gimli/libs_windows.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backtrace/dbghelp32.rs b/src/backtrace/dbghelp32.rs index 4b9ca8166..35ec03c4d 100644 --- a/src/backtrace/dbghelp32.rs +++ b/src/backtrace/dbghelp32.rs @@ -11,7 +11,7 @@ #![allow(bad_style)] -use super::super::{dbghelp, windows::*, windows_sys::*}; +use super::super::{dbghelp, windows_sys::*}; use core::ffi::c_void; use core::mem; diff --git a/src/symbolize/gimli/libs_windows.rs b/src/symbolize/gimli/libs_windows.rs index 9d69f8e48..9afeaf913 100644 --- a/src/symbolize/gimli/libs_windows.rs +++ b/src/symbolize/gimli/libs_windows.rs @@ -1,4 +1,3 @@ -use super::super::super::windows::*; use super::super::super::windows_sys::*; use super::mystd::os::windows::prelude::*; use super::{coff, mmap, Library, LibrarySegment, OsString}; From d2695699b2b34c2f6a7de5e75da6d8808438fc3c Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Sun, 9 Jun 2024 23:14:34 -0700 Subject: [PATCH 09/13] Removing bindgen build dep - should move this to a helper, or just add instruction to run riddle. --- Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4508ca042..2c49f60dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,8 +53,6 @@ features = ['read_core', 'elf', 'macho', 'pe', 'xcoff', 'unaligned', 'archive'] # Only needed for Android, but cannot be target dependent # https://github.com/rust-lang/cargo/issues/4932 cc = "1.0.97" -# Same as above but for Windows -windows-bindgen = "0.57" [dev-dependencies] dylib-dep = { path = "crates/dylib-dep" } From d00d319c9a997b7611a4449b0edc78b7e9727867 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Sun, 9 Jun 2024 23:19:06 -0700 Subject: [PATCH 10/13] Fix AArch64 --- src/backtrace/dbghelp64.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backtrace/dbghelp64.rs b/src/backtrace/dbghelp64.rs index 6d0dab623..88bf3d090 100644 --- a/src/backtrace/dbghelp64.rs +++ b/src/backtrace/dbghelp64.rs @@ -67,13 +67,13 @@ impl MyContext { #[cfg(target_arch = "aarch64")] impl MyContext { #[inline(always)] - fn ip(&self) -> DWORD64 { - self.0.Pc + fn ip(&self) -> usize { + self.0.Pc as usize } #[inline(always)] - fn sp(&self) -> DWORD64 { - self.0.Sp + fn sp(&self) -> usize { + self.0.Sp as usize } } From a18dee601d9e831b934fdd427011f656da540826 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Mon, 10 Jun 2024 13:31:16 -0700 Subject: [PATCH 11/13] Nits/Cleanups --- Cargo.lock | 25 ++----------------------- Cargo.toml | 10 +++++----- src/backtrace/dbghelp32.rs | 4 ++-- src/backtrace/dbghelp64.rs | 2 +- src/dbghelp.rs | 6 +++--- src/lib.rs | 2 +- 6 files changed, 14 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5cfcb0993..e21e11d9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,7 +28,7 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", - "windows-bindgen 0.56.0", + "windows-bindgen", ] [[package]] @@ -46,7 +46,6 @@ dependencies = [ "object", "rustc-demangle", "serde", - "windows-bindgen 0.57.0", ] [[package]] @@ -296,21 +295,7 @@ dependencies = [ "serde", "serde_json", "syn", - "windows-metadata 0.56.0", -] - -[[package]] -name = "windows-bindgen" -version = "0.57.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ccb96113d6277ba543c0f77e1c5494af8094bf9daf9b85acdc3f1b620e7c7b4" -dependencies = [ - "proc-macro2", - "rayon", - "serde", - "serde_json", - "syn", - "windows-metadata 0.57.0", + "windows-metadata", ] [[package]] @@ -318,9 +303,3 @@ name = "windows-metadata" version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3993f7827fff10c454e3a24847075598c7c08108304b8b07943c2c73d78f3b34" - -[[package]] -name = "windows-metadata" -version = "0.57.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8308d076825b9d9e5abc64f8113e96d02b2aeeba869b20fdd65c7e70cda13dfc" diff --git a/Cargo.toml b/Cargo.toml index 2c49f60dd..5e2ee1ee8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,10 +20,10 @@ rust-version = "1.65.0" [workspace] members = ['crates/cpp_smoke_test', 'crates/as-if-std'] exclude = [ - 'crates/without_debuginfo', - 'crates/macos_frames_test', - 'crates/line-tables-only', - 'crates/debuglink', + 'crates/without_debuginfo', + 'crates/macos_frames_test', + 'crates/line-tables-only', + 'crates/debuglink', ] [dependencies] @@ -36,7 +36,7 @@ serde = { version = "1.0", optional = true, features = ['derive'] } # Optionally demangle C++ frames' symbols in backtraces. cpp_demangle = { default-features = false, version = "0.4.0", optional = true, features = [ - "alloc", + "alloc", ] } [target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies] diff --git a/src/backtrace/dbghelp32.rs b/src/backtrace/dbghelp32.rs index 35ec03c4d..cc71edff7 100644 --- a/src/backtrace/dbghelp32.rs +++ b/src/backtrace/dbghelp32.rs @@ -93,7 +93,7 @@ impl Frame { } } -#[repr(C, align(16))] // required by `CONTEXT`, is a FIXME in winapi right now +#[repr(C, align(16))] // required by `CONTEXT`, is a FIXME in windows metadata right now struct MyContext(CONTEXT); #[inline(always)] @@ -176,7 +176,7 @@ pub unsafe fn trace(cb: &mut dyn FnMut(&super::Frame) -> bool) { }; while dbghelp.StackWalk64()( - image as _, + image as u32, process, thread, frame_ptr, diff --git a/src/backtrace/dbghelp64.rs b/src/backtrace/dbghelp64.rs index 88bf3d090..fd31388c9 100644 --- a/src/backtrace/dbghelp64.rs +++ b/src/backtrace/dbghelp64.rs @@ -48,7 +48,7 @@ impl Frame { } } -#[repr(C, align(16))] // required by `CONTEXT`, is a FIXME in winapi right now +#[repr(C, align(16))] // required by `CONTEXT`, is a FIXME in windows metadata right now struct MyContext(CONTEXT); #[cfg(any(target_arch = "x86_64", target_arch = "arm64ec"))] diff --git a/src/dbghelp.rs b/src/dbghelp.rs index a6250255c..cc0c23cc5 100644 --- a/src/dbghelp.rs +++ b/src/dbghelp.rs @@ -9,10 +9,10 @@ //! said, `dbghelp.dll` almost always successfully loads on Windows. //! //! Note though that since we're loading all this support dynamically we can't -//! actually use the raw definitions in `winapi`, but rather we need to define +//! actually use the raw definitions in `windows_sys`, but rather we need to define //! the function pointer types ourselves and use that. We don't really want to -//! be in the business of duplicating winapi, so we have a Cargo feature -//! `verify-windows-sys` which asserts that all bindings match those in winapi and +//! be in the business of duplicating auto-generated bindings, so we have a Cargo feature +//! `verify-windows-sys` which asserts that all bindings match those in `windows_sys.rs` and //! this feature is enabled on CI. //! //! Finally, you'll note here that the dll for `dbghelp.dll` is never unloaded, diff --git a/src/lib.rs b/src/lib.rs index 7f02405ce..0b9bb56ae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -248,6 +248,6 @@ mod lock { not(target_vendor = "uwp") ))] mod dbghelp; -// Auto-generated by windows_bindgen in build.rs +// Auto-generated by windows-bindgen/riddle #[cfg(windows)] mod windows_sys; From 1895284cea8dd09255914fe192ede1bc9084b712 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 14 Jun 2024 14:24:52 -0700 Subject: [PATCH 12/13] Use FALSE instead of 0 --- bindings.txt | 1 + src/dbghelp.rs | 4 ++-- src/windows_sys.rs | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bindings.txt b/bindings.txt index 6ec077b89..96ee781a2 100644 --- a/bindings.txt +++ b/bindings.txt @@ -2,6 +2,7 @@ --config std flatten --filter Windows.Win32.Foundation.CloseHandle +Windows.Win32.Foundation.FALSE Windows.Win32.Foundation.HINSTANCE Windows.Win32.Foundation.INVALID_HANDLE_VALUE Windows.Win32.Foundation.TRUE diff --git a/src/dbghelp.rs b/src/dbghelp.rs index cc0c23cc5..f773636cd 100644 --- a/src/dbghelp.rs +++ b/src/dbghelp.rs @@ -291,7 +291,7 @@ pub fn init() -> Result { let mut lock = LOCK.load(SeqCst); if lock.is_null() { let name = mutex_name(); - lock = CreateMutexA(ptr::null_mut(), 0, name.as_ptr()); + lock = CreateMutexA(ptr::null_mut(), FALSE, name.as_ptr()); if lock.is_null() { return Err(()); } @@ -302,7 +302,7 @@ pub fn init() -> Result { } } debug_assert!(!lock.is_null()); - let r = WaitForSingleObjectEx(lock, INFINITE, 0); + let r = WaitForSingleObjectEx(lock, INFINITE, FALSE); debug_assert_eq!(r, 0); let ret = Init { lock }; diff --git a/src/windows_sys.rs b/src/windows_sys.rs index f54f1a657..ead27b473 100644 --- a/src/windows_sys.rs +++ b/src/windows_sys.rs @@ -496,6 +496,7 @@ pub type EXCEPTION_ROUTINE = Option< dispatchercontext: *const core::ffi::c_void, ) -> EXCEPTION_DISPOSITION, >; +pub const FALSE: BOOL = 0i32; pub type FARPROC = Option isize>; pub type FILE_MAP = u32; pub const FILE_MAP_READ: FILE_MAP = 4u32; From 2831b30fa86885bf3ca3c97321a2c903a9f87ba7 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 14 Jun 2024 14:27:57 -0700 Subject: [PATCH 13/13] Remove verify-windows-sys in favor of always performing the check --- .github/workflows/main.yml | 336 ++++++++++++++++++------------------- Cargo.toml | 1 - src/dbghelp.rs | 12 +- 3 files changed, 172 insertions(+), 177 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c2439d136..0103a099d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,10 +3,10 @@ name: CI on: push: branches: - - master + - master pull_request: branches: - - master + - master jobs: test: @@ -39,112 +39,110 @@ jobs: - os: windows-latest rust: nightly-x86_64-gnu steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install Rust (rustup) - run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }} - shell: bash - - run: echo RUSTFLAGS=-Dwarnings >> $GITHUB_ENV - shell: bash + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install Rust (rustup) + run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }} + shell: bash + - run: echo RUSTFLAGS=-Dwarnings >> $GITHUB_ENV + shell: bash - # full fidelity of backtraces on 32-bit msvc requires frame pointers, so - # enable that for our tests - - name: Force frame pointers - run: echo RUSTFLAGS="-Cforce-frame-pointers $RUSTFLAGS" >> $GITHUB_ENV - shell: bash - if: contains(matrix.rust, 'i686') + # full fidelity of backtraces on 32-bit msvc requires frame pointers, so + # enable that for our tests + - name: Force frame pointers + run: echo RUSTFLAGS="-Cforce-frame-pointers $RUSTFLAGS" >> $GITHUB_ENV + shell: bash + if: contains(matrix.rust, 'i686') - - name: Enable collapse_debuginfo based on version - run: echo RUSTFLAGS="--cfg dbginfo=\"collapsible\" $RUSTFLAGS" >> $GITHUB_ENV - shell: bash - if: contains(matrix.rust, 'nightly') || contains(matrix.rust, 'beta') + - name: Enable collapse_debuginfo based on version + run: echo RUSTFLAGS="--cfg dbginfo=\"collapsible\" $RUSTFLAGS" >> $GITHUB_ENV + shell: bash + if: contains(matrix.rust, 'nightly') || contains(matrix.rust, 'beta') - - run: cargo build - - run: cargo test - - run: cargo test --features "serialize-serde" - - run: cargo test --features "verify-windows-sys" - - run: cargo test --features "cpp_demangle" - - run: cargo test --no-default-features - - run: cargo test --no-default-features --features "std" - - run: cargo test --manifest-path crates/cpp_smoke_test/Cargo.toml - # This test is specifically about packed debuginfo with `*.dSYM` files - - run: cargo test --manifest-path crates/macos_frames_test/Cargo.toml - env: - CARGO_PROFILE_DEV_SPLIT_DEBUGINFO: packed - CARGO_PROFILE_TEST_SPLIT_DEBUGINFO: packed - - run: cargo test --manifest-path crates/without_debuginfo/Cargo.toml - - run: cargo test --manifest-path crates/line-tables-only/Cargo.toml + - run: cargo build + - run: cargo test + - run: cargo test --features "serialize-serde" + - run: cargo test --features "cpp_demangle" + - run: cargo test --no-default-features + - run: cargo test --no-default-features --features "std" + - run: cargo test --manifest-path crates/cpp_smoke_test/Cargo.toml + # This test is specifically about packed debuginfo with `*.dSYM` files + - run: cargo test --manifest-path crates/macos_frames_test/Cargo.toml + env: + CARGO_PROFILE_DEV_SPLIT_DEBUGINFO: packed + CARGO_PROFILE_TEST_SPLIT_DEBUGINFO: packed + - run: cargo test --manifest-path crates/without_debuginfo/Cargo.toml + - run: cargo test --manifest-path crates/line-tables-only/Cargo.toml - # Test debuginfo compression still works - - run: cargo test - if: contains(matrix.os, 'ubuntu') - env: - RUSTFLAGS: "-C link-arg=-Wl,--compress-debug-sections=zlib" + # Test debuginfo compression still works + - run: cargo test + if: contains(matrix.os, 'ubuntu') + env: + RUSTFLAGS: "-C link-arg=-Wl,--compress-debug-sections=zlib" - # Test that, on macOS, packed/unpacked debuginfo both work - - run: cargo clean && cargo test - # Test that, on macOS, packed/unpacked debuginfo both work - if: matrix.os == 'macos-latest' - env: - CARGO_PROFILE_DEV_SPLIT_DEBUGINFO: unpacked - CARGO_PROFILE_TEST_SPLIT_DEBUGINFO: unpacked - - run: cargo clean && cargo test - if: matrix.os == 'macos-latest' - env: - CARGO_PROFILE_DEV_SPLIT_DEBUGINFO: packed - CARGO_PROFILE_TEST_SPLIT_DEBUGINFO: packed - # Test that, on macOS, binaries with no UUID work - - run: cargo clean && cargo test - if: matrix.os == 'macos-latest' - env: - RUSTFLAGS: "-C link-arg=-Wl,-no_uuid" + # Test that, on macOS, packed/unpacked debuginfo both work + - run: cargo clean && cargo test + # Test that, on macOS, packed/unpacked debuginfo both work + if: matrix.os == 'macos-latest' + env: + CARGO_PROFILE_DEV_SPLIT_DEBUGINFO: unpacked + CARGO_PROFILE_TEST_SPLIT_DEBUGINFO: unpacked + - run: cargo clean && cargo test + if: matrix.os == 'macos-latest' + env: + CARGO_PROFILE_DEV_SPLIT_DEBUGINFO: packed + CARGO_PROFILE_TEST_SPLIT_DEBUGINFO: packed + # Test that, on macOS, binaries with no UUID work + - run: cargo clean && cargo test + if: matrix.os == 'macos-latest' + env: + RUSTFLAGS: "-C link-arg=-Wl,-no_uuid" - # Test that, on Linux, packed/unpacked debuginfo both work - - run: cargo clean && cargo test - if: matrix.rust == 'nightly' - env: - RUSTFLAGS: "-C split-debuginfo=unpacked -Zunstable-options" - - run: cargo clean && cargo test - if: matrix.rust == 'nightly' - env: - RUSTFLAGS: "-C split-debuginfo=packed -Zunstable-options" + # Test that, on Linux, packed/unpacked debuginfo both work + - run: cargo clean && cargo test + if: matrix.rust == 'nightly' + env: + RUSTFLAGS: "-C split-debuginfo=unpacked -Zunstable-options" + - run: cargo clean && cargo test + if: matrix.rust == 'nightly' + env: + RUSTFLAGS: "-C split-debuginfo=packed -Zunstable-options" - # Test that separate debug info works - - run: ./ci/debuglink-docker.sh - if: contains(matrix.os, 'ubuntu') + # Test that separate debug info works + - run: ./ci/debuglink-docker.sh + if: contains(matrix.os, 'ubuntu') - # Test that backtraces are still symbolicated if we don't embed an absolute - # path to the PDB file in the binary. - # Add -Cforce-frame-pointers for stability. The test otherwise fails - # non-deterministically on i686-pc-windows-msvc because the stack cannot be - # unwound reliably. This failure is not related to the feature being tested. - - run: cargo clean && cargo test - if: contains(matrix.rust, 'msvc') - name: "Test that backtraces are symbolicated without absolute PDB path" - env: - RUSTFLAGS: "-Clink-arg=/PDBALTPATH:%_PDB% -Cforce-frame-pointers" + # Test that backtraces are still symbolicated if we don't embed an absolute + # path to the PDB file in the binary. + # Add -Cforce-frame-pointers for stability. The test otherwise fails + # non-deterministically on i686-pc-windows-msvc because the stack cannot be + # unwound reliably. This failure is not related to the feature being tested. + - run: cargo clean && cargo test + if: contains(matrix.rust, 'msvc') + name: "Test that backtraces are symbolicated without absolute PDB path" + env: + RUSTFLAGS: "-Clink-arg=/PDBALTPATH:%_PDB% -Cforce-frame-pointers" - # Test that including as a submodule will still work, both with and without - # the `backtrace` feature enabled. - - run: cargo build --manifest-path crates/as-if-std/Cargo.toml - - run: cargo build --manifest-path crates/as-if-std/Cargo.toml --no-default-features + # Test that including as a submodule will still work, both with and without + # the `backtrace` feature enabled. + - run: cargo build --manifest-path crates/as-if-std/Cargo.toml + - run: cargo build --manifest-path crates/as-if-std/Cargo.toml --no-default-features windows_arm64: name: Windows AArch64 runs-on: windows-latest steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install Rust - run: rustup update stable --no-self-update && rustup default stable - shell: bash - - run: echo RUSTFLAGS=-Dwarnings >> $GITHUB_ENV - shell: bash - - run: rustup target add aarch64-pc-windows-msvc - - run: cargo test --no-run --target aarch64-pc-windows-msvc - - run: cargo test --no-run --target aarch64-pc-windows-msvc --features verify-windows-sys + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install Rust + run: rustup update stable --no-self-update && rustup default stable + shell: bash + - run: echo RUSTFLAGS=-Dwarnings >> $GITHUB_ENV + shell: bash + - run: rustup target add aarch64-pc-windows-msvc + - run: cargo test --no-run --target aarch64-pc-windows-msvc ios: name: iOS @@ -152,21 +150,21 @@ jobs: strategy: matrix: include: - - target: aarch64-apple-ios - sdk: iphoneos - - target: x86_64-apple-ios - sdk: iphonesimulator + - target: aarch64-apple-ios + sdk: iphoneos + - target: x86_64-apple-ios + sdk: iphonesimulator steps: - - uses: actions/checkout@v3 - with: - submodules: true - - run: rustup target add ${{ matrix.target }} - - run: | - export RUSTFLAGS=-Dwarnings - export SDK_PATH=`xcrun --show-sdk-path --sdk ${{ matrix.sdk }}` - export RUSTFLAGS="-C link-arg=-isysroot -C link-arg=$SDK_PATH" - cargo test --no-run --target ${{ matrix.target }} - name: Build tests + - uses: actions/checkout@v3 + with: + submodules: true + - run: rustup target add ${{ matrix.target }} + - run: | + export RUSTFLAGS=-Dwarnings + export SDK_PATH=`xcrun --show-sdk-path --sdk ${{ matrix.sdk }}` + export RUSTFLAGS="-C link-arg=-isysroot -C link-arg=$SDK_PATH" + cargo test --no-run --target ${{ matrix.target }} + name: Build tests docker: name: Docker @@ -175,43 +173,43 @@ jobs: fail-fast: false matrix: target: - - aarch64-unknown-linux-gnu - - arm-unknown-linux-gnueabihf - - armv7-unknown-linux-gnueabihf - - i586-unknown-linux-gnu - - i686-unknown-linux-gnu - - powerpc64-unknown-linux-gnu - - s390x-unknown-linux-gnu - - x86_64-pc-windows-gnu - - x86_64-unknown-linux-gnu - - x86_64-unknown-linux-musl - - arm-linux-androideabi - - armv7-linux-androideabi - - aarch64-linux-android - - i686-linux-android - - x86_64-linux-android + - aarch64-unknown-linux-gnu + - arm-unknown-linux-gnueabihf + - armv7-unknown-linux-gnueabihf + - i586-unknown-linux-gnu + - i686-unknown-linux-gnu + - powerpc64-unknown-linux-gnu + - s390x-unknown-linux-gnu + - x86_64-pc-windows-gnu + - x86_64-unknown-linux-gnu + - x86_64-unknown-linux-musl + - arm-linux-androideabi + - armv7-linux-androideabi + - aarch64-linux-android + - i686-linux-android + - x86_64-linux-android steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install Rust - run: rustup update stable --no-self-update && rustup default stable - - run: rustup target add ${{ matrix.target }} - - run: cargo generate-lockfile - - run: echo RUSTFLAGS=-Dwarnings >> $GITHUB_ENV - shell: bash - - run: ./ci/run-docker.sh ${{ matrix.target }} + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install Rust + run: rustup update stable --no-self-update && rustup default stable + - run: rustup target add ${{ matrix.target }} + - run: cargo generate-lockfile + - run: echo RUSTFLAGS=-Dwarnings >> $GITHUB_ENV + shell: bash + - run: ./ci/run-docker.sh ${{ matrix.target }} rustfmt: name: Rustfmt runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install Rust - run: rustup update stable --no-self-update && rustup default stable && rustup component add rustfmt - - run: cargo fmt --all -- --check + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install Rust + run: rustup update stable --no-self-update && rustup default stable && rustup component add rustfmt + - run: cargo fmt --all -- --check build: name: Build Targets @@ -219,22 +217,22 @@ jobs: strategy: matrix: target: - - wasm32-unknown-unknown - - wasm32-wasi - - x86_64-unknown-fuchsia - - x86_64-fortanix-unknown-sgx - - x86_64-unknown-illumos + - wasm32-unknown-unknown + - wasm32-wasi + - x86_64-unknown-fuchsia + - x86_64-fortanix-unknown-sgx + - x86_64-unknown-illumos steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install Rust - run: rustup update nightly --no-self-update && rustup default nightly - - run: rustup target add ${{ matrix.target }} - - run: echo RUSTFLAGS=-Dwarnings >> $GITHUB_ENV - shell: bash - - run: cargo build --target ${{ matrix.target }} - - run: cargo build --manifest-path crates/as-if-std/Cargo.toml --target ${{ matrix.target }} + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install Rust + run: rustup update nightly --no-self-update && rustup default nightly + - run: rustup target add ${{ matrix.target }} + - run: echo RUSTFLAGS=-Dwarnings >> $GITHUB_ENV + shell: bash + - run: cargo build --target ${{ matrix.target }} + - run: cargo build --manifest-path crates/as-if-std/Cargo.toml --target ${{ matrix.target }} msrv: name: MSRV @@ -246,23 +244,23 @@ jobs: - os: ubuntu-20.04 - os: windows-latest steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install Rust - run: rustup update 1.65.0 --no-self-update && rustup default 1.65.0 - - run: cargo build + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install Rust + run: rustup update 1.65.0 --no-self-update && rustup default 1.65.0 + - run: cargo build miri: name: Miri runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install Miri - run: | - rustup toolchain install nightly --component miri - rustup override set nightly - cargo miri setup - - run: MIRIFLAGS="-Zmiri-disable-isolation" cargo miri test + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install Miri + run: | + rustup toolchain install nightly --component miri + rustup override set nightly + cargo miri setup + - run: MIRIFLAGS="-Zmiri-disable-isolation" cargo miri test diff --git a/Cargo.toml b/Cargo.toml index 5e2ee1ee8..f456d2696 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,7 +79,6 @@ dladdr = [] kernel32 = [] libunwind = [] unix-backtrace = [] -verify-windows-sys = [] [[example]] name = "backtrace" diff --git a/src/dbghelp.rs b/src/dbghelp.rs index f773636cd..9f94f2142 100644 --- a/src/dbghelp.rs +++ b/src/dbghelp.rs @@ -11,9 +11,8 @@ //! Note though that since we're loading all this support dynamically we can't //! actually use the raw definitions in `windows_sys`, but rather we need to define //! the function pointer types ourselves and use that. We don't really want to -//! be in the business of duplicating auto-generated bindings, so we have a Cargo feature -//! `verify-windows-sys` which asserts that all bindings match those in `windows_sys.rs` and -//! this feature is enabled on CI. +//! be in the business of duplicating auto-generated bindings, so we assert that all bindings match +//! those in `windows_sys.rs`. //! //! Finally, you'll note here that the dll for `dbghelp.dll` is never unloaded, //! and that's currently intentional. The thinking is that we can globally cache @@ -31,8 +30,8 @@ use core::mem; use core::ptr; use core::slice; -// This is only used when we're double-checking function signatures against windows-sys. -#[cfg(feature = "verify-windows-sys")] +// This is used when we're double-checking function signatures against windows-sys. +#[inline(always)] fn assert_equal_types(a: T, _b: T) -> T { a } @@ -92,8 +91,7 @@ macro_rules! dbghelp { self.$name = self.symbol(name.as_bytes())?; } let ret = mem::transmute::(self.$name); - #[cfg(feature = "verify-windows-sys")] - assert_equal_types(ret, $name); + assert_equal_types(ret, super::windows_sys::$name); Some(ret) } })*