|
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,18 +382,42 @@ 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 p1 = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId()); |
386 |
| - let mut len = buf.len() as u32; |
387 |
| - let rc = QueryFullProcessImageNameA(p1, 0, buf.as_mut_ptr(), &mut len); |
388 |
| - CloseHandle(p1); |
389 |
| - |
| 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 | + let mut len: u32; |
| 392 | + if ptrQueryFullProcessImageNameA == 0 |
| 393 | + { |
| 394 | + len = GetModuleFileNameA(0 as HMODULE, buf.as_mut_ptr(), buf.len() as u32); |
| 395 | + } |
| 396 | + else |
| 397 | + { |
| 398 | + use core::mem; |
| 399 | + let p1 = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId()); |
| 400 | + len = buf.len() as u32; |
| 401 | + let pfnQueryFullProcessImageNameA : extern "system" fn( |
| 402 | + hProcess: HANDLE, |
| 403 | + dwFlags: DWORD, |
| 404 | + lpExeName: LPSTR, |
| 405 | + lpdwSize: PDWORD, |
| 406 | + ) -> BOOL = mem::transmute(ptrQueryFullProcessImageNameA); |
| 407 | + |
| 408 | + let rc = pfnQueryFullProcessImageNameA(p1, 0, buf.as_mut_ptr(), &mut len); |
| 409 | + CloseHandle(p1); |
| 410 | + if rc == 0 { |
| 411 | + return Err(()) |
| 412 | + } |
| 413 | + } |
390 | 414 | // We want to return a slice that is nul-terminated, so if
|
391 | 415 | // everything was filled in and it equals the total length
|
392 | 416 | // then equate that to failure.
|
393 | 417 | //
|
394 | 418 | // Otherwise when returning success make sure the nul byte is
|
395 | 419 | // included in the slice.
|
396 |
| - if rc == 0 || len == buf.len() as u32 { |
| 420 | + if len == buf.len() as u32 { |
397 | 421 | Err(())
|
398 | 422 | } else {
|
399 | 423 | assert_eq!(buf[len as usize], 0);
|
|
0 commit comments