[PATCH] ntdll: Make RtlDeregisterWaitEx(handle, INVALID_HANDLE_VALUE) thread safe.

Sebastian Lackner sebastian at fds-team.de
Wed Sep 6 13:21:16 CDT 2017


On 05.09.2017 17:34, Stefan Dösinger wrote:
> Chromium signals the wait semaphore and calls DeregisterWaitEx with
> CompletionHandle = INVALID_HANDLE_VALUE in close succession. Sometimes
> the worker thread decides to run the callback, but before it sets
> CallbackInProgress RtlDeregisterWaitEx decides that the callback is not
> running and returns STATUS_SUCCESS. Chromium then releases resources
> that the callback needs to run, resulting in random crashes.
> 
> Signed-off-by: Stefan Dösinger <stefan at codeweavers.com>
> 
> ---
> 
> The tests show that we're only supposed to return STATUS_PENDING if the
> callback is running. Note that the choice between waiting and returning
> STATUS_SUCCESS and not waiting and returning STATUS_PENDING is still
> racy, but we'll no longer return STATUS_SUCCESS and run the callback
> afterwards.
> 
> I tried to extend the tests to show what happens when both events are
> available simultanously. The answer is that it is fairly random.
> INVALID_HANDLE_VALUE blocks and runs the callback one last time, the
> other ways of calling RtlDeregisterWait[Ex] randomly return STATUS_SUCCESS
> and do not run the callback, or they return STATUS_PENDING and may or
> may not run the callback. However, in no circumstance does the callback
> run after STATUS_SUCCESS is returned.
> 
> I am not including the tests because of the random outcome and because
> it plays with SuspendThread and makes the random failures in follow up
> tests worse. I'll send it to wine-devel for reference.
> ---
>  dlls/ntdll/threadpool.c | 59 +++++++++++++++++++++++++++----------------------
>  1 file changed, 32 insertions(+), 27 deletions(-)
> 

I'm fine with the patch, but please note that this is legacy code and will
be replaced with an implementation based on Tp* functions in the near future.
The only remaining blocker is the lack of support for WT_EXECUTEINIOTHREAD.

Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>



More information about the wine-patches mailing list