2005-03-12 22:31:22 +00:00
|
|
|
/*
|
2006-09-11 00:26:17 +00:00
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
1998-08-25 04:27:26 +00:00
|
|
|
* FILE: ntoskrnl/ke/apc.c
|
2008-09-28 20:53:51 +00:00
|
|
|
* PURPOSE: Implements the Asynchronous Procedure Call mechanism
|
2006-09-11 00:26:17 +00:00
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
1998-08-25 04:27:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
1998-10-05 04:01:30 +00:00
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2006-09-11 00:54:12 +00:00
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
2005-02-28 16:44:38 +00:00
|
|
|
|
2005-04-15 06:24:35 +00:00
|
|
|
/*++
|
2006-09-11 00:26:17 +00:00
|
|
|
* @name KiCheckForKernelApcDelivery
|
2005-04-15 06:24:35 +00:00
|
|
|
* @implemented NT 5.2
|
|
|
|
*
|
2006-09-11 01:15:03 +00:00
|
|
|
* The KiCheckForKernelApcDelivery routine is called whenever APCs have
|
|
|
|
* just been re-enabled in Kernel Mode, such as after leaving a Critical or
|
2005-04-15 06:24:35 +00:00
|
|
|
* Guarded Region. It delivers APCs if the environment is right.
|
|
|
|
*
|
2006-09-11 00:26:17 +00:00
|
|
|
* @param None.
|
2005-04-15 06:24:35 +00:00
|
|
|
*
|
2006-09-11 00:26:17 +00:00
|
|
|
* @return None.
|
2005-04-15 06:24:35 +00:00
|
|
|
*
|
2006-09-11 00:26:17 +00:00
|
|
|
* @remarks This routine allows KeLeave/EnterCritical/GuardedRegion to be used
|
2008-09-28 20:53:51 +00:00
|
|
|
* as macros from inside WIN32K or other Drivers, which will then only
|
|
|
|
* have to do an Import API call in the case where APCs are enabled again.
|
2005-04-15 06:24:35 +00:00
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
2006-09-11 00:26:17 +00:00
|
|
|
NTAPI
|
2005-11-03 16:58:43 +00:00
|
|
|
KiCheckForKernelApcDelivery(VOID)
|
2005-04-15 06:24:35 +00:00
|
|
|
{
|
2008-02-07 07:10:13 +00:00
|
|
|
KIRQL OldIrql;
|
|
|
|
|
2005-04-15 06:24:35 +00:00
|
|
|
/* We should only deliver at passive */
|
|
|
|
if (KeGetCurrentIrql() == PASSIVE_LEVEL)
|
|
|
|
{
|
|
|
|
/* Raise to APC and Deliver APCs, then lower back to Passive */
|
2008-02-07 07:10:13 +00:00
|
|
|
KeRaiseIrql(APC_LEVEL, &OldIrql);
|
2005-04-15 06:24:35 +00:00
|
|
|
KiDeliverApc(KernelMode, 0, 0);
|
2008-02-07 07:10:13 +00:00
|
|
|
KeLowerIrql(PASSIVE_LEVEL);
|
2005-04-15 06:24:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If we're not at passive level it means someone raised IRQL
|
2008-09-28 20:53:51 +00:00
|
|
|
* to APC level before the critical or guarded section was entered
|
2005-04-15 06:24:35 +00:00
|
|
|
* (e.g) by a fast mutex). This implies that the APCs shouldn't
|
|
|
|
* be delivered now, but after the IRQL is lowered to passive
|
|
|
|
* level again.
|
|
|
|
*/
|
2006-01-12 21:21:19 +00:00
|
|
|
KeGetCurrentThread()->ApcState.KernelApcPending = TRUE;
|
2005-04-15 06:24:35 +00:00
|
|
|
HalRequestSoftwareInterrupt(APC_LEVEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-12 22:31:22 +00:00
|
|
|
/*++
|
2006-09-11 04:34:25 +00:00
|
|
|
* @name KiInsertQueueApc
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
Thread/Process Termination/Repeaing Rewrite + Fixes
---------------------------------------------------
- ps/cid.c:
* Moved CID Lookup functions here
- ps/security.c:
* Moved all security related functions here. Makes other files neater and security functions
easier to locate.
- ps/thread.c:
* Moved most of the Thread Scheduling/Dispatching code that belongs in the Kernel to /ke and
renamed functions from Ps to Ki.
* Implemented PsIsSystemThread.
* Removed Reaper Thread Init (now obsolete).
* Renamed PiDeleteThread to PspDeleteThread.
* Moved Thread State functions from tinfo.c to here.
- ps/process.c:
* Removed Query/Set Process functions and moved to ps/query.c
* Renamed PiDeletePRocess to PspDeleteProcess
* Removed obsoleted Process Termination functions, moved persistent one to kill.c
- ps/create.c:
* Moved the security APIs to security.c
* Correctly implemented PsCreateSystemThread to actually create system threads.
- ps/suspend.c
* Rewrote Nt Executive functions to use Kernel functions.
* Moved Ps* Routines into ke/kthread.c and fixed them. The implementation was wrong in
some aspects, especially the issue of the APC looping around the KeWaitXxx call and the
fact that the routines excluded/ignored the FreezeCount.
- ps/debug.c
* Fixed completely broken implementation of Get/SetThreadContext. The old version crashed
when called and did not work at all. Suspend Regression test now works.
* Moved Context<->TrapFrame functions to ke/i386/
* Combined Set/GetThreadContext APCs into a single one, and used special context structure.
- ps/query.c:
* Moved Thread/Process Query/Set Routines here.
- ps/tinfo.c:
* Removed.
- ps/kill.c
* Removed complicated Process Termination semantics and useless Attach/Detach in favor for
a much more lightweight function which performs the same tasks as before and actually works.
TaskManager can now terminate foreign processes.
* Rewrote Thread Reaping to use the HyperCritical Work Queue instead of manually controlled
thread. This results in much less code as well as an increase in speed and less micro
management. The reaper is PspReapRoutine. Closing CMD.EXE now works properly without
requiring masks that were added as hacks to allow it.
* Renamed PiTerminateProcessThreads to PspTerminateProcessThreads. Fixed it to work with new
termination code.
* Added PspDeleteProcess to handle Process Object deletion. Kills the CID Handle here as done
by Hartmut.
* Added PspDeletethread here.
* Renamed and rewrote PsTerminateCurrentThread to PspExitThread. Used NT Implementation out-
lined in Windows Internals, Chapter 13. Uses less locks, a more concise order of actions,
actually parses the Termination Ports, handles Dbgk notification. Timers are now rundown,
and Mutex rundown is in a dedicated Kernel function. Final termination handled by KeTerminate
Thread as documented.
* Renamed PsTerminateOtherThread to PspTerminateThreadByPointer and modified implementation to
be compatible with the changes above.
* Renamed and regrouped Process Termination into PspExitProcess. Also implemented as described
above, and moved each subsystem specific termination helper into its own subsytem.
* Improved NtTerminateProcess and added more debugging messages.
* Improved NtTerminateThread and added check against System Thread and made it compatible with
new implementation.
* Corrected PsTerminateSystemThread now that we support System Threads.
* Corrected NtRegisterThreadTerminatePort to use same structure name as on windows for the
port, and added tag to pool allocation (documented in pooltag.txt)
include/internal/*.h:
* Defined Scheduler Functions and misc new functions or renamed functions.
ke/apc.c:
* Fixed critical bug where APCs were not delivered at all if the thread wastion and cancels any timers that are associated
to a thread, as well as their APCs and DPCs.
REGRESSIONS FOUND: NONE
BUGS/REGRESSIOSN FIXED:
* Thread/Get Set Context now works.
* Suspend Regression test now works.
* Task manager can now kill foreign processes, even hung ones (like it should).
* ExitProcess/closing cmd.exe with the 'x' button now works correctly without hacks.
KNOWN ISSUES: I left a bit of a mess in the headers and some stuff still needs to be moved into the right
places. I just wanted to have this first part ready first, so that it won't get too big.
svn path=/trunk/; revision=14174
2005-03-18 05:53:04 +00:00
|
|
|
* The KiInsertQueueApc routine queues a APC for execution when the right
|
2005-03-12 22:31:22 +00:00
|
|
|
* scheduler environment exists.
|
|
|
|
*
|
2006-09-11 04:34:25 +00:00
|
|
|
* @param Apc
|
2008-09-28 20:53:51 +00:00
|
|
|
* Pointer to an initialized control object of type APC for which the
|
2006-09-11 04:34:25 +00:00
|
|
|
* caller provides the storage.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
2006-09-11 04:34:25 +00:00
|
|
|
* @param PriorityBoost
|
|
|
|
* Priority Boost to apply to the Thread.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
2006-09-11 04:34:25 +00:00
|
|
|
* @return None
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
2006-09-11 04:34:25 +00:00
|
|
|
* @remarks The APC will execute at APC_LEVEL for the KernelRoutine registered,
|
|
|
|
* and at PASSIVE_LEVEL for the NormalRoutine registered.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
2006-09-11 04:34:25 +00:00
|
|
|
* Callers of this routine must have locked the dipatcher database.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
|
|
|
*--*/
|
2005-09-27 01:57:27 +00:00
|
|
|
VOID
|
|
|
|
FASTCALL
|
2006-09-11 03:14:26 +00:00
|
|
|
KiInsertQueueApc(IN PKAPC Apc,
|
|
|
|
IN KPRIORITY PriorityBoost)
|
1998-08-28 23:24:42 +00:00
|
|
|
{
|
Thread/Process Termination/Repeaing Rewrite + Fixes
---------------------------------------------------
- ps/cid.c:
* Moved CID Lookup functions here
- ps/security.c:
* Moved all security related functions here. Makes other files neater and security functions
easier to locate.
- ps/thread.c:
* Moved most of the Thread Scheduling/Dispatching code that belongs in the Kernel to /ke and
renamed functions from Ps to Ki.
* Implemented PsIsSystemThread.
* Removed Reaper Thread Init (now obsolete).
* Renamed PiDeleteThread to PspDeleteThread.
* Moved Thread State functions from tinfo.c to here.
- ps/process.c:
* Removed Query/Set Process functions and moved to ps/query.c
* Renamed PiDeletePRocess to PspDeleteProcess
* Removed obsoleted Process Termination functions, moved persistent one to kill.c
- ps/create.c:
* Moved the security APIs to security.c
* Correctly implemented PsCreateSystemThread to actually create system threads.
- ps/suspend.c
* Rewrote Nt Executive functions to use Kernel functions.
* Moved Ps* Routines into ke/kthread.c and fixed them. The implementation was wrong in
some aspects, especially the issue of the APC looping around the KeWaitXxx call and the
fact that the routines excluded/ignored the FreezeCount.
- ps/debug.c
* Fixed completely broken implementation of Get/SetThreadContext. The old version crashed
when called and did not work at all. Suspend Regression test now works.
* Moved Context<->TrapFrame functions to ke/i386/
* Combined Set/GetThreadContext APCs into a single one, and used special context structure.
- ps/query.c:
* Moved Thread/Process Query/Set Routines here.
- ps/tinfo.c:
* Removed.
- ps/kill.c
* Removed complicated Process Termination semantics and useless Attach/Detach in favor for
a much more lightweight function which performs the same tasks as before and actually works.
TaskManager can now terminate foreign processes.
* Rewrote Thread Reaping to use the HyperCritical Work Queue instead of manually controlled
thread. This results in much less code as well as an increase in speed and less micro
management. The reaper is PspReapRoutine. Closing CMD.EXE now works properly without
requiring masks that were added as hacks to allow it.
* Renamed PiTerminateProcessThreads to PspTerminateProcessThreads. Fixed it to work with new
termination code.
* Added PspDeleteProcess to handle Process Object deletion. Kills the CID Handle here as done
by Hartmut.
* Added PspDeletethread here.
* Renamed and rewrote PsTerminateCurrentThread to PspExitThread. Used NT Implementation out-
lined in Windows Internals, Chapter 13. Uses less locks, a more concise order of actions,
actually parses the Termination Ports, handles Dbgk notification. Timers are now rundown,
and Mutex rundown is in a dedicated Kernel function. Final termination handled by KeTerminate
Thread as documented.
* Renamed PsTerminateOtherThread to PspTerminateThreadByPointer and modified implementation to
be compatible with the changes above.
* Renamed and regrouped Process Termination into PspExitProcess. Also implemented as described
above, and moved each subsystem specific termination helper into its own subsytem.
* Improved NtTerminateProcess and added more debugging messages.
* Improved NtTerminateThread and added check against System Thread and made it compatible with
new implementation.
* Corrected PsTerminateSystemThread now that we support System Threads.
* Corrected NtRegisterThreadTerminatePort to use same structure name as on windows for the
port, and added tag to pool allocation (documented in pooltag.txt)
include/internal/*.h:
* Defined Scheduler Functions and misc new functions or renamed functions.
ke/apc.c:
* Fixed critical bug where APCs were not delivered at all if the thread wastion and cancels any timers that are associated
to a thread, as well as their APCs and DPCs.
REGRESSIONS FOUND: NONE
BUGS/REGRESSIOSN FIXED:
* Thread/Get Set Context now works.
* Suspend Regression test now works.
* Task manager can now kill foreign processes, even hung ones (like it should).
* ExitProcess/closing cmd.exe with the 'x' button now works correctly without hacks.
KNOWN ISSUES: I left a bit of a mess in the headers and some stuff still needs to be moved into the right
places. I just wanted to have this first part ready first, so that it won't get too big.
svn path=/trunk/; revision=14174
2005-03-18 05:53:04 +00:00
|
|
|
PKTHREAD Thread = Apc->Thread;
|
2005-09-27 01:57:27 +00:00
|
|
|
PKAPC_STATE ApcState;
|
|
|
|
KPROCESSOR_MODE ApcMode;
|
|
|
|
PLIST_ENTRY ListHead, NextEntry;
|
|
|
|
PKAPC QueuedApc;
|
2008-11-26 18:56:41 +00:00
|
|
|
PKGATE Gate;
|
2005-09-27 01:57:27 +00:00
|
|
|
NTSTATUS Status;
|
2007-01-16 01:27:36 +00:00
|
|
|
BOOLEAN RequestInterrupt = FALSE;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-11 03:14:26 +00:00
|
|
|
/*
|
|
|
|
* Check if the caller wanted this APC to use the thread's environment at
|
|
|
|
* insertion time.
|
|
|
|
*/
|
|
|
|
if (Apc->ApcStateIndex == InsertApcEnvironment)
|
2005-09-27 01:57:27 +00:00
|
|
|
{
|
2006-09-11 03:14:26 +00:00
|
|
|
/* Copy it over */
|
2005-09-27 01:57:27 +00:00
|
|
|
Apc->ApcStateIndex = Thread->ApcStateIndex;
|
2005-03-12 22:31:22 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-09-27 01:57:27 +00:00
|
|
|
/* Get the APC State for this Index, and the mode too */
|
2006-09-11 03:14:26 +00:00
|
|
|
ApcState = Thread->ApcStatePointer[(UCHAR)Apc->ApcStateIndex];
|
2005-09-27 01:57:27 +00:00
|
|
|
ApcMode = Apc->ApcMode;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-11 03:14:26 +00:00
|
|
|
/* The APC must be "inserted" already */
|
|
|
|
ASSERT(Apc->Inserted == TRUE);
|
|
|
|
|
2005-09-27 01:57:27 +00:00
|
|
|
/* Three scenarios:
|
|
|
|
* 1) Kernel APC with Normal Routine or User APC = Put it at the end of the List
|
|
|
|
* 2) User APC which is PsExitSpecialApc = Put it at the front of the List
|
|
|
|
* 3) Kernel APC without Normal Routine = Put it at the end of the No-Normal Routine Kernel APC list
|
|
|
|
*/
|
|
|
|
if (Apc->NormalRoutine)
|
|
|
|
{
|
|
|
|
/* Normal APC; is it the Thread Termination APC? */
|
2006-09-11 03:14:26 +00:00
|
|
|
if ((ApcMode != KernelMode) &&
|
|
|
|
(Apc->KernelRoutine == PsExitSpecialApc))
|
2005-09-27 01:57:27 +00:00
|
|
|
{
|
|
|
|
/* Set User APC pending to true */
|
|
|
|
Thread->ApcState.UserApcPending = TRUE;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-09-27 01:57:27 +00:00
|
|
|
/* Insert it at the top of the list */
|
2006-09-11 03:14:26 +00:00
|
|
|
InsertHeadList(&ApcState->ApcListHead[ApcMode],
|
|
|
|
&Apc->ApcListEntry);
|
2005-09-27 01:57:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Regular user or kernel Normal APC */
|
2006-09-11 03:14:26 +00:00
|
|
|
InsertTailList(&ApcState->ApcListHead[ApcMode],
|
|
|
|
&Apc->ApcListEntry);
|
2005-09-27 01:57:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-01 10:40:20 +00:00
|
|
|
/* Special APC, find the last one in the list */
|
2005-09-27 01:57:27 +00:00
|
|
|
ListHead = &ApcState->ApcListHead[ApcMode];
|
2007-01-16 01:27:36 +00:00
|
|
|
NextEntry = ListHead->Blink;
|
|
|
|
while (NextEntry != ListHead)
|
2005-09-27 01:57:27 +00:00
|
|
|
{
|
|
|
|
/* Get the APC */
|
|
|
|
QueuedApc = CONTAINING_RECORD(NextEntry, KAPC, ApcListEntry);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2008-07-01 10:08:14 +00:00
|
|
|
/* Is this a No-Normal APC? If so, break */
|
|
|
|
if (!QueuedApc->NormalRoutine) break;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2008-07-01 10:40:20 +00:00
|
|
|
/* Move to the previous APC in the Queue */
|
2007-01-16 01:27:36 +00:00
|
|
|
NextEntry = NextEntry->Blink;
|
2005-09-27 01:57:27 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-09-27 01:57:27 +00:00
|
|
|
/* Insert us here */
|
|
|
|
InsertHeadList(NextEntry, &Apc->ApcListEntry);
|
|
|
|
}
|
2005-07-17 18:27:46 +00:00
|
|
|
|
2005-09-27 01:57:27 +00:00
|
|
|
/* Now check if the Apc State Indexes match */
|
|
|
|
if (Thread->ApcStateIndex == Apc->ApcStateIndex)
|
|
|
|
{
|
2008-09-28 20:53:51 +00:00
|
|
|
/* Check that the thread matches */
|
2005-09-27 01:57:27 +00:00
|
|
|
if (Thread == KeGetCurrentThread())
|
|
|
|
{
|
2006-09-11 03:14:26 +00:00
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(Thread->State == Running);
|
|
|
|
|
2005-09-27 01:57:27 +00:00
|
|
|
/* Check if this is kernel mode */
|
|
|
|
if (ApcMode == KernelMode)
|
2005-07-17 18:27:46 +00:00
|
|
|
{
|
2005-09-27 01:57:27 +00:00
|
|
|
/* All valid, a Kernel APC is pending now */
|
|
|
|
Thread->ApcState.KernelApcPending = TRUE;
|
|
|
|
|
|
|
|
/* Check if Special APCs are disabled */
|
2006-09-11 03:14:26 +00:00
|
|
|
if (!Thread->SpecialApcDisable)
|
2005-09-27 01:57:27 +00:00
|
|
|
{
|
|
|
|
/* They're not, so request the interrupt */
|
|
|
|
HalRequestSoftwareInterrupt(APC_LEVEL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-09-11 03:14:26 +00:00
|
|
|
/* Acquire the dispatcher lock */
|
|
|
|
KiAcquireDispatcherLock();
|
|
|
|
|
2007-01-16 01:27:36 +00:00
|
|
|
/* Check if this is a kernel-mode APC */
|
|
|
|
if (ApcMode == KernelMode)
|
2005-07-17 18:27:46 +00:00
|
|
|
{
|
2005-09-27 01:57:27 +00:00
|
|
|
/* Kernel-mode APC, set us pending */
|
|
|
|
Thread->ApcState.KernelApcPending = TRUE;
|
|
|
|
|
|
|
|
/* Are we currently running? */
|
|
|
|
if (Thread->State == Running)
|
|
|
|
{
|
2006-09-11 03:14:26 +00:00
|
|
|
/* The thread is running, so remember to send a request */
|
|
|
|
RequestInterrupt = TRUE;
|
2005-09-27 01:57:27 +00:00
|
|
|
}
|
2007-01-16 01:27:36 +00:00
|
|
|
else if ((Thread->State == Waiting) &&
|
|
|
|
(Thread->WaitIrql == PASSIVE_LEVEL) &&
|
|
|
|
!(Thread->SpecialApcDisable) &&
|
|
|
|
(!(Apc->NormalRoutine) ||
|
|
|
|
(!(Thread->KernelApcDisable) &&
|
|
|
|
!(Thread->ApcState.KernelApcInProgress))))
|
2005-09-27 01:57:27 +00:00
|
|
|
{
|
2007-01-16 01:27:36 +00:00
|
|
|
/* We'll unwait with this status */
|
|
|
|
Status = STATUS_KERNEL_APC;
|
|
|
|
|
|
|
|
/* Wake up the thread */
|
|
|
|
KiUnwaitThread(Thread, Status, PriorityBoost);
|
|
|
|
}
|
|
|
|
else if (Thread->State == GateWait)
|
|
|
|
{
|
2008-11-26 18:56:41 +00:00
|
|
|
/* Lock the thread */
|
|
|
|
KiAcquireThreadLock(Thread);
|
|
|
|
|
|
|
|
/* Essentially do the same check as above */
|
|
|
|
if ((Thread->State == GateWait) &&
|
|
|
|
(Thread->WaitIrql == PASSIVE_LEVEL) &&
|
|
|
|
!(Thread->SpecialApcDisable) &&
|
|
|
|
(!(Apc->NormalRoutine) ||
|
|
|
|
(!(Thread->KernelApcDisable) &&
|
|
|
|
!(Thread->ApcState.KernelApcInProgress))))
|
|
|
|
{
|
|
|
|
/* We were in a gate wait. Handle this. */
|
|
|
|
DPRINT1("A thread was in a gate wait\n");
|
|
|
|
|
|
|
|
/* Get the gate */
|
|
|
|
Gate = Thread->GateObject;
|
2008-06-28 19:23:23 +00:00
|
|
|
|
2008-11-26 18:56:41 +00:00
|
|
|
/* Lock the gate */
|
|
|
|
KiAcquireDispatcherObject(&Gate->Header);
|
|
|
|
|
|
|
|
/* Remove it from the waiters list */
|
|
|
|
RemoveEntryList(&Thread->WaitBlock[0].WaitListEntry);
|
|
|
|
|
|
|
|
/* Unlock the gate */
|
|
|
|
KiReleaseDispatcherObject(&Gate->Header);
|
|
|
|
|
|
|
|
/* Increase the queue counter if needed */
|
|
|
|
if (Thread->Queue) Thread->Queue->CurrentCount++;
|
|
|
|
|
|
|
|
/* Put into deferred ready list with this status */
|
2008-11-29 02:57:21 +00:00
|
|
|
Thread->WaitStatus = STATUS_KERNEL_APC;
|
2008-11-26 18:56:41 +00:00
|
|
|
KiInsertDeferredReadyList(Thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the thread lock */
|
|
|
|
KiReleaseThreadLock(Thread);
|
2005-09-27 01:57:27 +00:00
|
|
|
}
|
2005-07-17 18:27:46 +00:00
|
|
|
}
|
2007-01-16 01:27:36 +00:00
|
|
|
else if ((Thread->State == Waiting) &&
|
|
|
|
(Thread->WaitMode == UserMode) &&
|
|
|
|
((Thread->Alertable) ||
|
|
|
|
(Thread->ApcState.UserApcPending)))
|
|
|
|
{
|
|
|
|
/* Set user-mode APC pending */
|
|
|
|
Thread->ApcState.UserApcPending = TRUE;
|
|
|
|
Status = STATUS_USER_APC;
|
2008-08-01 16:03:49 +00:00
|
|
|
|
|
|
|
/* Wake up the thread */
|
|
|
|
KiUnwaitThread(Thread, Status, PriorityBoost);
|
2007-01-16 01:27:36 +00:00
|
|
|
}
|
2006-09-11 03:14:26 +00:00
|
|
|
|
|
|
|
/* Release dispatcher lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseDispatcherLockFromSynchLevel();
|
2006-09-11 03:14:26 +00:00
|
|
|
|
|
|
|
/* Check if an interrupt was requested */
|
|
|
|
KiRequestApcInterrupt(RequestInterrupt, Thread->NextProcessor);
|
2005-03-12 22:31:22 +00:00
|
|
|
}
|
|
|
|
}
|
Thread/Process Termination/Repeaing Rewrite + Fixes
---------------------------------------------------
- ps/cid.c:
* Moved CID Lookup functions here
- ps/security.c:
* Moved all security related functions here. Makes other files neater and security functions
easier to locate.
- ps/thread.c:
* Moved most of the Thread Scheduling/Dispatching code that belongs in the Kernel to /ke and
renamed functions from Ps to Ki.
* Implemented PsIsSystemThread.
* Removed Reaper Thread Init (now obsolete).
* Renamed PiDeleteThread to PspDeleteThread.
* Moved Thread State functions from tinfo.c to here.
- ps/process.c:
* Removed Query/Set Process functions and moved to ps/query.c
* Renamed PiDeletePRocess to PspDeleteProcess
* Removed obsoleted Process Termination functions, moved persistent one to kill.c
- ps/create.c:
* Moved the security APIs to security.c
* Correctly implemented PsCreateSystemThread to actually create system threads.
- ps/suspend.c
* Rewrote Nt Executive functions to use Kernel functions.
* Moved Ps* Routines into ke/kthread.c and fixed them. The implementation was wrong in
some aspects, especially the issue of the APC looping around the KeWaitXxx call and the
fact that the routines excluded/ignored the FreezeCount.
- ps/debug.c
* Fixed completely broken implementation of Get/SetThreadContext. The old version crashed
when called and did not work at all. Suspend Regression test now works.
* Moved Context<->TrapFrame functions to ke/i386/
* Combined Set/GetThreadContext APCs into a single one, and used special context structure.
- ps/query.c:
* Moved Thread/Process Query/Set Routines here.
- ps/tinfo.c:
* Removed.
- ps/kill.c
* Removed complicated Process Termination semantics and useless Attach/Detach in favor for
a much more lightweight function which performs the same tasks as before and actually works.
TaskManager can now terminate foreign processes.
* Rewrote Thread Reaping to use the HyperCritical Work Queue instead of manually controlled
thread. This results in much less code as well as an increase in speed and less micro
management. The reaper is PspReapRoutine. Closing CMD.EXE now works properly without
requiring masks that were added as hacks to allow it.
* Renamed PiTerminateProcessThreads to PspTerminateProcessThreads. Fixed it to work with new
termination code.
* Added PspDeleteProcess to handle Process Object deletion. Kills the CID Handle here as done
by Hartmut.
* Added PspDeletethread here.
* Renamed and rewrote PsTerminateCurrentThread to PspExitThread. Used NT Implementation out-
lined in Windows Internals, Chapter 13. Uses less locks, a more concise order of actions,
actually parses the Termination Ports, handles Dbgk notification. Timers are now rundown,
and Mutex rundown is in a dedicated Kernel function. Final termination handled by KeTerminate
Thread as documented.
* Renamed PsTerminateOtherThread to PspTerminateThreadByPointer and modified implementation to
be compatible with the changes above.
* Renamed and regrouped Process Termination into PspExitProcess. Also implemented as described
above, and moved each subsystem specific termination helper into its own subsytem.
* Improved NtTerminateProcess and added more debugging messages.
* Improved NtTerminateThread and added check against System Thread and made it compatible with
new implementation.
* Corrected PsTerminateSystemThread now that we support System Threads.
* Corrected NtRegisterThreadTerminatePort to use same structure name as on windows for the
port, and added tag to pool allocation (documented in pooltag.txt)
include/internal/*.h:
* Defined Scheduler Functions and misc new functions or renamed functions.
ke/apc.c:
* Fixed critical bug where APCs were not delivered at all if the thread wastion and cancels any timers that are associated
to a thread, as well as their APCs and DPCs.
REGRESSIONS FOUND: NONE
BUGS/REGRESSIOSN FIXED:
* Thread/Get Set Context now works.
* Suspend Regression test now works.
* Task manager can now kill foreign processes, even hung ones (like it should).
* ExitProcess/closing cmd.exe with the 'x' button now works correctly without hacks.
KNOWN ISSUES: I left a bit of a mess in the headers and some stuff still needs to be moved into the right
places. I just wanted to have this first part ready first, so that it won't get too big.
svn path=/trunk/; revision=14174
2005-03-18 05:53:04 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
Thread/Process Termination/Repeaing Rewrite + Fixes
---------------------------------------------------
- ps/cid.c:
* Moved CID Lookup functions here
- ps/security.c:
* Moved all security related functions here. Makes other files neater and security functions
easier to locate.
- ps/thread.c:
* Moved most of the Thread Scheduling/Dispatching code that belongs in the Kernel to /ke and
renamed functions from Ps to Ki.
* Implemented PsIsSystemThread.
* Removed Reaper Thread Init (now obsolete).
* Renamed PiDeleteThread to PspDeleteThread.
* Moved Thread State functions from tinfo.c to here.
- ps/process.c:
* Removed Query/Set Process functions and moved to ps/query.c
* Renamed PiDeletePRocess to PspDeleteProcess
* Removed obsoleted Process Termination functions, moved persistent one to kill.c
- ps/create.c:
* Moved the security APIs to security.c
* Correctly implemented PsCreateSystemThread to actually create system threads.
- ps/suspend.c
* Rewrote Nt Executive functions to use Kernel functions.
* Moved Ps* Routines into ke/kthread.c and fixed them. The implementation was wrong in
some aspects, especially the issue of the APC looping around the KeWaitXxx call and the
fact that the routines excluded/ignored the FreezeCount.
- ps/debug.c
* Fixed completely broken implementation of Get/SetThreadContext. The old version crashed
when called and did not work at all. Suspend Regression test now works.
* Moved Context<->TrapFrame functions to ke/i386/
* Combined Set/GetThreadContext APCs into a single one, and used special context structure.
- ps/query.c:
* Moved Thread/Process Query/Set Routines here.
- ps/tinfo.c:
* Removed.
- ps/kill.c
* Removed complicated Process Termination semantics and useless Attach/Detach in favor for
a much more lightweight function which performs the same tasks as before and actually works.
TaskManager can now terminate foreign processes.
* Rewrote Thread Reaping to use the HyperCritical Work Queue instead of manually controlled
thread. This results in much less code as well as an increase in speed and less micro
management. The reaper is PspReapRoutine. Closing CMD.EXE now works properly without
requiring masks that were added as hacks to allow it.
* Renamed PiTerminateProcessThreads to PspTerminateProcessThreads. Fixed it to work with new
termination code.
* Added PspDeleteProcess to handle Process Object deletion. Kills the CID Handle here as done
by Hartmut.
* Added PspDeletethread here.
* Renamed and rewrote PsTerminateCurrentThread to PspExitThread. Used NT Implementation out-
lined in Windows Internals, Chapter 13. Uses less locks, a more concise order of actions,
actually parses the Termination Ports, handles Dbgk notification. Timers are now rundown,
and Mutex rundown is in a dedicated Kernel function. Final termination handled by KeTerminate
Thread as documented.
* Renamed PsTerminateOtherThread to PspTerminateThreadByPointer and modified implementation to
be compatible with the changes above.
* Renamed and regrouped Process Termination into PspExitProcess. Also implemented as described
above, and moved each subsystem specific termination helper into its own subsytem.
* Improved NtTerminateProcess and added more debugging messages.
* Improved NtTerminateThread and added check against System Thread and made it compatible with
new implementation.
* Corrected PsTerminateSystemThread now that we support System Threads.
* Corrected NtRegisterThreadTerminatePort to use same structure name as on windows for the
port, and added tag to pool allocation (documented in pooltag.txt)
include/internal/*.h:
* Defined Scheduler Functions and misc new functions or renamed functions.
ke/apc.c:
* Fixed critical bug where APCs were not delivered at all if the thread wastion and cancels any timers that are associated
to a thread, as well as their APCs and DPCs.
REGRESSIONS FOUND: NONE
BUGS/REGRESSIOSN FIXED:
* Thread/Get Set Context now works.
* Suspend Regression test now works.
* Task manager can now kill foreign processes, even hung ones (like it should).
* ExitProcess/closing cmd.exe with the 'x' button now works correctly without hacks.
KNOWN ISSUES: I left a bit of a mess in the headers and some stuff still needs to be moved into the right
places. I just wanted to have this first part ready first, so that it won't get too big.
svn path=/trunk/; revision=14174
2005-03-18 05:53:04 +00:00
|
|
|
/*++
|
2006-09-11 04:34:25 +00:00
|
|
|
* @name KiDeliverApc
|
2006-09-11 00:54:12 +00:00
|
|
|
* @implemented @NT4
|
Thread/Process Termination/Repeaing Rewrite + Fixes
---------------------------------------------------
- ps/cid.c:
* Moved CID Lookup functions here
- ps/security.c:
* Moved all security related functions here. Makes other files neater and security functions
easier to locate.
- ps/thread.c:
* Moved most of the Thread Scheduling/Dispatching code that belongs in the Kernel to /ke and
renamed functions from Ps to Ki.
* Implemented PsIsSystemThread.
* Removed Reaper Thread Init (now obsolete).
* Renamed PiDeleteThread to PspDeleteThread.
* Moved Thread State functions from tinfo.c to here.
- ps/process.c:
* Removed Query/Set Process functions and moved to ps/query.c
* Renamed PiDeletePRocess to PspDeleteProcess
* Removed obsoleted Process Termination functions, moved persistent one to kill.c
- ps/create.c:
* Moved the security APIs to security.c
* Correctly implemented PsCreateSystemThread to actually create system threads.
- ps/suspend.c
* Rewrote Nt Executive functions to use Kernel functions.
* Moved Ps* Routines into ke/kthread.c and fixed them. The implementation was wrong in
some aspects, especially the issue of the APC looping around the KeWaitXxx call and the
fact that the routines excluded/ignored the FreezeCount.
- ps/debug.c
* Fixed completely broken implementation of Get/SetThreadContext. The old version crashed
when called and did not work at all. Suspend Regression test now works.
* Moved Context<->TrapFrame functions to ke/i386/
* Combined Set/GetThreadContext APCs into a single one, and used special context structure.
- ps/query.c:
* Moved Thread/Process Query/Set Routines here.
- ps/tinfo.c:
* Removed.
- ps/kill.c
* Removed complicated Process Termination semantics and useless Attach/Detach in favor for
a much more lightweight function which performs the same tasks as before and actually works.
TaskManager can now terminate foreign processes.
* Rewrote Thread Reaping to use the HyperCritical Work Queue instead of manually controlled
thread. This results in much less code as well as an increase in speed and less micro
management. The reaper is PspReapRoutine. Closing CMD.EXE now works properly without
requiring masks that were added as hacks to allow it.
* Renamed PiTerminateProcessThreads to PspTerminateProcessThreads. Fixed it to work with new
termination code.
* Added PspDeleteProcess to handle Process Object deletion. Kills the CID Handle here as done
by Hartmut.
* Added PspDeletethread here.
* Renamed and rewrote PsTerminateCurrentThread to PspExitThread. Used NT Implementation out-
lined in Windows Internals, Chapter 13. Uses less locks, a more concise order of actions,
actually parses the Termination Ports, handles Dbgk notification. Timers are now rundown,
and Mutex rundown is in a dedicated Kernel function. Final termination handled by KeTerminate
Thread as documented.
* Renamed PsTerminateOtherThread to PspTerminateThreadByPointer and modified implementation to
be compatible with the changes above.
* Renamed and regrouped Process Termination into PspExitProcess. Also implemented as described
above, and moved each subsystem specific termination helper into its own subsytem.
* Improved NtTerminateProcess and added more debugging messages.
* Improved NtTerminateThread and added check against System Thread and made it compatible with
new implementation.
* Corrected PsTerminateSystemThread now that we support System Threads.
* Corrected NtRegisterThreadTerminatePort to use same structure name as on windows for the
port, and added tag to pool allocation (documented in pooltag.txt)
include/internal/*.h:
* Defined Scheduler Functions and misc new functions or renamed functions.
ke/apc.c:
* Fixed critical bug where APCs were not delivered at all if the thread wastion and cancels any timers that are associated
to a thread, as well as their APCs and DPCs.
REGRESSIONS FOUND: NONE
BUGS/REGRESSIOSN FIXED:
* Thread/Get Set Context now works.
* Suspend Regression test now works.
* Task manager can now kill foreign processes, even hung ones (like it should).
* ExitProcess/closing cmd.exe with the 'x' button now works correctly without hacks.
KNOWN ISSUES: I left a bit of a mess in the headers and some stuff still needs to be moved into the right
places. I just wanted to have this first part ready first, so that it won't get too big.
svn path=/trunk/; revision=14174
2005-03-18 05:53:04 +00:00
|
|
|
*
|
2006-09-11 00:54:12 +00:00
|
|
|
* The KiDeliverApc routine is called from IRQL switching code if the
|
|
|
|
* thread is returning from an IRQL >= APC_LEVEL and Kernel-Mode APCs are
|
|
|
|
* pending.
|
Thread/Process Termination/Repeaing Rewrite + Fixes
---------------------------------------------------
- ps/cid.c:
* Moved CID Lookup functions here
- ps/security.c:
* Moved all security related functions here. Makes other files neater and security functions
easier to locate.
- ps/thread.c:
* Moved most of the Thread Scheduling/Dispatching code that belongs in the Kernel to /ke and
renamed functions from Ps to Ki.
* Implemented PsIsSystemThread.
* Removed Reaper Thread Init (now obsolete).
* Renamed PiDeleteThread to PspDeleteThread.
* Moved Thread State functions from tinfo.c to here.
- ps/process.c:
* Removed Query/Set Process functions and moved to ps/query.c
* Renamed PiDeletePRocess to PspDeleteProcess
* Removed obsoleted Process Termination functions, moved persistent one to kill.c
- ps/create.c:
* Moved the security APIs to security.c
* Correctly implemented PsCreateSystemThread to actually create system threads.
- ps/suspend.c
* Rewrote Nt Executive functions to use Kernel functions.
* Moved Ps* Routines into ke/kthread.c and fixed them. The implementation was wrong in
some aspects, especially the issue of the APC looping around the KeWaitXxx call and the
fact that the routines excluded/ignored the FreezeCount.
- ps/debug.c
* Fixed completely broken implementation of Get/SetThreadContext. The old version crashed
when called and did not work at all. Suspend Regression test now works.
* Moved Context<->TrapFrame functions to ke/i386/
* Combined Set/GetThreadContext APCs into a single one, and used special context structure.
- ps/query.c:
* Moved Thread/Process Query/Set Routines here.
- ps/tinfo.c:
* Removed.
- ps/kill.c
* Removed complicated Process Termination semantics and useless Attach/Detach in favor for
a much more lightweight function which performs the same tasks as before and actually works.
TaskManager can now terminate foreign processes.
* Rewrote Thread Reaping to use the HyperCritical Work Queue instead of manually controlled
thread. This results in much less code as well as an increase in speed and less micro
management. The reaper is PspReapRoutine. Closing CMD.EXE now works properly without
requiring masks that were added as hacks to allow it.
* Renamed PiTerminateProcessThreads to PspTerminateProcessThreads. Fixed it to work with new
termination code.
* Added PspDeleteProcess to handle Process Object deletion. Kills the CID Handle here as done
by Hartmut.
* Added PspDeletethread here.
* Renamed and rewrote PsTerminateCurrentThread to PspExitThread. Used NT Implementation out-
lined in Windows Internals, Chapter 13. Uses less locks, a more concise order of actions,
actually parses the Termination Ports, handles Dbgk notification. Timers are now rundown,
and Mutex rundown is in a dedicated Kernel function. Final termination handled by KeTerminate
Thread as documented.
* Renamed PsTerminateOtherThread to PspTerminateThreadByPointer and modified implementation to
be compatible with the changes above.
* Renamed and regrouped Process Termination into PspExitProcess. Also implemented as described
above, and moved each subsystem specific termination helper into its own subsytem.
* Improved NtTerminateProcess and added more debugging messages.
* Improved NtTerminateThread and added check against System Thread and made it compatible with
new implementation.
* Corrected PsTerminateSystemThread now that we support System Threads.
* Corrected NtRegisterThreadTerminatePort to use same structure name as on windows for the
port, and added tag to pool allocation (documented in pooltag.txt)
include/internal/*.h:
* Defined Scheduler Functions and misc new functions or renamed functions.
ke/apc.c:
* Fixed critical bug where APCs were not delivered at all if the thread wastion and cancels any timers that are associated
to a thread, as well as their APCs and DPCs.
REGRESSIONS FOUND: NONE
BUGS/REGRESSIOSN FIXED:
* Thread/Get Set Context now works.
* Suspend Regression test now works.
* Task manager can now kill foreign processes, even hung ones (like it should).
* ExitProcess/closing cmd.exe with the 'x' button now works correctly without hacks.
KNOWN ISSUES: I left a bit of a mess in the headers and some stuff still needs to be moved into the right
places. I just wanted to have this first part ready first, so that it won't get too big.
svn path=/trunk/; revision=14174
2005-03-18 05:53:04 +00:00
|
|
|
*
|
2006-09-11 04:34:25 +00:00
|
|
|
* @param DeliveryMode
|
|
|
|
* Specifies the current processor mode.
|
Thread/Process Termination/Repeaing Rewrite + Fixes
---------------------------------------------------
- ps/cid.c:
* Moved CID Lookup functions here
- ps/security.c:
* Moved all security related functions here. Makes other files neater and security functions
easier to locate.
- ps/thread.c:
* Moved most of the Thread Scheduling/Dispatching code that belongs in the Kernel to /ke and
renamed functions from Ps to Ki.
* Implemented PsIsSystemThread.
* Removed Reaper Thread Init (now obsolete).
* Renamed PiDeleteThread to PspDeleteThread.
* Moved Thread State functions from tinfo.c to here.
- ps/process.c:
* Removed Query/Set Process functions and moved to ps/query.c
* Renamed PiDeletePRocess to PspDeleteProcess
* Removed obsoleted Process Termination functions, moved persistent one to kill.c
- ps/create.c:
* Moved the security APIs to security.c
* Correctly implemented PsCreateSystemThread to actually create system threads.
- ps/suspend.c
* Rewrote Nt Executive functions to use Kernel functions.
* Moved Ps* Routines into ke/kthread.c and fixed them. The implementation was wrong in
some aspects, especially the issue of the APC looping around the KeWaitXxx call and the
fact that the routines excluded/ignored the FreezeCount.
- ps/debug.c
* Fixed completely broken implementation of Get/SetThreadContext. The old version crashed
when called and did not work at all. Suspend Regression test now works.
* Moved Context<->TrapFrame functions to ke/i386/
* Combined Set/GetThreadContext APCs into a single one, and used special context structure.
- ps/query.c:
* Moved Thread/Process Query/Set Routines here.
- ps/tinfo.c:
* Removed.
- ps/kill.c
* Removed complicated Process Termination semantics and useless Attach/Detach in favor for
a much more lightweight function which performs the same tasks as before and actually works.
TaskManager can now terminate foreign processes.
* Rewrote Thread Reaping to use the HyperCritical Work Queue instead of manually controlled
thread. This results in much less code as well as an increase in speed and less micro
management. The reaper is PspReapRoutine. Closing CMD.EXE now works properly without
requiring masks that were added as hacks to allow it.
* Renamed PiTerminateProcessThreads to PspTerminateProcessThreads. Fixed it to work with new
termination code.
* Added PspDeleteProcess to handle Process Object deletion. Kills the CID Handle here as done
by Hartmut.
* Added PspDeletethread here.
* Renamed and rewrote PsTerminateCurrentThread to PspExitThread. Used NT Implementation out-
lined in Windows Internals, Chapter 13. Uses less locks, a more concise order of actions,
actually parses the Termination Ports, handles Dbgk notification. Timers are now rundown,
and Mutex rundown is in a dedicated Kernel function. Final termination handled by KeTerminate
Thread as documented.
* Renamed PsTerminateOtherThread to PspTerminateThreadByPointer and modified implementation to
be compatible with the changes above.
* Renamed and regrouped Process Termination into PspExitProcess. Also implemented as described
above, and moved each subsystem specific termination helper into its own subsytem.
* Improved NtTerminateProcess and added more debugging messages.
* Improved NtTerminateThread and added check against System Thread and made it compatible with
new implementation.
* Corrected PsTerminateSystemThread now that we support System Threads.
* Corrected NtRegisterThreadTerminatePort to use same structure name as on windows for the
port, and added tag to pool allocation (documented in pooltag.txt)
include/internal/*.h:
* Defined Scheduler Functions and misc new functions or renamed functions.
ke/apc.c:
* Fixed critical bug where APCs were not delivered at all if the thread wastion and cancels any timers that are associated
to a thread, as well as their APCs and DPCs.
REGRESSIONS FOUND: NONE
BUGS/REGRESSIOSN FIXED:
* Thread/Get Set Context now works.
* Suspend Regression test now works.
* Task manager can now kill foreign processes, even hung ones (like it should).
* ExitProcess/closing cmd.exe with the 'x' button now works correctly without hacks.
KNOWN ISSUES: I left a bit of a mess in the headers and some stuff still needs to be moved into the right
places. I just wanted to have this first part ready first, so that it won't get too big.
svn path=/trunk/; revision=14174
2005-03-18 05:53:04 +00:00
|
|
|
*
|
2006-09-11 04:34:25 +00:00
|
|
|
* @param ExceptionFrame
|
|
|
|
* Pointer to the Exception Frame on non-i386 builds.
|
Thread/Process Termination/Repeaing Rewrite + Fixes
---------------------------------------------------
- ps/cid.c:
* Moved CID Lookup functions here
- ps/security.c:
* Moved all security related functions here. Makes other files neater and security functions
easier to locate.
- ps/thread.c:
* Moved most of the Thread Scheduling/Dispatching code that belongs in the Kernel to /ke and
renamed functions from Ps to Ki.
* Implemented PsIsSystemThread.
* Removed Reaper Thread Init (now obsolete).
* Renamed PiDeleteThread to PspDeleteThread.
* Moved Thread State functions from tinfo.c to here.
- ps/process.c:
* Removed Query/Set Process functions and moved to ps/query.c
* Renamed PiDeletePRocess to PspDeleteProcess
* Removed obsoleted Process Termination functions, moved persistent one to kill.c
- ps/create.c:
* Moved the security APIs to security.c
* Correctly implemented PsCreateSystemThread to actually create system threads.
- ps/suspend.c
* Rewrote Nt Executive functions to use Kernel functions.
* Moved Ps* Routines into ke/kthread.c and fixed them. The implementation was wrong in
some aspects, especially the issue of the APC looping around the KeWaitXxx call and the
fact that the routines excluded/ignored the FreezeCount.
- ps/debug.c
* Fixed completely broken implementation of Get/SetThreadContext. The old version crashed
when called and did not work at all. Suspend Regression test now works.
* Moved Context<->TrapFrame functions to ke/i386/
* Combined Set/GetThreadContext APCs into a single one, and used special context structure.
- ps/query.c:
* Moved Thread/Process Query/Set Routines here.
- ps/tinfo.c:
* Removed.
- ps/kill.c
* Removed complicated Process Termination semantics and useless Attach/Detach in favor for
a much more lightweight function which performs the same tasks as before and actually works.
TaskManager can now terminate foreign processes.
* Rewrote Thread Reaping to use the HyperCritical Work Queue instead of manually controlled
thread. This results in much less code as well as an increase in speed and less micro
management. The reaper is PspReapRoutine. Closing CMD.EXE now works properly without
requiring masks that were added as hacks to allow it.
* Renamed PiTerminateProcessThreads to PspTerminateProcessThreads. Fixed it to work with new
termination code.
* Added PspDeleteProcess to handle Process Object deletion. Kills the CID Handle here as done
by Hartmut.
* Added PspDeletethread here.
* Renamed and rewrote PsTerminateCurrentThread to PspExitThread. Used NT Implementation out-
lined in Windows Internals, Chapter 13. Uses less locks, a more concise order of actions,
actually parses the Termination Ports, handles Dbgk notification. Timers are now rundown,
and Mutex rundown is in a dedicated Kernel function. Final termination handled by KeTerminate
Thread as documented.
* Renamed PsTerminateOtherThread to PspTerminateThreadByPointer and modified implementation to
be compatible with the changes above.
* Renamed and regrouped Process Termination into PspExitProcess. Also implemented as described
above, and moved each subsystem specific termination helper into its own subsytem.
* Improved NtTerminateProcess and added more debugging messages.
* Improved NtTerminateThread and added check against System Thread and made it compatible with
new implementation.
* Corrected PsTerminateSystemThread now that we support System Threads.
* Corrected NtRegisterThreadTerminatePort to use same structure name as on windows for the
port, and added tag to pool allocation (documented in pooltag.txt)
include/internal/*.h:
* Defined Scheduler Functions and misc new functions or renamed functions.
ke/apc.c:
* Fixed critical bug where APCs were not delivered at all if the thread wastion and cancels any timers that are associated
to a thread, as well as their APCs and DPCs.
REGRESSIONS FOUND: NONE
BUGS/REGRESSIOSN FIXED:
* Thread/Get Set Context now works.
* Suspend Regression test now works.
* Task manager can now kill foreign processes, even hung ones (like it should).
* ExitProcess/closing cmd.exe with the 'x' button now works correctly without hacks.
KNOWN ISSUES: I left a bit of a mess in the headers and some stuff still needs to be moved into the right
places. I just wanted to have this first part ready first, so that it won't get too big.
svn path=/trunk/; revision=14174
2005-03-18 05:53:04 +00:00
|
|
|
*
|
2006-09-11 04:34:25 +00:00
|
|
|
* @param TrapFrame
|
|
|
|
* Pointer to the Trap Frame.
|
Thread/Process Termination/Repeaing Rewrite + Fixes
---------------------------------------------------
- ps/cid.c:
* Moved CID Lookup functions here
- ps/security.c:
* Moved all security related functions here. Makes other files neater and security functions
easier to locate.
- ps/thread.c:
* Moved most of the Thread Scheduling/Dispatching code that belongs in the Kernel to /ke and
renamed functions from Ps to Ki.
* Implemented PsIsSystemThread.
* Removed Reaper Thread Init (now obsolete).
* Renamed PiDeleteThread to PspDeleteThread.
* Moved Thread State functions from tinfo.c to here.
- ps/process.c:
* Removed Query/Set Process functions and moved to ps/query.c
* Renamed PiDeletePRocess to PspDeleteProcess
* Removed obsoleted Process Termination functions, moved persistent one to kill.c
- ps/create.c:
* Moved the security APIs to security.c
* Correctly implemented PsCreateSystemThread to actually create system threads.
- ps/suspend.c
* Rewrote Nt Executive functions to use Kernel functions.
* Moved Ps* Routines into ke/kthread.c and fixed them. The implementation was wrong in
some aspects, especially the issue of the APC looping around the KeWaitXxx call and the
fact that the routines excluded/ignored the FreezeCount.
- ps/debug.c
* Fixed completely broken implementation of Get/SetThreadContext. The old version crashed
when called and did not work at all. Suspend Regression test now works.
* Moved Context<->TrapFrame functions to ke/i386/
* Combined Set/GetThreadContext APCs into a single one, and used special context structure.
- ps/query.c:
* Moved Thread/Process Query/Set Routines here.
- ps/tinfo.c:
* Removed.
- ps/kill.c
* Removed complicated Process Termination semantics and useless Attach/Detach in favor for
a much more lightweight function which performs the same tasks as before and actually works.
TaskManager can now terminate foreign processes.
* Rewrote Thread Reaping to use the HyperCritical Work Queue instead of manually controlled
thread. This results in much less code as well as an increase in speed and less micro
management. The reaper is PspReapRoutine. Closing CMD.EXE now works properly without
requiring masks that were added as hacks to allow it.
* Renamed PiTerminateProcessThreads to PspTerminateProcessThreads. Fixed it to work with new
termination code.
* Added PspDeleteProcess to handle Process Object deletion. Kills the CID Handle here as done
by Hartmut.
* Added PspDeletethread here.
* Renamed and rewrote PsTerminateCurrentThread to PspExitThread. Used NT Implementation out-
lined in Windows Internals, Chapter 13. Uses less locks, a more concise order of actions,
actually parses the Termination Ports, handles Dbgk notification. Timers are now rundown,
and Mutex rundown is in a dedicated Kernel function. Final termination handled by KeTerminate
Thread as documented.
* Renamed PsTerminateOtherThread to PspTerminateThreadByPointer and modified implementation to
be compatible with the changes above.
* Renamed and regrouped Process Termination into PspExitProcess. Also implemented as described
above, and moved each subsystem specific termination helper into its own subsytem.
* Improved NtTerminateProcess and added more debugging messages.
* Improved NtTerminateThread and added check against System Thread and made it compatible with
new implementation.
* Corrected PsTerminateSystemThread now that we support System Threads.
* Corrected NtRegisterThreadTerminatePort to use same structure name as on windows for the
port, and added tag to pool allocation (documented in pooltag.txt)
include/internal/*.h:
* Defined Scheduler Functions and misc new functions or renamed functions.
ke/apc.c:
* Fixed critical bug where APCs were not delivered at all if the thread wastion and cancels any timers that are associated
to a thread, as well as their APCs and DPCs.
REGRESSIONS FOUND: NONE
BUGS/REGRESSIOSN FIXED:
* Thread/Get Set Context now works.
* Suspend Regression test now works.
* Task manager can now kill foreign processes, even hung ones (like it should).
* ExitProcess/closing cmd.exe with the 'x' button now works correctly without hacks.
KNOWN ISSUES: I left a bit of a mess in the headers and some stuff still needs to be moved into the right
places. I just wanted to have this first part ready first, so that it won't get too big.
svn path=/trunk/; revision=14174
2005-03-18 05:53:04 +00:00
|
|
|
*
|
2006-09-11 04:34:25 +00:00
|
|
|
* @return None.
|
Thread/Process Termination/Repeaing Rewrite + Fixes
---------------------------------------------------
- ps/cid.c:
* Moved CID Lookup functions here
- ps/security.c:
* Moved all security related functions here. Makes other files neater and security functions
easier to locate.
- ps/thread.c:
* Moved most of the Thread Scheduling/Dispatching code that belongs in the Kernel to /ke and
renamed functions from Ps to Ki.
* Implemented PsIsSystemThread.
* Removed Reaper Thread Init (now obsolete).
* Renamed PiDeleteThread to PspDeleteThread.
* Moved Thread State functions from tinfo.c to here.
- ps/process.c:
* Removed Query/Set Process functions and moved to ps/query.c
* Renamed PiDeletePRocess to PspDeleteProcess
* Removed obsoleted Process Termination functions, moved persistent one to kill.c
- ps/create.c:
* Moved the security APIs to security.c
* Correctly implemented PsCreateSystemThread to actually create system threads.
- ps/suspend.c
* Rewrote Nt Executive functions to use Kernel functions.
* Moved Ps* Routines into ke/kthread.c and fixed them. The implementation was wrong in
some aspects, especially the issue of the APC looping around the KeWaitXxx call and the
fact that the routines excluded/ignored the FreezeCount.
- ps/debug.c
* Fixed completely broken implementation of Get/SetThreadContext. The old version crashed
when called and did not work at all. Suspend Regression test now works.
* Moved Context<->TrapFrame functions to ke/i386/
* Combined Set/GetThreadContext APCs into a single one, and used special context structure.
- ps/query.c:
* Moved Thread/Process Query/Set Routines here.
- ps/tinfo.c:
* Removed.
- ps/kill.c
* Removed complicated Process Termination semantics and useless Attach/Detach in favor for
a much more lightweight function which performs the same tasks as before and actually works.
TaskManager can now terminate foreign processes.
* Rewrote Thread Reaping to use the HyperCritical Work Queue instead of manually controlled
thread. This results in much less code as well as an increase in speed and less micro
management. The reaper is PspReapRoutine. Closing CMD.EXE now works properly without
requiring masks that were added as hacks to allow it.
* Renamed PiTerminateProcessThreads to PspTerminateProcessThreads. Fixed it to work with new
termination code.
* Added PspDeleteProcess to handle Process Object deletion. Kills the CID Handle here as done
by Hartmut.
* Added PspDeletethread here.
* Renamed and rewrote PsTerminateCurrentThread to PspExitThread. Used NT Implementation out-
lined in Windows Internals, Chapter 13. Uses less locks, a more concise order of actions,
actually parses the Termination Ports, handles Dbgk notification. Timers are now rundown,
and Mutex rundown is in a dedicated Kernel function. Final termination handled by KeTerminate
Thread as documented.
* Renamed PsTerminateOtherThread to PspTerminateThreadByPointer and modified implementation to
be compatible with the changes above.
* Renamed and regrouped Process Termination into PspExitProcess. Also implemented as described
above, and moved each subsystem specific termination helper into its own subsytem.
* Improved NtTerminateProcess and added more debugging messages.
* Improved NtTerminateThread and added check against System Thread and made it compatible with
new implementation.
* Corrected PsTerminateSystemThread now that we support System Threads.
* Corrected NtRegisterThreadTerminatePort to use same structure name as on windows for the
port, and added tag to pool allocation (documented in pooltag.txt)
include/internal/*.h:
* Defined Scheduler Functions and misc new functions or renamed functions.
ke/apc.c:
* Fixed critical bug where APCs were not delivered at all if the thread wastion and cancels any timers that are associated
to a thread, as well as their APCs and DPCs.
REGRESSIONS FOUND: NONE
BUGS/REGRESSIOSN FIXED:
* Thread/Get Set Context now works.
* Suspend Regression test now works.
* Task manager can now kill foreign processes, even hung ones (like it should).
* ExitProcess/closing cmd.exe with the 'x' button now works correctly without hacks.
KNOWN ISSUES: I left a bit of a mess in the headers and some stuff still needs to be moved into the right
places. I just wanted to have this first part ready first, so that it won't get too big.
svn path=/trunk/; revision=14174
2005-03-18 05:53:04 +00:00
|
|
|
*
|
2006-09-11 04:34:25 +00:00
|
|
|
* @remarks First, Special APCs are delivered, followed by Kernel-Mode APCs and
|
|
|
|
* User-Mode APCs. Note that the TrapFrame is only valid if the
|
|
|
|
* delivery mode is User-Mode.
|
|
|
|
* Upon entry, this routine executes at APC_LEVEL.
|
Thread/Process Termination/Repeaing Rewrite + Fixes
---------------------------------------------------
- ps/cid.c:
* Moved CID Lookup functions here
- ps/security.c:
* Moved all security related functions here. Makes other files neater and security functions
easier to locate.
- ps/thread.c:
* Moved most of the Thread Scheduling/Dispatching code that belongs in the Kernel to /ke and
renamed functions from Ps to Ki.
* Implemented PsIsSystemThread.
* Removed Reaper Thread Init (now obsolete).
* Renamed PiDeleteThread to PspDeleteThread.
* Moved Thread State functions from tinfo.c to here.
- ps/process.c:
* Removed Query/Set Process functions and moved to ps/query.c
* Renamed PiDeletePRocess to PspDeleteProcess
* Removed obsoleted Process Termination functions, moved persistent one to kill.c
- ps/create.c:
* Moved the security APIs to security.c
* Correctly implemented PsCreateSystemThread to actually create system threads.
- ps/suspend.c
* Rewrote Nt Executive functions to use Kernel functions.
* Moved Ps* Routines into ke/kthread.c and fixed them. The implementation was wrong in
some aspects, especially the issue of the APC looping around the KeWaitXxx call and the
fact that the routines excluded/ignored the FreezeCount.
- ps/debug.c
* Fixed completely broken implementation of Get/SetThreadContext. The old version crashed
when called and did not work at all. Suspend Regression test now works.
* Moved Context<->TrapFrame functions to ke/i386/
* Combined Set/GetThreadContext APCs into a single one, and used special context structure.
- ps/query.c:
* Moved Thread/Process Query/Set Routines here.
- ps/tinfo.c:
* Removed.
- ps/kill.c
* Removed complicated Process Termination semantics and useless Attach/Detach in favor for
a much more lightweight function which performs the same tasks as before and actually works.
TaskManager can now terminate foreign processes.
* Rewrote Thread Reaping to use the HyperCritical Work Queue instead of manually controlled
thread. This results in much less code as well as an increase in speed and less micro
management. The reaper is PspReapRoutine. Closing CMD.EXE now works properly without
requiring masks that were added as hacks to allow it.
* Renamed PiTerminateProcessThreads to PspTerminateProcessThreads. Fixed it to work with new
termination code.
* Added PspDeleteProcess to handle Process Object deletion. Kills the CID Handle here as done
by Hartmut.
* Added PspDeletethread here.
* Renamed and rewrote PsTerminateCurrentThread to PspExitThread. Used NT Implementation out-
lined in Windows Internals, Chapter 13. Uses less locks, a more concise order of actions,
actually parses the Termination Ports, handles Dbgk notification. Timers are now rundown,
and Mutex rundown is in a dedicated Kernel function. Final termination handled by KeTerminate
Thread as documented.
* Renamed PsTerminateOtherThread to PspTerminateThreadByPointer and modified implementation to
be compatible with the changes above.
* Renamed and regrouped Process Termination into PspExitProcess. Also implemented as described
above, and moved each subsystem specific termination helper into its own subsytem.
* Improved NtTerminateProcess and added more debugging messages.
* Improved NtTerminateThread and added check against System Thread and made it compatible with
new implementation.
* Corrected PsTerminateSystemThread now that we support System Threads.
* Corrected NtRegisterThreadTerminatePort to use same structure name as on windows for the
port, and added tag to pool allocation (documented in pooltag.txt)
include/internal/*.h:
* Defined Scheduler Functions and misc new functions or renamed functions.
ke/apc.c:
* Fixed critical bug where APCs were not delivered at all if the thread wastion and cancels any timers that are associated
to a thread, as well as their APCs and DPCs.
REGRESSIONS FOUND: NONE
BUGS/REGRESSIOSN FIXED:
* Thread/Get Set Context now works.
* Suspend Regression test now works.
* Task manager can now kill foreign processes, even hung ones (like it should).
* ExitProcess/closing cmd.exe with the 'x' button now works correctly without hacks.
KNOWN ISSUES: I left a bit of a mess in the headers and some stuff still needs to be moved into the right
places. I just wanted to have this first part ready first, so that it won't get too big.
svn path=/trunk/; revision=14174
2005-03-18 05:53:04 +00:00
|
|
|
*
|
|
|
|
*--*/
|
2006-09-11 00:54:12 +00:00
|
|
|
VOID
|
2006-09-11 04:34:25 +00:00
|
|
|
NTAPI
|
|
|
|
KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode,
|
|
|
|
IN PKEXCEPTION_FRAME ExceptionFrame,
|
|
|
|
IN PKTRAP_FRAME TrapFrame)
|
Thread/Process Termination/Repeaing Rewrite + Fixes
---------------------------------------------------
- ps/cid.c:
* Moved CID Lookup functions here
- ps/security.c:
* Moved all security related functions here. Makes other files neater and security functions
easier to locate.
- ps/thread.c:
* Moved most of the Thread Scheduling/Dispatching code that belongs in the Kernel to /ke and
renamed functions from Ps to Ki.
* Implemented PsIsSystemThread.
* Removed Reaper Thread Init (now obsolete).
* Renamed PiDeleteThread to PspDeleteThread.
* Moved Thread State functions from tinfo.c to here.
- ps/process.c:
* Removed Query/Set Process functions and moved to ps/query.c
* Renamed PiDeletePRocess to PspDeleteProcess
* Removed obsoleted Process Termination functions, moved persistent one to kill.c
- ps/create.c:
* Moved the security APIs to security.c
* Correctly implemented PsCreateSystemThread to actually create system threads.
- ps/suspend.c
* Rewrote Nt Executive functions to use Kernel functions.
* Moved Ps* Routines into ke/kthread.c and fixed them. The implementation was wrong in
some aspects, especially the issue of the APC looping around the KeWaitXxx call and the
fact that the routines excluded/ignored the FreezeCount.
- ps/debug.c
* Fixed completely broken implementation of Get/SetThreadContext. The old version crashed
when called and did not work at all. Suspend Regression test now works.
* Moved Context<->TrapFrame functions to ke/i386/
* Combined Set/GetThreadContext APCs into a single one, and used special context structure.
- ps/query.c:
* Moved Thread/Process Query/Set Routines here.
- ps/tinfo.c:
* Removed.
- ps/kill.c
* Removed complicated Process Termination semantics and useless Attach/Detach in favor for
a much more lightweight function which performs the same tasks as before and actually works.
TaskManager can now terminate foreign processes.
* Rewrote Thread Reaping to use the HyperCritical Work Queue instead of manually controlled
thread. This results in much less code as well as an increase in speed and less micro
management. The reaper is PspReapRoutine. Closing CMD.EXE now works properly without
requiring masks that were added as hacks to allow it.
* Renamed PiTerminateProcessThreads to PspTerminateProcessThreads. Fixed it to work with new
termination code.
* Added PspDeleteProcess to handle Process Object deletion. Kills the CID Handle here as done
by Hartmut.
* Added PspDeletethread here.
* Renamed and rewrote PsTerminateCurrentThread to PspExitThread. Used NT Implementation out-
lined in Windows Internals, Chapter 13. Uses less locks, a more concise order of actions,
actually parses the Termination Ports, handles Dbgk notification. Timers are now rundown,
and Mutex rundown is in a dedicated Kernel function. Final termination handled by KeTerminate
Thread as documented.
* Renamed PsTerminateOtherThread to PspTerminateThreadByPointer and modified implementation to
be compatible with the changes above.
* Renamed and regrouped Process Termination into PspExitProcess. Also implemented as described
above, and moved each subsystem specific termination helper into its own subsytem.
* Improved NtTerminateProcess and added more debugging messages.
* Improved NtTerminateThread and added check against System Thread and made it compatible with
new implementation.
* Corrected PsTerminateSystemThread now that we support System Threads.
* Corrected NtRegisterThreadTerminatePort to use same structure name as on windows for the
port, and added tag to pool allocation (documented in pooltag.txt)
include/internal/*.h:
* Defined Scheduler Functions and misc new functions or renamed functions.
ke/apc.c:
* Fixed critical bug where APCs were not delivered at all if the thread wastion and cancels any timers that are associated
to a thread, as well as their APCs and DPCs.
REGRESSIONS FOUND: NONE
BUGS/REGRESSIOSN FIXED:
* Thread/Get Set Context now works.
* Suspend Regression test now works.
* Task manager can now kill foreign processes, even hung ones (like it should).
* ExitProcess/closing cmd.exe with the 'x' button now works correctly without hacks.
KNOWN ISSUES: I left a bit of a mess in the headers and some stuff still needs to be moved into the right
places. I just wanted to have this first part ready first, so that it won't get too big.
svn path=/trunk/; revision=14174
2005-03-18 05:53:04 +00:00
|
|
|
{
|
2006-09-11 00:54:12 +00:00
|
|
|
PKTHREAD Thread = KeGetCurrentThread();
|
|
|
|
PKPROCESS Process = Thread->ApcState.Process;
|
|
|
|
PKTRAP_FRAME OldTrapFrame;
|
|
|
|
PLIST_ENTRY ApcListEntry;
|
|
|
|
PKAPC Apc;
|
2006-09-11 04:34:25 +00:00
|
|
|
KLOCK_QUEUE_HANDLE ApcLock;
|
2006-09-11 00:54:12 +00:00
|
|
|
PKKERNEL_ROUTINE KernelRoutine;
|
|
|
|
PVOID NormalContext;
|
|
|
|
PKNORMAL_ROUTINE NormalRoutine;
|
|
|
|
PVOID SystemArgument1;
|
|
|
|
PVOID SystemArgument2;
|
|
|
|
ASSERT_IRQL_EQUAL(APC_LEVEL);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-11 04:34:25 +00:00
|
|
|
/* Save the old trap frame and set current one */
|
2006-09-11 00:54:12 +00:00
|
|
|
OldTrapFrame = Thread->TrapFrame;
|
2006-09-11 04:34:25 +00:00
|
|
|
Thread->TrapFrame = TrapFrame;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-11 00:54:12 +00:00
|
|
|
/* Clear Kernel APC Pending */
|
|
|
|
Thread->ApcState.KernelApcPending = FALSE;
|
|
|
|
|
|
|
|
/* Check if Special APCs are disabled */
|
2006-09-11 04:34:25 +00:00
|
|
|
if (Thread->SpecialApcDisable) goto Quickie;
|
2006-09-11 00:54:12 +00:00
|
|
|
|
|
|
|
/* Do the Kernel APCs first */
|
|
|
|
while (!IsListEmpty(&Thread->ApcState.ApcListHead[KernelMode]))
|
2006-09-10 18:26:50 +00:00
|
|
|
{
|
2006-09-11 04:34:25 +00:00
|
|
|
/* Lock the APC Queue */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireApcLockRaiseToDpc(Thread, &ApcLock);
|
2006-09-11 04:34:25 +00:00
|
|
|
|
|
|
|
/* Check if the list became empty now */
|
|
|
|
if (IsListEmpty(&Thread->ApcState.ApcListHead[KernelMode]))
|
|
|
|
{
|
|
|
|
/* It is, release the lock and break out */
|
|
|
|
KiReleaseApcLock(&ApcLock);
|
|
|
|
break;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2011-03-30 11:05:40 +00:00
|
|
|
/* Kernel APC is not pending anymore */
|
|
|
|
Thread->ApcState.KernelApcPending = FALSE;
|
|
|
|
|
2006-09-11 00:54:12 +00:00
|
|
|
/* Get the next Entry */
|
|
|
|
ApcListEntry = Thread->ApcState.ApcListHead[KernelMode].Flink;
|
|
|
|
Apc = CONTAINING_RECORD(ApcListEntry, KAPC, ApcListEntry);
|
2005-03-12 22:31:22 +00:00
|
|
|
|
2008-09-28 20:53:51 +00:00
|
|
|
/* Save Parameters so that it's safe to free the Object in the Kernel Routine*/
|
2006-09-11 00:54:12 +00:00
|
|
|
NormalRoutine = Apc->NormalRoutine;
|
|
|
|
KernelRoutine = Apc->KernelRoutine;
|
|
|
|
NormalContext = Apc->NormalContext;
|
|
|
|
SystemArgument1 = Apc->SystemArgument1;
|
|
|
|
SystemArgument2 = Apc->SystemArgument2;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-12 22:31:22 +00:00
|
|
|
/* Special APC */
|
2005-09-27 01:57:27 +00:00
|
|
|
if (!NormalRoutine)
|
|
|
|
{
|
2005-03-12 22:31:22 +00:00
|
|
|
/* Remove the APC from the list */
|
|
|
|
RemoveEntryList(ApcListEntry);
|
2005-07-18 19:50:23 +00:00
|
|
|
Apc->Inserted = FALSE;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2008-09-28 20:53:51 +00:00
|
|
|
/* Release the APC lock */
|
2006-09-11 04:34:25 +00:00
|
|
|
KiReleaseApcLock(&ApcLock);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-12 22:31:22 +00:00
|
|
|
/* Call the Special APC */
|
|
|
|
KernelRoutine(Apc,
|
2005-07-18 19:50:23 +00:00
|
|
|
&NormalRoutine,
|
|
|
|
&NormalContext,
|
|
|
|
&SystemArgument1,
|
|
|
|
&SystemArgument2);
|
2006-09-11 04:34:25 +00:00
|
|
|
|
|
|
|
/* Make sure it returned correctly */
|
|
|
|
if (KeGetCurrentIrql() != ApcLock.OldIrql)
|
|
|
|
{
|
|
|
|
KeBugCheckEx(IRQL_UNEXPECTED_VALUE,
|
|
|
|
(KeGetCurrentIrql() << 16) |
|
|
|
|
(ApcLock.OldIrql << 8),
|
|
|
|
(ULONG_PTR)KernelRoutine,
|
|
|
|
(ULONG_PTR)Apc,
|
|
|
|
(ULONG_PTR)NormalRoutine);
|
|
|
|
}
|
2005-09-27 01:57:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-09-11 04:34:25 +00:00
|
|
|
/* Normal Kernel APC, make sure it's safe to deliver */
|
2005-09-27 01:57:27 +00:00
|
|
|
if ((Thread->ApcState.KernelApcInProgress) ||
|
|
|
|
(Thread->KernelApcDisable))
|
|
|
|
{
|
|
|
|
/* Release lock and return */
|
2006-09-11 04:34:25 +00:00
|
|
|
KiReleaseApcLock(&ApcLock);
|
2005-09-27 01:57:27 +00:00
|
|
|
goto Quickie;
|
2005-03-12 22:31:22 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-12 22:31:22 +00:00
|
|
|
/* Dequeue the APC */
|
2005-07-18 19:50:23 +00:00
|
|
|
RemoveEntryList(ApcListEntry);
|
2005-08-15 22:44:32 +00:00
|
|
|
Apc->Inserted = FALSE;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-12 22:31:22 +00:00
|
|
|
/* Go back to APC_LEVEL */
|
2006-09-11 04:34:25 +00:00
|
|
|
KiReleaseApcLock(&ApcLock);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-12 22:31:22 +00:00
|
|
|
/* Call the Kernel APC */
|
|
|
|
KernelRoutine(Apc,
|
2005-07-18 19:50:23 +00:00
|
|
|
&NormalRoutine,
|
|
|
|
&NormalContext,
|
|
|
|
&SystemArgument1,
|
|
|
|
&SystemArgument2);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-11 04:34:25 +00:00
|
|
|
/* Make sure it returned correctly */
|
|
|
|
if (KeGetCurrentIrql() != ApcLock.OldIrql)
|
|
|
|
{
|
|
|
|
KeBugCheckEx(IRQL_UNEXPECTED_VALUE,
|
|
|
|
(KeGetCurrentIrql() << 16) |
|
|
|
|
(ApcLock.OldIrql << 8),
|
|
|
|
(ULONG_PTR)KernelRoutine,
|
|
|
|
(ULONG_PTR)Apc,
|
|
|
|
(ULONG_PTR)NormalRoutine);
|
|
|
|
}
|
|
|
|
|
2008-09-28 20:53:51 +00:00
|
|
|
/* Check if there still is a Normal Routine */
|
2005-09-27 01:57:27 +00:00
|
|
|
if (NormalRoutine)
|
|
|
|
{
|
2006-09-11 04:34:25 +00:00
|
|
|
/* At Passive Level, an APC can be prempted by a Special APC */
|
2005-03-12 22:31:22 +00:00
|
|
|
Thread->ApcState.KernelApcInProgress = TRUE;
|
|
|
|
KeLowerIrql(PASSIVE_LEVEL);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2008-09-28 20:53:51 +00:00
|
|
|
/* Call and Raise IRQL back to APC_LEVEL */
|
2005-07-18 19:50:23 +00:00
|
|
|
NormalRoutine(NormalContext, SystemArgument1, SystemArgument2);
|
2006-09-11 04:34:25 +00:00
|
|
|
KeRaiseIrql(APC_LEVEL, &ApcLock.OldIrql);
|
2005-03-12 22:31:22 +00:00
|
|
|
}
|
|
|
|
|
2005-09-27 01:57:27 +00:00
|
|
|
/* Set Kernel APC in progress to false and loop again */
|
2005-03-12 22:31:22 +00:00
|
|
|
Thread->ApcState.KernelApcInProgress = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-12 22:31:22 +00:00
|
|
|
/* Now we do the User APCs */
|
2005-09-27 01:57:27 +00:00
|
|
|
if ((DeliveryMode == UserMode) &&
|
2006-09-11 04:34:25 +00:00
|
|
|
!(IsListEmpty(&Thread->ApcState.ApcListHead[UserMode])) &&
|
|
|
|
(Thread->ApcState.UserApcPending))
|
2005-09-27 01:57:27 +00:00
|
|
|
{
|
2006-09-11 04:34:25 +00:00
|
|
|
/* Lock the APC Queue */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireApcLockRaiseToDpc(Thread, &ApcLock);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-12 22:31:22 +00:00
|
|
|
/* It's not pending anymore */
|
|
|
|
Thread->ApcState.UserApcPending = FALSE;
|
|
|
|
|
2006-09-11 04:34:25 +00:00
|
|
|
/* Check if the list became empty now */
|
|
|
|
if (IsListEmpty(&Thread->ApcState.ApcListHead[UserMode]))
|
2005-09-27 01:57:27 +00:00
|
|
|
{
|
2006-09-11 04:34:25 +00:00
|
|
|
/* It is, release the lock and break out */
|
|
|
|
KiReleaseApcLock(&ApcLock);
|
2005-09-27 01:57:27 +00:00
|
|
|
goto Quickie;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the actual APC object */
|
2006-09-11 04:34:25 +00:00
|
|
|
ApcListEntry = Thread->ApcState.ApcListHead[UserMode].Flink;
|
2005-03-12 22:31:22 +00:00
|
|
|
Apc = CONTAINING_RECORD(ApcListEntry, KAPC, ApcListEntry);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2008-09-28 20:53:51 +00:00
|
|
|
/* Save Parameters so that it's safe to free the Object in the Kernel Routine*/
|
2005-07-18 19:50:23 +00:00
|
|
|
NormalRoutine = Apc->NormalRoutine;
|
|
|
|
KernelRoutine = Apc->KernelRoutine;
|
|
|
|
NormalContext = Apc->NormalContext;
|
2005-03-12 22:31:22 +00:00
|
|
|
SystemArgument1 = Apc->SystemArgument1;
|
2005-05-09 01:38:29 +00:00
|
|
|
SystemArgument2 = Apc->SystemArgument2;
|
|
|
|
|
2006-09-11 04:34:25 +00:00
|
|
|
/* Remove the APC from Queue, and release the lock */
|
2005-03-12 22:31:22 +00:00
|
|
|
RemoveEntryList(ApcListEntry);
|
|
|
|
Apc->Inserted = FALSE;
|
2006-09-11 04:34:25 +00:00
|
|
|
KiReleaseApcLock(&ApcLock);
|
2005-07-18 19:50:23 +00:00
|
|
|
|
2006-09-11 04:34:25 +00:00
|
|
|
/* Call the kernel routine */
|
2005-03-12 22:31:22 +00:00
|
|
|
KernelRoutine(Apc,
|
2005-07-18 19:50:23 +00:00
|
|
|
&NormalRoutine,
|
|
|
|
&NormalContext,
|
|
|
|
&SystemArgument1,
|
|
|
|
&SystemArgument2);
|
2005-03-12 22:31:22 +00:00
|
|
|
|
2006-09-11 04:34:25 +00:00
|
|
|
/* Check if there's no normal routine */
|
2005-09-27 01:57:27 +00:00
|
|
|
if (!NormalRoutine)
|
|
|
|
{
|
2005-03-12 22:31:22 +00:00
|
|
|
/* Check if more User APCs are Pending */
|
|
|
|
KeTestAlertThread(UserMode);
|
2005-09-27 01:57:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-12 22:31:22 +00:00
|
|
|
/* Set up the Trap Frame and prepare for Execution in NTDLL.DLL */
|
2006-09-11 04:34:25 +00:00
|
|
|
KiInitializeUserApc(ExceptionFrame,
|
2005-07-18 19:50:23 +00:00
|
|
|
TrapFrame,
|
|
|
|
NormalRoutine,
|
|
|
|
NormalContext,
|
|
|
|
SystemArgument1,
|
|
|
|
SystemArgument2);
|
2005-03-12 22:31:22 +00:00
|
|
|
}
|
2005-09-27 01:57:27 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-09-27 01:57:27 +00:00
|
|
|
Quickie:
|
|
|
|
/* Make sure we're still in the same process */
|
|
|
|
if (Process != Thread->ApcState.Process)
|
|
|
|
{
|
|
|
|
/* Erm, we got attached or something! BAD! */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheckEx(INVALID_PROCESS_ATTACH_ATTEMPT,
|
2005-09-27 01:57:27 +00:00
|
|
|
(ULONG_PTR)Process,
|
|
|
|
(ULONG_PTR)Thread->ApcState.Process,
|
|
|
|
Thread->ApcStateIndex,
|
|
|
|
KeGetCurrentPrcb()->DpcRoutineActive);
|
2005-03-12 22:31:22 +00:00
|
|
|
}
|
2005-09-27 01:57:27 +00:00
|
|
|
|
|
|
|
/* Restore the trap frame */
|
|
|
|
Thread->TrapFrame = OldTrapFrame;
|
2004-11-10 02:51:00 +00:00
|
|
|
}
|
|
|
|
|
2006-09-11 01:30:24 +00:00
|
|
|
FORCEINLINE
|
|
|
|
VOID
|
|
|
|
RepairList(IN PLIST_ENTRY Original,
|
|
|
|
IN PLIST_ENTRY Copy,
|
|
|
|
IN KPROCESSOR_MODE Mode)
|
2006-09-11 00:54:12 +00:00
|
|
|
{
|
2006-09-11 01:30:24 +00:00
|
|
|
/* Check if the list for this mode is empty */
|
|
|
|
if (IsListEmpty(&Original[Mode]))
|
|
|
|
{
|
|
|
|
/* It is, all we need to do is initialize it */
|
|
|
|
InitializeListHead(&Copy[Mode]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Copy the lists */
|
|
|
|
Copy[Mode].Flink = Original[Mode].Flink;
|
|
|
|
Copy[Mode].Blink = Original[Mode].Blink;
|
|
|
|
Original[Mode].Flink->Blink = &Copy[Mode];
|
|
|
|
Original[Mode].Blink->Flink = &Copy[Mode];
|
2006-09-11 00:54:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
2006-09-11 01:30:24 +00:00
|
|
|
NTAPI
|
2006-09-11 00:54:12 +00:00
|
|
|
KiMoveApcState(PKAPC_STATE OldState,
|
|
|
|
PKAPC_STATE NewState)
|
|
|
|
{
|
|
|
|
/* Restore backup of Original Environment */
|
2007-09-09 13:00:14 +00:00
|
|
|
RtlCopyMemory(NewState, OldState, KAPC_STATE_ACTUAL_LENGTH);
|
2006-09-11 00:54:12 +00:00
|
|
|
|
|
|
|
/* Repair Lists */
|
2008-07-20 22:48:06 +00:00
|
|
|
RepairList(OldState->ApcListHead, NewState->ApcListHead, KernelMode);
|
|
|
|
RepairList(OldState->ApcListHead, NewState->ApcListHead, UserMode);
|
2006-09-11 00:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
|
|
|
|
2005-03-12 22:31:22 +00:00
|
|
|
/*++
|
2006-09-11 00:54:12 +00:00
|
|
|
* @name KeEnterCriticalRegion
|
|
|
|
* @implemented NT4
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
2006-09-11 00:54:12 +00:00
|
|
|
* The KeEnterCriticalRegion routine temporarily disables the delivery of
|
|
|
|
* normal kernel APCs; special kernel-mode APCs are still delivered.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
2006-09-11 00:54:12 +00:00
|
|
|
* @param None.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
2006-09-11 00:54:12 +00:00
|
|
|
* @return None.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
2006-09-11 00:54:12 +00:00
|
|
|
* @remarks Highest-level drivers can call this routine while running in the
|
|
|
|
* context of the thread that requested the current I/O operation.
|
|
|
|
* Any caller of this routine should call KeLeaveCriticalRegion as
|
|
|
|
* quickly as possible.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
2006-09-11 00:54:12 +00:00
|
|
|
* Callers of KeEnterCriticalRegion must be running at IRQL <=
|
|
|
|
* APC_LEVEL.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
2006-09-11 00:54:12 +00:00
|
|
|
NTAPI
|
|
|
|
_KeEnterCriticalRegion(VOID)
|
2004-11-10 02:51:00 +00:00
|
|
|
{
|
2006-09-11 00:54:12 +00:00
|
|
|
/* Use inlined function */
|
|
|
|
KeEnterCriticalRegion();
|
2004-11-10 02:51:00 +00:00
|
|
|
}
|
|
|
|
|
2005-03-12 22:31:22 +00:00
|
|
|
/*++
|
2006-09-11 00:54:12 +00:00
|
|
|
* KeLeaveCriticalRegion
|
2005-03-12 22:31:22 +00:00
|
|
|
* @implemented NT4
|
2005-05-09 01:38:29 +00:00
|
|
|
*
|
2006-09-11 00:54:12 +00:00
|
|
|
* The KeLeaveCriticalRegion routine reenables the delivery of normal
|
|
|
|
* kernel-mode APCs that were disabled by a call to KeEnterCriticalRegion.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
2006-09-11 00:54:12 +00:00
|
|
|
* @param None.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
2006-09-11 00:54:12 +00:00
|
|
|
* @return None.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
2006-09-11 00:54:12 +00:00
|
|
|
* @remarks Highest-level drivers can call this routine while running in the
|
|
|
|
* context of the thread that requested the current I/O operation.
|
|
|
|
*
|
|
|
|
* Callers of KeLeaveCriticalRegion must be running at IRQL <=
|
|
|
|
* DISPATCH_LEVEL.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
_KeLeaveCriticalRegion(VOID)
|
|
|
|
{
|
|
|
|
/* Use inlined version */
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
|
|
|
* KeInitializeApc
|
|
|
|
* @implemented NT4
|
|
|
|
*
|
2008-09-28 20:53:51 +00:00
|
|
|
* The KeInitializeApc routine initializes an APC object, and registers
|
2006-09-11 00:54:12 +00:00
|
|
|
* the Kernel, Rundown and Normal routines for that object.
|
|
|
|
*
|
2006-09-11 02:28:09 +00:00
|
|
|
* @param Apc
|
|
|
|
* Pointer to a KAPC structure that represents the APC object to
|
|
|
|
* initialize. The caller must allocate storage for the structure
|
|
|
|
* from resident memory.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:28:09 +00:00
|
|
|
* @param Thread
|
|
|
|
* Thread to which to deliver the APC.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:28:09 +00:00
|
|
|
* @param TargetEnvironment
|
|
|
|
* APC Environment to be used.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:28:09 +00:00
|
|
|
* @param KernelRoutine
|
|
|
|
* Points to the KernelRoutine to associate with the APC.
|
|
|
|
* This routine is executed for all APCs.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:28:09 +00:00
|
|
|
* @param RundownRoutine
|
|
|
|
* Points to the RundownRoutine to associate with the APC.
|
2008-09-28 20:53:51 +00:00
|
|
|
* This routine is executed when the Thread exits during APC execution.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:28:09 +00:00
|
|
|
* @param NormalRoutine
|
|
|
|
* Points to the NormalRoutine to associate with the APC.
|
|
|
|
* This routine is executed at PASSIVE_LEVEL. If this is not specifed,
|
|
|
|
* the APC becomes a Special APC and the Mode and Context parameters are
|
|
|
|
* ignored.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:28:09 +00:00
|
|
|
* @param Mode
|
|
|
|
* Specifies the processor mode at which to run the Normal Routine.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:28:09 +00:00
|
|
|
* @param Context
|
|
|
|
* Specifices the value to pass as Context parameter to the registered
|
|
|
|
* routines.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:28:09 +00:00
|
|
|
* @return None.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:28:09 +00:00
|
|
|
* @remarks The caller can queue an initialized APC with KeInsertQueueApc.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
VOID
|
2006-09-11 02:28:09 +00:00
|
|
|
NTAPI
|
2006-09-11 00:54:12 +00:00
|
|
|
KeInitializeApc(IN PKAPC Apc,
|
|
|
|
IN PKTHREAD Thread,
|
|
|
|
IN KAPC_ENVIRONMENT TargetEnvironment,
|
|
|
|
IN PKKERNEL_ROUTINE KernelRoutine,
|
|
|
|
IN PKRUNDOWN_ROUTINE RundownRoutine OPTIONAL,
|
|
|
|
IN PKNORMAL_ROUTINE NormalRoutine,
|
|
|
|
IN KPROCESSOR_MODE Mode,
|
|
|
|
IN PVOID Context)
|
|
|
|
{
|
2006-09-11 02:28:09 +00:00
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(TargetEnvironment <= InsertApcEnvironment);
|
2006-09-11 00:54:12 +00:00
|
|
|
|
|
|
|
/* Set up the basic APC Structure Data */
|
|
|
|
Apc->Type = ApcObject;
|
|
|
|
Apc->Size = sizeof(KAPC);
|
|
|
|
|
|
|
|
/* Set the Environment */
|
2006-09-11 02:28:09 +00:00
|
|
|
if (TargetEnvironment == CurrentApcEnvironment)
|
|
|
|
{
|
|
|
|
/* Use the current one for the thread */
|
2006-09-11 00:54:12 +00:00
|
|
|
Apc->ApcStateIndex = Thread->ApcStateIndex;
|
2006-09-11 02:28:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT((TargetEnvironment <= Thread->ApcStateIndex) ||
|
|
|
|
(TargetEnvironment == InsertApcEnvironment));
|
2006-09-11 00:54:12 +00:00
|
|
|
|
2006-09-11 02:28:09 +00:00
|
|
|
/* Use the one that was given */
|
2006-09-11 00:54:12 +00:00
|
|
|
Apc->ApcStateIndex = TargetEnvironment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the Thread and Routines */
|
|
|
|
Apc->Thread = Thread;
|
|
|
|
Apc->KernelRoutine = KernelRoutine;
|
|
|
|
Apc->RundownRoutine = RundownRoutine;
|
|
|
|
Apc->NormalRoutine = NormalRoutine;
|
|
|
|
|
2006-09-11 02:28:09 +00:00
|
|
|
/* Check if this is a special APC */
|
|
|
|
if (NormalRoutine)
|
|
|
|
{
|
|
|
|
/* It's a normal one. Set the context and mode */
|
2006-09-11 00:54:12 +00:00
|
|
|
Apc->ApcMode = Mode;
|
|
|
|
Apc->NormalContext = Context;
|
2006-09-11 02:28:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* It's a special APC, which can only be kernel mode */
|
2006-09-11 00:54:12 +00:00
|
|
|
Apc->ApcMode = KernelMode;
|
2006-09-11 02:28:09 +00:00
|
|
|
Apc->NormalContext = NULL;
|
2006-09-11 00:54:12 +00:00
|
|
|
}
|
2006-09-11 02:28:09 +00:00
|
|
|
|
2008-09-28 20:53:51 +00:00
|
|
|
/* The APC is not inserted */
|
2006-09-11 02:28:09 +00:00
|
|
|
Apc->Inserted = FALSE;
|
2006-09-11 00:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
2006-09-11 02:17:57 +00:00
|
|
|
* @name KeInsertQueueApc
|
2006-09-11 00:54:12 +00:00
|
|
|
* @implemented NT4
|
|
|
|
*
|
|
|
|
* The KeInsertQueueApc routine queues a APC for execution when the right
|
|
|
|
* scheduler environment exists.
|
|
|
|
*
|
2006-09-11 02:17:57 +00:00
|
|
|
* @param Apc
|
2008-09-28 20:53:51 +00:00
|
|
|
* Pointer to an initialized control object of type APC for which the
|
2006-09-11 02:17:57 +00:00
|
|
|
* caller provides the storage.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:17:57 +00:00
|
|
|
* @param SystemArgument[1,2]
|
|
|
|
* Pointer to a set of two parameters that contain untyped data.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:17:57 +00:00
|
|
|
* @param PriorityBoost
|
|
|
|
* Priority Boost to apply to the Thread.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:17:57 +00:00
|
|
|
* @return If the APC is already inserted or APC queueing is disabled, FALSE.
|
|
|
|
* Otherwise, TRUE.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:17:57 +00:00
|
|
|
* @remarks The APC will execute at APC_LEVEL for the KernelRoutine registered,
|
|
|
|
* and at PASSIVE_LEVEL for the NormalRoutine registered.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:17:57 +00:00
|
|
|
* Callers of this routine must be running at IRQL <= DISPATCH_LEVEL.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
BOOLEAN
|
2006-09-11 02:17:57 +00:00
|
|
|
NTAPI
|
|
|
|
KeInsertQueueApc(IN PKAPC Apc,
|
|
|
|
IN PVOID SystemArgument1,
|
|
|
|
IN PVOID SystemArgument2,
|
|
|
|
IN KPRIORITY PriorityBoost)
|
2006-09-11 00:54:12 +00:00
|
|
|
{
|
|
|
|
PKTHREAD Thread = Apc->Thread;
|
|
|
|
KLOCK_QUEUE_HANDLE ApcLock;
|
|
|
|
BOOLEAN State = TRUE;
|
2006-09-11 02:17:57 +00:00
|
|
|
ASSERT_APC(Apc);
|
|
|
|
ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
|
2006-09-11 00:54:12 +00:00
|
|
|
|
|
|
|
/* Get the APC lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireApcLockRaiseToSynch(Thread, &ApcLock);
|
2006-09-11 00:54:12 +00:00
|
|
|
|
|
|
|
/* Make sure we can Queue APCs and that this one isn't already inserted */
|
2008-07-20 23:00:18 +00:00
|
|
|
if (!(Thread->ApcQueueable) || (Apc->Inserted))
|
2006-09-11 00:54:12 +00:00
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
State = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Set the System Arguments and set it as inserted */
|
|
|
|
Apc->SystemArgument1 = SystemArgument1;
|
|
|
|
Apc->SystemArgument2 = SystemArgument2;
|
|
|
|
Apc->Inserted = TRUE;
|
|
|
|
|
|
|
|
/* Call the Internal Function */
|
|
|
|
KiInsertQueueApc(Apc, PriorityBoost);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the APC lock and return success */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseApcLockFromSynchLevel(&ApcLock);
|
2006-09-11 00:54:12 +00:00
|
|
|
KiExitDispatcher(ApcLock.OldIrql);
|
|
|
|
return State;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
2006-09-11 02:17:57 +00:00
|
|
|
* @name KeFlushQueueApc
|
|
|
|
* @implemented NT4
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
|
|
|
* The KeFlushQueueApc routine flushes all APCs of the given processor mode
|
|
|
|
* from the specified Thread's APC queue.
|
|
|
|
*
|
2006-09-11 02:17:57 +00:00
|
|
|
* @param Thread
|
|
|
|
* Pointer to the thread whose APC queue will be flushed.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2008-09-28 20:53:51 +00:00
|
|
|
* @param PreviousMode
|
2006-09-11 02:17:57 +00:00
|
|
|
* Specifies which APC Queue to flush.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:17:57 +00:00
|
|
|
* @return A pointer to the first entry in the flushed APC queue.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 02:17:57 +00:00
|
|
|
* @remarks If the routine returns NULL, it means that no APCs were flushed.
|
|
|
|
* Callers of this routine must be running at DISPATCH_LEVEL or lower.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
PLIST_ENTRY
|
2006-09-11 02:09:13 +00:00
|
|
|
NTAPI
|
2006-09-11 00:54:12 +00:00
|
|
|
KeFlushQueueApc(IN PKTHREAD Thread,
|
|
|
|
IN KPROCESSOR_MODE PreviousMode)
|
|
|
|
{
|
|
|
|
PKAPC Apc;
|
|
|
|
PLIST_ENTRY FirstEntry, CurrentEntry;
|
|
|
|
KLOCK_QUEUE_HANDLE ApcLock;
|
2006-09-11 02:09:13 +00:00
|
|
|
ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
|
2006-09-11 00:54:12 +00:00
|
|
|
|
2006-09-11 02:09:13 +00:00
|
|
|
/* Check if this was user mode */
|
|
|
|
if (PreviousMode == UserMode)
|
|
|
|
{
|
|
|
|
/* Get the APC lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireApcLockRaiseToSynch(Thread, &ApcLock);
|
2006-09-11 00:54:12 +00:00
|
|
|
|
2006-09-11 02:09:13 +00:00
|
|
|
/* Select user list and check if it's empty */
|
|
|
|
if (IsListEmpty(&Thread->ApcState.ApcListHead[UserMode]))
|
|
|
|
{
|
|
|
|
/* Don't return anything */
|
|
|
|
FirstEntry = NULL;
|
|
|
|
goto FlushDone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Select kernel list and check if it's empty */
|
|
|
|
if (IsListEmpty( &Thread->ApcState.ApcListHead[KernelMode]))
|
|
|
|
{
|
|
|
|
/* Don't return anything */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, acquire the APC lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireApcLockRaiseToSynch(Thread, &ApcLock);
|
2006-09-11 02:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the first entry and check if the list is empty now */
|
|
|
|
FirstEntry = Thread->ApcState.ApcListHead[PreviousMode].Flink;
|
|
|
|
if (FirstEntry == &Thread->ApcState.ApcListHead[PreviousMode])
|
|
|
|
{
|
|
|
|
/* It is, clear the returned entry */
|
2006-09-11 00:54:12 +00:00
|
|
|
FirstEntry = NULL;
|
2006-09-11 02:09:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* It's not, remove the first entry */
|
2006-09-11 00:54:12 +00:00
|
|
|
RemoveEntryList(&Thread->ApcState.ApcListHead[PreviousMode]);
|
2006-09-11 02:09:13 +00:00
|
|
|
|
|
|
|
/* Loop all the entries */
|
2006-09-11 00:54:12 +00:00
|
|
|
CurrentEntry = FirstEntry;
|
2006-09-11 02:09:13 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Get the APC and make it un-inserted */
|
2006-09-11 00:54:12 +00:00
|
|
|
Apc = CONTAINING_RECORD(CurrentEntry, KAPC, ApcListEntry);
|
|
|
|
Apc->Inserted = FALSE;
|
2006-09-11 02:09:13 +00:00
|
|
|
|
|
|
|
/* Get the next entry */
|
2006-09-11 00:54:12 +00:00
|
|
|
CurrentEntry = CurrentEntry->Flink;
|
|
|
|
} while (CurrentEntry != FirstEntry);
|
2006-09-11 02:09:13 +00:00
|
|
|
|
|
|
|
/* Re-initialize the list */
|
|
|
|
InitializeListHead(&Thread->ApcState.ApcListHead[PreviousMode]);
|
2006-09-11 00:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the lock */
|
2006-09-11 02:09:13 +00:00
|
|
|
FlushDone:
|
2006-09-11 00:54:12 +00:00
|
|
|
KiReleaseApcLock(&ApcLock);
|
|
|
|
|
|
|
|
/* Return the first entry */
|
|
|
|
return FirstEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
2006-09-11 01:45:11 +00:00
|
|
|
* @name KeRemoveQueueApc
|
|
|
|
* @implemented NT4
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
|
|
|
* The KeRemoveQueueApc routine removes a given APC object from the system
|
|
|
|
* APC queue.
|
|
|
|
*
|
2008-09-28 20:53:51 +00:00
|
|
|
* @param Apc
|
2006-09-11 01:45:11 +00:00
|
|
|
* Pointer to an initialized APC object that was queued by calling
|
|
|
|
* KeInsertQueueApc.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 01:45:11 +00:00
|
|
|
* @return TRUE if the APC Object is in the APC Queue. Otherwise, no operation
|
|
|
|
* is performed and FALSE is returned.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 01:45:11 +00:00
|
|
|
* @remarks If the given APC Object is currently queued, it is removed from the
|
|
|
|
* queue and any calls to the registered routines are cancelled.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 01:45:11 +00:00
|
|
|
* Callers of this routine must be running at IRQL <= DISPATCH_LEVEL.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
BOOLEAN
|
2006-09-11 01:45:11 +00:00
|
|
|
NTAPI
|
|
|
|
KeRemoveQueueApc(IN PKAPC Apc)
|
2006-09-11 00:54:12 +00:00
|
|
|
{
|
|
|
|
PKTHREAD Thread = Apc->Thread;
|
|
|
|
PKAPC_STATE ApcState;
|
|
|
|
BOOLEAN Inserted;
|
|
|
|
KLOCK_QUEUE_HANDLE ApcLock;
|
2006-09-11 01:45:11 +00:00
|
|
|
ASSERT_APC(Apc);
|
|
|
|
ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
|
2006-09-11 00:54:12 +00:00
|
|
|
|
2019-12-30 14:34:38 +00:00
|
|
|
/* Get the APC lock (this raises IRQL to SYNCH_LEVEL) */
|
|
|
|
KiAcquireApcLockRaiseToSynch(Thread, &ApcLock);
|
2006-09-11 00:54:12 +00:00
|
|
|
|
|
|
|
/* Check if it's inserted */
|
2006-09-11 01:45:11 +00:00
|
|
|
Inserted = Apc->Inserted;
|
|
|
|
if (Inserted)
|
2006-09-11 00:54:12 +00:00
|
|
|
{
|
2006-09-11 01:45:11 +00:00
|
|
|
/* Set it as non-inserted and get the APC state */
|
2006-09-11 00:54:12 +00:00
|
|
|
Apc->Inserted = FALSE;
|
2006-09-11 03:14:26 +00:00
|
|
|
ApcState = Thread->ApcStatePointer[(UCHAR)Apc->ApcStateIndex];
|
2006-09-11 01:45:11 +00:00
|
|
|
|
|
|
|
/* Acquire the dispatcher lock and remove it from the list */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireDispatcherLockAtSynchLevel();
|
2008-06-28 19:23:23 +00:00
|
|
|
if (RemoveEntryList(&Apc->ApcListEntry))
|
2006-09-11 00:54:12 +00:00
|
|
|
{
|
2006-09-11 01:45:11 +00:00
|
|
|
/* Set the correct state based on the APC Mode */
|
2006-09-11 00:54:12 +00:00
|
|
|
if (Apc->ApcMode == KernelMode)
|
|
|
|
{
|
2006-09-11 01:45:11 +00:00
|
|
|
/* No more pending kernel APCs */
|
2006-09-11 00:54:12 +00:00
|
|
|
ApcState->KernelApcPending = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-09-11 01:45:11 +00:00
|
|
|
/* No more pending user APCs */
|
2006-09-11 00:54:12 +00:00
|
|
|
ApcState->UserApcPending = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2006-09-11 01:45:11 +00:00
|
|
|
|
|
|
|
/* Release dispatcher lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseDispatcherLockFromSynchLevel();
|
2006-09-11 00:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the lock and return */
|
|
|
|
KiReleaseApcLock(&ApcLock);
|
|
|
|
return Inserted;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*++
|
2006-09-11 01:30:24 +00:00
|
|
|
* @name KeAreApcsDisabled
|
2006-09-11 00:54:12 +00:00
|
|
|
* @implemented NT4
|
|
|
|
*
|
2006-09-11 01:30:24 +00:00
|
|
|
* The KeAreApcsDisabled routine returns whether kernel APC delivery is
|
|
|
|
* disabled for the current thread.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 01:30:24 +00:00
|
|
|
* @param None.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 01:30:24 +00:00
|
|
|
* @return KeAreApcsDisabled returns TRUE if the thread is within a critical
|
|
|
|
* region or a guarded region, and FALSE otherwise.
|
2006-09-11 00:54:12 +00:00
|
|
|
*
|
2006-09-11 01:30:24 +00:00
|
|
|
* @remarks A thread running at IRQL = PASSIVE_LEVEL can use KeAreApcsDisabled
|
2008-09-28 20:53:51 +00:00
|
|
|
* to determine if normal kernel APCs are disabled.
|
2006-09-11 01:30:24 +00:00
|
|
|
*
|
|
|
|
* A thread that is inside critical region has both user APCs and
|
|
|
|
* normal kernel APCs disabled, but not special kernel APCs.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
2006-09-11 01:30:24 +00:00
|
|
|
* A thread that is inside a guarded region has all APCs disabled,
|
|
|
|
* including special kernel APCs.
|
|
|
|
*
|
|
|
|
* Callers of this routine must be running at IRQL <= DISPATCH_LEVEL.
|
2005-03-12 22:31:22 +00:00
|
|
|
*
|
|
|
|
*--*/
|
2004-11-10 02:51:00 +00:00
|
|
|
BOOLEAN
|
2006-09-11 01:30:24 +00:00
|
|
|
NTAPI
|
2005-03-12 22:31:22 +00:00
|
|
|
KeAreApcsDisabled(VOID)
|
2004-11-10 02:51:00 +00:00
|
|
|
{
|
2005-03-12 22:31:22 +00:00
|
|
|
/* Return the Kernel APC State */
|
2005-09-27 01:57:27 +00:00
|
|
|
return KeGetCurrentThread()->CombinedApcDisable ? TRUE : FALSE;
|
1998-08-28 23:24:42 +00:00
|
|
|
}
|
|
|
|
|
2006-09-11 01:30:24 +00:00
|
|
|
/*++
|
|
|
|
* @name KeAreAllApcsDisabled
|
|
|
|
* @implemented NT5.1
|
|
|
|
*
|
|
|
|
* The KeAreAllApcsDisabled routine returns whether the calling thread is
|
2008-09-28 20:53:51 +00:00
|
|
|
* inside a guarded region or running at IRQL >= APC_LEVEL, which disables
|
2006-09-11 01:30:24 +00:00
|
|
|
* all APC delivery.
|
|
|
|
*
|
|
|
|
* @param None.
|
|
|
|
*
|
|
|
|
* @return KeAreAllApcsDisabled returns TRUE if the thread is within a guarded
|
|
|
|
* guarded region or running at IRQL >= APC_LEVEL, and FALSE otherwise.
|
|
|
|
*
|
|
|
|
* @remarks A thread running at IRQL = PASSIVE_LEVEL can use this routine to
|
2008-09-28 20:53:51 +00:00
|
|
|
* determine if all APC delivery is disabled.
|
2006-09-11 01:30:24 +00:00
|
|
|
*
|
|
|
|
* Callers of this routine must be running at IRQL <= DISPATCH_LEVEL.
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
KeAreAllApcsDisabled(VOID)
|
|
|
|
{
|
|
|
|
/* Return the Special APC State */
|
|
|
|
return ((KeGetCurrentThread()->SpecialApcDisable) ||
|
|
|
|
(KeGetCurrentIrql() >= APC_LEVEL)) ? TRUE : FALSE;
|
|
|
|
}
|