Skip to content

Commit 8343679

Browse files
committed
Add downlevel implementations for Mutex and Condvar
1 parent 5e835c3 commit 8343679

File tree

14 files changed

+643
-4
lines changed

14 files changed

+643
-4
lines changed

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ pub const INVALID_HANDLE_VALUE: HANDLE = ::core::ptr::without_provenance_mut(-1i
2121
pub const EXIT_SUCCESS: u32 = 0;
2222
pub const EXIT_FAILURE: u32 = 1;
2323

24-
#[cfg(target_vendor = "win7")]
24+
#[cfg(any(target_vendor = "win7", target_vendor = "rust9x"))]
2525
pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE { Ptr: ptr::null_mut() };
26-
#[cfg(target_vendor = "win7")]
26+
#[cfg(any(target_vendor = "win7", target_vendor = "rust9x"))]
2727
pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { Ptr: ptr::null_mut() };
2828
#[cfg(not(target_thread_local))]
2929
pub const INIT_ONCE_STATIC_INIT: INIT_ONCE = INIT_ONCE { Ptr: ptr::null_mut() };
@@ -291,3 +291,44 @@ compat_fn_with_fallback! {
291291
Status as u32
292292
}
293293
}
294+
295+
#[cfg(target_vendor = "rust9x")]
296+
compat_fn_with_fallback! {
297+
pub static KERNEL32: &CStr = c"kernel32" => { load: false, unicows: false };
298+
299+
// >= NT 4
300+
// https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-signalobjectandwait
301+
pub fn SignalObjectAndWait(
302+
hobjecttosignal: HANDLE,
303+
hobjecttowaiton: HANDLE,
304+
dwmilliseconds: u32,
305+
balertable: BOOL
306+
) -> WAIT_EVENT { unimplemented!() }
307+
// >= NT 4
308+
// https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-tryentercriticalsection
309+
pub fn TryEnterCriticalSection(lpcriticalsection: *mut CRITICAL_SECTION) -> BOOL {
310+
unimplemented!()
311+
}
312+
// >= Win7 / Server 2008 R2
313+
// https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-tryacquiresrwlockexclusive
314+
pub fn TryAcquireSRWLockExclusive(srwlock: *mut SRWLOCK) -> BOOLEAN { unimplemented!() }
315+
pub fn TryAcquireSRWLockShared(srwlock: *mut SRWLOCK) -> BOOLEAN { unimplemented!() }
316+
// >= Vista / Server 2008
317+
// https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-acquiresrwlockexclusive
318+
pub fn AcquireSRWLockExclusive(srwlock: *mut SRWLOCK) -> () { unimplemented!() }
319+
pub fn AcquireSRWLockShared(srwlock: *mut SRWLOCK) -> () { unimplemented!() }
320+
pub fn ReleaseSRWLockExclusive(srwlock: *mut SRWLOCK) -> () { unimplemented!() }
321+
pub fn ReleaseSRWLockShared(srwlock: *mut SRWLOCK) -> () { unimplemented!() }
322+
pub fn SleepConditionVariableSRW(
323+
conditionvariable: *mut CONDITION_VARIABLE,
324+
srwlock: *mut SRWLOCK,
325+
dwmilliseconds: u32,
326+
flags: u32,
327+
) -> BOOL { unimplemented!() }
328+
pub fn WakeAllConditionVariable(conditionvariable: *mut CONDITION_VARIABLE) -> () {
329+
unimplemented!()
330+
}
331+
pub fn WakeConditionVariable(conditionvariable: *mut CONDITION_VARIABLE) -> () {
332+
unimplemented!()
333+
}
334+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,14 +2524,18 @@ Windows.Win32.System.Threading.CREATE_SUSPENDED
25242524
Windows.Win32.System.Threading.CREATE_UNICODE_ENVIRONMENT
25252525
Windows.Win32.System.Threading.CREATE_WAITABLE_TIMER_HIGH_RESOLUTION
25262526
Windows.Win32.System.Threading.CREATE_WAITABLE_TIMER_MANUAL_RESET
2527+
Windows.Win32.System.Threading.CreateEventA
25272528
Windows.Win32.System.Threading.CreateEventW
2529+
Windows.Win32.System.Threading.CreateMutexA
25282530
Windows.Win32.System.Threading.CreateProcessW
25292531
Windows.Win32.System.Threading.CreateThread
25302532
Windows.Win32.System.Threading.CreateWaitableTimerExW
25312533
Windows.Win32.System.Threading.DEBUG_ONLY_THIS_PROCESS
25322534
Windows.Win32.System.Threading.DEBUG_PROCESS
2535+
Windows.Win32.System.Threading.DeleteCriticalSection
25332536
Windows.Win32.System.Threading.DeleteProcThreadAttributeList
25342537
Windows.Win32.System.Threading.DETACHED_PROCESS
2538+
Windows.Win32.System.Threading.EnterCriticalSection
25352539
Windows.Win32.System.Threading.ExitProcess
25362540
Windows.Win32.System.Threading.EXTENDED_STARTUPINFO_PRESENT
25372541
Windows.Win32.System.Threading.GetActiveProcessorCount
@@ -2546,9 +2550,11 @@ Windows.Win32.System.Threading.INFINITE
25462550
Windows.Win32.System.Threading.INHERIT_CALLER_PRIORITY
25472551
Windows.Win32.System.Threading.INHERIT_PARENT_AFFINITY
25482552
Windows.Win32.System.Threading.INIT_ONCE_INIT_FAILED
2553+
Windows.Win32.System.Threading.InitializeCriticalSection
25492554
Windows.Win32.System.Threading.InitializeProcThreadAttributeList
25502555
Windows.Win32.System.Threading.InitOnceBeginInitialize
25512556
Windows.Win32.System.Threading.InitOnceComplete
2557+
Windows.Win32.System.Threading.LeaveCriticalSection
25522558
Windows.Win32.System.Threading.LPPROC_THREAD_ATTRIBUTE_LIST
25532559
Windows.Win32.System.Threading.LPTHREAD_START_ROUTINE
25542560
Windows.Win32.System.Threading.NORMAL_PRIORITY_CLASS
@@ -2561,10 +2567,14 @@ Windows.Win32.System.Threading.PROFILE_KERNEL
25612567
Windows.Win32.System.Threading.PROFILE_SERVER
25622568
Windows.Win32.System.Threading.PROFILE_USER
25632569
Windows.Win32.System.Threading.REALTIME_PRIORITY_CLASS
2570+
Windows.Win32.System.Threading.ReleaseMutex
25642571
Windows.Win32.System.Threading.ReleaseSRWLockExclusive
25652572
Windows.Win32.System.Threading.ReleaseSRWLockShared
2573+
Windows.Win32.System.Threading.ResetEvent
2574+
Windows.Win32.System.Threading.SetEvent
25662575
Windows.Win32.System.Threading.SetThreadStackGuarantee
25672576
Windows.Win32.System.Threading.SetWaitableTimer
2577+
Windows.Win32.System.Threading.SignalObjectAndWait
25682578
Windows.Win32.System.Threading.Sleep
25692579
Windows.Win32.System.Threading.SleepConditionVariableSRW
25702580
Windows.Win32.System.Threading.SleepEx
@@ -2600,6 +2610,7 @@ Windows.Win32.System.Threading.TlsGetValue
26002610
Windows.Win32.System.Threading.TlsSetValue
26012611
Windows.Win32.System.Threading.TryAcquireSRWLockExclusive
26022612
Windows.Win32.System.Threading.TryAcquireSRWLockShared
2613+
Windows.Win32.System.Threading.TryEnterCriticalSection
26032614
Windows.Win32.System.Threading.UpdateProcThreadAttribute
26042615
Windows.Win32.System.Threading.WaitForMultipleObjects
26052616
Windows.Win32.System.Threading.WaitForSingleObject

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@ windows_targets::link!("kernel32.dll" "system" fn CloseHandle(hobject : HANDLE)
1111
windows_targets::link!("kernel32.dll" "system" fn CompareStringOrdinal(lpstring1 : PCWSTR, cchcount1 : i32, lpstring2 : PCWSTR, cchcount2 : i32, bignorecase : BOOL) -> COMPARESTRING_RESULT);
1212
windows_targets::link!("kernel32.dll" "system" fn CopyFileExW(lpexistingfilename : PCWSTR, lpnewfilename : PCWSTR, lpprogressroutine : LPPROGRESS_ROUTINE, lpdata : *const core::ffi::c_void, pbcancel : *mut BOOL, dwcopyflags : u32) -> BOOL);
1313
windows_targets::link!("kernel32.dll" "system" fn CreateDirectoryW(lppathname : PCWSTR, lpsecurityattributes : *const SECURITY_ATTRIBUTES) -> BOOL);
14+
windows_targets::link!("kernel32.dll" "system" fn CreateEventA(lpeventattributes : *const SECURITY_ATTRIBUTES, bmanualreset : BOOL, binitialstate : BOOL, lpname : PCSTR) -> HANDLE);
1415
windows_targets::link!("kernel32.dll" "system" fn CreateEventW(lpeventattributes : *const SECURITY_ATTRIBUTES, bmanualreset : BOOL, binitialstate : BOOL, lpname : PCWSTR) -> HANDLE);
1516
windows_targets::link!("kernel32.dll" "system" fn CreateFileW(lpfilename : PCWSTR, dwdesiredaccess : u32, dwsharemode : FILE_SHARE_MODE, lpsecurityattributes : *const SECURITY_ATTRIBUTES, dwcreationdisposition : FILE_CREATION_DISPOSITION, dwflagsandattributes : FILE_FLAGS_AND_ATTRIBUTES, htemplatefile : HANDLE) -> HANDLE);
1617
windows_targets::link!("kernel32.dll" "system" fn CreateHardLinkW(lpfilename : PCWSTR, lpexistingfilename : PCWSTR, lpsecurityattributes : *const SECURITY_ATTRIBUTES) -> BOOL);
18+
windows_targets::link!("kernel32.dll" "system" fn CreateMutexA(lpmutexattributes : *const SECURITY_ATTRIBUTES, binitialowner : BOOL, lpname : PCSTR) -> HANDLE);
1719
windows_targets::link!("kernel32.dll" "system" fn CreateNamedPipeW(lpname : PCWSTR, dwopenmode : FILE_FLAGS_AND_ATTRIBUTES, dwpipemode : NAMED_PIPE_MODE, nmaxinstances : u32, noutbuffersize : u32, ninbuffersize : u32, ndefaulttimeout : u32, lpsecurityattributes : *const SECURITY_ATTRIBUTES) -> HANDLE);
1820
windows_targets::link!("kernel32.dll" "system" fn CreatePipe(hreadpipe : *mut HANDLE, hwritepipe : *mut HANDLE, lppipeattributes : *const SECURITY_ATTRIBUTES, nsize : u32) -> BOOL);
1921
windows_targets::link!("kernel32.dll" "system" fn CreateProcessW(lpapplicationname : PCWSTR, lpcommandline : PWSTR, lpprocessattributes : *const SECURITY_ATTRIBUTES, lpthreadattributes : *const SECURITY_ATTRIBUTES, binherithandles : BOOL, dwcreationflags : PROCESS_CREATION_FLAGS, lpenvironment : *const core::ffi::c_void, lpcurrentdirectory : PCWSTR, lpstartupinfo : *const STARTUPINFOW, lpprocessinformation : *mut PROCESS_INFORMATION) -> BOOL);
2022
windows_targets::link!("kernel32.dll" "system" fn CreateSymbolicLinkW(lpsymlinkfilename : PCWSTR, lptargetfilename : PCWSTR, dwflags : SYMBOLIC_LINK_FLAGS) -> BOOLEAN);
2123
windows_targets::link!("kernel32.dll" "system" fn CreateThread(lpthreadattributes : *const SECURITY_ATTRIBUTES, dwstacksize : usize, lpstartaddress : LPTHREAD_START_ROUTINE, lpparameter : *const core::ffi::c_void, dwcreationflags : THREAD_CREATION_FLAGS, lpthreadid : *mut u32) -> HANDLE);
2224
windows_targets::link!("kernel32.dll" "system" fn CreateWaitableTimerExW(lptimerattributes : *const SECURITY_ATTRIBUTES, lptimername : PCWSTR, dwflags : u32, dwdesiredaccess : u32) -> HANDLE);
25+
windows_targets::link!("kernel32.dll" "system" fn DeleteCriticalSection(lpcriticalsection : *mut CRITICAL_SECTION));
2326
windows_targets::link!("kernel32.dll" "system" fn DeleteFileW(lpfilename : PCWSTR) -> BOOL);
2427
windows_targets::link!("kernel32.dll" "system" fn DeleteProcThreadAttributeList(lpattributelist : LPPROC_THREAD_ATTRIBUTE_LIST));
2528
windows_targets::link!("kernel32.dll" "system" fn DeviceIoControl(hdevice : HANDLE, dwiocontrolcode : u32, lpinbuffer : *const core::ffi::c_void, ninbuffersize : u32, lpoutbuffer : *mut core::ffi::c_void, noutbuffersize : u32, lpbytesreturned : *mut u32, lpoverlapped : *mut OVERLAPPED) -> BOOL);
2629
windows_targets::link!("kernel32.dll" "system" fn DuplicateHandle(hsourceprocesshandle : HANDLE, hsourcehandle : HANDLE, htargetprocesshandle : HANDLE, lptargethandle : *mut HANDLE, dwdesiredaccess : u32, binherithandle : BOOL, dwoptions : DUPLICATE_HANDLE_OPTIONS) -> BOOL);
30+
windows_targets::link!("kernel32.dll" "system" fn EnterCriticalSection(lpcriticalsection : *mut CRITICAL_SECTION));
2731
windows_targets::link!("kernel32.dll" "system" fn ExitProcess(uexitcode : u32) -> !);
2832
windows_targets::link!("kernel32.dll" "system" fn FindClose(hfindfile : HANDLE) -> BOOL);
2933
windows_targets::link!("kernel32.dll" "system" fn FindFirstFileExW(lpfilename : PCWSTR, finfolevelid : FINDEX_INFO_LEVELS, lpfindfiledata : *mut core::ffi::c_void, fsearchop : FINDEX_SEARCH_OPS, lpsearchfilter : *const core::ffi::c_void, dwadditionalflags : FIND_FIRST_EX_FLAGS) -> HANDLE);
@@ -64,7 +68,9 @@ windows_targets::link!("kernel32.dll" "system" fn GetVersion() -> u32);
6468
windows_targets::link!("kernel32.dll" "system" fn GetWindowsDirectoryW(lpbuffer : PWSTR, usize : u32) -> u32);
6569
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);
6670
windows_targets::link!("kernel32.dll" "system" fn InitOnceComplete(lpinitonce : *mut INIT_ONCE, dwflags : u32, lpcontext : *const core::ffi::c_void) -> BOOL);
71+
windows_targets::link!("kernel32.dll" "system" fn InitializeCriticalSection(lpcriticalsection : *mut CRITICAL_SECTION));
6772
windows_targets::link!("kernel32.dll" "system" fn InitializeProcThreadAttributeList(lpattributelist : LPPROC_THREAD_ATTRIBUTE_LIST, dwattributecount : u32, dwflags : u32, lpsize : *mut usize) -> BOOL);
73+
windows_targets::link!("kernel32.dll" "system" fn LeaveCriticalSection(lpcriticalsection : *mut CRITICAL_SECTION));
6874
windows_targets::link!("kernel32.dll" "system" fn LoadLibraryA(lplibfilename : PCSTR) -> HMODULE);
6975
windows_targets::link!("kernel32.dll" "system" fn LocalFree(hmem : HLOCAL) -> HLOCAL);
7076
windows_targets::link!("kernel32.dll" "system" fn LockFileEx(hfile : HANDLE, dwflags : LOCK_FILE_FLAGS, dwreserved : u32, nnumberofbytestolocklow : u32, nnumberofbytestolockhigh : u32, lpoverlapped : *mut OVERLAPPED) -> BOOL);
@@ -75,11 +81,14 @@ windows_targets::link!("kernel32.dll" "system" fn QueryPerformanceFrequency(lpfr
7581
windows_targets::link!("kernel32.dll" "system" fn ReadConsoleW(hconsoleinput : HANDLE, lpbuffer : *mut core::ffi::c_void, nnumberofcharstoread : u32, lpnumberofcharsread : *mut u32, pinputcontrol : *const CONSOLE_READCONSOLE_CONTROL) -> BOOL);
7682
windows_targets::link!("kernel32.dll" "system" fn ReadFile(hfile : HANDLE, lpbuffer : *mut u8, nnumberofbytestoread : u32, lpnumberofbytesread : *mut u32, lpoverlapped : *mut OVERLAPPED) -> BOOL);
7783
windows_targets::link!("kernel32.dll" "system" fn ReadFileEx(hfile : HANDLE, lpbuffer : *mut u8, nnumberofbytestoread : u32, lpoverlapped : *mut OVERLAPPED, lpcompletionroutine : LPOVERLAPPED_COMPLETION_ROUTINE) -> BOOL);
84+
windows_targets::link!("kernel32.dll" "system" fn ReleaseMutex(hmutex : HANDLE) -> BOOL);
7885
windows_targets::link!("kernel32.dll" "system" fn ReleaseSRWLockExclusive(srwlock : *mut SRWLOCK));
7986
windows_targets::link!("kernel32.dll" "system" fn ReleaseSRWLockShared(srwlock : *mut SRWLOCK));
8087
windows_targets::link!("kernel32.dll" "system" fn RemoveDirectoryW(lppathname : PCWSTR) -> BOOL);
88+
windows_targets::link!("kernel32.dll" "system" fn ResetEvent(hevent : HANDLE) -> BOOL);
8189
windows_targets::link!("kernel32.dll" "system" fn SetCurrentDirectoryW(lppathname : PCWSTR) -> BOOL);
8290
windows_targets::link!("kernel32.dll" "system" fn SetEnvironmentVariableW(lpname : PCWSTR, lpvalue : PCWSTR) -> BOOL);
91+
windows_targets::link!("kernel32.dll" "system" fn SetEvent(hevent : HANDLE) -> BOOL);
8392
windows_targets::link!("kernel32.dll" "system" fn SetFileAttributesW(lpfilename : PCWSTR, dwfileattributes : FILE_FLAGS_AND_ATTRIBUTES) -> BOOL);
8493
windows_targets::link!("kernel32.dll" "system" fn SetFileInformationByHandle(hfile : HANDLE, fileinformationclass : FILE_INFO_BY_HANDLE_CLASS, lpfileinformation : *const core::ffi::c_void, dwbuffersize : u32) -> BOOL);
8594
windows_targets::link!("kernel32.dll" "system" fn SetFilePointerEx(hfile : HANDLE, lidistancetomove : i64, lpnewfilepointer : *mut i64, dwmovemethod : SET_FILE_POINTER_MOVE_METHOD) -> BOOL);
@@ -88,6 +97,7 @@ windows_targets::link!("kernel32.dll" "system" fn SetHandleInformation(hobject :
8897
windows_targets::link!("kernel32.dll" "system" fn SetLastError(dwerrcode : WIN32_ERROR));
8998
windows_targets::link!("kernel32.dll" "system" fn SetThreadStackGuarantee(stacksizeinbytes : *mut u32) -> BOOL);
9099
windows_targets::link!("kernel32.dll" "system" fn SetWaitableTimer(htimer : HANDLE, lpduetime : *const i64, lperiod : i32, pfncompletionroutine : PTIMERAPCROUTINE, lpargtocompletionroutine : *const core::ffi::c_void, fresume : BOOL) -> BOOL);
100+
windows_targets::link!("kernel32.dll" "system" fn SignalObjectAndWait(hobjecttosignal : HANDLE, hobjecttowaiton : HANDLE, dwmilliseconds : u32, balertable : BOOL) -> WAIT_EVENT);
91101
windows_targets::link!("kernel32.dll" "system" fn Sleep(dwmilliseconds : u32));
92102
windows_targets::link!("kernel32.dll" "system" fn SleepConditionVariableSRW(conditionvariable : *mut CONDITION_VARIABLE, srwlock : *mut SRWLOCK, dwmilliseconds : u32, flags : u32) -> BOOL);
93103
windows_targets::link!("kernel32.dll" "system" fn SleepEx(dwmilliseconds : u32, balertable : BOOL) -> u32);
@@ -99,6 +109,7 @@ windows_targets::link!("kernel32.dll" "system" fn TlsGetValue(dwtlsindex : u32)
99109
windows_targets::link!("kernel32.dll" "system" fn TlsSetValue(dwtlsindex : u32, lptlsvalue : *const core::ffi::c_void) -> BOOL);
100110
windows_targets::link!("kernel32.dll" "system" fn TryAcquireSRWLockExclusive(srwlock : *mut SRWLOCK) -> BOOLEAN);
101111
windows_targets::link!("kernel32.dll" "system" fn TryAcquireSRWLockShared(srwlock : *mut SRWLOCK) -> BOOLEAN);
112+
windows_targets::link!("kernel32.dll" "system" fn TryEnterCriticalSection(lpcriticalsection : *mut CRITICAL_SECTION) -> BOOL);
102113
windows_targets::link!("kernel32.dll" "system" fn UnlockFile(hfile : HANDLE, dwfileoffsetlow : u32, dwfileoffsethigh : u32, nnumberofbytestounlocklow : u32, nnumberofbytestounlockhigh : u32) -> BOOL);
103114
windows_targets::link!("kernel32.dll" "system" fn UpdateProcThreadAttribute(lpattributelist : LPPROC_THREAD_ATTRIBUTE_LIST, dwflags : u32, attribute : usize, lpvalue : *const core::ffi::c_void, cbsize : usize, lppreviousvalue : *mut core::ffi::c_void, lpreturnsize : *const usize) -> BOOL);
104115
windows_targets::link!("kernel32.dll" "system" fn WaitForMultipleObjects(ncount : u32, lphandles : *const HANDLE, bwaitall : BOOL, dwmilliseconds : u32) -> WAIT_EVENT);
@@ -398,6 +409,29 @@ pub const CREATE_SUSPENDED: PROCESS_CREATION_FLAGS = 4u32;
398409
pub const CREATE_UNICODE_ENVIRONMENT: PROCESS_CREATION_FLAGS = 1024u32;
399410
pub const CREATE_WAITABLE_TIMER_HIGH_RESOLUTION: u32 = 2u32;
400411
pub const CREATE_WAITABLE_TIMER_MANUAL_RESET: u32 = 1u32;
412+
#[repr(C)]
413+
#[derive(Clone, Copy)]
414+
pub struct CRITICAL_SECTION {
415+
pub DebugInfo: *mut CRITICAL_SECTION_DEBUG,
416+
pub LockCount: i32,
417+
pub RecursionCount: i32,
418+
pub OwningThread: HANDLE,
419+
pub LockSemaphore: HANDLE,
420+
pub SpinCount: usize,
421+
}
422+
#[repr(C)]
423+
#[derive(Clone, Copy)]
424+
pub struct CRITICAL_SECTION_DEBUG {
425+
pub Type: u16,
426+
pub CreatorBackTraceIndex: u16,
427+
pub CriticalSection: *mut CRITICAL_SECTION,
428+
pub ProcessLocksList: LIST_ENTRY,
429+
pub EntryCount: u32,
430+
pub ContentionCount: u32,
431+
pub Flags: u32,
432+
pub CreatorBackTraceIndexHigh: u16,
433+
pub Identifier: u16,
434+
}
401435
pub const CSTR_EQUAL: COMPARESTRING_RESULT = 2i32;
402436
pub const CSTR_GREATER_THAN: COMPARESTRING_RESULT = 3i32;
403437
pub const CSTR_LESS_THAN: COMPARESTRING_RESULT = 1i32;
@@ -2734,6 +2768,12 @@ pub struct LINGER {
27342768
pub l_onoff: u16,
27352769
pub l_linger: u16,
27362770
}
2771+
#[repr(C)]
2772+
#[derive(Clone, Copy)]
2773+
pub struct LIST_ENTRY {
2774+
pub Flink: *mut LIST_ENTRY,
2775+
pub Blink: *mut LIST_ENTRY,
2776+
}
27372777
pub const LOCKFILE_EXCLUSIVE_LOCK: LOCK_FILE_FLAGS = 2u32;
27382778
pub const LOCKFILE_FAIL_IMMEDIATELY: LOCK_FILE_FLAGS = 1u32;
27392779
pub type LOCK_FILE_FLAGS = u32;
@@ -3319,6 +3359,7 @@ pub struct XSAVE_FORMAT {
33193359
pub XmmRegisters: [M128A; 8],
33203360
pub Reserved4: [u8; 224],
33213361
}
3362+
33223363
#[cfg(target_arch = "arm")]
33233364
#[repr(C)]
33243365
pub struct WSADATA {

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub fn init_rust9x_checks() {
1515
// do any dynamic allocation, don't call LoadLibrary, etc.
1616

1717
init_windows_version_check();
18+
init_mutex_kind_check();
1819
}
1920

2021
static mut IS_NT: bool = true;
@@ -23,3 +24,38 @@ fn init_windows_version_check() {
2324
// according to old MSDN info, the high-order bit is set only on 95/98/ME.
2425
unsafe { IS_NT = c::GetVersion() < 0x8000_0000 };
2526
}
27+
28+
#[derive(Clone, Copy, PartialEq)]
29+
pub(crate) enum MutexKind {
30+
/// Win 7+ (Vista doesn't support the `Try*` APIs)
31+
SrwLock,
32+
/// NT 4+ (9x/ME/NT3.x support critical sections, but don't support `TryEnterCriticalSection`)
33+
CriticalSection,
34+
/// `CreateMutex`, available everywhere
35+
Legacy,
36+
}
37+
38+
static mut MUTEX_KIND: MutexKind = MutexKind::Legacy;
39+
40+
#[inline(always)]
41+
pub(crate) fn mutex_kind() -> MutexKind {
42+
unsafe { MUTEX_KIND }
43+
}
44+
45+
fn init_mutex_kind_check() {
46+
let kind = if c::TryAcquireSRWLockExclusive::available().is_some() {
47+
MutexKind::SrwLock
48+
} else if {
49+
// Windows 9x exports `TryEnterCriticalSection`, but it returns ERROR_CALL_NOT_IMPLEMENTED.
50+
// MSDN specifies that the function is available on NT4 and later.
51+
is_windows_nt() && c::TryEnterCriticalSection::available().is_some()
52+
} {
53+
MutexKind::CriticalSection
54+
} else {
55+
MutexKind::Legacy
56+
};
57+
58+
unsafe {
59+
MUTEX_KIND = kind;
60+
}
61+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(dead_code)]
2+
13
use core::ffi::c_void;
24
use core::sync::atomic::{
35
AtomicBool, AtomicI8, AtomicI16, AtomicI32, AtomicI64, AtomicIsize, AtomicPtr, AtomicU8,

library/std/src/sys/sync/condvar/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cfg_if::cfg_if! {
22
if #[cfg(any(
3-
all(target_os = "windows", not(target_vendor="win7")),
3+
all(target_os = "windows", not(any(target_vendor="win7", target_vendor = "rust9x"))),
44
target_os = "linux",
55
target_os = "android",
66
target_os = "freebsd",
@@ -21,6 +21,10 @@ cfg_if::cfg_if! {
2121
} else if #[cfg(all(target_os = "windows", target_vendor = "win7"))] {
2222
mod windows7;
2323
pub use windows7::Condvar;
24+
} else if #[cfg(all(target_os = "windows", target_vendor = "rust9x"))] {
25+
mod windows7;
26+
mod rust9x;
27+
pub use rust9x::Condvar;
2428
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
2529
mod sgx;
2630
pub use sgx::Condvar;

0 commit comments

Comments
 (0)