2005-03-12 18:10:03 +00:00
|
|
|
/*
|
2005-12-04 03:24:11 +00:00
|
|
|
* PROJECT: ReactOS Kernel
|
2006-09-10 20:23:02 +00:00
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2015-10-04 11:54:25 +00:00
|
|
|
* FILE: ntoskrnl/ke/procobj.c
|
2005-12-04 03:24:11 +00:00
|
|
|
* PURPOSE: Kernel Process Management and System Call Tables
|
|
|
|
* PROGRAMMERS: Alex Ionescu
|
|
|
|
* Gregor Anich
|
1999-03-30 12:55:31 +00:00
|
|
|
*/
|
|
|
|
|
2006-09-10 20:23:02 +00:00
|
|
|
/* INCLUDES ******************************************************************/
|
1999-03-30 12:55:31 +00:00
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
1999-04-10 12:08:24 +00:00
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
1999-03-30 12:55:31 +00:00
|
|
|
|
2006-09-03 21:06:30 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
2005-03-12 18:10:03 +00:00
|
|
|
|
2006-09-02 04:40:09 +00:00
|
|
|
LIST_ENTRY KiProcessListHead;
|
|
|
|
LIST_ENTRY KiProcessInSwapListHead, KiProcessOutSwapListHead;
|
|
|
|
LIST_ENTRY KiStackInSwapListHead;
|
|
|
|
KEVENT KiSwapEvent;
|
2005-03-12 18:10:03 +00:00
|
|
|
|
2006-09-02 04:40:09 +00:00
|
|
|
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[SSDT_MAX_ENTRIES];
|
|
|
|
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES];
|
2005-03-12 18:10:03 +00:00
|
|
|
|
2006-09-03 21:06:30 +00:00
|
|
|
PVOID KeUserApcDispatcher;
|
|
|
|
PVOID KeUserCallbackDispatcher;
|
|
|
|
PVOID KeUserExceptionDispatcher;
|
|
|
|
PVOID KeRaiseUserExceptionDispatcher;
|
|
|
|
|
2006-09-10 20:23:02 +00:00
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
1999-03-30 12:55:31 +00:00
|
|
|
|
2005-12-04 03:24:11 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
2006-09-10 23:17:22 +00:00
|
|
|
KiAttachProcess(IN PKTHREAD Thread,
|
|
|
|
IN PKPROCESS Process,
|
|
|
|
IN PKLOCK_QUEUE_HANDLE ApcLock,
|
|
|
|
IN PRKAPC_STATE SavedApcState)
|
2005-04-18 02:12:30 +00:00
|
|
|
{
|
2006-09-16 21:21:05 +00:00
|
|
|
#if 0
|
2006-09-14 12:13:32 +00:00
|
|
|
PLIST_ENTRY ListHead, NextEntry;
|
|
|
|
PKTHREAD CurrentThread;
|
2006-09-16 21:21:05 +00:00
|
|
|
#endif
|
2005-12-04 03:24:11 +00:00
|
|
|
ASSERT(Process != Thread->ApcState.Process);
|
|
|
|
|
|
|
|
/* Increase Stack Count */
|
2006-09-10 20:23:02 +00:00
|
|
|
ASSERT(Process->StackCount != MAXULONG_PTR);
|
2005-12-04 03:24:11 +00:00
|
|
|
Process->StackCount++;
|
|
|
|
|
|
|
|
/* Swap the APC Environment */
|
|
|
|
KiMoveApcState(&Thread->ApcState, SavedApcState);
|
|
|
|
|
|
|
|
/* Reinitialize Apc State */
|
|
|
|
InitializeListHead(&Thread->ApcState.ApcListHead[KernelMode]);
|
|
|
|
InitializeListHead(&Thread->ApcState.ApcListHead[UserMode]);
|
|
|
|
Thread->ApcState.Process = Process;
|
|
|
|
Thread->ApcState.KernelApcInProgress = FALSE;
|
|
|
|
Thread->ApcState.KernelApcPending = FALSE;
|
|
|
|
Thread->ApcState.UserApcPending = FALSE;
|
|
|
|
|
|
|
|
/* Update Environment Pointers if needed*/
|
|
|
|
if (SavedApcState == &Thread->SavedApcState)
|
|
|
|
{
|
2006-09-10 20:23:02 +00:00
|
|
|
Thread->ApcStatePointer[OriginalApcEnvironment] = &Thread->
|
|
|
|
SavedApcState;
|
2005-12-04 03:24:11 +00:00
|
|
|
Thread->ApcStatePointer[AttachedApcEnvironment] = &Thread->ApcState;
|
|
|
|
Thread->ApcStateIndex = AttachedApcEnvironment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the process is paged in */
|
|
|
|
if (Process->State == ProcessInMemory)
|
|
|
|
{
|
2006-09-14 12:13:32 +00:00
|
|
|
/* Scan the ready list */
|
2006-09-16 20:27:53 +00:00
|
|
|
#if 0
|
2006-09-14 12:13:32 +00:00
|
|
|
ListHead = &Process->ReadyListHead;
|
|
|
|
NextEntry = ListHead->Flink;
|
|
|
|
while (NextEntry != ListHead)
|
|
|
|
{
|
|
|
|
/* Get the thread */
|
|
|
|
CurrentThread = CONTAINING_RECORD(NextEntry, KTHREAD, WaitListEntry);
|
|
|
|
|
|
|
|
/* Remove it */
|
|
|
|
RemoveEntryList(NextEntry);
|
|
|
|
CurrentThread->ProcessReadyQueue = FALSE;
|
|
|
|
|
|
|
|
/* Mark it ready */
|
|
|
|
KiReadyThread(CurrentThread);
|
|
|
|
|
|
|
|
/* Go to the next one */
|
|
|
|
NextEntry = ListHead->Flink;
|
|
|
|
}
|
2006-09-16 20:27:53 +00:00
|
|
|
#endif
|
2005-12-04 03:24:11 +00:00
|
|
|
|
2006-09-10 23:41:08 +00:00
|
|
|
/* Release dispatcher lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseDispatcherLockFromSynchLevel();
|
2006-09-10 23:41:08 +00:00
|
|
|
|
2006-09-10 18:26:50 +00:00
|
|
|
/* Release lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseApcLockFromSynchLevel(ApcLock);
|
2006-09-10 18:26:50 +00:00
|
|
|
|
|
|
|
/* Swap Processes */
|
2005-12-04 03:24:11 +00:00
|
|
|
KiSwapProcess(Process, SavedApcState->Process);
|
|
|
|
|
2006-09-10 18:26:50 +00:00
|
|
|
/* Exit the dispatcher */
|
|
|
|
KiExitDispatcher(ApcLock->OldIrql);
|
2005-12-04 03:24:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DPRINT1("Errr. ReactOS doesn't support paging out processes yet...\n");
|
2006-09-10 20:23:02 +00:00
|
|
|
ASSERT(FALSE);
|
2005-12-04 03:24:11 +00:00
|
|
|
}
|
2005-04-18 02:12:30 +00:00
|
|
|
}
|
|
|
|
|
2005-04-18 00:42:31 +00:00
|
|
|
VOID
|
2005-12-04 03:24:11 +00:00
|
|
|
NTAPI
|
2006-07-17 01:40:10 +00:00
|
|
|
KeInitializeProcess(IN OUT PKPROCESS Process,
|
|
|
|
IN KPRIORITY Priority,
|
|
|
|
IN KAFFINITY Affinity,
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
IN PULONG_PTR DirectoryTableBase,
|
2006-09-10 23:17:22 +00:00
|
|
|
IN BOOLEAN Enable)
|
2005-04-18 00:42:31 +00:00
|
|
|
{
|
2006-09-10 23:17:22 +00:00
|
|
|
#ifdef CONFIG_SMP
|
2006-07-17 01:40:10 +00:00
|
|
|
ULONG i = 0;
|
|
|
|
UCHAR IdealNode = 0;
|
|
|
|
PKNODE Node;
|
2006-09-10 23:17:22 +00:00
|
|
|
#endif
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-04-18 00:42:31 +00:00
|
|
|
/* Initialize the Dispatcher Header */
|
2011-10-07 16:18:52 +00:00
|
|
|
Process->Header.Type = ProcessObject;
|
|
|
|
Process->Header.Size = sizeof(KPROCESS) / sizeof(ULONG);
|
|
|
|
Process->Header.SignalState = 0;
|
|
|
|
InitializeListHead(&(Process->Header.WaitListHead));
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-17 01:40:10 +00:00
|
|
|
/* Initialize Scheduler Data, Alignment Faults and Set the PDE */
|
2005-04-18 00:42:31 +00:00
|
|
|
Process->Affinity = Affinity;
|
2006-07-17 01:40:10 +00:00
|
|
|
Process->BasePriority = (CHAR)Priority;
|
2005-05-05 22:40:05 +00:00
|
|
|
Process->QuantumReset = 6;
|
2008-08-11 08:40:52 +00:00
|
|
|
Process->DirectoryTableBase[0] = DirectoryTableBase[0];
|
|
|
|
Process->DirectoryTableBase[1] = DirectoryTableBase[1];
|
2006-09-10 23:17:22 +00:00
|
|
|
Process->AutoAlignment = Enable;
|
2007-03-26 20:28:13 +00:00
|
|
|
#if defined(_M_IX86)
|
2006-09-10 23:17:22 +00:00
|
|
|
Process->IopmOffset = KiComputeIopmOffset(IO_ACCESS_MAP_NONE);
|
2007-03-26 20:28:13 +00:00
|
|
|
#endif
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-17 01:40:10 +00:00
|
|
|
/* Initialize the lists */
|
2005-05-09 01:38:29 +00:00
|
|
|
InitializeListHead(&Process->ThreadListHead);
|
2006-07-17 01:40:10 +00:00
|
|
|
InitializeListHead(&Process->ProfileListHead);
|
|
|
|
InitializeListHead(&Process->ReadyListHead);
|
|
|
|
|
|
|
|
/* Initialize the current State */
|
|
|
|
Process->State = ProcessInMemory;
|
|
|
|
|
|
|
|
/* Check how many Nodes there are on the system */
|
2006-09-10 23:17:22 +00:00
|
|
|
#ifdef CONFIG_SMP
|
2006-07-17 01:40:10 +00:00
|
|
|
if (KeNumberNodes > 1)
|
|
|
|
{
|
|
|
|
/* Set the new seed */
|
|
|
|
KeProcessNodeSeed = (KeProcessNodeSeed + 1) / KeNumberNodes;
|
|
|
|
IdealNode = KeProcessNodeSeed;
|
|
|
|
|
|
|
|
/* Loop every node */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Check if the affinity matches */
|
|
|
|
if (KeNodeBlock[IdealNode]->ProcessorMask != Affinity) break;
|
|
|
|
|
|
|
|
/* No match, try next Ideal Node and increase node loop index */
|
|
|
|
IdealNode++;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
/* Check if the Ideal Node is beyond the total number of nodes */
|
|
|
|
if (IdealNode >= KeNumberNodes)
|
|
|
|
{
|
|
|
|
/* Normalize the Ideal Node */
|
|
|
|
IdealNode -= KeNumberNodes;
|
|
|
|
}
|
|
|
|
} while (i < KeNumberNodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the ideal node and get the ideal node block */
|
|
|
|
Process->IdealNode = IdealNode;
|
|
|
|
Node = KeNodeBlock[IdealNode];
|
|
|
|
ASSERT(Node->ProcessorMask & Affinity);
|
|
|
|
|
|
|
|
/* Find the matching affinity set to calculate the thread seed */
|
|
|
|
Affinity &= Node->ProcessorMask;
|
|
|
|
Process->ThreadSeed = KeFindNextRightSetAffinity(Node->Seed,
|
|
|
|
(ULONG)Affinity);
|
|
|
|
Node->Seed = Process->ThreadSeed;
|
2006-09-10 23:17:22 +00:00
|
|
|
#endif
|
2005-04-18 00:42:31 +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
|
|
|
ULONG
|
2005-12-04 03:24:11 +00:00
|
|
|
NTAPI
|
2006-09-10 23:17:22 +00:00
|
|
|
KeSetProcess(IN PKPROCESS Process,
|
|
|
|
IN KPRIORITY Increment,
|
|
|
|
IN BOOLEAN InWait)
|
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
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
|
|
|
ULONG OldState;
|
2006-09-10 20:23:02 +00:00
|
|
|
ASSERT_PROCESS(Process);
|
|
|
|
ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
|
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
|
|
|
/* Lock Dispatcher */
|
2006-09-10 18:26:50 +00:00
|
|
|
OldIrql = KiAcquireDispatcherLock();
|
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
|
|
|
/* Get Old State */
|
2005-05-05 22:40:05 +00:00
|
|
|
OldState = Process->Header.SignalState;
|
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
|
|
|
/* Signal the Process */
|
2005-05-05 22:40:05 +00:00
|
|
|
Process->Header.SignalState = TRUE;
|
2006-09-10 20:23:02 +00:00
|
|
|
|
|
|
|
/* Check if was unsignaled and has waiters */
|
|
|
|
if (!(OldState) &&
|
|
|
|
!(IsListEmpty(&Process->Header.WaitListHead)))
|
2005-12-04 03:24:11 +00:00
|
|
|
{
|
2006-09-14 03:49:20 +00:00
|
|
|
/* Unwait the threads */
|
|
|
|
KxUnwaitThread(&Process->Header, Increment);
|
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
|
|
|
|
|
|
|
/* Release Dispatcher Database */
|
2006-09-10 18:26:50 +00:00
|
|
|
KiReleaseDispatcherLock(OldIrql);
|
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
|
|
|
/* Return the previous State */
|
2005-05-09 01:38:29 +00:00
|
|
|
return OldState;
|
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-07-21 19:28:38 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KeSetQuantumProcess(IN PKPROCESS Process,
|
|
|
|
IN UCHAR Quantum)
|
|
|
|
{
|
2006-09-10 18:26:50 +00:00
|
|
|
KLOCK_QUEUE_HANDLE ProcessLock;
|
2006-07-21 19:28:38 +00:00
|
|
|
PLIST_ENTRY NextEntry, ListHead;
|
|
|
|
PKTHREAD Thread;
|
|
|
|
ASSERT_PROCESS(Process);
|
|
|
|
ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
|
|
|
|
|
2006-09-10 18:26:50 +00:00
|
|
|
/* Lock the process */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireProcessLockRaiseToSynch(Process, &ProcessLock);
|
2006-07-21 19:28:38 +00:00
|
|
|
|
|
|
|
/* Set new quantum */
|
|
|
|
Process->QuantumReset = Quantum;
|
|
|
|
|
|
|
|
/* Loop all child threads */
|
|
|
|
ListHead = &Process->ThreadListHead;
|
|
|
|
NextEntry = ListHead->Flink;
|
|
|
|
while (ListHead != NextEntry)
|
|
|
|
{
|
|
|
|
/* Get the thread */
|
|
|
|
Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
|
|
|
|
|
|
|
|
/* Set quantum */
|
|
|
|
Thread->QuantumReset = Quantum;
|
|
|
|
|
|
|
|
/* Go to the next one */
|
|
|
|
NextEntry = NextEntry->Flink;
|
|
|
|
}
|
|
|
|
|
2006-09-10 18:26:50 +00:00
|
|
|
/* Release lock */
|
|
|
|
KiReleaseProcessLock(&ProcessLock);
|
2006-07-21 19:28:38 +00:00
|
|
|
}
|
|
|
|
|
2011-12-18 04:27:20 +00:00
|
|
|
KAFFINITY
|
|
|
|
NTAPI
|
|
|
|
KeSetAffinityProcess(IN PKPROCESS Process,
|
|
|
|
IN KAFFINITY Affinity)
|
|
|
|
{
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2011-12-18 04:27:20 +00:00
|
|
|
KLOCK_QUEUE_HANDLE ProcessLock;
|
|
|
|
PLIST_ENTRY NextEntry, ListHead;
|
|
|
|
KAFFINITY OldAffinity;
|
|
|
|
PKTHREAD Thread;
|
|
|
|
ASSERT_PROCESS(Process);
|
|
|
|
ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
|
|
|
|
ASSERT((Affinity & KeActiveProcessors) != 0);
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2011-12-18 04:27:20 +00:00
|
|
|
/* Lock the process */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireProcessLockRaiseToSynch(Process, &ProcessLock);
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2011-12-18 04:27:20 +00:00
|
|
|
/* Acquire the dispatcher lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireDispatcherLockAtSynchLevel();
|
2011-12-18 04:27:20 +00:00
|
|
|
|
|
|
|
/* Capture old affinity and update it */
|
|
|
|
OldAffinity = Process->Affinity;
|
|
|
|
Process->Affinity = Affinity;
|
|
|
|
|
|
|
|
/* Loop all child threads */
|
|
|
|
ListHead = &Process->ThreadListHead;
|
|
|
|
NextEntry = ListHead->Flink;
|
|
|
|
while (ListHead != NextEntry)
|
|
|
|
{
|
|
|
|
/* Get the thread */
|
|
|
|
Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2011-12-18 04:27:20 +00:00
|
|
|
/* Set affinity on it */
|
|
|
|
KiSetAffinityThread(Thread, Affinity);
|
|
|
|
NextEntry = NextEntry->Flink;
|
|
|
|
}
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2011-12-18 04:27:20 +00:00
|
|
|
/* Release Dispatcher Database */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseDispatcherLockFromSynchLevel();
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2011-12-18 04:27:20 +00:00
|
|
|
/* Release the process lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseProcessLockFromSynchLevel(&ProcessLock);
|
2011-12-18 04:27:20 +00:00
|
|
|
KiExitDispatcher(ProcessLock.OldIrql);
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2011-12-18 04:27:20 +00:00
|
|
|
/* Return previous affinity */
|
|
|
|
return OldAffinity;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
KeSetAutoAlignmentProcess(IN PKPROCESS Process,
|
|
|
|
IN BOOLEAN Enable)
|
|
|
|
{
|
|
|
|
/* Set or reset the bit depending on what the enable flag says */
|
|
|
|
if (Enable)
|
|
|
|
{
|
|
|
|
return InterlockedBitTestAndSet(&Process->ProcessFlags,
|
|
|
|
KPSF_AUTO_ALIGNMENT_BIT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return InterlockedBitTestAndReset(&Process->ProcessFlags,
|
|
|
|
KPSF_AUTO_ALIGNMENT_BIT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
KeSetDisableBoostProcess(IN PKPROCESS Process,
|
|
|
|
IN BOOLEAN Disable)
|
|
|
|
{
|
|
|
|
/* Set or reset the bit depending on what the disable flag says */
|
|
|
|
if (Disable)
|
|
|
|
{
|
|
|
|
return InterlockedBitTestAndSet(&Process->ProcessFlags,
|
|
|
|
KPSF_DISABLE_BOOST_BIT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return InterlockedBitTestAndReset(&Process->ProcessFlags,
|
|
|
|
KPSF_DISABLE_BOOST_BIT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-21 19:28:38 +00:00
|
|
|
KPRIORITY
|
|
|
|
NTAPI
|
|
|
|
KeSetPriorityAndQuantumProcess(IN PKPROCESS Process,
|
|
|
|
IN KPRIORITY Priority,
|
|
|
|
IN UCHAR Quantum OPTIONAL)
|
|
|
|
{
|
2006-09-13 03:02:40 +00:00
|
|
|
KLOCK_QUEUE_HANDLE ProcessLock;
|
2006-07-21 19:28:38 +00:00
|
|
|
KPRIORITY Delta;
|
|
|
|
PLIST_ENTRY NextEntry, ListHead;
|
|
|
|
KPRIORITY NewPriority, OldPriority;
|
|
|
|
PKTHREAD Thread;
|
|
|
|
ASSERT_PROCESS(Process);
|
|
|
|
ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
|
|
|
|
|
|
|
|
/* Check if the process already has this priority */
|
2006-09-13 03:02:40 +00:00
|
|
|
if (Process->BasePriority == Priority) return Process->BasePriority;
|
2006-07-21 19:28:38 +00:00
|
|
|
|
|
|
|
/* If the caller gave priority 0, normalize to 1 */
|
2009-06-10 18:09:15 +00:00
|
|
|
if (!Priority) Priority = LOW_PRIORITY + 1;
|
2006-07-21 19:28:38 +00:00
|
|
|
|
2006-09-13 03:02:40 +00:00
|
|
|
/* Lock the process */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireProcessLockRaiseToSynch(Process, &ProcessLock);
|
2006-07-21 19:28:38 +00:00
|
|
|
|
2021-06-07 08:23:01 +00:00
|
|
|
/* Acquire the dispatcher lock */
|
|
|
|
KiAcquireDispatcherLockAtSynchLevel();
|
|
|
|
|
2006-07-21 19:28:38 +00:00
|
|
|
/* Check if we are modifying the quantum too */
|
|
|
|
if (Quantum) Process->QuantumReset = Quantum;
|
|
|
|
|
|
|
|
/* Save the current base priority and update it */
|
|
|
|
OldPriority = Process->BasePriority;
|
2007-08-04 08:49:47 +00:00
|
|
|
Process->BasePriority = (SCHAR)Priority;
|
2006-07-21 19:28:38 +00:00
|
|
|
|
|
|
|
/* Calculate the priority delta */
|
|
|
|
Delta = Priority - OldPriority;
|
|
|
|
|
|
|
|
/* Set the list head and list entry */
|
|
|
|
ListHead = &Process->ThreadListHead;
|
|
|
|
NextEntry = ListHead->Flink;
|
|
|
|
|
|
|
|
/* Check if this is a real-time priority */
|
|
|
|
if (Priority >= LOW_REALTIME_PRIORITY)
|
|
|
|
{
|
|
|
|
/* Loop the thread list */
|
|
|
|
while (NextEntry != ListHead)
|
|
|
|
{
|
|
|
|
/* Get the thread */
|
|
|
|
Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
|
|
|
|
|
|
|
|
/* Update the quantum if we had one */
|
|
|
|
if (Quantum) Thread->QuantumReset = Quantum;
|
|
|
|
|
2006-09-13 03:02:40 +00:00
|
|
|
/* Acquire the thread lock */
|
|
|
|
KiAcquireThreadLock(Thread);
|
|
|
|
|
2006-07-21 19:28:38 +00:00
|
|
|
/* Calculate the new priority */
|
|
|
|
NewPriority = Thread->BasePriority + Delta;
|
|
|
|
if (NewPriority < LOW_REALTIME_PRIORITY)
|
|
|
|
{
|
|
|
|
/* We're in real-time range, don't let it go below */
|
|
|
|
NewPriority = LOW_REALTIME_PRIORITY;
|
|
|
|
}
|
|
|
|
else if (NewPriority > HIGH_PRIORITY)
|
|
|
|
{
|
|
|
|
/* We're going beyond the maximum priority, normalize */
|
|
|
|
NewPriority = HIGH_PRIORITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If priority saturation occured or the old priority was still in
|
|
|
|
* the real-time range, don't do anything.
|
|
|
|
*/
|
|
|
|
if (!(Thread->Saturation) || (OldPriority < LOW_REALTIME_PRIORITY))
|
|
|
|
{
|
|
|
|
/* Check if we had priority saturation */
|
|
|
|
if (Thread->Saturation > 0)
|
|
|
|
{
|
|
|
|
/* Boost priority to maximum */
|
|
|
|
NewPriority = HIGH_PRIORITY;
|
|
|
|
}
|
|
|
|
else if (Thread->Saturation < 0)
|
|
|
|
{
|
|
|
|
/* If we had negative saturation, set minimum priority */
|
|
|
|
NewPriority = LOW_REALTIME_PRIORITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update priority and quantum */
|
2007-08-04 08:49:47 +00:00
|
|
|
Thread->BasePriority = (SCHAR)NewPriority;
|
2006-07-21 19:28:38 +00:00
|
|
|
Thread->Quantum = Thread->QuantumReset;
|
|
|
|
|
|
|
|
/* Disable decrements and update priority */
|
|
|
|
Thread->PriorityDecrement = 0;
|
2007-01-17 21:53:45 +00:00
|
|
|
KiSetPriorityThread(Thread, NewPriority);
|
2006-07-21 19:28:38 +00:00
|
|
|
}
|
|
|
|
|
2006-09-13 03:02:40 +00:00
|
|
|
/* Release the thread lock */
|
|
|
|
KiReleaseThreadLock(Thread);
|
|
|
|
|
2006-07-21 19:28:38 +00:00
|
|
|
/* Go to the next thread */
|
|
|
|
NextEntry = NextEntry->Flink;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Loop the thread list */
|
|
|
|
while (NextEntry != ListHead)
|
|
|
|
{
|
|
|
|
/* Get the thread */
|
|
|
|
Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
|
|
|
|
|
|
|
|
/* Update the quantum if we had one */
|
|
|
|
if (Quantum) Thread->QuantumReset = Quantum;
|
|
|
|
|
2006-09-13 03:02:40 +00:00
|
|
|
/* Lock the thread */
|
|
|
|
KiAcquireThreadLock(Thread);
|
|
|
|
|
2006-07-21 19:28:38 +00:00
|
|
|
/* Calculate the new priority */
|
|
|
|
NewPriority = Thread->BasePriority + Delta;
|
|
|
|
if (NewPriority >= LOW_REALTIME_PRIORITY)
|
|
|
|
{
|
|
|
|
/* We're not real-time range, don't let it enter RT range */
|
|
|
|
NewPriority = LOW_REALTIME_PRIORITY - 1;
|
|
|
|
}
|
|
|
|
else if (NewPriority <= LOW_PRIORITY)
|
|
|
|
{
|
|
|
|
/* We're going below the minimum priority, normalize */
|
|
|
|
NewPriority = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If priority saturation occured or the old priority was still in
|
|
|
|
* the real-time range, don't do anything.
|
|
|
|
*/
|
|
|
|
if (!(Thread->Saturation) ||
|
|
|
|
(OldPriority >= LOW_REALTIME_PRIORITY))
|
|
|
|
{
|
|
|
|
/* Check if we had priority saturation */
|
|
|
|
if (Thread->Saturation > 0)
|
|
|
|
{
|
|
|
|
/* Boost priority to maximum */
|
|
|
|
NewPriority = LOW_REALTIME_PRIORITY - 1;
|
|
|
|
}
|
|
|
|
else if (Thread->Saturation < 0)
|
|
|
|
{
|
|
|
|
/* If we had negative saturation, set minimum priority */
|
|
|
|
NewPriority = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update priority and quantum */
|
2007-08-04 08:49:47 +00:00
|
|
|
Thread->BasePriority = (SCHAR)NewPriority;
|
2006-07-21 19:28:38 +00:00
|
|
|
Thread->Quantum = Thread->QuantumReset;
|
|
|
|
|
|
|
|
/* Disable decrements and update priority */
|
|
|
|
Thread->PriorityDecrement = 0;
|
2007-01-17 21:53:45 +00:00
|
|
|
KiSetPriorityThread(Thread, NewPriority);
|
2006-07-21 19:28:38 +00:00
|
|
|
}
|
|
|
|
|
2006-09-13 03:02:40 +00:00
|
|
|
/* Release the thread lock */
|
|
|
|
KiReleaseThreadLock(Thread);
|
|
|
|
|
2006-07-21 19:28:38 +00:00
|
|
|
/* Go to the next thread */
|
|
|
|
NextEntry = NextEntry->Flink;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release Dispatcher Database */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseDispatcherLockFromSynchLevel();
|
2006-09-13 03:02:40 +00:00
|
|
|
|
|
|
|
/* Release the process lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseProcessLockFromSynchLevel(&ProcessLock);
|
2006-09-13 03:02:40 +00:00
|
|
|
KiExitDispatcher(ProcessLock.OldIrql);
|
2006-07-21 19:28:38 +00:00
|
|
|
|
|
|
|
/* Return previous priority */
|
|
|
|
return OldPriority;
|
|
|
|
}
|
|
|
|
|
2018-05-25 19:40:39 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KeQueryValuesProcess(IN PKPROCESS Process,
|
|
|
|
PPROCESS_VALUES Values)
|
|
|
|
{
|
|
|
|
PEPROCESS EProcess;
|
|
|
|
PLIST_ENTRY NextEntry;
|
|
|
|
ULONG TotalKernel, TotalUser;
|
|
|
|
KLOCK_QUEUE_HANDLE ProcessLock;
|
|
|
|
|
|
|
|
ASSERT_PROCESS(Process);
|
|
|
|
ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
|
|
|
|
|
|
|
|
/* Lock the process */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireProcessLockRaiseToSynch(Process, &ProcessLock);
|
2018-05-25 19:40:39 +00:00
|
|
|
|
|
|
|
/* Initialize user and kernel times */
|
|
|
|
TotalKernel = Process->KernelTime;
|
|
|
|
TotalUser = Process->UserTime;
|
|
|
|
|
|
|
|
/* Copy the IO_COUNTERS from the process */
|
|
|
|
EProcess = (PEPROCESS)Process;
|
|
|
|
Values->IoInfo.ReadOperationCount = EProcess->ReadOperationCount.QuadPart;
|
|
|
|
Values->IoInfo.WriteOperationCount = EProcess->WriteOperationCount.QuadPart;
|
|
|
|
Values->IoInfo.OtherOperationCount = EProcess->OtherOperationCount.QuadPart;
|
|
|
|
Values->IoInfo.ReadTransferCount = EProcess->ReadTransferCount.QuadPart;
|
|
|
|
Values->IoInfo.WriteTransferCount = EProcess->WriteTransferCount.QuadPart;
|
|
|
|
Values->IoInfo.OtherTransferCount = EProcess->OtherTransferCount.QuadPart;
|
|
|
|
|
|
|
|
/* Loop all child threads and sum up their times */
|
|
|
|
for (NextEntry = Process->ThreadListHead.Flink;
|
|
|
|
NextEntry != &Process->ThreadListHead;
|
|
|
|
NextEntry = NextEntry->Flink)
|
|
|
|
{
|
|
|
|
PKTHREAD Thread;
|
|
|
|
|
|
|
|
/* Get the thread */
|
|
|
|
Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
|
|
|
|
|
|
|
|
/* Sum up times */
|
|
|
|
TotalKernel += Thread->KernelTime;
|
|
|
|
TotalUser += Thread->UserTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the process lock */
|
|
|
|
KiReleaseProcessLock(&ProcessLock);
|
|
|
|
|
|
|
|
/* Compute total times */
|
|
|
|
Values->TotalKernelTime.QuadPart = TotalKernel * (LONGLONG)KeMaximumIncrement;
|
|
|
|
Values->TotalUserTime.QuadPart = TotalUser * (LONGLONG)KeMaximumIncrement;
|
|
|
|
}
|
|
|
|
|
2006-09-10 20:23:02 +00:00
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
|
|
|
|
2003-07-10 17:44:06 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
VOID
|
2005-12-04 03:24:11 +00:00
|
|
|
NTAPI
|
2006-09-10 23:41:08 +00:00
|
|
|
KeAttachProcess(IN PKPROCESS Process)
|
1999-03-30 12:55:31 +00:00
|
|
|
{
|
2006-09-10 18:26:50 +00:00
|
|
|
KLOCK_QUEUE_HANDLE ApcLock;
|
2007-09-27 16:28:56 +00:00
|
|
|
PKTHREAD Thread = KeGetCurrentThread();
|
2006-09-10 23:41:08 +00:00
|
|
|
ASSERT_PROCESS(Process);
|
2005-12-04 03:24:11 +00:00
|
|
|
ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
|
2004-11-27 16:42:50 +00:00
|
|
|
|
2005-12-04 03:24:11 +00:00
|
|
|
/* Check if we're already in that process */
|
2006-09-10 18:26:50 +00:00
|
|
|
if (Thread->ApcState.Process == Process) return;
|
|
|
|
|
|
|
|
/* Check if a DPC is executing or if we're already attached */
|
|
|
|
if ((Thread->ApcStateIndex != OriginalApcEnvironment) ||
|
|
|
|
(KeIsExecutingDpc()))
|
2005-12-04 03:24:11 +00:00
|
|
|
{
|
2006-09-10 18:26:50 +00:00
|
|
|
/* Invalid attempt */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheckEx(INVALID_PROCESS_ATTACH_ATTEMPT,
|
2005-12-04 03:24:11 +00:00
|
|
|
(ULONG_PTR)Process,
|
|
|
|
(ULONG_PTR)Thread->ApcState.Process,
|
|
|
|
Thread->ApcStateIndex,
|
|
|
|
KeIsExecutingDpc());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-09-10 23:41:08 +00:00
|
|
|
/* Acquire APC Lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireApcLockRaiseToSynch(Thread, &ApcLock);
|
2006-09-10 23:41:08 +00:00
|
|
|
|
|
|
|
/* Acquire the dispatcher lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireDispatcherLockAtSynchLevel();
|
2006-09-10 23:41:08 +00:00
|
|
|
|
2005-12-04 03:24:11 +00:00
|
|
|
/* Legit attach attempt: do it! */
|
2006-09-10 18:26:50 +00:00
|
|
|
KiAttachProcess(Thread, Process, &ApcLock, &Thread->SavedApcState);
|
2005-03-12 18:10:03 +00:00
|
|
|
}
|
1999-03-30 12:55:31 +00:00
|
|
|
}
|
|
|
|
|
2005-12-04 03:24:11 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2004-11-11 22:23:52 +00:00
|
|
|
VOID
|
2005-12-04 03:24:11 +00:00
|
|
|
NTAPI
|
2006-09-10 20:23:02 +00:00
|
|
|
KeDetachProcess(VOID)
|
1999-03-30 12:55:31 +00:00
|
|
|
{
|
2006-09-10 18:26:50 +00:00
|
|
|
PKTHREAD Thread = KeGetCurrentThread();
|
|
|
|
KLOCK_QUEUE_HANDLE ApcLock;
|
2006-09-10 20:23:02 +00:00
|
|
|
PKPROCESS Process;
|
2005-12-04 03:24:11 +00:00
|
|
|
ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-12-04 03:24:11 +00:00
|
|
|
/* Check if it's attached */
|
2006-09-10 18:26:50 +00:00
|
|
|
if (Thread->ApcStateIndex == OriginalApcEnvironment) return;
|
|
|
|
|
|
|
|
/* Acquire APC Lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireApcLockRaiseToSynch(Thread, &ApcLock);
|
2006-09-10 18:26:50 +00:00
|
|
|
|
2006-09-10 20:23:02 +00:00
|
|
|
/* Check for invalid attach attempts */
|
|
|
|
if ((Thread->ApcState.KernelApcInProgress) ||
|
|
|
|
!(IsListEmpty(&Thread->ApcState.ApcListHead[KernelMode])) ||
|
|
|
|
!(IsListEmpty(&Thread->ApcState.ApcListHead[UserMode])))
|
|
|
|
{
|
|
|
|
/* Crash the system */
|
|
|
|
KeBugCheck(INVALID_PROCESS_DETACH_ATTEMPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the process */
|
|
|
|
Process = Thread->ApcState.Process;
|
|
|
|
|
|
|
|
/* Acquire dispatcher lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireDispatcherLockAtSynchLevel();
|
2006-09-10 20:23:02 +00:00
|
|
|
|
|
|
|
/* Decrease the stack count */
|
|
|
|
ASSERT(Process->StackCount != 0);
|
|
|
|
ASSERT(Process->State == ProcessInMemory);
|
|
|
|
Process->StackCount--;
|
|
|
|
|
|
|
|
/* Check if we can swap the process out */
|
|
|
|
if (!Process->StackCount)
|
2005-12-04 03:24:11 +00:00
|
|
|
{
|
2006-09-10 18:26:50 +00:00
|
|
|
/* FIXME: Swap the process out */
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-10 20:23:02 +00:00
|
|
|
/* Release dispatcher lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseDispatcherLockFromSynchLevel();
|
2006-09-10 20:23:02 +00:00
|
|
|
|
2006-09-10 18:26:50 +00:00
|
|
|
/* Restore the APC State */
|
|
|
|
KiMoveApcState(&Thread->SavedApcState, &Thread->ApcState);
|
|
|
|
Thread->SavedApcState.Process = NULL;
|
|
|
|
Thread->ApcStatePointer[OriginalApcEnvironment] = &Thread->ApcState;
|
|
|
|
Thread->ApcStatePointer[AttachedApcEnvironment] = &Thread->SavedApcState;
|
|
|
|
Thread->ApcStateIndex = OriginalApcEnvironment;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-10 18:26:50 +00:00
|
|
|
/* Release lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseApcLockFromSynchLevel(&ApcLock);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-10 18:26:50 +00:00
|
|
|
/* Swap Processes */
|
2009-06-27 11:07:58 +00:00
|
|
|
KiSwapProcess(Thread->ApcState.Process, Process);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-10 18:26:50 +00:00
|
|
|
/* Exit the dispatcher */
|
|
|
|
KiExitDispatcher(ApcLock.OldIrql);
|
|
|
|
|
|
|
|
/* Check if we have pending APCs */
|
2011-04-24 06:48:50 +00:00
|
|
|
if (!(IsListEmpty(&Thread->ApcState.ApcListHead[KernelMode])))
|
2006-09-10 18:26:50 +00:00
|
|
|
{
|
|
|
|
/* What do you know, we do! Request them to be delivered */
|
|
|
|
Thread->ApcState.KernelApcPending = TRUE;
|
|
|
|
HalRequestSoftwareInterrupt(APC_LEVEL);
|
|
|
|
}
|
1999-03-30 12:55:31 +00:00
|
|
|
}
|
2000-06-04 19:51:05 +00:00
|
|
|
|
2004-06-23 22:32:24 +00:00
|
|
|
/*
|
2004-10-13 22:27:03 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
2005-12-04 03:24:11 +00:00
|
|
|
NTAPI
|
2005-03-12 18:10:03 +00:00
|
|
|
KeIsAttachedProcess(VOID)
|
2004-10-13 22:27:03 +00:00
|
|
|
{
|
2005-03-12 18:10:03 +00:00
|
|
|
/* Return the APC State */
|
|
|
|
return KeGetCurrentThread()->ApcStateIndex;
|
2004-10-13 22:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
2004-06-23 22:32:24 +00:00
|
|
|
*/
|
|
|
|
VOID
|
2005-12-04 03:24:11 +00:00
|
|
|
NTAPI
|
2005-03-12 18:10:03 +00:00
|
|
|
KeStackAttachProcess(IN PKPROCESS Process,
|
|
|
|
OUT PRKAPC_STATE ApcState)
|
2004-06-23 22:32:24 +00:00
|
|
|
{
|
2006-09-10 18:26:50 +00:00
|
|
|
KLOCK_QUEUE_HANDLE ApcLock;
|
|
|
|
PKTHREAD Thread = KeGetCurrentThread();
|
2006-09-10 20:23:02 +00:00
|
|
|
ASSERT_PROCESS(Process);
|
2005-12-04 03:24:11 +00:00
|
|
|
ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
|
2004-11-27 16:42:50 +00:00
|
|
|
|
2005-03-12 18:10:03 +00:00
|
|
|
/* Crash system if DPC is being executed! */
|
2005-12-04 03:24:11 +00:00
|
|
|
if (KeIsExecutingDpc())
|
|
|
|
{
|
|
|
|
/* Executing a DPC, crash! */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheckEx(INVALID_PROCESS_ATTACH_ATTEMPT,
|
2005-12-04 03:24:11 +00:00
|
|
|
(ULONG_PTR)Process,
|
|
|
|
(ULONG_PTR)Thread->ApcState.Process,
|
|
|
|
Thread->ApcStateIndex,
|
|
|
|
KeIsExecutingDpc());
|
2005-03-12 18:10:03 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-12-04 03:24:11 +00:00
|
|
|
/* Check if we are already in the target process */
|
|
|
|
if (Thread->ApcState.Process == Process)
|
|
|
|
{
|
|
|
|
/* Set magic value so we don't crash later when detaching */
|
|
|
|
ApcState->Process = (PKPROCESS)1;
|
2006-09-10 18:26:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Acquire APC Lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireApcLockRaiseToSynch(Thread, &ApcLock);
|
2006-09-10 18:26:50 +00:00
|
|
|
|
2006-09-10 23:41:08 +00:00
|
|
|
/* Acquire dispatcher lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireDispatcherLockAtSynchLevel();
|
2006-09-10 23:41:08 +00:00
|
|
|
|
2006-09-10 18:26:50 +00:00
|
|
|
/* Check if the Current Thread is already attached */
|
|
|
|
if (Thread->ApcStateIndex != OriginalApcEnvironment)
|
|
|
|
{
|
|
|
|
/* We're already attached, so save the APC State into what we got */
|
|
|
|
KiAttachProcess(Thread, Process, &ApcLock, ApcState);
|
2005-12-04 03:24:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-09-10 18:26:50 +00:00
|
|
|
/* We're not attached, so save the APC State into SavedApcState */
|
|
|
|
KiAttachProcess(Thread, Process, &ApcLock, &Thread->SavedApcState);
|
|
|
|
ApcState->Process = NULL;
|
2005-03-12 18:10:03 +00:00
|
|
|
}
|
2004-11-11 22:23:52 +00:00
|
|
|
}
|
|
|
|
|
2004-06-23 22:32:24 +00:00
|
|
|
/*
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
* @implemented
|
2004-06-23 22:32:24 +00:00
|
|
|
*/
|
|
|
|
VOID
|
2005-12-04 03:24:11 +00:00
|
|
|
NTAPI
|
|
|
|
KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
|
2004-06-23 22:32:24 +00:00
|
|
|
{
|
2006-09-10 18:26:50 +00:00
|
|
|
KLOCK_QUEUE_HANDLE ApcLock;
|
|
|
|
PKTHREAD Thread = KeGetCurrentThread();
|
2006-09-10 20:23:02 +00:00
|
|
|
PKPROCESS Process;
|
2005-12-04 03:24:11 +00:00
|
|
|
ASSERT_IRQL_LESS_OR_EQUAL(DISPATCH_LEVEL);
|
2005-02-18 18:28:49 +00:00
|
|
|
|
2005-12-04 03:24:11 +00:00
|
|
|
/* Check for magic value meaning we were already in the same process */
|
2006-09-10 18:26:50 +00:00
|
|
|
if (ApcState->Process == (PKPROCESS)1) return;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-10 23:41:08 +00:00
|
|
|
/* Loop to make sure no APCs are pending */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* Acquire APC Lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireApcLockRaiseToSynch(Thread, &ApcLock);
|
2006-09-10 23:41:08 +00:00
|
|
|
|
|
|
|
/* Check if a kernel APC is pending */
|
|
|
|
if (Thread->ApcState.KernelApcPending)
|
|
|
|
{
|
|
|
|
/* Check if kernel APC should be delivered */
|
|
|
|
if (!(Thread->KernelApcDisable) && (ApcLock.OldIrql <= APC_LEVEL))
|
|
|
|
{
|
|
|
|
/* Release the APC lock so that the APC can be delivered */
|
|
|
|
KiReleaseApcLock(&ApcLock);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, break out */
|
|
|
|
break;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-10 18:26:50 +00:00
|
|
|
/*
|
|
|
|
* Check if the process isn't attacked, or has a Kernel APC in progress
|
|
|
|
* or has pending APC of any kind.
|
|
|
|
*/
|
|
|
|
if ((Thread->ApcStateIndex == OriginalApcEnvironment) ||
|
|
|
|
(Thread->ApcState.KernelApcInProgress) ||
|
|
|
|
(!IsListEmpty(&Thread->ApcState.ApcListHead[KernelMode])) ||
|
|
|
|
(!IsListEmpty(&Thread->ApcState.ApcListHead[UserMode])))
|
|
|
|
{
|
2006-09-10 20:23:02 +00:00
|
|
|
/* Bugcheck the system */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheck(INVALID_PROCESS_DETACH_ATTEMPT);
|
2006-09-10 18:26:50 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-10 20:23:02 +00:00
|
|
|
/* Get the process */
|
|
|
|
Process = Thread->ApcState.Process;
|
|
|
|
|
|
|
|
/* Acquire dispatcher lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireDispatcherLockAtSynchLevel();
|
2006-09-10 20:23:02 +00:00
|
|
|
|
|
|
|
/* Decrease the stack count */
|
|
|
|
ASSERT(Process->StackCount != 0);
|
|
|
|
ASSERT(Process->State == ProcessInMemory);
|
|
|
|
Process->StackCount--;
|
|
|
|
|
|
|
|
/* Check if we can swap the process out */
|
|
|
|
if (!Process->StackCount)
|
2006-09-10 18:26:50 +00:00
|
|
|
{
|
|
|
|
/* FIXME: Swap the process out */
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-10 20:23:02 +00:00
|
|
|
/* Release dispatcher lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseDispatcherLockFromSynchLevel();
|
2006-09-10 20:23:02 +00:00
|
|
|
|
|
|
|
/* Check if there's an APC state to restore */
|
|
|
|
if (ApcState->Process)
|
2006-09-10 18:26:50 +00:00
|
|
|
{
|
|
|
|
/* Restore the APC State */
|
|
|
|
KiMoveApcState(ApcState, &Thread->ApcState);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The ApcState parameter is useless, so use the saved data and reset it */
|
|
|
|
KiMoveApcState(&Thread->SavedApcState, &Thread->ApcState);
|
|
|
|
Thread->SavedApcState.Process = NULL;
|
|
|
|
Thread->ApcStateIndex = OriginalApcEnvironment;
|
|
|
|
Thread->ApcStatePointer[OriginalApcEnvironment] = &Thread->ApcState;
|
|
|
|
Thread->ApcStatePointer[AttachedApcEnvironment] = &Thread->SavedApcState;
|
2005-03-12 18:10:03 +00:00
|
|
|
}
|
Implemented KeAreApcsDisabled, KeFlushEntireTb, KeIsExecutingDpc, KeSetKernelStackSwapEnable, KeQueryPriorityThread, KeRevertToUserAffinityThread, KeSetIdealProcessorThread, KeSetSystemAffinityThread, KeTerminateThread, KeStackAttachProcess, KeUnstackDetachProcess
svn path=/trunk/; revision=11284
2004-10-13 01:42:14 +00:00
|
|
|
|
2006-09-10 18:26:50 +00:00
|
|
|
/* Release lock */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiReleaseApcLockFromSynchLevel(&ApcLock);
|
2006-09-10 18:26:50 +00:00
|
|
|
|
|
|
|
/* Swap Processes */
|
2009-06-27 11:07:58 +00:00
|
|
|
KiSwapProcess(Thread->ApcState.Process, Process);
|
2006-09-10 18:26:50 +00:00
|
|
|
|
|
|
|
/* Exit the dispatcher */
|
|
|
|
KiExitDispatcher(ApcLock.OldIrql);
|
|
|
|
|
|
|
|
/* Check if we have pending APCs */
|
2011-04-24 06:48:50 +00:00
|
|
|
if (!(IsListEmpty(&Thread->ApcState.ApcListHead[KernelMode])))
|
2006-09-10 18:26:50 +00:00
|
|
|
{
|
|
|
|
/* What do you know, we do! Request them to be delivered */
|
|
|
|
Thread->ApcState.KernelApcPending = TRUE;
|
|
|
|
HalRequestSoftwareInterrupt(APC_LEVEL);
|
|
|
|
}
|
2004-06-23 22:32:24 +00:00
|
|
|
}
|
|
|
|
|
2008-12-08 12:57:53 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
ULONG
|
|
|
|
NTAPI
|
|
|
|
KeQueryRuntimeProcess(IN PKPROCESS Process,
|
|
|
|
OUT PULONG UserTime)
|
|
|
|
{
|
|
|
|
ULONG TotalUser, TotalKernel;
|
|
|
|
KLOCK_QUEUE_HANDLE ProcessLock;
|
|
|
|
PLIST_ENTRY NextEntry, ListHead;
|
|
|
|
PKTHREAD Thread;
|
|
|
|
|
|
|
|
ASSERT_PROCESS(Process);
|
|
|
|
|
|
|
|
/* Initialize user and kernel times */
|
|
|
|
TotalUser = Process->UserTime;
|
|
|
|
TotalKernel = Process->KernelTime;
|
|
|
|
|
|
|
|
/* Lock the process */
|
2019-12-30 14:34:38 +00:00
|
|
|
KiAcquireProcessLockRaiseToSynch(Process, &ProcessLock);
|
2008-12-08 12:57:53 +00:00
|
|
|
|
|
|
|
/* Loop all child threads and sum up their times */
|
|
|
|
ListHead = &Process->ThreadListHead;
|
|
|
|
NextEntry = ListHead->Flink;
|
|
|
|
while (ListHead != NextEntry)
|
|
|
|
{
|
|
|
|
/* Get the thread */
|
|
|
|
Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
|
|
|
|
|
|
|
|
/* Sum up times */
|
|
|
|
TotalKernel += Thread->KernelTime;
|
|
|
|
TotalUser += Thread->UserTime;
|
|
|
|
|
|
|
|
/* Go to the next one */
|
|
|
|
NextEntry = NextEntry->Flink;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release lock */
|
|
|
|
KiReleaseProcessLock(&ProcessLock);
|
|
|
|
|
|
|
|
/* Return the user time */
|
|
|
|
*UserTime = TotalUser;
|
|
|
|
|
|
|
|
/* Return the kernel time */
|
|
|
|
return TotalKernel;
|
|
|
|
}
|
|
|
|
|
2005-01-17 07:10:34 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-09-05 04:48:20 +00:00
|
|
|
BOOLEAN
|
2005-12-04 03:24:11 +00:00
|
|
|
NTAPI
|
2006-09-10 23:41:08 +00:00
|
|
|
KeAddSystemServiceTable(IN PULONG_PTR Base,
|
|
|
|
IN PULONG Count OPTIONAL,
|
|
|
|
IN ULONG Limit,
|
|
|
|
IN PUCHAR Number,
|
|
|
|
IN ULONG Index)
|
2005-01-17 07:10:34 +00:00
|
|
|
{
|
2006-09-10 23:41:08 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2005-09-05 04:48:20 +00:00
|
|
|
/* Check if descriptor table entry is free */
|
|
|
|
if ((Index > SSDT_MAX_ENTRIES - 1) ||
|
|
|
|
(KeServiceDescriptorTable[Index].Base) ||
|
|
|
|
(KeServiceDescriptorTableShadow[Index].Base))
|
|
|
|
{
|
2006-09-10 23:41:08 +00:00
|
|
|
/* It's not, fail */
|
2005-01-17 07:10:34 +00:00
|
|
|
return FALSE;
|
2005-09-05 04:48:20 +00:00
|
|
|
}
|
2005-01-17 07:10:34 +00:00
|
|
|
|
2005-09-05 04:48:20 +00:00
|
|
|
/* Initialize the shadow service descriptor table */
|
|
|
|
KeServiceDescriptorTableShadow[Index].Base = Base;
|
|
|
|
KeServiceDescriptorTableShadow[Index].Limit = Limit;
|
|
|
|
KeServiceDescriptorTableShadow[Index].Number = Number;
|
|
|
|
KeServiceDescriptorTableShadow[Index].Count = Count;
|
2005-01-17 07:10:34 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-03-12 18:10:03 +00:00
|
|
|
* @implemented
|
2005-01-17 07:10:34 +00:00
|
|
|
*/
|
|
|
|
BOOLEAN
|
2005-12-04 03:24:11 +00:00
|
|
|
NTAPI
|
2005-09-05 04:48:20 +00:00
|
|
|
KeRemoveSystemServiceTable(IN ULONG Index)
|
2005-01-17 07:10:34 +00:00
|
|
|
{
|
2006-09-10 23:41:08 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2005-03-12 18:10:03 +00:00
|
|
|
/* Make sure the Index is valid */
|
2006-09-10 23:41:08 +00:00
|
|
|
if (Index > (SSDT_MAX_ENTRIES - 1)) return FALSE;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-12 18:10:03 +00:00
|
|
|
/* Is there a Normal Descriptor Table? */
|
2005-09-05 04:48:20 +00:00
|
|
|
if (!KeServiceDescriptorTable[Index].Base)
|
|
|
|
{
|
2005-03-12 18:10:03 +00:00
|
|
|
/* Not with the index, is there a shadow at least? */
|
2005-09-05 04:48:20 +00:00
|
|
|
if (!KeServiceDescriptorTableShadow[Index].Base) return FALSE;
|
2005-03-12 18:10:03 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-12 18:10:03 +00:00
|
|
|
/* Now clear from the Shadow Table. */
|
2005-09-05 04:48:20 +00:00
|
|
|
KeServiceDescriptorTableShadow[Index].Base = NULL;
|
|
|
|
KeServiceDescriptorTableShadow[Index].Number = NULL;
|
|
|
|
KeServiceDescriptorTableShadow[Index].Limit = 0;
|
|
|
|
KeServiceDescriptorTableShadow[Index].Count = NULL;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-12 18:10:03 +00:00
|
|
|
/* Check if we should clean from the Master one too */
|
2005-09-05 04:48:20 +00:00
|
|
|
if (Index == 1)
|
|
|
|
{
|
|
|
|
KeServiceDescriptorTable[Index].Base = NULL;
|
|
|
|
KeServiceDescriptorTable[Index].Number = NULL;
|
|
|
|
KeServiceDescriptorTable[Index].Limit = 0;
|
|
|
|
KeServiceDescriptorTable[Index].Count = NULL;
|
2005-03-12 18:10:03 +00:00
|
|
|
}
|
|
|
|
|
2006-09-10 23:41:08 +00:00
|
|
|
/* Return success */
|
2005-03-12 18:10:03 +00:00
|
|
|
return TRUE;
|
2005-01-17 07:10:34 +00:00
|
|
|
}
|
2000-06-04 19:51:05 +00:00
|
|
|
/* EOF */
|