Skip to content

Commit e528d5d

Browse files
committed
Switch std to using raw-dylib by default
We were already using it to work around various import library issues, this just makes it the default for everything. The `windows_use_import_libs` std feature can be used to disable this.
1 parent 7f4b270 commit e528d5d

File tree

7 files changed

+25
-44
lines changed

7 files changed

+25
-44
lines changed

library/std/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ std_detect_file_io = ["std_detect/std_detect_file_io"]
117117
std_detect_dlsym_getauxval = ["std_detect/std_detect_dlsym_getauxval"]
118118
std_detect_env_override = ["std_detect/std_detect_env_override"]
119119

120-
# Enable using raw-dylib for Windows imports.
121-
# This will eventually be the default.
122-
windows_raw_dylib = ["windows-targets/windows_raw_dylib"]
120+
# Enable using Windows import libraries instead of raw-dylib.
121+
windows_use_import_libs = ["windows-targets/windows_use_import_libs"]
123122

124123
[package.metadata.fortanix-sgx]
125124
# Maximum possible number of threads when testing

library/std/src/sys/pal/windows/c.rs

+8-34
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,14 @@ if #[cfg(not(target_vendor = "uwp"))] {
108108
}
109109
}
110110

111-
// Use raw-dylib to import ProcessPrng as we can't rely on there being an import library.
112-
#[cfg(not(target_vendor = "win7"))]
113-
#[cfg_attr(
114-
target_arch = "x86",
115-
link(name = "bcryptprimitives", kind = "raw-dylib", import_name_type = "undecorated")
116-
)]
117-
#[cfg_attr(not(target_arch = "x86"), link(name = "bcryptprimitives", kind = "raw-dylib"))]
118-
extern "system" {
119-
pub fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL;
111+
// When not using raw-dylib, there isn't a reliable import library for ProcessPrng
112+
// so we lazily load it instead.
113+
#[cfg(all(feature = "windows_use_import_libs", not(target_vendor = "win7")))]
114+
compat_fn_with_fallback! {
115+
pub static BCRYPTPRIMITIVES: &CStr = c"bcryptprimitives";
116+
pub fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL {
117+
panic!("ProcessPrng is not available");
118+
}
120119
}
121120

122121
// Functions that aren't available on every version of Windows that we support,
@@ -150,31 +149,6 @@ compat_fn_with_fallback! {
150149
}
151150
}
152151

