about summary refs log tree commit diff
path: root/library/windows_targets
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2025-07-07 15:39:31 +0000
committerChris Denton <chris@chrisdenton.dev>2025-07-07 15:39:31 +0000
commit2412f8921ce39b986664e27c71b07f0ae24ac100 (patch)
tree718a2188fb874cd6be394eb0def443d1bf27f431 /library/windows_targets
parent8df4a58ac47b778b093652d6190a6f9d54638774 (diff)
downloadrust-2412f8921ce39b986664e27c71b07f0ae24ac100.tar.gz
rust-2412f8921ce39b986664e27c71b07f0ae24ac100.zip
UWP: link ntdll functions using raw-dylib
Diffstat (limited to 'library/windows_targets')
-rw-r--r--library/windows_targets/src/lib.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/library/windows_targets/src/lib.rs b/library/windows_targets/src/lib.rs
index bce54c5ffce..9e82e6a7200 100644
--- a/library/windows_targets/src/lib.rs
+++ b/library/windows_targets/src/lib.rs
@@ -7,8 +7,7 @@
 #![feature(decl_macro)]
 #![feature(no_core)]
 
-#[cfg(feature = "windows_raw_dylib")]
-pub macro link {
+pub macro link_raw_dylib {
     ($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
         #[cfg_attr(not(target_arch = "x86"), link(name = $library, kind = "raw-dylib", modifiers = "+verbatim"))]
         #[cfg_attr(target_arch = "x86", link(name = $library, kind = "raw-dylib", modifiers = "+verbatim", import_name_type = "undecorated"))]
@@ -18,6 +17,26 @@ pub macro link {
         }
     )
 }
+
+pub macro link_dylib {
+    ($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
+        // Note: the windows-targets crate uses a pre-built Windows.lib import library which we don't
+        // have in this repo. So instead we always link kernel32.lib and add the rest of the import
+        // libraries below by using an empty extern block. This works because extern blocks are not
+        // connected to the library given in the #[link] attribute.
+        #[link(name = "kernel32")]
+        unsafe extern $abi {
+            $(#[link_name=$link_name])?
+            pub fn $($function)*;
+        }
+    )
+}
+
+#[cfg(feature = "windows_raw_dylib")]
+pub macro link($($tt:tt)*) {
+    $crate::link_raw_dylib!($($tt)*)
+}
+
 #[cfg(not(feature = "windows_raw_dylib"))]
 pub macro link {
     ($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (