+ntoskrnl/ke/mutex.c
authorshort <>
Tue, 25 Mar 2003 12:31:48 +0000 (12:31 +0000)
committershort <>
Tue, 25 Mar 2003 12:31:48 +0000 (12:31 +0000)
 - +KeInitializeMutant()
 - +KeReleaseMutant()
   - +workaround for ntfs.sys Mutant release w/o being hold

ntoskrnl/ke/mutex.c

index b387df5..15b6177 100644 (file)
@@ -37,6 +37,8 @@
 
 /* FUNCTIONS *****************************************************************/
 
+#ifndef LIBCAPTIVE
+
 VOID STDCALL
 KeInitializeMutex(IN PKMUTEX Mutex,
                  IN ULONG Level)
@@ -91,6 +93,7 @@ KeWaitForMutexObject(IN PKMUTEX Mutex,
   return(KeWaitForSingleObject(Mutex,WaitReason,WaitMode,Alertable,Timeout));
 }
 
+#endif /* LIBCAPTIVE */
 
 VOID STDCALL
 KeInitializeMutant(IN PKMUTANT Mutant,
@@ -120,12 +123,16 @@ KeInitializeMutant(IN PKMUTANT Mutant,
   Mutant->ApcDisable = 0;
 }
 
+#ifndef LIBCAPTIVE
+
 LONG STDCALL
 KeReadStateMutant(IN PKMUTANT Mutant)
 {
   return(Mutant->Header.SignalState);
 }
 
+#endif /* LIBCAPTIVE */
+
 LONG STDCALL
 KeReleaseMutant(IN PKMUTANT Mutant,
                IN KPRIORITY Increment,
@@ -142,7 +149,18 @@ KeReleaseMutant(IN PKMUTANT Mutant,
                   KeGetCurrentThread());
          KeBugCheck(0); /* THREAD_NOT_MUTEX_OWNER */
        }
-      Mutant->Header.SignalState++;
+      if (Mutant->Header.SignalState==0)
+       {
+         Mutant->Header.SignalState++;
+       }
+      else
+       {
+         /* ntfs.sys behaviour: KeInitializeMutant(,FALSE); KeReleaseMutant(,0,FALSE,FALSE;
+          * Ugh.
+          */
+         DbgPrint("WARNING: Releasing already unlocked KMUTANT %p CurrentThread %p !!!\n",
+                  Mutant,KeGetCurrentThread());
+       }
       assert(Mutant->Header.SignalState <= 1);
     }
   else
@@ -159,7 +177,9 @@ KeReleaseMutant(IN PKMUTANT Mutant,
       Mutant->OwnerThread = NULL;
       if (Mutant->MutantListEntry.Flink && Mutant->MutantListEntry.Blink)
        RemoveEntryList(&Mutant->MutantListEntry);
+#ifndef LIBCAPTIVE
       KeDispatcherObjectWake(&Mutant->Header);
+#endif /* LIBCAPTIVE */
     }
 
   KeReleaseDispatcherDatabaseLock(Wait);