1998-08-25 04:27:26 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
1998-09-05 17:34:23 +00:00
|
|
|
* FILE: ntoskrnl/ke/dpc.c
|
1998-08-25 04:27:26 +00:00
|
|
|
* PURPOSE: Handle DPCs (Delayed Procedure Calls)
|
|
|
|
* PROGRAMMER: David Welch (welch@mcmail.com)
|
|
|
|
* UPDATE HISTORY:
|
|
|
|
* 28/05/98: Created
|
1999-12-05 08:30:10 +00:00
|
|
|
* 12/3/99: Phillip Susi: Fixed IRQL problem
|
1998-08-25 04:27:26 +00:00
|
|
|
*/
|
1999-12-05 08:30:10 +00:00
|
|
|
|
1998-08-25 04:27:26 +00:00
|
|
|
/*
|
1998-09-05 17:34:23 +00:00
|
|
|
* NOTE: See also the higher level support routines in ntoskrnl/io/dpc.c
|
1998-08-25 04:27:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ***************************************************************/
|
|
|
|
|
|
|
|
#include <ddk/ntddk.h>
|
|
|
|
|
1998-09-05 17:34:23 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <internal/debug.h>
|
1998-08-25 04:27:26 +00:00
|
|
|
|
|
|
|
/* TYPES *******************************************************************/
|
|
|
|
|
|
|
|
/* GLOBALS ******************************************************************/
|
|
|
|
|
1999-12-02 20:53:55 +00:00
|
|
|
static LIST_ENTRY DpcQueueHead;
|
|
|
|
static KSPIN_LOCK DpcQueueLock;
|
1998-12-08 19:44:04 +00:00
|
|
|
ULONG DpcQueueSize = 0;
|
1998-08-25 04:27:26 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
|
|
|
VOID KeInitializeDpc(PKDPC Dpc, PKDEFERRED_ROUTINE DeferredRoutine,
|
|
|
|
PVOID DeferredContext)
|
|
|
|
/*
|
|
|
|
* FUNCTION: Initalizes a DPC
|
|
|
|
* ARGUMENTS:
|
|
|
|
* Dpc = Caller supplied DPC to be initialized
|
|
|
|
* DeferredRoutine = Associated DPC callback
|
|
|
|
* DeferredContext = Parameter to be passed to the callback
|
|
|
|
* NOTE: Callers must be running at IRQL PASSIVE_LEVEL
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
Dpc->Type=0;
|
|
|
|
Dpc->DeferredRoutine=DeferredRoutine;
|
|
|
|
Dpc->DeferredContext=DeferredContext;
|
|
|
|
Dpc->Lock=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeDrainDpcQueue(void)
|
|
|
|
/*
|
|
|
|
* FUNCTION: Called to execute queued dpcs
|
|
|
|
*/
|
|
|
|
{
|
1998-09-05 17:34:23 +00:00
|
|
|
PLIST_ENTRY current_entry;
|
|
|
|
PKDPC current;
|
1998-12-08 16:51:47 +00:00
|
|
|
KIRQL oldlvl;
|
1999-01-04 23:01:18 +00:00
|
|
|
|
1999-06-27 13:01:23 +00:00
|
|
|
assert_irql(DISPATCH_LEVEL);
|
1999-06-10 20:59:19 +00:00
|
|
|
|
1999-05-29 00:15:17 +00:00
|
|
|
if (DpcQueueSize == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
1999-01-04 23:01:18 +00:00
|
|
|
DPRINT("KeDrainDpcQueue()\n");
|
|
|
|
|
1999-12-10 17:04:37 +00:00
|
|
|
KeRaiseIrql(HIGH_LEVEL, &oldlvl);
|
1998-09-05 17:34:23 +00:00
|
|
|
KeAcquireSpinLockAtDpcLevel(&DpcQueueLock);
|
|
|
|
current_entry = RemoveHeadList(&DpcQueueHead);
|
1999-12-10 17:04:37 +00:00
|
|
|
KeReleaseSpinLockFromDpcLevel(&DpcQueueLock);
|
1998-12-08 16:51:47 +00:00
|
|
|
KeLowerIrql(oldlvl);
|
1998-09-05 17:34:23 +00:00
|
|
|
current = CONTAINING_RECORD(current_entry,KDPC,DpcListEntry);
|
|
|
|
while (current_entry!=(&DpcQueueHead))
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
1998-09-05 17:34:23 +00:00
|
|
|
CHECKPOINT;
|
1999-11-12 12:01:17 +00:00
|
|
|
DPRINT("DpcQueueSize %d current %x current->DeferredContext %x\n",
|
|
|
|
DpcQueueSize, current, current->DeferredContext);
|
|
|
|
DPRINT("current->Flink %x\n", current->DpcListEntry.Flink);
|
1998-08-25 04:27:26 +00:00
|
|
|
current->DeferredRoutine(current,current->DeferredContext,
|
|
|
|
current->SystemArgument1,
|
|
|
|
current->SystemArgument2);
|
1999-11-12 12:01:17 +00:00
|
|
|
CHECKPOINT;
|
1998-09-05 17:34:23 +00:00
|
|
|
current->Lock=FALSE;
|
1999-12-10 17:04:37 +00:00
|
|
|
KeRaiseIrql(HIGH_LEVEL, &oldlvl);
|
|
|
|
KeAcquireSpinLockAtDpcLevel(&DpcQueueLock);
|
1998-09-05 17:34:23 +00:00
|
|
|
current_entry = RemoveHeadList(&DpcQueueHead);
|
1999-11-12 12:01:17 +00:00
|
|
|
DPRINT("current_entry %x\n", current_entry);
|
1998-12-08 19:44:04 +00:00
|
|
|
DpcQueueSize--;
|
1999-12-10 17:04:37 +00:00
|
|
|
KeReleaseSpinLockFromDpcLevel(&DpcQueueLock);
|
1998-12-08 16:51:47 +00:00
|
|
|
KeLowerIrql(oldlvl);
|
1999-11-12 12:01:17 +00:00
|
|
|
current = CONTAINING_RECORD(current_entry,KDPC,DpcListEntry);
|
|
|
|
DPRINT("current %x\n", current);
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN KeRemoveQueueDpc(PKDPC Dpc)
|
|
|
|
/*
|
|
|
|
* FUNCTION: Removes DPC object from the system dpc queue
|
|
|
|
* ARGUMENTS:
|
|
|
|
* Dpc = DPC to remove
|
|
|
|
* RETURNS: TRUE if the DPC was in the queue
|
|
|
|
* FALSE otherwise
|
|
|
|
*/
|
|
|
|
{
|
1999-11-12 12:01:17 +00:00
|
|
|
KIRQL oldIrql;
|
|
|
|
|
1999-12-05 08:30:10 +00:00
|
|
|
KeAcquireSpinLockAtDpcLevel( &DpcQueueLock );
|
|
|
|
KeRaiseIrql( HIGH_LEVEL, &oldIrql );
|
1998-08-25 04:27:26 +00:00
|
|
|
if (!Dpc->Lock)
|
|
|
|
{
|
1999-11-12 12:01:17 +00:00
|
|
|
KeReleaseSpinLock(&DpcQueueLock, oldIrql);
|
1998-08-25 04:27:26 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
1998-09-05 17:34:23 +00:00
|
|
|
RemoveEntryList(&Dpc->DpcListEntry);
|
1998-12-08 19:44:04 +00:00
|
|
|
DpcQueueSize--;
|
1998-08-25 04:27:26 +00:00
|
|
|
Dpc->Lock=0;
|
1999-11-12 12:01:17 +00:00
|
|
|
KeReleaseSpinLock(&DpcQueueLock, oldIrql);
|
1998-09-05 17:34:23 +00:00
|
|
|
return(TRUE);
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN KeInsertQueueDpc(PKDPC dpc, PVOID SystemArgument1,
|
|
|
|
PVOID SystemArgument2)
|
|
|
|
/*
|
|
|
|
* FUNCTION: Queues a DPC for execution when the IRQL of a processor
|
|
|
|
* drops below DISPATCH_LEVEL
|
|
|
|
* ARGUMENTS:
|
|
|
|
* Dpc = Initalizes DPC
|
|
|
|
* SystemArguments[1-2] = Undocumented
|
|
|
|
* RETURNS: TRUE if the DPC object wasn't already in the queue
|
|
|
|
* FALSE otherwise
|
|
|
|
*/
|
|
|
|
{
|
1999-12-05 08:30:10 +00:00
|
|
|
KIRQL oldlvl;
|
1999-05-29 00:15:17 +00:00
|
|
|
DPRINT("KeInsertQueueDpc(dpc %x, SystemArgument1 %x, SystemArgument2 %x)\n",
|
|
|
|
dpc, SystemArgument1, SystemArgument2);
|
1999-06-27 13:01:23 +00:00
|
|
|
|
1998-09-15 14:31:18 +00:00
|
|
|
assert(KeGetCurrentIrql()>=DISPATCH_LEVEL);
|
1999-06-27 13:01:23 +00:00
|
|
|
|
1998-08-25 04:27:26 +00:00
|
|
|
dpc->Number=0;
|
|
|
|
dpc->Importance=Medium;
|
|
|
|
dpc->SystemArgument1=SystemArgument1;
|
|
|
|
dpc->SystemArgument2=SystemArgument2;
|
|
|
|
if (dpc->Lock)
|
|
|
|
{
|
|
|
|
return(FALSE);
|
|
|
|
}
|
1999-12-05 08:30:10 +00:00
|
|
|
KeRaiseIrql( HIGH_LEVEL, &oldlvl );
|
1998-09-05 17:34:23 +00:00
|
|
|
KeAcquireSpinLockAtDpcLevel(&DpcQueueLock);
|
|
|
|
InsertHeadList(&DpcQueueHead,&dpc->DpcListEntry);
|
1999-11-12 12:01:17 +00:00
|
|
|
DPRINT("dpc->DpcListEntry.Flink %x\n", dpc->DpcListEntry.Flink);
|
1998-12-08 19:44:04 +00:00
|
|
|
DpcQueueSize++;
|
1998-09-15 14:31:18 +00:00
|
|
|
dpc->Lock=(PULONG)1;
|
1999-12-05 19:26:11 +00:00
|
|
|
KeReleaseSpinLock( &DpcQueueLock, oldlvl );
|
1998-09-05 17:34:23 +00:00
|
|
|
DPRINT("DpcQueueHead.Flink %x\n",DpcQueueHead.Flink);
|
|
|
|
DPRINT("Leaving KeInsertQueueDpc()\n",0);
|
1998-08-25 04:27:26 +00:00
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeInitDpc(void)
|
|
|
|
/*
|
|
|
|
* FUNCTION: Initialize DPC handling
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
InitializeListHead(&DpcQueueHead);
|
1999-12-02 20:53:55 +00:00
|
|
|
KeInitializeSpinLock(&DpcQueueLock);
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
|