diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 9a31fd21dc71a..6ed3491104eec 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -117,9 +117,8 @@ std_detect_file_io = ["std_detect/std_detect_file_io"] std_detect_dlsym_getauxval = ["std_detect/std_detect_dlsym_getauxval"] std_detect_env_override = ["std_detect/std_detect_env_override"] -# Enable using raw-dylib for Windows imports. -# This will eventually be the default. -windows_raw_dylib = ["windows-targets/windows_raw_dylib"] +# Enable using Windows import libraries instead of raw-dylib. +windows_use_import_libs = ["windows-targets/windows_use_import_libs"] [package.metadata.fortanix-sgx] # Maximum possible number of threads when testing diff --git a/library/std/src/sys/pal/windows/c.rs b/library/std/src/sys/pal/windows/c.rs index b888eb7d95ca3..d62f67d34836d 100644 --- a/library/std/src/sys/pal/windows/c.rs +++ b/library/std/src/sys/pal/windows/c.rs @@ -108,15 +108,14 @@ if #[cfg(not(target_vendor = "uwp"))] { } } -// Use raw-dylib to import ProcessPrng as we can't rely on there being an import library. -#[cfg(not(target_vendor = "win7"))] -#[cfg_attr( - target_arch = "x86", - link(name = "bcryptprimitives", kind = "raw-dylib", import_name_type = "undecorated") -)] -#[cfg_attr(not(target_arch = "x86"), link(name = "bcryptprimitives", kind = "raw-dylib"))] -extern "system" { - pub fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL; +// When not using raw-dylib, there isn't a reliable import library for ProcessPrng +// so we lazily load it instead. +#[cfg(all(feature = "windows_use_import_libs", not(target_vendor = "win7")))] +compat_fn_with_fallback! { + pub static BCRYPTPRIMITIVES: &CStr = c"bcryptprimitives"; + pub fn ProcessPrng(pbdata: *mut u8, cbdata: usize) -> BOOL { + panic!("ProcessPrng is not available"); + } } // Functions that aren't available on every version of Windows that we support, @@ -150,31 +149,6 @@ compat_fn_with_fallback! { } } -#[cfg(not(target_vendor = "win7"))] -// Use raw-dylib to import synchronization functions to workaround issues with the older mingw import library. -#[cfg_attr( - target_arch = "x86", - link( - name = "api-ms-win-core-synch-l1-2-0", - kind = "raw-dylib", - import_name_type = "undecorated" - ) -)] -#[cfg_attr( - not(target_arch = "x86"), - link(name = "api-ms-win-core-synch-l1-2-0", kind = "raw-dylib") -)] -extern "system" { - pub fn WaitOnAddress( - address: *const c_void, - compareaddress: *const c_void, - addresssize: usize, - dwmilliseconds: u32, - ) -> BOOL; - pub fn WakeByAddressSingle(address: *const c_void); - pub fn WakeByAddressAll(address: *const c_void); -} - #[cfg(target_vendor = "win7")] compat_fn_optional! { crate::sys::compat::load_synch_functions(); diff --git a/library/std/src/sys/pal/windows/c/bindings.txt b/library/std/src/sys/pal/windows/c/bindings.txt index 9c2e4500da068..c2ebda837e6dc 100644 --- a/library/std/src/sys/pal/windows/c/bindings.txt +++ b/library/std/src/sys/pal/windows/c/bindings.txt @@ -2188,6 +2188,7 @@ Windows.Win32.Networking.WinSock.WSATRY_AGAIN Windows.Win32.Networking.WinSock.WSATYPE_NOT_FOUND Windows.Win32.Networking.WinSock.WSAVERNOTSUPPORTED Windows.Win32.Security.Authentication.Identity.RtlGenRandom +Windows.Win32.Security.Cryptography.ProcessPrng Windows.Win32.Security.SECURITY_ATTRIBUTES Windows.Win32.Security.TOKEN_ACCESS_MASK Windows.Win32.Security.TOKEN_ACCESS_PSEUDO_HANDLE @@ -2595,7 +2596,10 @@ Windows.Win32.System.Threading.TryAcquireSRWLockShared Windows.Win32.System.Threading.UpdateProcThreadAttribute Windows.Win32.System.Threading.WaitForMultipleObjects Windows.Win32.System.Threading.WaitForSingleObject +Windows.Win32.System.Threading.WaitOnAddress Windows.Win32.System.Threading.WakeAllConditionVariable +Windows.Win32.System.Threading.WakeByAddressAll +Windows.Win32.System.Threading.WakeByAddressSingle Windows.Win32.System.Threading.WakeConditionVariable Windows.Win32.System.WindowsProgramming.PROGRESS_CONTINUE Windows.Win32.UI.Shell.GetUserProfileDirectoryW diff --git a/library/std/src/sys/pal/windows/c/windows_sys.rs b/library/std/src/sys/pal/windows/c/windows_sys.rs index ab5f8919d7af6..f3cc542c4a027 100644 --- a/library/std/src/sys/pal/windows/c/windows_sys.rs +++ b/library/std/src/sys/pal/windows/c/windows_sys.rs @@ -3,6 +3,10 @@ #![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, dead_code, clippy::all)] windows_targets::link!("advapi32.dll" "system" fn OpenProcessToken(processhandle : HANDLE, desiredaccess : TOKEN_ACCESS_MASK, tokenhandle : *mut HANDLE) -> BOOL); windows_targets::link!("advapi32.dll" "system" "SystemFunction036" fn RtlGenRandom(randombuffer : *mut core::ffi::c_void, randombufferlength : u32) -> BOOLEAN); +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); +windows_targets::link!("api-ms-win-core-synch-l1-2-0.dll" "system" fn WakeByAddressAll(address : *const core::ffi::c_void)); +windows_targets::link!("api-ms-win-core-synch-l1-2-0.dll" "system" fn WakeByAddressSingle(address : *const core::ffi::c_void)); +windows_targets::link!("bcryptprimitives.dll" "system" fn ProcessPrng(pbdata : *mut u8, cbdata : usize) -> BOOL); windows_targets::link!("kernel32.dll" "system" fn AcquireSRWLockExclusive(srwlock : *mut SRWLOCK)); windows_targets::link!("kernel32.dll" "system" fn AcquireSRWLockShared(srwlock : *mut SRWLOCK)); windows_targets::link!("kernel32.dll" "system" fn AddVectoredExceptionHandler(first : u32, handler : PVECTORED_EXCEPTION_HANDLER) -> *mut core::ffi::c_void); diff --git a/library/sysroot/Cargo.toml b/library/sysroot/Cargo.toml index 7165c3e48af42..e84840c5a8a36 100644 --- a/library/sysroot/Cargo.toml +++ b/library/sysroot/Cargo.toml @@ -27,4 +27,4 @@ profiler = ["std/profiler"] std_detect_file_io = ["std/std_detect_file_io"] std_detect_dlsym_getauxval = ["std/std_detect_dlsym_getauxval"] std_detect_env_override = ["std/std_detect_env_override"] -windows_raw_dylib = ["std/windows_raw_dylib"] +windows_use_import_libs = ["std/windows_use_import_libs"] diff --git a/library/windows_targets/Cargo.toml b/library/windows_targets/Cargo.toml index 94d7c8210647c..e6d6b9b60cdc7 100644 --- a/library/windows_targets/Cargo.toml +++ b/library/windows_targets/Cargo.toml @@ -5,6 +5,5 @@ version = "0.0.0" edition = "2021" [features] -# Enable using raw-dylib for Windows imports. -# This will eventually be the default. -windows_raw_dylib = [] +# Enable using Windows import libraries instead of raw-dylib. +windows_use_import_libs = [] diff --git a/library/windows_targets/src/lib.rs b/library/windows_targets/src/lib.rs index 395cd6a4bab55..4678ec0543dfb 100644 --- a/library/windows_targets/src/lib.rs +++ b/library/windows_targets/src/lib.rs @@ -7,7 +7,7 @@ #![feature(decl_macro)] #![feature(no_core)] -#[cfg(feature = "windows_raw_dylib")] +#[cfg(not(feature = "windows_use_import_libs"))] pub macro link { ($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"))] @@ -18,7 +18,7 @@ pub macro link { } ) } -#[cfg(not(feature = "windows_raw_dylib"))] +#[cfg(feature = "windows_use_import_libs")] pub macro link { ($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 @@ -33,10 +33,11 @@ pub macro link { ) } -#[cfg(not(feature = "windows_raw_dylib"))] +#[cfg(feature = "windows_use_import_libs")] #[link(name = "advapi32")] #[link(name = "ntdll")] #[link(name = "userenv")] #[link(name = "ws2_32")] #[link(name = "dbghelp")] // required for backtrace-rs symbolization +#[link(name = "synchronization")] extern "C" {}