ntdll: Don't call RtlLeaveCriticalSection when thread doesn't own the CS

Sebastian Lackner sebastian at fds-team.de
Tue Jan 7 21:38:16 CST 2014


In case of an error in NtWaitForSingleObject the current implementation
of RtlAcquireResourceExclusive and RtlAcquireResourceShared tries to
leave the critical section, although its not owned by the current thread.

Please note that this doesn't fix all possible bugs in the current
implementation: Lets assume we have a thread waiting for the shared lock
using a semaphore, and this fails, then either rwl->uSharedWaiters or
rwl->iNumberActive is messed up, because it is never decremented again.
Nevertheless it isn't that easy to fix, since this would probably mean
that the underlying semaphore is corrupted somehow.

BTW: Would be nice to get some feedback to 101426 - if such an approach
turns out to be suitable I would like to submit a few more similar
patches to implement new synchronization primitives.

---
 dlls/ntdll/rtl.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
-------------- next part --------------
>From a9c9a2578bcfd158d50664fa0834d83ab82008b2 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian at fds-team.de>
Date: Wed, 8 Jan 2014 03:38:54 +0100
Subject: ntdll: Don't call RtlLeaveCriticalSection when thread doesn't own
 the CS

---
 dlls/ntdll/rtl.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/dlls/ntdll/rtl.c b/dlls/ntdll/rtl.c
index 8f6f386..1e0a786 100644
--- a/dlls/ntdll/rtl.c
+++ b/dlls/ntdll/rtl.c
@@ -187,7 +187,7 @@ wait:
 	     RtlLeaveCriticalSection( &rwl->rtlCS );
 	     status = NtWaitForSingleObject( rwl->hExclusiveReleaseSemaphore, FALSE, NULL );
 	     if( HIWORD(status) )
-		 goto done;
+                return retVal;
 	     goto start; /* restart the acquisition to avoid deadlocks */
 	 }
     }
@@ -228,7 +228,7 @@ start:
 	    RtlLeaveCriticalSection( &rwl->rtlCS );
 	    status = NtWaitForSingleObject( rwl->hSharedReleaseSemaphore, FALSE, NULL );
 	    if( HIWORD(status) )
-		goto done;
+                return retVal;
 	    goto start;
 	}
     }
-- 
1.7.9.5



More information about the wine-patches mailing list