From 4c05e3a6c2309781ee0dc298766bb9d21c82401a Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sat, 10 Sep 2022 09:22:22 +0100 Subject: [PATCH] Use `raw-dylib` in the std --- library/std/src/sys/windows/c.rs | 55 ++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index c61a7e7d1e4ab..a3100aada2827 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -278,6 +278,7 @@ pub const STATUS_INVALID_PARAMETER: NTSTATUS = 0xc000000d_u32 as _; pub const STATUS_PENDING: NTSTATUS = 0x103 as _; pub const STATUS_END_OF_FILE: NTSTATUS = 0xC0000011_u32 as _; +#[cfg(target_arch = "x86")] pub const STATUS_NOT_IMPLEMENTED: NTSTATUS = 0xC0000002_u32 as _; // Equivalent to the `NT_SUCCESS` C preprocessor macro. @@ -825,7 +826,8 @@ if #[cfg(not(target_vendor = "uwp"))] { ) -> BOOL; } - #[link(name = "userenv")] + #[cfg_attr(not(target_arch = "x86"), link(name = "userenv", kind = "raw-dylib"))] + #[cfg_attr(target_arch = "x86", link(name = "userenv"))] extern "system" { // Allowed but unused by UWP pub fn GetUserProfileDirectoryW( @@ -1130,7 +1132,8 @@ extern "system" { pub fn GetFileAttributesW(lpFileName: LPCWSTR) -> DWORD; } -#[link(name = "ws2_32")] +#[cfg_attr(not(target_arch = "x86"), link(name = "ws2_32", kind = "raw-dylib"))] +#[cfg_attr(target_arch = "x86", link(name = "ws2_32"))] extern "system" { pub fn WSAStartup(wVersionRequested: WORD, lpWSAData: LPWSADATA) -> c_int; pub fn WSACleanup() -> c_int; @@ -1223,7 +1226,8 @@ extern "system" { ) -> c_int; } -#[link(name = "bcrypt")] +#[cfg_attr(not(target_arch = "x86"), link(name = "bcrypt", kind = "raw-dylib"))] +#[cfg_attr(target_arch = "x86", link(name = "bcrypt"))] extern "system" { // >= Vista / Server 2008 // https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom @@ -1242,6 +1246,47 @@ extern "system" { pub fn BCryptCloseAlgorithmProvider(hAlgorithm: BCRYPT_ALG_HANDLE, dwFlags: ULONG) -> NTSTATUS; } +#[cfg(not(target_arch = "x86"))] +#[link(name = "ntdll", kind = "raw-dylib")] +extern "system" { + pub fn NtCreateFile( + FileHandle: *mut HANDLE, + DesiredAccess: ACCESS_MASK, + ObjectAttributes: *const OBJECT_ATTRIBUTES, + IoStatusBlock: *mut IO_STATUS_BLOCK, + AllocationSize: *mut i64, + FileAttributes: ULONG, + ShareAccess: ULONG, + CreateDisposition: ULONG, + CreateOptions: ULONG, + EaBuffer: *mut c_void, + EaLength: ULONG, + ) -> NTSTATUS; + pub fn NtReadFile( + FileHandle: BorrowedHandle<'_>, + Event: HANDLE, + ApcRoutine: Option, + ApcContext: *mut c_void, + IoStatusBlock: &mut IO_STATUS_BLOCK, + Buffer: *mut crate::mem::MaybeUninit, + Length: ULONG, + ByteOffset: Option<&LARGE_INTEGER>, + Key: Option<&ULONG>, + ) -> NTSTATUS; + pub fn NtWriteFile( + FileHandle: BorrowedHandle<'_>, + Event: HANDLE, + ApcRoutine: Option, + ApcContext: *mut c_void, + IoStatusBlock: &mut IO_STATUS_BLOCK, + Buffer: *const u8, + Length: ULONG, + ByteOffset: Option<&LARGE_INTEGER>, + Key: Option<&ULONG>, + ) -> NTSTATUS; + pub fn RtlNtStatusToDosError(Status: NTSTATUS) -> ULONG; +} + // Functions that aren't available on every version of Windows that we support, // but we still use them and just provide some form of a fallback implementation. compat_fn_with_fallback! { @@ -1282,6 +1327,7 @@ compat_fn_optional! { compat_fn_with_fallback! { pub static NTDLL: &CStr = ansi_str!("ntdll"); + #[cfg(target_arch = "x86")] pub fn NtCreateFile( FileHandle: *mut HANDLE, DesiredAccess: ACCESS_MASK, @@ -1297,6 +1343,7 @@ compat_fn_with_fallback! { ) -> NTSTATUS { STATUS_NOT_IMPLEMENTED } + #[cfg(target_arch = "x86")] pub fn NtReadFile( FileHandle: BorrowedHandle<'_>, Event: HANDLE, @@ -1310,6 +1357,7 @@ compat_fn_with_fallback! { ) -> NTSTATUS { STATUS_NOT_IMPLEMENTED } + #[cfg(target_arch = "x86")] pub fn NtWriteFile( FileHandle: BorrowedHandle<'_>, Event: HANDLE, @@ -1323,6 +1371,7 @@ compat_fn_with_fallback! { ) -> NTSTATUS { STATUS_NOT_IMPLEMENTED } + #[cfg(target_arch = "x86")] pub fn RtlNtStatusToDosError( Status: NTSTATUS ) -> ULONG {