v5: - Add much more tests and organize those with a table and loops; - Handle lower bit set in file handle in GetOverlappedResultEx(); - Still use GetOverlappedResultEx() from GetOverlappedResult() with the "compatibility" flag passed in file handle lower bit.
On the way of testing that I found that our waits, given both signaled state and user APC are available, are preferring user APC. That is the opposite on Windows and the difference is responsible for the TODO tests in the latest patch version (I prepended WaitForSingleObjectEx there which illustrates the difference). I tried to fix that at once in v4 also adding a separate test, but turned out that broke a couple of things which look not that trivial to fix (while the behaviour of Wait itself looks correct with preferring user APC).
One thing is ntdll/tests/pipe.c: test_blocking(FILE_SYNCHRONOUS_IO_ALERT). The call to NtReadFile on pipe with ioapc requested waits alertable for async in server_read_file(). When server finishes async, it both queues io completion user APC and signals the wait object. Signaling async object before queueing APC doesn't help, maybe it is because the wait is not started yet and when it starts both are signaled anyway. I didn't look in all the details yet, not sure how that can be fixed. But broadly this looks like async handling details which don't work quite right, or what if that io completion APC is queued in a bit different way or something is special about it.
Another failure from attempt to fix WaitFor... is in user32/tests/msg.c:test_MsgWaitForMultipleObjects(). The test result directly reads as MsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_POSTMESSAGE,, MWMO_ALERTABLE ) should prefer message queue wake up to the APC (while maybe more things should be tested around to see at least what happens if there are some other wait handles). No idea yet what is the culrpit here, is it maybe message queue is special or some other specifics with MsgWaitForMultipleObjectsEx.
So for now I just made the tests in this patch depending on user APC taking precedence over signaled event state TODO.