Skip to content

Commit 7dca083

Browse files
authored
Rollup merge of #112484 - bdbai:fix/uwpntdll, r=ChrisDenton
Fix ntdll linkage issues on Windows UWP platforms See discussion: rust-lang/rust#112265 (comment) Static loading `ntdll` functions does not work for UWP programs, which will end up link errors complaining about missing symbols, or failure to pass the WACK tests. The breakage was introduced in #108262. This PR basically reverts part of the changes in #108262 for UWP only, and fixes some lint suggestions.
2 parents 1b1530d + c107466 commit 7dca083

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

std/src/sys/windows/c.rs

+55
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub use windows_sys::*;
1919
pub type DWORD = c_ulong;
2020
pub type NonZeroDWORD = NonZero_c_ulong;
2121
pub type LARGE_INTEGER = c_longlong;
22+
#[cfg_attr(target_vendor = "uwp", allow(unused))]
2223
pub type LONG = c_long;
2324
pub type UINT = c_uint;
2425
pub type WCHAR = u16;
@@ -267,6 +268,8 @@ pub unsafe fn getaddrinfo(
267268
windows_sys::getaddrinfo(node.cast::<u8>(), service.cast::<u8>(), hints, res)
268269
}
269270

271+
cfg_if::cfg_if! {
272+
if #[cfg(not(target_vendor = "uwp"))] {
270273
pub unsafe fn NtReadFile(
271274
filehandle: BorrowedHandle<'_>,
272275
event: HANDLE,
@@ -313,6 +316,8 @@ pub unsafe fn NtWriteFile(
313316
key.map(|k| k as *const u32).unwrap_or(ptr::null()),
314317
)
315318
}
319+
}
320+
}
316321

317322
// Functions that aren't available on every version of Windows that we support,
318323
// but we still use them and just provide some form of a fallback implementation.
@@ -376,4 +381,54 @@ compat_fn_with_fallback! {
376381
) -> NTSTATUS {
377382
panic!("keyed events not available")
378383
}
384+
385+
// These functions are available on UWP when lazily loaded. They will fail WACK if loaded statically.
386+
#[cfg(target_vendor = "uwp")]
387+
pub fn NtCreateFile(
388+
filehandle: *mut HANDLE,
389+
desiredaccess: FILE_ACCESS_RIGHTS,
390+
objectattributes: *const OBJECT_ATTRIBUTES,
391+
iostatusblock: *mut IO_STATUS_BLOCK,
392+
allocationsize: *const i64,
393+
fileattributes: FILE_FLAGS_AND_ATTRIBUTES,
394+
shareaccess: FILE_SHARE_MODE,
395+
createdisposition: NTCREATEFILE_CREATE_DISPOSITION,
396+
createoptions: NTCREATEFILE_CREATE_OPTIONS,
397+
eabuffer: *const ::core::ffi::c_void,
398+
ealength: u32
399+
) -> NTSTATUS {
400+
STATUS_NOT_IMPLEMENTED
401+
}
402+
#[cfg(target_vendor = "uwp")]
403+
pub fn NtReadFile(
404+
filehandle: BorrowedHandle<'_>,
405+
event: HANDLE,
406+
apcroutine: PIO_APC_ROUTINE,
407+
apccontext: *mut c_void,
408+
iostatusblock: &mut IO_STATUS_BLOCK,
409+
buffer: *mut crate::mem::MaybeUninit<u8>,
410+
length: ULONG,
411+
byteoffset: Option<&LARGE_INTEGER>,
412+
key: Option<&ULONG>
413+
) -> NTSTATUS {
414+
STATUS_NOT_IMPLEMENTED
415+
}
416+
#[cfg(target_vendor = "uwp")]
417+
pub fn NtWriteFile(
418+
filehandle: BorrowedHandle<'_>,
419+
event: HANDLE,
420+
apcroutine: PIO_APC_ROUTINE,
421+
apccontext: *mut c_void,
422+
iostatusblock: &mut IO_STATUS_BLOCK,
423+
buffer: *const u8,
424+
length: ULONG,
425+
byteoffset: Option<&LARGE_INTEGER>,
426+
key: Option<&ULONG>
427+
) -> NTSTATUS {
428+
STATUS_NOT_IMPLEMENTED
429+
}
430+
#[cfg(target_vendor = "uwp")]
431+
pub fn RtlNtStatusToDosError(Status: NTSTATUS) -> u32 {
432+
Status as u32
433+
}
379434
}

std/src/sys/windows/c/windows_sys.lst

+1
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,7 @@ Windows.Win32.Foundation.SetLastError
19301930
Windows.Win32.Foundation.STATUS_DELETE_PENDING
19311931
Windows.Win32.Foundation.STATUS_END_OF_FILE
19321932
Windows.Win32.Foundation.STATUS_INVALID_PARAMETER
1933+
Windows.Win32.Foundation.STATUS_NOT_IMPLEMENTED
19331934
Windows.Win32.Foundation.STATUS_PENDING
19341935
Windows.Win32.Foundation.STATUS_SUCCESS
19351936
Windows.Win32.Foundation.TRUE

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

+1
Original file line numberDiff line numberDiff line change
@@ -3888,6 +3888,7 @@ pub type STARTUPINFOW_FLAGS = u32;
38883888
pub const STATUS_DELETE_PENDING: NTSTATUS = -1073741738i32;
38893889
pub const STATUS_END_OF_FILE: NTSTATUS = -1073741807i32;
38903890
pub const STATUS_INVALID_PARAMETER: NTSTATUS = -1073741811i32;
3891+
pub const STATUS_NOT_IMPLEMENTED: NTSTATUS = -1073741822i32;
38913892
pub const STATUS_PENDING: NTSTATUS = 259i32;
38923893
pub const STATUS_SUCCESS: NTSTATUS = 0i32;
38933894
pub const STD_ERROR_HANDLE: STD_HANDLE = 4294967284u32;

std/src/sys/windows/rand.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use crate::ffi::c_void;
2-
use crate::io;
31
use crate::mem;
42
use crate::ptr;
53
use crate::sys::c;
@@ -25,6 +23,9 @@ pub fn hashmap_random_keys() -> (u64, u64) {
2523
#[cfg(not(target_vendor = "uwp"))]
2624
#[inline(never)]
2725
fn fallback_rng() -> (u64, u64) {
26+
use crate::ffi::c_void;
27+
use crate::io;
28+
2829
let mut v = (0, 0);
2930
let ret = unsafe {
3031
c::RtlGenRandom(&mut v as *mut _ as *mut c_void, mem::size_of_val(&v) as c::ULONG)

0 commit comments

Comments
 (0)