From 2a86d79cd2f689f2ec9b737d9384d40a6474f7f5 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sat, 20 Jan 2024 21:36:49 -0500 Subject: [PATCH] Clean up windows bindings --- src/dbghelp.rs | 25 +++------------------- src/windows.rs | 58 +++----------------------------------------------- 2 files changed, 6 insertions(+), 77 deletions(-) diff --git a/src/dbghelp.rs b/src/dbghelp.rs index e456dd45..13b4df1e 100644 --- a/src/dbghelp.rs +++ b/src/dbghelp.rs @@ -145,9 +145,9 @@ macro_rules! dbghelp { // Convenience proxy to use the cleanup locks to reference dbghelp // functions. - #[allow(dead_code)] impl Init { - $(pub fn $name(&self) -> $name { + $(#[allow(dead_code)] + pub fn $name(&self) -> $name { unsafe { DBGHELP.$name().unwrap() } @@ -155,7 +155,7 @@ macro_rules! dbghelp { pub fn dbghelp(&self) -> *mut Dbghelp { unsafe { - &mut DBGHELP + ptr::addr_of_mut!(DBGHELP) } } } @@ -174,25 +174,6 @@ dbghelp! { path: PCWSTR, invade: BOOL ) -> BOOL; - fn StackWalk64( - MachineType: DWORD, - hProcess: HANDLE, - hThread: HANDLE, - StackFrame: LPSTACKFRAME64, - ContextRecord: PVOID, - ReadMemoryRoutine: PREAD_PROCESS_MEMORY_ROUTINE64, - FunctionTableAccessRoutine: PFUNCTION_TABLE_ACCESS_ROUTINE64, - GetModuleBaseRoutine: PGET_MODULE_BASE_ROUTINE64, - TranslateAddress: PTRANSLATE_ADDRESS_ROUTINE64 - ) -> BOOL; - fn SymFunctionTableAccess64( - hProcess: HANDLE, - AddrBase: DWORD64 - ) -> PVOID; - fn SymGetModuleBase64( - hProcess: HANDLE, - AddrBase: DWORD64 - ) -> DWORD64; fn StackWalkEx( MachineType: DWORD, hProcess: HANDLE, diff --git a/src/windows.rs b/src/windows.rs index 4e72de8a..2b00af9d 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -7,7 +7,7 @@ //! This module largely exists to integrate into libstd itself where winapi is //! not currently available. -#![allow(bad_style, dead_code, unused)] +#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] cfg_if::cfg_if! { if #[cfg(feature = "verify-winapi")] { @@ -235,8 +235,6 @@ ffi! { pub KdHelp: KDHELP64, } - pub type LPSTACKFRAME64 = *mut STACKFRAME64; - #[repr(C)] pub struct STACKFRAME_EX { pub AddrPC: ADDRESS64, @@ -294,7 +292,7 @@ ffi! { pub type PGET_MODULE_BASE_ROUTINE64 = Option DWORD64>; pub type PFUNCTION_TABLE_ACCESS_ROUTINE64 = - Option PVOID>; + Option PVOID>; pub type PREAD_PROCESS_MEMORY_ROUTINE64 = Option< unsafe extern "system" fn( hProcess: HANDLE, @@ -305,6 +303,7 @@ ffi! { ) -> BOOL, >; + #[repr(C)] pub struct ADDRESS64 { pub Offset: DWORD64, @@ -313,7 +312,6 @@ ffi! { } pub type LPADDRESS64 = *mut ADDRESS64; - pub type ADDRESS_MODE = u32; #[repr(C)] @@ -349,23 +347,9 @@ ffi! { } 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; @@ -377,11 +361,9 @@ ffi! { 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; @@ -389,17 +371,11 @@ ffi! { 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; @@ -416,34 +392,6 @@ ffi! { 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; } }