Skip to content

Commit

Permalink
Explicitly link kernel32.lib (#482)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ChrisDenton committed Sep 12, 2022
1 parent 07872f2 commit 37b80f2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ macro_rules! ffi {
ffi!($($rest)*);
);

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

Expand Down Expand Up @@ -371,6 +371,7 @@ ffi! {
pub type LPCVOID = *const c_void;
pub type LPMODULEENTRY32W = *mut MODULEENTRY32W;

#[link(name = "kernel32")]
extern "system" {
pub fn GetCurrentProcess() -> HANDLE;
pub fn GetCurrentThread() -> HANDLE;
Expand Down Expand Up @@ -438,6 +439,7 @@ ffi! {

#[cfg(target_pointer_width = "64")]
ffi! {
#[link(name = "kernel32")]
extern "system" {
pub fn RtlLookupFunctionEntry(
ControlPc: DWORD64,
Expand Down

0 comments on commit 37b80f2

Please sign in to comment.