Skip to content

Commit fb2ee91

Browse files
seritoolsmbilker
authored andcommitted
Add static 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 8e610b2 commit fb2ee91

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,4 +721,5 @@ extern "system" {
721721

722722
pub fn GetTickCount() -> DWORD;
723723
pub fn GetCurrentThreadId() -> DWORD;
724+
pub fn GetVersion() -> DWORD;
724725
}

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

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

27+
pub(crate) mod version;
28+
2729
// This uses a static initializer to preload some imported functions.
2830
// The CRT (C runtime) executes static initializers before `main`
2931
// is called (for binaries) and before `DllMain` is called (for DLLs).
@@ -65,6 +67,8 @@ unsafe extern "C" fn init() {
6567

6668
// Attempt to preload the synch functions.
6769
load_synch_functions();
70+
// Determine if running on 9x or NT
71+
version::init();
6872
}
6973

7074
/// Helper macro for creating CStrs from literals and symbol names.
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(super) unsafe extern "C" fn init() {
6+
// according to old MSDN info, the high-order bit is set only on 95/98/ME.
7+
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(crate) fn is_windows_nt() -> bool {
14+
unsafe { IS_NT }
15+
}

0 commit comments

Comments
 (0)