Skip to content

Commit 37b80f2

Browse files
authored
Explicitly link kernel32.lib (#482)
Currently backtrace depends on something else to link kernel32.lib, which is usually a safe assumption. However, it may become more of a problem once raw-dylib is stable and used by the standard library and other crates. Using `#[link]` also allows calling into the function directly instead of going through a jump stub.
1 parent 07872f2 commit 37b80f2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/windows.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ macro_rules! ffi {
162162
ffi!($($rest)*);
163163
);
164164

165-
(extern "system" { $(pub fn $name:ident($($args:tt)*) -> $ret:ty;)* } $($rest:tt)*) => (
166-
extern "system" {
165+
($(#[$meta:meta])* extern "system" { $(pub fn $name:ident($($args:tt)*) -> $ret:ty;)* } $($rest:tt)*) => (
166+
$(#[$meta])* extern "system" {
167167
$(pub fn $name($($args)*) -> $ret;)*
168168
}
169169

@@ -371,6 +371,7 @@ ffi! {
371371
pub type LPCVOID = *const c_void;
372372
pub type LPMODULEENTRY32W = *mut MODULEENTRY32W;
373373

374+
#[link(name = "kernel32")]
374375
extern "system" {
375376
pub fn GetCurrentProcess() -> HANDLE;
376377
pub fn GetCurrentThread() -> HANDLE;
@@ -438,6 +439,7 @@ ffi! {
438439

439440
#[cfg(target_pointer_width = "64")]
440441
ffi! {
442+
#[link(name = "kernel32")]
441443
extern "system" {
442444
pub fn RtlLookupFunctionEntry(
443445
ControlPc: DWORD64,

0 commit comments

Comments
 (0)