Skip to content

Commit d4bc045

Browse files
authored
Merge pull request #263 from lynnux/master
dynamic get `QueryFullProcessImageNameA` for XP support
2 parents 36750b9 + 21f4e57 commit d4bc045

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/symbolize/libbacktrace.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -382,9 +382,27 @@ unsafe fn init_state() -> *mut bt::backtrace_state {
382382
}
383383

384384
unsafe fn query_full_name(buf: &mut [i8]) -> Result<&[i8], ()> {
385+
let dll = GetModuleHandleA(b"kernel32.dll\0".as_ptr() as *const i8);
386+
if dll.is_null() {
387+
return Err(())
388+
}
389+
let ptrQueryFullProcessImageNameA =
390+
GetProcAddress(dll, b"QueryFullProcessImageNameA\0".as_ptr() as *const _) as usize;
391+
if ptrQueryFullProcessImageNameA == 0
392+
{
393+
return Err(());
394+
}
395+
use core::mem;
385396
let p1 = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
386397
let mut len = buf.len() as u32;
387-
let rc = QueryFullProcessImageNameA(p1, 0, buf.as_mut_ptr(), &mut len);
398+
let pfnQueryFullProcessImageNameA : extern "system" fn(
399+
hProcess: HANDLE,
400+
dwFlags: DWORD,
401+
lpExeName: LPSTR,
402+
lpdwSize: PDWORD,
403+
) -> BOOL = mem::transmute(ptrQueryFullProcessImageNameA);
404+
405+
let rc = pfnQueryFullProcessImageNameA(p1, 0, buf.as_mut_ptr(), &mut len);
388406
CloseHandle(p1);
389407

390408
// We want to return a slice that is nul-terminated, so if

src/windows.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! A module to define the FFI definitions we use on Windows for `dbghelp.dll`
1+
//! A module to define the FFI definitions we use on Windows for `dbghelp.dll`
22
//!
33
//! This module uses a custom macro, `ffi!`, to wrap all definitions to
44
//! automatically generate tests to assert that our definitions here are the
@@ -343,19 +343,14 @@ ffi! {
343343
pub fn RtlCaptureContext(ContextRecord: PCONTEXT) -> ();
344344
pub fn LoadLibraryA(a: *const i8) -> HMODULE;
345345
pub fn GetProcAddress(h: HMODULE, name: *const i8) -> FARPROC;
346+
pub fn GetModuleHandleA(name: *const i8) -> HMODULE;
346347
pub fn OpenProcess(
347348
dwDesiredAccess: DWORD,
348349
bInheitHandle: BOOL,
349350
dwProcessId: DWORD,
350351
) -> HANDLE;
351352
pub fn GetCurrentProcessId() -> DWORD;
352353
pub fn CloseHandle(h: HANDLE) -> BOOL;
353-
pub fn QueryFullProcessImageNameA(
354-
hProcess: HANDLE,
355-
dwFlags: DWORD,
356-
lpExeName: LPSTR,
357-
lpdwSize: PDWORD,
358-
) -> BOOL;
359354
pub fn CreateFileA(
360355
lpFileName: LPCSTR,
361356
dwDesiredAccess: DWORD,

0 commit comments

Comments
 (0)