Author: ion Date: Tue Jul 11 19:36:44 2006 New Revision: 23011
URL: http://svn.reactos.org/svn/reactos?rev=23011&view=rev Log: - Fix up some stuff in Kernel Gates support. - Fix up some implementation bugs in Executive Rundown support.
Modified: trunk/reactos/include/ddk/winddk.h trunk/reactos/include/ndk/ketypes.h trunk/reactos/ntoskrnl/ex/rundown.c trunk/reactos/ntoskrnl/include/internal/ex.h trunk/reactos/ntoskrnl/include/internal/ob.h trunk/reactos/ntoskrnl/ke/gate.c (contents, props changed)
Modified: trunk/reactos/include/ddk/winddk.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ddk/winddk.h?rev=23... ============================================================================== --- trunk/reactos/include/ddk/winddk.h (original) +++ trunk/reactos/include/ddk/winddk.h Tue Jul 11 19:36:44 2006 @@ -1157,6 +1157,10 @@ PVOID Ptr; }; } EX_RUNDOWN_REF, *PEX_RUNDOWN_REF; + +#define ASSERT_GATE(object) \ + ASSERT((((object)->Header.Type & KOBJECT_TYPE_MASK) == GateObject) || \ + (((object)->Header.Type & KOBJECT_TYPE_MASK) == EventSynchronizationObject))
typedef struct _KGATE { @@ -5240,6 +5244,10 @@ #define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) \ ((PVOID) InterlockedCompareExchange((PLONG) Destination, (LONG) Exchange, (LONG) Comparand))
+#define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b) +#define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a) +#define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a) + #endif /* !__INTERLOCKED_DECLARED */
NTOSAPI
Modified: trunk/reactos/include/ndk/ketypes.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/ketypes.h?rev=2... ============================================================================== --- trunk/reactos/include/ndk/ketypes.h (original) +++ trunk/reactos/include/ndk/ketypes.h Tue Jul 11 19:36:44 2006 @@ -38,6 +38,11 @@ // Maximum System Descriptor Table Entries // #define SSDT_MAX_ENTRIES 2 + +// +// Object Type Mask for Kernel Dispatcher Objects +// +#define KOBJECT_TYPE_MASK 0x7F
// // Dispatcher Priority increments @@ -240,7 +245,7 @@ Waiting, Transition, DeferredReady, -#if (NTDDI_VERSION >= NTDDI_LONGHORN) +#if (NTDDI_VERSION >= NTDDI_WS03) GateWait, #endif } KTHREAD_STATE, *PKTHREAD_STATE;
Modified: trunk/reactos/ntoskrnl/ex/rundown.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/rundown.c?rev=2... ============================================================================== --- trunk/reactos/ntoskrnl/ex/rundown.c (original) +++ trunk/reactos/ntoskrnl/ex/rundown.c Tue Jul 11 19:36:44 2006 @@ -148,7 +148,7 @@ ASSERT((RunRef->Count & EX_RUNDOWN_ACTIVE) != 0);
/* Reset the count */ - InterlockedExchange((PLONG)&RunRef->Count, 0); + ExpSetRundown(&RunRef->Count, 0); }
/*++ @@ -176,7 +176,7 @@ ASSERT((RunRef->Count & EX_RUNDOWN_ACTIVE) != 0);
/* Mark the counter as active */ - InterlockedExchange((PLONG)&RunRef->Count, EX_RUNDOWN_ACTIVE); + ExpSetRundown(&RunRef->Count, EX_RUNDOWN_ACTIVE); }
/*++ @@ -227,7 +227,7 @@ ASSERT((WaitBlock->Count > 0) || (KeNumberProcessors > 1));
/* Remove the one count */ - if (InterlockedExchangeAddSizeT(&WaitBlock->Count, -1)) + if (!InterlockedDecrementSizeT(&WaitBlock->Count)) { /* We're down to 0 now, so signal the event */ KeSetEvent(&WaitBlock->WakeEvent, IO_NO_INCREMENT, FALSE); @@ -286,7 +286,7 @@ ASSERT((WaitBlock->Count >= Count) || (KeNumberProcessors > 1));
/* Remove the count */ - if (InterlockedExchangeAddSizeT(WaitBlock->Count, -(LONG)Count) == + if (InterlockedExchangeAddSizeT(&WaitBlock->Count, -(LONG)Count) == (LONG)Count) { /* We're down to 0 now, so signal the event */
Modified: trunk/reactos/ntoskrnl/include/internal/ex.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/e... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/ex.h (original) +++ trunk/reactos/ntoskrnl/include/internal/ex.h Tue Jul 11 19:36:44 2006 @@ -7,6 +7,8 @@ extern LARGE_INTEGER ExpTimeZoneBias; extern ULONG ExpTimeZoneId; extern POBJECT_TYPE ExEventPairObjectType; + +#define MAX_FAST_REFS 7
#define EX_OBJ_TO_HDR(eob) ((POBJECT_HEADER)((ULONG_PTR)(eob) & \ ~(EX_HANDLE_ENTRY_PROTECTFROMCLOSE | EX_HANDLE_ENTRY_INHERITABLE | \
Modified: trunk/reactos/ntoskrnl/include/internal/ob.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/o... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/ob.h (original) +++ trunk/reactos/ntoskrnl/include/internal/ob.h Tue Jul 11 19:36:44 2006 @@ -292,6 +292,12 @@ IN PEX_FAST_REF FastRef );
+PVOID +FASTCALL +ObFastReferenceObjectLocked( + IN PEX_FAST_REF FastRef +); + VOID FASTCALL ObFastDereferenceObject(
Modified: trunk/reactos/ntoskrnl/ke/gate.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/gate.c?rev=2301... ============================================================================== --- trunk/reactos/ntoskrnl/ke/gate.c (original) +++ trunk/reactos/ntoskrnl/ke/gate.c Tue Jul 11 19:36:44 2006 @@ -9,6 +9,7 @@
/* INCLUDES *****************************************************************/
+#define NTDDI_VERSION NTDDI_WS03 #include <ntoskrnl.h> #define NDEBUG #include <internal/debug.h> @@ -30,67 +31,68 @@
VOID FASTCALL -KeWaitForGate(PKGATE Gate, - KWAIT_REASON WaitReason, - KPROCESSOR_MODE WaitMode) +KeWaitForGate(IN PKGATE Gate, + IN KWAIT_REASON WaitReason, + IN KPROCESSOR_MODE WaitMode) { KIRQL OldIrql; PKTHREAD CurrentThread = KeGetCurrentThread(); PKWAIT_BLOCK GateWaitBlock; NTSTATUS Status; + ASSERT_GATE(Gate); + ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
- DPRINT("KeWaitForGate(Gate %x)\n", Gate); - + /* Start wait loop */ do { - /* Lock the APC Queue */ + /* Lock the dispatcher */ OldIrql = KeAcquireDispatcherDatabaseLock(); - - /* Check if it's already signaled */ - if (Gate->Header.SignalState) + + /* Check if a kernel APC is pending and we're below APC_LEVEL */ + if ((CurrentThread->ApcState.KernelApcPending) && + !(CurrentThread->SpecialApcDisable) && (OldIrql < APC_LEVEL)) { - /* Unsignal it */ - Gate->Header.SignalState = 0; + /* Unlock the dispatcher, this will fire the APC */ + KeReleaseDispatcherDatabaseLock(OldIrql); + } + else + { + /* Check if it's already signaled */ + if (Gate->Header.SignalState) + { + /* Unsignal it */ + Gate->Header.SignalState = 0;
- /* Unlock the Queue and return */ - KeReleaseDispatcherDatabaseLock(OldIrql); - return; + /* Unlock the Queue and return */ + KeReleaseDispatcherDatabaseLock(OldIrql); + return; + } + + /* Setup a Wait Block */ + GateWaitBlock = &CurrentThread->WaitBlock[0]; + GateWaitBlock->Object = (PVOID)Gate; + GateWaitBlock->Thread = CurrentThread; + + /* Set the Thread Wait Data */ + CurrentThread->WaitMode = WaitMode; + CurrentThread->WaitReason = WaitReason; + CurrentThread->WaitIrql = OldIrql; + CurrentThread->State = GateWait; + CurrentThread->GateObject = Gate; + + /* Insert into the Wait List */ + InsertTailList(&Gate->Header.WaitListHead, + &GateWaitBlock->WaitListEntry); + + /* Handle Kernel Queues */ + if (CurrentThread->Queue) KiWakeQueue(CurrentThread->Queue); + + /* Find a new thread to run */ + Status = KiSwapThread(); + + /* Check if we were executing an APC */ + if (Status != STATUS_KERNEL_APC) return; } - - /* Setup a Wait Block */ - GateWaitBlock = &CurrentThread->WaitBlock[0]; - GateWaitBlock->Object = (PVOID)Gate; - GateWaitBlock->Thread = CurrentThread; - - /* Set the Thread Wait Data */ - CurrentThread->WaitIrql = OldIrql; - CurrentThread->GateObject = Gate; - - /* Insert into the Wait List */ - InsertTailList(&Gate->Header.WaitListHead, - &GateWaitBlock->WaitListEntry); - - /* Handle Kernel Queues */ - if (CurrentThread->Queue) - { - DPRINT("Waking Queue\n"); - KiWakeQueue(CurrentThread->Queue); - } - - /* Setup the wait information */ - CurrentThread->WaitMode = WaitMode; - CurrentThread->WaitReason = WaitReason; - CurrentThread->WaitTime = ((PLARGE_INTEGER)&KeTickCount)->LowPart; - CurrentThread->State = Waiting; - - /* Find a new thread to run */ - DPRINT("Swapping threads\n"); - Status = KiSwapThread(); - - /* Check if we were executing an APC */ - if (Status != STATUS_KERNEL_APC) return; - - DPRINT("Looping Again\n"); } while (TRUE); }
@@ -102,8 +104,8 @@ PKWAIT_BLOCK WaitBlock; KIRQL OldIrql; NTSTATUS WaitStatus = STATUS_SUCCESS; - - DPRINT("KeSignalGateBoostPriority(EveGate %x)\n", Gate); + ASSERT_GATE(Gate); + ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
/* Acquire Dispatcher Database Lock */ OldIrql = KeAcquireDispatcherDatabaseLock(); @@ -111,33 +113,31 @@ /* Make sure we're not already signaled or that the list is empty */ if (Gate->Header.SignalState) goto quit;
- /* If our wait list is empty, then signal the event and return */ + /* Check if our wait list is empty */ if (IsListEmpty(&Gate->Header.WaitListHead)) { + /* It is, so signal the event */ Gate->Header.SignalState = 1; - goto quit; } + else + { + /* Get WaitBlock */ + WaitBlock = CONTAINING_RECORD(Gate->Header.WaitListHead.Flink, + KWAIT_BLOCK, + WaitListEntry);
- /* Get WaitBlock */ - WaitBlock = CONTAINING_RECORD(Gate->Header.WaitListHead.Flink, - KWAIT_BLOCK, - WaitListEntry); - /* Remove it */ - RemoveEntryList(&WaitBlock->WaitListEntry); + /* Remove it */ + RemoveEntryList(&WaitBlock->WaitListEntry);
- /* Get the Associated thread */ - WaitThread = WaitBlock->Thread; + /* Get the Associated thread */ + WaitThread = WaitBlock->Thread;
- /* Increment the Queue's active threads */ - if (WaitThread->Queue) - { - DPRINT("Incrementing Queue's active threads\n"); - WaitThread->Queue->CurrentCount++; + /* Increment the Queue's active threads */ + if (WaitThread->Queue) WaitThread->Queue->CurrentCount++; + + /* Reschedule the Thread */ + KiUnblockThread(WaitThread, &WaitStatus, EVENT_INCREMENT); } - - /* Reschedule the Thread */ - DPRINT("Unblocking the Thread\n"); - KiUnblockThread(WaitThread, &WaitStatus, EVENT_INCREMENT);
quit: /* Release the Dispatcher Database Lock */
Propchange: trunk/reactos/ntoskrnl/ke/gate.c ------------------------------------------------------------------------------ --- svn:needs-lock (original) +++ svn:needs-lock (removed) @@ -1,1 +1,0 @@ -*