File tree Expand file tree Collapse file tree 2 files changed +22
-9
lines changed Expand file tree Collapse file tree 2 files changed +22
-9
lines changed Original file line number Diff line number Diff line change 1
- // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
@@ -382,9 +382,27 @@ unsafe fn init_state() -> *mut bt::backtrace_state {
382
382
}
383
383
384
384
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;
385
396
let p1 = OpenProcess ( PROCESS_QUERY_INFORMATION , FALSE , GetCurrentProcessId ( ) ) ;
386
397
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) ;
388
406
CloseHandle ( p1) ;
389
407
390
408
// We want to return a slice that is nul-terminated, so if
Original file line number Diff line number Diff line change 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`
2
2
//!
3
3
//! This module uses a custom macro, `ffi!`, to wrap all definitions to
4
4
//! automatically generate tests to assert that our definitions here are the
@@ -343,19 +343,14 @@ ffi! {
343
343
pub fn RtlCaptureContext ( ContextRecord : PCONTEXT ) -> ( ) ;
344
344
pub fn LoadLibraryA ( a: * const i8 ) -> HMODULE ;
345
345
pub fn GetProcAddress ( h: HMODULE , name: * const i8 ) -> FARPROC ;
346
+ pub fn GetModuleHandleA ( name: * const i8 ) -> HMODULE ;
346
347
pub fn OpenProcess (
347
348
dwDesiredAccess: DWORD ,
348
349
bInheitHandle: BOOL ,
349
350
dwProcessId: DWORD ,
350
351
) -> HANDLE ;
351
352
pub fn GetCurrentProcessId ( ) -> DWORD ;
352
353
pub fn CloseHandle ( h: HANDLE ) -> BOOL ;
353
- pub fn QueryFullProcessImageNameA (
354
- hProcess: HANDLE ,
355
- dwFlags: DWORD ,
356
- lpExeName: LPSTR ,
357
- lpdwSize: PDWORD ,
358
- ) -> BOOL ;
359
354
pub fn CreateFileA (
360
355
lpFileName: LPCSTR ,
361
356
dwDesiredAccess: DWORD ,
You can’t perform that action at this time.
0 commit comments