release the dispatcher lock in KeReleaseMutant before raising an exception and handle the exception in NtReleaseMutant
Modified: trunk/reactos/ntoskrnl/ex/mutant.c
Modified: trunk/reactos/ntoskrnl/ke/mutex.c

Modified: trunk/reactos/ntoskrnl/ex/mutant.c
--- trunk/reactos/ntoskrnl/ex/mutant.c	2005-03-28 10:56:29 UTC (rev 14362)
+++ trunk/reactos/ntoskrnl/ex/mutant.c	2005-03-28 15:17:54 UTC (rev 14363)
@@ -332,23 +332,35 @@
         
         LONG Prev;
         
-        /* Save the Old State */
-        DPRINT("Releasing Mutant\n");
-        Prev = KeReleaseMutant(Mutant, MUTANT_INCREMENT, FALSE, FALSE);
+        /* release the mutant. doing so might raise an exception which we're
+           required to catch! */
+        _SEH_TRY {
+
+            Prev = KeReleaseMutant(Mutant, MUTANT_INCREMENT, FALSE, FALSE);
+
+        } _SEH_HANDLE {
+
+            Status = _SEH_GetExceptionCode();
+
+        } _SEH_END;
+        
         ObDereferenceObject(Mutant);
 
-        /* Return it */        
-        if(PreviousCount) {
-            
-            _SEH_TRY {
+        if(NT_SUCCESS(Status)) {
+
+            /* Return it */
+            if(PreviousCount) {
+
+                _SEH_TRY {
+
+                    *PreviousCount = Prev;
+
+                } _SEH_HANDLE {
                 
-                *PreviousCount = Prev;
-            
-            } _SEH_HANDLE {
-                
-                Status = _SEH_GetExceptionCode();
-            
-            } _SEH_END;
+                    Status = _SEH_GetExceptionCode();
+
+                } _SEH_END;
+            }
         }
     }
 

Modified: trunk/reactos/ntoskrnl/ke/mutex.c
--- trunk/reactos/ntoskrnl/ke/mutex.c	2005-03-28 10:56:29 UTC (rev 14362)
+++ trunk/reactos/ntoskrnl/ke/mutex.c	2005-03-28 15:17:54 UTC (rev 14363)
@@ -144,6 +144,8 @@
         /* Make sure that the Owner Thread is the current Thread */
         if (Mutant->OwnerThread != CurrentThread) {
             
+            KeReleaseDispatcherDatabaseLock(OldIrql);
+            
             DPRINT1("Trying to touch a Mutant that the caller doesn't own!\n");
             ExRaiseStatus(STATUS_MUTANT_NOT_OWNED);
         }