2007-10-29 14:44:26 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: ntoskrnl/config/cmdelay.c
|
|
|
|
* PURPOSE: Routines for handling delay close and allocate.
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
|
|
|
WORK_QUEUE_ITEM CmpDelayDerefKCBWorkItem;
|
|
|
|
|
|
|
|
ULONG CmpDelayedCloseSize = 2048;
|
|
|
|
ULONG CmpDelayedCloseElements;
|
|
|
|
KGUARDED_MUTEX CmpDelayedCloseTableLock;
|
|
|
|
BOOLEAN CmpDelayCloseWorkItemActive;
|
|
|
|
WORK_QUEUE_ITEM CmpDelayCloseWorkItem;
|
|
|
|
LIST_ENTRY CmpDelayedLRUListHead;
|
|
|
|
ULONG CmpDelayCloseIntervalInSeconds = 5;
|
|
|
|
KDPC CmpDelayCloseDpc;
|
|
|
|
KTIMER CmpDelayCloseTimer;
|
|
|
|
|
|
|
|
KGUARDED_MUTEX CmpDelayDerefKCBLock;
|
|
|
|
BOOLEAN CmpDelayDerefKCBWorkItemActive;
|
|
|
|
LIST_ENTRY CmpDelayDerefKCBListHead;
|
|
|
|
ULONG CmpDelayDerefKCBIntervalInSeconds = 5;
|
|
|
|
KDPC CmpDelayDerefKCBDpc;
|
|
|
|
KTIMER CmpDelayDerefKCBTimer;
|
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2012-12-19 23:49:13 +00:00
|
|
|
_Function_class_(KDEFERRED_ROUTINE)
|
2007-10-29 14:44:26 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpDelayCloseDpcRoutine(IN PKDPC Dpc,
|
|
|
|
IN PVOID DeferredContext,
|
|
|
|
IN PVOID SystemArgument1,
|
|
|
|
IN PVOID SystemArgument2)
|
|
|
|
{
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(CmpDelayCloseWorkItemActive);
|
|
|
|
|
|
|
|
/* Queue the work item */
|
|
|
|
ExQueueWorkItem(&CmpDelayCloseWorkItem, DelayedWorkQueue);
|
|
|
|
}
|
|
|
|
|
2012-12-19 23:49:13 +00:00
|
|
|
_Function_class_(WORKER_THREAD_ROUTINE)
|
2007-10-29 14:44:26 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpDelayCloseWorker(IN PVOID Context)
|
|
|
|
{
|
2008-09-08 12:41:30 +00:00
|
|
|
PCM_DELAYED_CLOSE_ENTRY ListEntry;
|
|
|
|
ULONG i, ConvKey;
|
2007-10-29 14:44:26 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(CmpDelayCloseWorkItemActive);
|
|
|
|
|
2008-09-08 12:41:30 +00:00
|
|
|
/* Lock the registry */
|
|
|
|
CmpLockRegistry();
|
|
|
|
|
|
|
|
/* Acquire the delayed close table lock */
|
|
|
|
KeAcquireGuardedMutex(&CmpDelayedCloseTableLock);
|
|
|
|
|
|
|
|
/* Iterate */
|
|
|
|
for (i = 0; i < (CmpDelayedCloseSize >> 2); i++)
|
|
|
|
{
|
|
|
|
/* Break out of the loop if there is nothing to process */
|
|
|
|
if (CmpDelayedCloseElements <= CmpDelayedCloseSize) break;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(!IsListEmpty(&CmpDelayedLRUListHead));
|
|
|
|
|
|
|
|
/* Get the entry */
|
|
|
|
ListEntry = CONTAINING_RECORD(CmpDelayedLRUListHead.Blink,
|
|
|
|
CM_DELAYED_CLOSE_ENTRY,
|
|
|
|
DelayedLRUList);
|
|
|
|
|
|
|
|
/* Save the ConvKey value of the KCB */
|
|
|
|
ConvKey = ListEntry->KeyControlBlock->ConvKey;
|
|
|
|
|
|
|
|
/* Release the delayed close table lock */
|
|
|
|
KeReleaseGuardedMutex(&CmpDelayedCloseTableLock);
|
|
|
|
|
|
|
|
/* Acquire the KCB lock */
|
|
|
|
CmpAcquireKcbLockExclusiveByKey(ConvKey);
|
|
|
|
|
|
|
|
/* Reacquire the delayed close table lock */
|
|
|
|
KeAcquireGuardedMutex(&CmpDelayedCloseTableLock);
|
|
|
|
|
|
|
|
/* Get the entry */
|
|
|
|
ListEntry = CONTAINING_RECORD(CmpDelayedLRUListHead.Blink,
|
|
|
|
CM_DELAYED_CLOSE_ENTRY,
|
|
|
|
DelayedLRUList);
|
|
|
|
|
|
|
|
/* Is the entry we have still the first one? */
|
|
|
|
if (CmpDelayedCloseElements <= CmpDelayedCloseSize)
|
|
|
|
{
|
|
|
|
/* No, someone already inserted an entry there */
|
|
|
|
CmpReleaseKcbLockByKey(ConvKey);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is it a different entry? */
|
|
|
|
if (ConvKey != ListEntry->KeyControlBlock->ConvKey)
|
|
|
|
{
|
|
|
|
/* Release the delayed close table lock */
|
|
|
|
KeReleaseGuardedMutex(&CmpDelayedCloseTableLock);
|
|
|
|
|
|
|
|
/* Release the KCB lock */
|
|
|
|
CmpReleaseKcbLockByKey(ConvKey);
|
|
|
|
|
|
|
|
/* Reacquire the delayed close table lock */
|
|
|
|
KeAcquireGuardedMutex(&CmpDelayedCloseTableLock);
|
|
|
|
|
|
|
|
/* Iterate again */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove it from the end of the list */
|
|
|
|
ListEntry =
|
|
|
|
(PCM_DELAYED_CLOSE_ENTRY)RemoveTailList(&CmpDelayedLRUListHead);
|
|
|
|
|
|
|
|
/* Get the containing entry */
|
|
|
|
ListEntry = CONTAINING_RECORD(ListEntry,
|
|
|
|
CM_DELAYED_CLOSE_ENTRY,
|
|
|
|
DelayedLRUList);
|
|
|
|
|
|
|
|
/* Process the entry */
|
|
|
|
if ((ListEntry->KeyControlBlock->RefCount) ||
|
|
|
|
(ListEntry->KeyControlBlock->DelayedCloseIndex))
|
|
|
|
{
|
|
|
|
/* Add it to the beginning of the list */
|
|
|
|
InsertHeadList(&CmpDelayedLRUListHead, &ListEntry->DelayedLRUList);
|
|
|
|
|
|
|
|
/* Release the delayed close table lock */
|
|
|
|
KeReleaseGuardedMutex(&CmpDelayedCloseTableLock);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Release the delayed close table lock */
|
|
|
|
KeReleaseGuardedMutex(&CmpDelayedCloseTableLock);
|
|
|
|
|
|
|
|
/* Zero out the DelayCloseEntry pointer */
|
|
|
|
ListEntry->KeyControlBlock->DelayCloseEntry = NULL;
|
|
|
|
|
|
|
|
/* Cleanup the KCB cache */
|
|
|
|
CmpCleanUpKcbCacheWithLock(ListEntry->KeyControlBlock, FALSE);
|
|
|
|
|
|
|
|
/* Free the delay item */
|
|
|
|
CmpFreeDelayItem(ListEntry);
|
|
|
|
|
|
|
|
/* Decrement delayed close elements count */
|
|
|
|
InterlockedDecrement((PLONG)&CmpDelayedCloseElements);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the KCB lock */
|
|
|
|
CmpReleaseKcbLockByKey(ConvKey);
|
|
|
|
|
|
|
|
/* Reacquire the delayed close table lock */
|
|
|
|
KeAcquireGuardedMutex(&CmpDelayedCloseTableLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CmpDelayedCloseElements <= CmpDelayedCloseSize)
|
|
|
|
{
|
|
|
|
/* We're not active anymore */
|
|
|
|
CmpDelayCloseWorkItemActive = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We didn't process all things, so reschedule for the next time */
|
|
|
|
CmpArmDelayedCloseTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the delayed close table lock */
|
|
|
|
KeReleaseGuardedMutex(&CmpDelayedCloseTableLock);
|
|
|
|
|
|
|
|
/* Unlock the registry */
|
|
|
|
CmpUnlockRegistry();
|
2007-10-29 14:44:26 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 19:44:01 +00:00
|
|
|
CODE_SEG("INIT")
|
2007-10-29 14:44:26 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpInitializeDelayedCloseTable(VOID)
|
|
|
|
{
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-10-29 14:44:26 +00:00
|
|
|
/* Setup the delayed close lock */
|
|
|
|
KeInitializeGuardedMutex(&CmpDelayedCloseTableLock);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-10-29 14:44:26 +00:00
|
|
|
/* Setup the work item */
|
|
|
|
ExInitializeWorkItem(&CmpDelayCloseWorkItem, CmpDelayCloseWorker, NULL);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-10-29 14:44:26 +00:00
|
|
|
/* Setup the list head */
|
|
|
|
InitializeListHead(&CmpDelayedLRUListHead);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-10-29 14:44:26 +00:00
|
|
|
/* Setup the DPC and its timer */
|
|
|
|
KeInitializeDpc(&CmpDelayCloseDpc, CmpDelayCloseDpcRoutine, NULL);
|
|
|
|
KeInitializeTimer(&CmpDelayCloseTimer);
|
|
|
|
}
|
|
|
|
|
2012-12-19 23:49:13 +00:00
|
|
|
_Function_class_(KDEFERRED_ROUTINE)
|
2007-10-29 14:44:26 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpDelayDerefKCBDpcRoutine(IN PKDPC Dpc,
|
|
|
|
IN PVOID DeferredContext,
|
|
|
|
IN PVOID SystemArgument1,
|
|
|
|
IN PVOID SystemArgument2)
|
|
|
|
{
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(CmpDelayDerefKCBWorkItemActive);
|
|
|
|
|
|
|
|
/* Queue the work item */
|
|
|
|
ExQueueWorkItem(&CmpDelayDerefKCBWorkItem, DelayedWorkQueue);
|
|
|
|
}
|
|
|
|
|
2012-12-19 23:49:13 +00:00
|
|
|
_Function_class_(WORKER_THREAD_ROUTINE)
|
2007-10-29 14:44:26 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpDelayDerefKCBWorker(IN PVOID Context)
|
|
|
|
{
|
2007-12-16 16:37:15 +00:00
|
|
|
PCM_DELAY_DEREF_KCB_ITEM Entry;
|
2007-10-29 14:44:26 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(CmpDelayDerefKCBWorkItemActive);
|
|
|
|
|
2007-12-16 16:37:15 +00:00
|
|
|
/* Lock the registry and and list lock */
|
|
|
|
CmpLockRegistry();
|
|
|
|
KeAcquireGuardedMutex(&CmpDelayDerefKCBLock);
|
|
|
|
|
|
|
|
/* Check if the list is empty */
|
|
|
|
while (!IsListEmpty(&CmpDelayDerefKCBListHead))
|
|
|
|
{
|
|
|
|
/* Grab an entry */
|
|
|
|
Entry = (PVOID)RemoveHeadList(&CmpDelayDerefKCBListHead);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-12-16 16:37:15 +00:00
|
|
|
/* We can release the lock now */
|
|
|
|
KeReleaseGuardedMutex(&CmpDelayDerefKCBLock);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-12-16 16:37:15 +00:00
|
|
|
/* Now grab the actual entry */
|
|
|
|
Entry = CONTAINING_RECORD(Entry, CM_DELAY_DEREF_KCB_ITEM, ListEntry);
|
|
|
|
Entry->ListEntry.Flink = Entry->ListEntry.Blink = NULL;
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-12-16 16:37:15 +00:00
|
|
|
/* Dereference and free */
|
|
|
|
CmpDereferenceKeyControlBlock(Entry->Kcb);
|
|
|
|
CmpFreeDelayItem(Entry);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-12-16 16:37:15 +00:00
|
|
|
/* Lock the list again */
|
|
|
|
KeAcquireGuardedMutex(&CmpDelayDerefKCBLock);
|
|
|
|
}
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-12-16 16:37:15 +00:00
|
|
|
/* We're done */
|
|
|
|
CmpDelayDerefKCBWorkItemActive = FALSE;
|
|
|
|
KeReleaseGuardedMutex(&CmpDelayDerefKCBLock);
|
|
|
|
CmpUnlockRegistry();
|
2007-10-29 14:44:26 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 19:44:01 +00:00
|
|
|
CODE_SEG("INIT")
|
2007-10-29 14:44:26 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpInitDelayDerefKCBEngine(VOID)
|
|
|
|
{
|
|
|
|
/* Initialize lock and list */
|
|
|
|
KeInitializeGuardedMutex(&CmpDelayDerefKCBLock);
|
|
|
|
InitializeListHead(&CmpDelayDerefKCBListHead);
|
|
|
|
|
|
|
|
/* Setup the work item */
|
|
|
|
ExInitializeWorkItem(&CmpDelayDerefKCBWorkItem,
|
|
|
|
CmpDelayDerefKCBWorker,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Setup the DPC and timer for it */
|
|
|
|
KeInitializeDpc(&CmpDelayDerefKCBDpc, CmpDelayDerefKCBDpcRoutine, NULL);
|
|
|
|
KeInitializeTimer(&CmpDelayDerefKCBTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpDelayDerefKeyControlBlock(IN PCM_KEY_CONTROL_BLOCK Kcb)
|
|
|
|
{
|
2007-12-16 16:37:15 +00:00
|
|
|
LONG OldRefCount, NewRefCount;
|
2007-10-29 14:44:26 +00:00
|
|
|
LARGE_INTEGER Timeout;
|
|
|
|
PCM_DELAY_DEREF_KCB_ITEM Entry;
|
|
|
|
PAGED_CODE();
|
2008-10-21 14:47:20 +00:00
|
|
|
CMTRACE(CM_REFERENCE_DEBUG,
|
|
|
|
"%s - Dereferencing KCB: %p\n", __FUNCTION__, Kcb);
|
2007-10-29 14:44:26 +00:00
|
|
|
|
|
|
|
/* Get the previous reference count */
|
2007-12-16 16:37:15 +00:00
|
|
|
OldRefCount = *(PLONG)&Kcb->RefCount;
|
|
|
|
NewRefCount = OldRefCount - 1;
|
|
|
|
if (((NewRefCount & 0xFFFF) > 0) &&
|
|
|
|
(InterlockedCompareExchange((PLONG)&Kcb->RefCount,
|
|
|
|
NewRefCount,
|
|
|
|
OldRefCount) == OldRefCount))
|
|
|
|
{
|
|
|
|
/* KCB still had references, so we're done */
|
|
|
|
return;
|
|
|
|
}
|
2007-10-29 14:44:26 +00:00
|
|
|
|
|
|
|
/* Allocate a delay item */
|
|
|
|
Entry = CmpAllocateDelayItem();
|
|
|
|
if (!Entry) return;
|
|
|
|
|
|
|
|
/* Set the KCB */
|
|
|
|
Entry->Kcb = Kcb;
|
|
|
|
|
|
|
|
/* Acquire the delayed deref table lock */
|
|
|
|
KeAcquireGuardedMutex(&CmpDelayDerefKCBLock);
|
|
|
|
|
|
|
|
/* Insert the entry into the list */
|
|
|
|
InsertTailList(&CmpDelayDerefKCBListHead, &Entry->ListEntry);
|
|
|
|
|
|
|
|
/* Check if we need to enable anything */
|
|
|
|
if (!CmpDelayDerefKCBWorkItemActive)
|
|
|
|
{
|
|
|
|
/* Yes, we have no work item, setup the interval */
|
2007-12-07 17:38:03 +00:00
|
|
|
CmpDelayDerefKCBWorkItemActive = TRUE;
|
2007-10-29 14:44:26 +00:00
|
|
|
Timeout.QuadPart = CmpDelayDerefKCBIntervalInSeconds * -10000000;
|
|
|
|
KeSetTimer(&CmpDelayDerefKCBTimer, Timeout, &CmpDelayDerefKCBDpc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the table lock */
|
|
|
|
KeReleaseGuardedMutex(&CmpDelayDerefKCBLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpArmDelayedCloseTimer(VOID)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER Timeout;
|
|
|
|
PAGED_CODE();
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-12-16 16:37:15 +00:00
|
|
|
/* Set the worker active */
|
|
|
|
CmpDelayCloseWorkItemActive = TRUE;
|
2007-10-29 14:44:26 +00:00
|
|
|
|
|
|
|
/* Setup the interval */
|
|
|
|
Timeout.QuadPart = CmpDelayCloseIntervalInSeconds * -10000000;
|
|
|
|
KeSetTimer(&CmpDelayCloseTimer, Timeout, &CmpDelayCloseDpc);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpAddToDelayedClose(IN PCM_KEY_CONTROL_BLOCK Kcb,
|
|
|
|
IN BOOLEAN LockHeldExclusively)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
ULONG OldRefCount, NewRefCount;
|
|
|
|
PCM_DELAYED_CLOSE_ENTRY Entry;
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Sanity check */
|
2017-06-19 23:18:42 +00:00
|
|
|
CMP_ASSERT_KCB_LOCK(Kcb);
|
2007-10-29 14:44:26 +00:00
|
|
|
|
|
|
|
/* Make sure it's valid */
|
|
|
|
if (Kcb->DelayedCloseIndex != CmpDelayedCloseSize) ASSERT(FALSE);
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(Kcb->RefCount == 0);
|
|
|
|
ASSERT(IsListEmpty(&Kcb->KeyBodyListHead) == TRUE);
|
|
|
|
for (i = 0; i < 4; i++) ASSERT(Kcb->KeyBodyArray[i] == NULL);
|
|
|
|
|
|
|
|
/* Allocate a delay item */
|
|
|
|
Entry = CmpAllocateDelayItem();
|
|
|
|
if (!Entry)
|
|
|
|
{
|
|
|
|
/* Cleanup immediately */
|
|
|
|
CmpCleanUpKcbCacheWithLock(Kcb, LockHeldExclusively);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (Kcb->InDelayClose) ASSERT(FALSE);
|
|
|
|
|
|
|
|
/* Get the previous reference count */
|
2007-12-16 16:37:15 +00:00
|
|
|
OldRefCount = *(PLONG)&Kcb->InDelayClose;
|
2007-10-29 14:44:26 +00:00
|
|
|
ASSERT(OldRefCount == 0);
|
|
|
|
|
|
|
|
/* Write the new one */
|
2007-12-16 16:37:15 +00:00
|
|
|
NewRefCount = 1;
|
|
|
|
if (InterlockedCompareExchange((PLONG)&Kcb->InDelayClose,
|
|
|
|
NewRefCount,
|
|
|
|
OldRefCount) != OldRefCount)
|
|
|
|
{
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(FALSE);
|
|
|
|
}
|
2007-10-29 14:44:26 +00:00
|
|
|
|
|
|
|
/* Reset the delayed close index */
|
|
|
|
Kcb->DelayedCloseIndex = 0;
|
|
|
|
|
|
|
|
/* Set up the close entry */
|
|
|
|
Kcb->DelayCloseEntry = Entry;
|
|
|
|
Entry->KeyControlBlock = Kcb;
|
|
|
|
|
|
|
|
/* Increase the number of elements */
|
|
|
|
InterlockedIncrement((PLONG)&CmpDelayedCloseElements);
|
|
|
|
|
|
|
|
/* Acquire the delayed close table lock */
|
|
|
|
KeAcquireGuardedMutex(&CmpDelayedCloseTableLock);
|
|
|
|
|
|
|
|
/* Insert the entry into the list */
|
|
|
|
InsertHeadList(&CmpDelayedLRUListHead, &Entry->DelayedLRUList);
|
|
|
|
|
|
|
|
/* Check if we need to enable anything */
|
|
|
|
if ((CmpDelayedCloseElements > CmpDelayedCloseSize) &&
|
|
|
|
!(CmpDelayCloseWorkItemActive))
|
|
|
|
{
|
|
|
|
/* Yes, we have too many elements to close, and no work item */
|
|
|
|
CmpArmDelayedCloseTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the table lock */
|
|
|
|
KeReleaseGuardedMutex(&CmpDelayedCloseTableLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
CmpRemoveFromDelayedClose(IN PCM_KEY_CONTROL_BLOCK Kcb)
|
|
|
|
{
|
|
|
|
PCM_DELAYED_CLOSE_ENTRY Entry;
|
|
|
|
ULONG NewRefCount, OldRefCount;
|
|
|
|
PAGED_CODE();
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-10-29 14:44:26 +00:00
|
|
|
/* Sanity checks */
|
2017-06-19 23:18:42 +00:00
|
|
|
CMP_ASSERT_KCB_LOCK(Kcb);
|
2007-10-29 14:44:26 +00:00
|
|
|
if (Kcb->DelayedCloseIndex == CmpDelayedCloseSize) ASSERT(FALSE);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-10-29 14:44:26 +00:00
|
|
|
/* Get the entry and lock the table */
|
|
|
|
Entry = Kcb->DelayCloseEntry;
|
|
|
|
ASSERT(Entry);
|
|
|
|
KeAcquireGuardedMutex(&CmpDelayedCloseTableLock);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-10-29 14:44:26 +00:00
|
|
|
/* Remove the entry */
|
|
|
|
RemoveEntryList(&Entry->DelayedLRUList);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-10-29 14:44:26 +00:00
|
|
|
/* Release the lock */
|
|
|
|
KeReleaseGuardedMutex(&CmpDelayedCloseTableLock);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-10-29 14:44:26 +00:00
|
|
|
/* Free the entry */
|
|
|
|
CmpFreeDelayItem(Entry);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-10-29 14:44:26 +00:00
|
|
|
/* Reduce the number of elements */
|
|
|
|
InterlockedDecrement((PLONG)&CmpDelayedCloseElements);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-10-29 14:44:26 +00:00
|
|
|
/* Sanity check */
|
|
|
|
if (!Kcb->InDelayClose) ASSERT(FALSE);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-12-16 16:37:15 +00:00
|
|
|
/* Get the previous reference count */
|
|
|
|
OldRefCount = *(PLONG)&Kcb->InDelayClose;
|
2007-10-29 14:44:26 +00:00
|
|
|
ASSERT(OldRefCount == 1);
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-12-16 16:37:15 +00:00
|
|
|
/* Write the new one */
|
|
|
|
NewRefCount = 0;
|
|
|
|
if (InterlockedCompareExchange((PLONG)&Kcb->InDelayClose,
|
|
|
|
NewRefCount,
|
|
|
|
OldRefCount) != OldRefCount)
|
|
|
|
{
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(FALSE);
|
|
|
|
}
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-10-29 14:44:26 +00:00
|
|
|
/* Remove the link to the entry */
|
|
|
|
Kcb->DelayCloseEntry = NULL;
|
2012-12-19 23:49:13 +00:00
|
|
|
|
2007-10-29 14:44:26 +00:00
|
|
|
/* Set new delay size and remove the delete flag */
|
|
|
|
Kcb->DelayedCloseIndex = CmpDelayedCloseSize;
|
|
|
|
}
|