Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/dbghelp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ use core::mem;
use core::ptr;
use core::slice;

// This is used when we're double-checking function signatures against windows-sys.
#[inline(always)]
fn assert_equal_types<T>(a: T, _b: T) -> T {
a
}

// This macro is used to define a `Dbghelp` structure which internally contains
// all the function pointers that we might load.
macro_rules! dbghelp {
Expand Down Expand Up @@ -85,14 +79,23 @@ macro_rules! dbghelp {
// either read the cached function pointer or load it and return the
// loaded value. Loads are asserted to succeed.
$(pub fn $name(&mut self) -> Option<$name> {
// Assert that windows_sys::$name is declared to have the same
// argument types and return type as our declaration, although
// it might be either extern "C" or extern "system".
cfg_if::cfg_if! {
if #[cfg(any(target_arch = "x86", not(windows_raw_dylib)))] {
let _: unsafe extern "system" fn($($argty),*) -> $ret = super::windows_sys::$name;
} else {
let _: unsafe extern "C" fn($($argty),*) -> $ret = super::windows_sys::$name;
}
}

unsafe {
if self.$name == 0 {
let name = concat!(stringify!($name), "\0");
self.$name = self.symbol(name.as_bytes())?;
}
let ret = mem::transmute::<usize, $name>(self.$name);
assert_equal_types(ret, super::windows_sys::$name);
Some(ret)
Some(mem::transmute::<usize, $name>(self.$name))
}
})*

Expand Down
Loading