Skip to content

Commit f841709

Browse files
committed
Add static 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 e3f6ad0 commit f841709

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,3 +2623,6 @@ Windows.Win32.System.Threading.GetCurrentThreadId
26232623
Windows.Win32.Networking.WinSock.WSAPROTOCOL_INFOA
26242624
Windows.Win32.Networking.WinSock.WSASocketA
26252625
Windows.Win32.Networking.WinSock.WSADuplicateSocketA
2626+
2627+
// NT vs 9x compat
2628+
Windows.Win32.System.SystemInformation.GetVersion

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,10 @@ extern "system" {
401401
pub fn GetTickCount() -> u32;
402402
}
403403
#[link(name = "kernel32")]
404+
extern "system" {
405+
pub fn GetVersion() -> u32;
406+
}
407+
#[link(name = "kernel32")]
404408
extern "system" {
405409
pub fn GetWindowsDirectoryW(lpbuffer: PWSTR, usize: u32) -> u32;
406410
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ use crate::ptr::NonNull;
2424
use crate::sync::atomic::Ordering;
2525
use crate::sys::c;
2626

27+
mod version;
28+
pub use version::is_windows_nt;
29+
2730
// This uses a static initializer to preload some imported functions.
2831
// The CRT (C runtime) executes static initializers before `main`
2932
// is called (for binaries) and before `DllMain` is called (for DLLs).
@@ -63,6 +66,8 @@ unsafe extern "C" fn init() {
6366
// because this function runs during global initialization. For example, DO NOT
6467
// do any dynamic allocation, don't call LoadLibrary, etc.
6568

69+
version::init_windows_version_check();
70+
6671
// check all the different synchronization primitives ...
6772
load_try_enter_critical_section_function();
6873
load_srw_functions();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use crate::sys::c;
2+
3+
static mut IS_NT: bool = true;
4+
5+
pub fn init_windows_version_check() {
6+
// according to old MSDN info, the high-order bit is set only on 95/98/ME.
7+
unsafe { IS_NT = c::GetVersion() < 0x8000_0000 };
8+
}
9+
10+
/// Returns true if we are running on a Windows NT-based system. Only use this for APIs where the
11+
/// same API differs in behavior or capability on 9x/ME compared to NT.
12+
#[inline(always)]
13+
pub fn is_windows_nt() -> bool {
14+
unsafe { IS_NT }
15+
}

0 commit comments

Comments
 (0)