https://bugs.winehq.org/show_bug.cgi?id=44620
Bug ID: 44620 Summary: `Nt{WaitFor,Release}KeyedEvent()` don't accept null handles, while Windows 7 does. Product: Wine Version: 3.0 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: ntdll Assignee: wine-bugs@winehq.org Reporter: lh_mouse@126.com Distribution: ---
Created attachment 60609 --> https://bugs.winehq.org/attachment.cgi?id=60609 testcase
Testcase (also attached as 'ntwaitforkeyedevent.c'):
------ #include <winternl.h> #include <winnt.h> #include <stdio.h>
__attribute__((__dllimport__, __stdcall__)) extern NTSTATUS NtWaitForKeyedEvent(HANDLE hKeyedEvent, void *pKey, BOOLEAN bAlertable, const LARGE_INTEGER *pliTimeout);
int main(void){ LARGE_INTEGER liTimeout; NTSTATUS lStatus;
liTimeout.QuadPart = -10000000; printf("Waiting...\n"); lStatus = NtWaitForKeyedEvent(NULL, &lStatus, FALSE, &liTimeout); printf("NtWaitForKeyedEvent() returned %08lx\n", lStatus);
return 0; } ------
Compiling and running this program on Linux Mint 18.3 results in the following output:
------ lh_mouse@lhmouse-ideapad-720S ~/桌面 $ x86_64-w64-mingw32-gcc ntwaitforkeyedevent.c -Wall -Wextra -Wpedantic -lntdll && ./a.exe Waiting... NtWaitForKeyedEvent() returned c0000008 lh_mouse@lhmouse-ideapad-720S ~/桌面 $ wine --version wine-3.0 lh_mouse@lhmouse-ideapad-720S ~/桌面 $ ------
On Windows 7 `NtWaitForKeyedEvent()` returns `STATUS_TIMEOUT` i.e. it succeeds:
------ E:\Desktop>x86_64-w64-mingw32-gcc ntwaitforkeyedevent.c -Wall -Wextra -Wpedantic -lntdll && a.exe Waiting... NtWaitForKeyedEvent() returned 00000102 ------
Passing null handles to `Nt{WaitFor,Release}KeyedEvent()` is how SRW locks and condition variables are implemented on Windows 7. I presume that a handle to the preallocated global keyed event with the name '\KernelObjects\CritSecOutOfMemoryEvent' is used in this case.
At the moment https://github.com/lhmouse/mcfgthread expects the Windows behavior and fails in Wine.