https://bugs.winehq.org/show_bug.cgi?id=37669
--- Comment #17 from Dmitry Timoshkov dmitry@baikal.ru --- (In reply to Dmitry Timoshkov from comment #16)
In order to solve this either apc callback should avoid generating exceptions, or it should be executed on win32 stack instead, perhaps wine_call_on_stack is the way to achieve that. Avoiding generating exceptions seems unfeasible to me, VirtualQuery() doesn't provide a way to detect write watchable memory, and I don't see another way to determine why recvmsg has returned EFAULT.
There is an obvious way to avoid generating exceptions and detecting a write watchable memory region - GetWriteWatch. But the apc callback can't avoid generating exceptions (by calling IsBadWritePtr) when recvmsg() returns EFAULT because that's the only way for ntdll to make the buffer writable before calling recvmsg() again.
So the Sebastian's patch can't work for asynchronous winsock recv() calls without allowing exception handlers (at least inside of ntdll) work on a signal stack, but that's a serious architectural violation of current design of signal/SEH handling in wine.
I'll attach a test application which demonstrates both the current problem with unexpected EFAULT return from asynchronous WSARecv(), and the receiver thread dying due to an exception on signal stack with Sebastian's patch.