153-
#[cfg(not(target_vendor = "win7"))]
154-
// Use raw-dylib to import synchronization functions to workaround issues with the older mingw import library.
155-
#[cfg_attr(
156-
target_arch = "x86",
157-
link(
158-
name = "api-ms-win-core-synch-l1-2-0",
159-
kind = "raw-dylib",
160-
import_name_type = "undecorated"
161-
)
162-
)]
163-
#[cfg_attr(
164-
not(target_arch = "x86"),
165-
link(name = "api-ms-win-core-synch-l1-2-0", kind = "raw-dylib")
166-
)]
167-
extern "system" {
168-
pub fn WaitOnAddress(
169-
address: *const c_void,
170-
compareaddress: *const c_void,
171-
addresssize: usize,
172-
dwmilliseconds: u32,
173-
) -> BOOL;
174-
pub fn WakeByAddressSingle(address: *const c_void);
175-
pub fn WakeByAddressAll(address: *const c_void);
176-
}
177-
178152
#[cfg(target_vendor = "win7")]
179153
compat_fn_optional! {
180154
crate::sys::compat::load_synch_functions();

library/std/src/sys/pal/windows/c/bindings.txt

+4
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,7 @@ Windows.Win32.Networking.WinSock.WSATRY_AGAIN
21882188
Windows.Win32.Networking.WinSock.WSATYPE_NOT_FOUND
21892189
Windows.Win32.Networking.WinSock.WSAVERNOTSUPPORTED
21902190
Windows.Win32.Security.Authentication.Identity.RtlGenRandom
2191+
Windows.Win32.Security.Cryptography.ProcessPrng
21912192
Windows.Win32.Security.SECURITY_ATTRIBUTES
21922193
Windows.Win32.Security.TOKEN_ACCESS_MASK
21932194
Windows.Win32.Security.TOKEN_ACCESS_PSEUDO_HANDLE
@@ -2595,7 +2596,10 @@ Windows.Win32.System.Threading.TryAcquireSRWLockShared
25952596
Windows.Win32.System.Threading.UpdateProcThreadAttribute
25962597
Windows.Win32.System.Threading.WaitForMultipleObjects
25972598
Windows.Win32.System.Threading.WaitForSingleObject
2599+
Windows.Win32.System.Threading.WaitOnAddress
25982600
Windows.Win32.System.Threading.WakeAllConditionVariable
2601+
Windows.Win32.System.Threading.WakeByAddressAll
2602+
Windows.Win32.System.Threading.WakeByAddressSingle
25992603
Windows.Win32.System.Threading.WakeConditionVariable
26002604
Windows.Win32.System.WindowsProgramming.PROGRESS_CONTINUE
26012605
Windows.Win32.UI.Shell.GetUserProfileDirectoryW

library/std/src/sys/pal/windows/c/windows_sys.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, dead_code, clippy::all)]
44
windows_targets::link!("advapi32.dll" "system" fn OpenProcessToken(processhandle : HANDLE, desiredaccess : TOKEN_ACCESS_MASK, tokenhandle : *mut HANDLE) -> BOOL);
55
windows_targets::link!("advapi32.dll" "system" "SystemFunction036" fn RtlGenRandom(randombuffer : *mut core::ffi::c_void, randombufferlength : u32) -> BOOLEAN);
6+
windows_targets::link!("api-ms-win-core-synch-l1-2-0.dll" "system" fn WaitOnAddress(address : *const core::ffi::c_void, compareaddress : *const core::ffi::c_void, addresssize : usize, dwmilliseconds : u32) -> BOOL);
7+
windows_targets::link!("api-ms-win-core-synch-l1-2-0.dll" "system" fn WakeByAddressAll(address : *const core::ffi::c_void));
8+
windows_targets::link!("api-ms-win-core-synch-l1-2-0.dll" "system" fn WakeByAddressSingle(address : *const core::ffi::c_void));
9+
windows_targets::link!("bcryptprimitives.dll" "system" fn ProcessPrng(pbdata : *mut u8, cbdata : usize) -> BOOL);
610
windows_targets::link!("kernel32.dll" "system" fn AcquireSRWLockExclusive(srwlock : *mut SRWLOCK));
711
windows_targets::link!("kernel32.dll" "system" fn AcquireSRWLockShared(srwlock : *mut SRWLOCK));
812
windows_targets::link!("kernel32.dll" "system" fn AddVectoredExceptionHandler(first : u32, handler : PVECTORED_EXCEPTION_HANDLER) -> *mut core::ffi::c_void);

library/sysroot/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ profiler = ["std/profiler"]
2727
std_detect_file_io = ["std/std_detect_file_io"]
2828
std_detect_dlsym_getauxval = ["std/std_detect_dlsym_getauxval"]
2929
std_detect_env_override = ["std/std_detect_env_override"]
30-
windows_raw_dylib = ["std/windows_raw_dylib"]
30+
windows_use_import_libs = ["std/windows_use_import_libs"]

library/windows_targets/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ version = "0.0.0"
55
edition = "2021"
66

77
[features]
8-
# Enable using raw-dylib for Windows imports.
9-
# This will eventually be the default.
10-
windows_raw_dylib = []
8+
# Enable using Windows import libraries instead of raw-dylib.
9+
windows_use_import_libs = []

library/windows_targets/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#![feature(decl_macro)]
88
#![feature(no_core)]
99

10-
#[cfg(feature = "windows_raw_dylib")]
10+
#[cfg(not(feature = "windows_use_import_libs"))]
1111
pub macro link {
1212
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
1313
#[cfg_attr(not(target_arch = "x86"), link(name = $library, kind = "raw-dylib", modifiers = "+verbatim"))]
@@ -18,7 +18,7 @@ pub macro link {
1818
}
1919
)
2020
}
21-
#[cfg(not(feature = "windows_raw_dylib"))]
21+
#[cfg(feature = "windows_use_import_libs")]
2222
pub macro link {
2323
($library:literal $abi:literal $($link_name:literal)? $(#[$doc:meta])? fn $($function:tt)*) => (
2424
// Note: the windows-targets crate uses a pre-built Windows.lib import library which we don't
@@ -33,10 +33,11 @@ pub macro link {
3333
)
3434
}
3535

36-
#[cfg(not(feature = "windows_raw_dylib"))]
36+
#[cfg(feature = "windows_use_import_libs")]
3737
#[link(name = "advapi32")]
3838
#[link(name = "ntdll")]
3939
#[link(name = "userenv")]
4040
#[link(name = "ws2_32")]
4141
#[link(name = "dbghelp")] // required for backtrace-rs symbolization
42+
#[link(name = "synchronization")]
4243
extern "C" {}

0 commit comments

Comments
 (0)