From d295d5da5735519232d7f35d99cf669dc6114740 Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Mon, 28 Mar 2005 15:17:54 +0000 Subject: [PATCH] release the dispatcher lock in KeReleaseMutant before raising an exception and handle the exception in NtReleaseMutant svn path=/trunk/; revision=14363 --- reactos/ntoskrnl/ex/mutant.c | 40 +++++++++++++++++++++++------------- reactos/ntoskrnl/ke/mutex.c | 2 ++ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/reactos/ntoskrnl/ex/mutant.c b/reactos/ntoskrnl/ex/mutant.c index 8323e8a6b6a..116fcab87c6 100644 --- a/reactos/ntoskrnl/ex/mutant.c +++ b/reactos/ntoskrnl/ex/mutant.c @@ -332,23 +332,35 @@ NtReleaseMutant(IN HANDLE MutantHandle, 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; + } } } diff --git a/reactos/ntoskrnl/ke/mutex.c b/reactos/ntoskrnl/ke/mutex.c index 998669a132a..2ff0507fd5c 100644 --- a/reactos/ntoskrnl/ke/mutex.c +++ b/reactos/ntoskrnl/ke/mutex.c @@ -144,6 +144,8 @@ KeReleaseMutant(IN PKMUTANT Mutant, /* 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); }