Skip to content

Commit 17cfea6

Browse files
committed
Add startup check indicating NT vs 9x/ME
This will be used/needed for some APIs that exist on both platforms but with different behavior/capabilities.
1 parent a57dba0 commit 17cfea6

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,6 +2493,7 @@ Windows.Win32.System.SystemInformation.GetSystemDirectoryW
24932493
Windows.Win32.System.SystemInformation.GetSystemInfo
24942494
Windows.Win32.System.SystemInformation.GetSystemTimeAsFileTime
24952495
Windows.Win32.System.SystemInformation.GetSystemTimePreciseAsFileTime
2496+
Windows.Win32.System.SystemInformation.GetVersion
24962497
Windows.Win32.System.SystemInformation.GetWindowsDirectoryW
24972498
Windows.Win32.System.SystemInformation.PROCESSOR_ARCHITECTURE
24982499
Windows.Win32.System.SystemInformation.SYSTEM_INFO

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ windows_targets::link!("kernel32.dll" "system" fn GetSystemInfo(lpsysteminfo : *
6060
windows_targets::link!("kernel32.dll" "system" fn GetSystemTimeAsFileTime(lpsystemtimeasfiletime : *mut FILETIME));
6161
windows_targets::link!("kernel32.dll" "system" fn GetSystemTimePreciseAsFileTime(lpsystemtimeasfiletime : *mut FILETIME));
6262
windows_targets::link!("kernel32.dll" "system" fn GetTempPathW(nbufferlength : u32, lpbuffer : PWSTR) -> u32);
63+
windows_targets::link!("kernel32.dll" "system" fn GetVersion() -> u32);
6364
windows_targets::link!("kernel32.dll" "system" fn GetWindowsDirectoryW(lpbuffer : PWSTR, usize : u32) -> u32);
6465
windows_targets::link!("kernel32.dll" "system" fn InitOnceBeginInitialize(lpinitonce : *mut INIT_ONCE, dwflags : u32, fpending : *mut BOOL, lpcontext : *mut *mut core::ffi::c_void) -> BOOL);
6566
windows_targets::link!("kernel32.dll" "system" fn InitOnceComplete(lpinitonce : *mut INIT_ONCE, dwflags : u32, lpcontext : *const core::ffi::c_void) -> BOOL);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ use crate::ffi::{CStr, c_void};
2323
use crate::ptr::NonNull;
2424
use crate::sys::c;
2525

26+
#[cfg(target_vendor = "rust9x")]
27+
pub(crate) mod checks;
28+
2629
// This uses a static initializer to preload some imported functions.
2730
// The CRT (C runtime) executes static initializers before `main`
2831
// is called (for binaries) and before `DllMain` is called (for DLLs).
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use crate::sys::c;
2+
3+
/// Returns true if we are running on a Windows NT-based system. Only use this for APIs where the
4+
/// same API differs in behavior or capability on 9x/ME compared to NT.
5+
#[allow(dead_code)]
6+
#[inline(always)]
7+
pub fn is_windows_nt() -> bool {
8+
unsafe { IS_NT }
9+
}
10+
11+
pub fn init_rust9x_checks() {
12+
// DO NOT do anything interesting or complicated in this function! DO NOT call
13+
// any Rust functions or CRT functions if those functions touch any global state,
14+
// because this function runs during global initialization. For example, DO NOT
15+
// do any dynamic allocation, don't call LoadLibrary, etc.
16+
17+
init_windows_version_check();
18+
}
19+
20+
static mut IS_NT: bool = true;
21+
22+
fn init_windows_version_check() {
23+
// according to old MSDN info, the high-order bit is set only on 95/98/ME.
24+
unsafe { IS_NT = c::GetVersion() < 0x8000_0000 };
25+
}

0 commit comments

Comments
 (0)