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-09 18:54:13 +00:00
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
1999-01-16 21:03:00 +00:00
|
|
|
* FILE: ntoskrnl/ps/kill.c
|
2006-07-09 18:54:13 +00:00
|
|
|
* PURPOSE: Process Manager: Process and Thread Termination
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
|
|
|
* Filip Navara (xnavara@reactos.org)
|
|
|
|
* Thomas Weidenmueller (w3seek@reactos.org
|
1999-01-16 21:03:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
1999-12-13 22:04:41 +00:00
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
1999-01-16 21:03:00 +00:00
|
|
|
|
1999-04-10 12:08:24 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2008-12-03 17:28:59 +00:00
|
|
|
LIST_ENTRY PspReaperListHead = { NULL, NULL };
|
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
|
|
|
WORK_QUEUE_ITEM PspReaperWorkItem;
|
2007-01-18 09:44:49 +00:00
|
|
|
LARGE_INTEGER ShortTime = {{-10 * 100 * 1000, -1}};
|
2005-02-23 18:43:25 +00:00
|
|
|
|
2006-07-20 15:46:10 +00:00
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
1999-01-16 21:03:00 +00:00
|
|
|
|
2006-07-21 19:59:16 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
PspCatchCriticalBreak(IN PCHAR Message,
|
|
|
|
IN PVOID ProcessOrThread,
|
|
|
|
IN PCHAR ImageName)
|
|
|
|
{
|
2006-07-23 19:14:19 +00:00
|
|
|
CHAR Action[2];
|
2006-07-21 19:59:16 +00:00
|
|
|
BOOLEAN Handled = FALSE;
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Check if a debugger is enabled */
|
|
|
|
if (KdDebuggerEnabled)
|
|
|
|
{
|
|
|
|
/* Print out the message */
|
|
|
|
DbgPrint(Message, ProcessOrThread, ImageName);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* If a debugger isn't present, don't prompt */
|
|
|
|
if (KdDebuggerNotPresent) break;
|
|
|
|
|
2022-11-27 18:11:29 +00:00
|
|
|
/* A debugger is active, prompt for action */
|
|
|
|
DbgPrompt("Break, or Ignore (bi)? ", Action, sizeof(Action));
|
2006-07-21 19:59:16 +00:00
|
|
|
switch (Action[0])
|
|
|
|
{
|
|
|
|
/* Break */
|
|
|
|
case 'B': case 'b':
|
|
|
|
DbgBreakPoint();
|
2022-11-27 18:11:29 +00:00
|
|
|
/* Fall through */
|
2006-07-21 19:59:16 +00:00
|
|
|
|
2022-11-27 18:11:29 +00:00
|
|
|
/* Ignore: Handle it */
|
2006-07-21 19:59:16 +00:00
|
|
|
case 'I': case 'i':
|
|
|
|
Handled = TRUE;
|
|
|
|
|
2022-11-27 18:11:29 +00:00
|
|
|
/* Unrecognized: Prompt again */
|
2006-07-21 19:59:16 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!Handled);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Did we ultimately handle this? */
|
|
|
|
if (!Handled)
|
|
|
|
{
|
|
|
|
/* We didn't, bugcheck */
|
|
|
|
KeBugCheckEx(CRITICAL_OBJECT_TERMINATION,
|
|
|
|
((PKPROCESS)ProcessOrThread)->Header.Type,
|
|
|
|
(ULONG_PTR)ProcessOrThread,
|
|
|
|
(ULONG_PTR)ImageName,
|
|
|
|
(ULONG_PTR)Message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
PspTerminateProcess(IN PEPROCESS Process,
|
|
|
|
IN NTSTATUS ExitStatus)
|
2004-09-28 15:02:31 +00:00
|
|
|
{
|
2007-01-18 09:44:49 +00:00
|
|
|
PETHREAD Thread;
|
|
|
|
NTSTATUS Status = STATUS_NOTHING_TO_TERMINATE;
|
2006-07-23 07:13:19 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
PSTRACE(PS_KILL_DEBUG,
|
2013-08-31 16:02:13 +00:00
|
|
|
"Process: %p ExitStatus: %d\n", Process, ExitStatus);
|
2006-07-23 19:45:16 +00:00
|
|
|
PSREFTRACE(Process);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-21 19:59:16 +00:00
|
|
|
/* Check if this is a Critical Process */
|
2006-07-09 18:54:13 +00:00
|
|
|
if (Process->BreakOnTermination)
|
|
|
|
{
|
2006-07-21 19:59:16 +00:00
|
|
|
/* Break to debugger */
|
|
|
|
PspCatchCriticalBreak("Terminating critical process 0x%p (%s)\n",
|
|
|
|
Process,
|
|
|
|
Process->ImageFileName);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Set the delete flag */
|
2006-07-20 16:26:10 +00:00
|
|
|
InterlockedOr((PLONG)&Process->Flags, PSF_PROCESS_DELETE_BIT);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Get the first thread */
|
2007-01-18 09:44:49 +00:00
|
|
|
Thread = PsGetNextProcessThread(Process, NULL);
|
2006-07-20 15:46:10 +00:00
|
|
|
while (Thread)
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
|
|
|
/* Kill it */
|
|
|
|
PspTerminateThreadByPointer(Thread, ExitStatus, FALSE);
|
2006-07-20 15:46:10 +00:00
|
|
|
Thread = PsGetNextProcessThread(Process, Thread);
|
2007-01-18 09:44:49 +00:00
|
|
|
|
|
|
|
/* We had at least one thread, so termination is OK */
|
|
|
|
Status = STATUS_SUCCESS;
|
2006-07-20 15:46:10 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Check if there was nothing to terminate or if we have a debug port */
|
|
|
|
if ((Status == STATUS_NOTHING_TO_TERMINATE) || (Process->DebugPort))
|
|
|
|
{
|
|
|
|
/* Clear the handle table anyway */
|
|
|
|
ObClearProcessHandleTable(Process);
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Return status */
|
|
|
|
return Status;
|
2004-09-28 15:02:31 +00:00
|
|
|
}
|
|
|
|
|
2006-10-19 20:08:52 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
PsTerminateProcess(IN PEPROCESS Process,
|
|
|
|
IN NTSTATUS ExitStatus)
|
|
|
|
{
|
|
|
|
/* Call the internal API */
|
|
|
|
return PspTerminateProcess(Process, ExitStatus);
|
|
|
|
}
|
|
|
|
|
2005-04-18 02:12:30 +00:00
|
|
|
VOID
|
2006-07-09 18:54:13 +00:00
|
|
|
NTAPI
|
|
|
|
PspShutdownProcessManager(VOID)
|
2005-04-18 02:12:30 +00:00
|
|
|
{
|
2006-07-09 18:54:13 +00:00
|
|
|
PEPROCESS Process = NULL;
|
2005-07-17 18:34:23 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Loop every process */
|
2006-07-23 19:14:19 +00:00
|
|
|
Process = PsGetNextProcess(Process);
|
2006-07-20 15:46:10 +00:00
|
|
|
while (Process)
|
2005-04-18 02:12:30 +00:00
|
|
|
{
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Make sure this isn't the idle or initial process */
|
|
|
|
if ((Process != PsInitialSystemProcess) && (Process != PsIdleProcess))
|
2005-04-18 02:12:30 +00:00
|
|
|
{
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Kill it */
|
|
|
|
PspTerminateProcess(Process, STATUS_SYSTEM_SHUTDOWN);
|
2005-04-18 02:12:30 +00:00
|
|
|
}
|
2006-07-20 15:46:10 +00:00
|
|
|
|
|
|
|
/* Get the next process */
|
2006-07-23 19:14:19 +00:00
|
|
|
Process = PsGetNextProcess(Process);
|
2005-04-18 02:12:30 +00:00
|
|
|
}
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
PspExitApcRundown(IN PKAPC Apc)
|
|
|
|
{
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Free the APC */
|
|
|
|
ExFreePool(Apc);
|
2005-04-18 02:12:30 +00:00
|
|
|
}
|
|
|
|
|
2004-09-28 15:02:31 +00:00
|
|
|
VOID
|
2006-07-09 18:54:13 +00:00
|
|
|
NTAPI
|
2006-07-20 16:30:07 +00:00
|
|
|
PspReapRoutine(IN PVOID Context)
|
2004-09-28 15:02:31 +00:00
|
|
|
{
|
2007-01-18 09:44:49 +00:00
|
|
|
PSINGLE_LIST_ENTRY NextEntry;
|
2006-07-09 18:54:13 +00:00
|
|
|
PETHREAD Thread;
|
2006-07-23 07:13:19 +00:00
|
|
|
PSTRACE(PS_KILL_DEBUG, "Context: %p\n", Context);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Start main loop */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Write magic value and return the next entry to process */
|
2015-04-12 12:24:01 +00:00
|
|
|
NextEntry = InterlockedExchangePointer((PVOID*)&PspReaperListHead.Flink,
|
2007-01-18 09:44:49 +00:00
|
|
|
(PVOID)1);
|
2006-07-09 18:54:13 +00:00
|
|
|
ASSERT((NextEntry != NULL) && (NextEntry != (PVOID)1));
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Start inner loop */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Get the first Thread Entry */
|
|
|
|
Thread = CONTAINING_RECORD(NextEntry, ETHREAD, ReaperLink);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Delete this entry's kernel stack */
|
2008-09-12 11:13:15 +00:00
|
|
|
MmDeleteKernelStack((PVOID)Thread->Tcb.StackBase,
|
2006-07-09 18:54:13 +00:00
|
|
|
Thread->Tcb.LargeStack);
|
|
|
|
Thread->Tcb.InitialStack = NULL;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Move to the next entry */
|
2007-01-18 09:44:49 +00:00
|
|
|
NextEntry = NextEntry->Next;
|
2005-03-22 02:32:14 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Dereference this thread */
|
|
|
|
ObDereferenceObject(Thread);
|
|
|
|
} while ((NextEntry != NULL) && (NextEntry != (PVOID)1));
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Remove magic value, keep looping if it got changed */
|
2015-04-12 12:24:01 +00:00
|
|
|
} while (InterlockedCompareExchangePointer((PVOID*)&PspReaperListHead.Flink,
|
2018-07-12 13:18:53 +00:00
|
|
|
NULL,
|
[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
|
|
|
(PVOID)1) != (PVOID)1);
|
2004-09-28 15:02:31 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 18:13:55 +00:00
|
|
|
#if DBG
|
|
|
|
VOID
|
|
|
|
NTAPI
|
2015-09-03 23:57:39 +00:00
|
|
|
PspCheckProcessList(VOID)
|
2013-03-13 18:13:55 +00:00
|
|
|
{
|
|
|
|
PLIST_ENTRY Entry;
|
|
|
|
|
|
|
|
KeAcquireGuardedMutex(&PspActiveProcessMutex);
|
|
|
|
DbgPrint("# checking PsActiveProcessHead @ %p\n", &PsActiveProcessHead);
|
|
|
|
for (Entry = PsActiveProcessHead.Flink;
|
|
|
|
Entry != &PsActiveProcessHead;
|
|
|
|
Entry = Entry->Flink)
|
|
|
|
{
|
|
|
|
PEPROCESS Process = CONTAINING_RECORD(Entry, EPROCESS, ActiveProcessLinks);
|
|
|
|
POBJECT_HEADER Header;
|
|
|
|
PVOID Info, HeaderLocation;
|
|
|
|
|
|
|
|
/* Get the header and assume this is what we'll free */
|
|
|
|
Header = OBJECT_TO_OBJECT_HEADER(Process);
|
|
|
|
HeaderLocation = Header;
|
|
|
|
|
|
|
|
/* To find the header, walk backwards from how we allocated */
|
|
|
|
if ((Info = OBJECT_HEADER_TO_CREATOR_INFO(Header)))
|
|
|
|
{
|
|
|
|
HeaderLocation = Info;
|
|
|
|
}
|
|
|
|
if ((Info = OBJECT_HEADER_TO_NAME_INFO(Header)))
|
|
|
|
{
|
|
|
|
HeaderLocation = Info;
|
|
|
|
}
|
|
|
|
if ((Info = OBJECT_HEADER_TO_HANDLE_INFO(Header)))
|
|
|
|
{
|
|
|
|
HeaderLocation = Info;
|
|
|
|
}
|
|
|
|
if ((Info = OBJECT_HEADER_TO_QUOTA_INFO(Header)))
|
|
|
|
{
|
|
|
|
HeaderLocation = Info;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpCheckPoolAllocation(HeaderLocation, NonPagedPool, 'corP');
|
|
|
|
}
|
|
|
|
|
|
|
|
KeReleaseGuardedMutex(&PspActiveProcessMutex);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-05-09 01:38:29 +00:00
|
|
|
VOID
|
2006-07-09 18:54:13 +00:00
|
|
|
NTAPI
|
2006-07-20 16:30:07 +00:00
|
|
|
PspDeleteProcess(IN PVOID ObjectBody)
|
2004-09-28 15:02: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
|
|
|
PEPROCESS Process = (PEPROCESS)ObjectBody;
|
2006-07-09 18:54:13 +00:00
|
|
|
KAPC_STATE ApcState;
|
|
|
|
PAGED_CODE();
|
2006-07-23 07:13:19 +00:00
|
|
|
PSTRACE(PS_KILL_DEBUG, "ObjectBody: %p\n", ObjectBody);
|
2006-07-23 19:45:16 +00:00
|
|
|
PSREFTRACE(Process);
|
2004-09-28 15:02:31 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if it has an Active Process Link */
|
|
|
|
if (Process->ActiveProcessLinks.Flink)
|
|
|
|
{
|
2006-07-20 15:46:10 +00:00
|
|
|
/* Remove it from the Active List */
|
2006-07-20 16:26:10 +00:00
|
|
|
KeAcquireGuardedMutex(&PspActiveProcessMutex);
|
2006-07-20 15:46:10 +00:00
|
|
|
RemoveEntryList(&Process->ActiveProcessLinks);
|
2013-03-13 18:13:55 +00:00
|
|
|
Process->ActiveProcessLinks.Flink = NULL;
|
|
|
|
Process->ActiveProcessLinks.Blink = NULL;
|
2006-07-20 16:26:10 +00:00
|
|
|
KeReleaseGuardedMutex(&PspActiveProcessMutex);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check for Auditing information */
|
|
|
|
if (Process->SeAuditProcessCreationInfo.ImageFileName)
|
|
|
|
{
|
|
|
|
/* Free it */
|
2013-07-20 17:46:38 +00:00
|
|
|
ExFreePoolWithTag(Process->SeAuditProcessCreationInfo.ImageFileName,
|
|
|
|
TAG_SEPA);
|
2006-07-09 18:54:13 +00:00
|
|
|
Process->SeAuditProcessCreationInfo.ImageFileName = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we have a job */
|
|
|
|
if (Process->Job)
|
|
|
|
{
|
|
|
|
/* Remove the process from the job */
|
|
|
|
PspRemoveProcessFromJob(Process, Process->Job);
|
|
|
|
|
|
|
|
/* Dereference it */
|
|
|
|
ObDereferenceObject(Process->Job);
|
|
|
|
Process->Job = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Increase the stack count */
|
|
|
|
Process->Pcb.StackCount++;
|
|
|
|
|
|
|
|
/* Check if we have a debug port */
|
|
|
|
if (Process->DebugPort)
|
2005-08-07 22:48:07 +00:00
|
|
|
{
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Deference the Debug Port */
|
2006-07-09 18:54:13 +00:00
|
|
|
ObDereferenceObject(Process->DebugPort);
|
|
|
|
Process->DebugPort = NULL;
|
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
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if we have an exception port */
|
|
|
|
if (Process->ExceptionPort)
|
|
|
|
{
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Deference the Exception Port */
|
2006-07-09 18:54:13 +00:00
|
|
|
ObDereferenceObject(Process->ExceptionPort);
|
|
|
|
Process->ExceptionPort = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we have a section object */
|
|
|
|
if (Process->SectionObject)
|
|
|
|
{
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Deference the Section Object */
|
2006-07-09 18:54:13 +00:00
|
|
|
ObDereferenceObject(Process->SectionObject);
|
|
|
|
Process->SectionObject = NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-29 10:04:15 +00:00
|
|
|
#if defined(_X86_)
|
|
|
|
/* Clean Ldt and Vdm objects */
|
2006-07-09 18:54:13 +00:00
|
|
|
PspDeleteLdt(Process);
|
|
|
|
PspDeleteVdmObjects(Process);
|
2009-10-29 10:04:15 +00:00
|
|
|
#endif
|
2006-07-09 18:54:13 +00:00
|
|
|
|
|
|
|
/* Delete the Object Table */
|
|
|
|
if (Process->ObjectTable)
|
|
|
|
{
|
|
|
|
/* Attach to the process */
|
|
|
|
KeStackAttachProcess(&Process->Pcb, &ApcState);
|
|
|
|
|
|
|
|
/* Kill the Object Info */
|
|
|
|
ObKillProcess(Process);
|
|
|
|
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Detach */
|
2006-07-09 18:54:13 +00:00
|
|
|
KeUnstackDetachProcess(&ApcState);
|
|
|
|
}
|
2006-05-18 18:55:38 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if we have an address space, and clean it */
|
|
|
|
if (Process->HasAddressSpace)
|
|
|
|
{
|
|
|
|
/* Attach to the process */
|
|
|
|
KeStackAttachProcess(&Process->Pcb, &ApcState);
|
|
|
|
|
|
|
|
/* Clean the Address Space */
|
|
|
|
PspExitProcess(FALSE, Process);
|
|
|
|
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Detach */
|
2006-07-09 18:54:13 +00:00
|
|
|
KeUnstackDetachProcess(&ApcState);
|
|
|
|
|
|
|
|
/* Completely delete the Address Space */
|
|
|
|
MmDeleteProcessAddressSpace(Process);
|
2006-07-20 15:46:10 +00:00
|
|
|
}
|
2006-07-09 18:54:13 +00:00
|
|
|
|
|
|
|
/* See if we have a PID */
|
2007-01-18 09:44:49 +00:00
|
|
|
if (Process->UniqueProcessId)
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
|
|
|
/* Delete the PID */
|
2007-01-22 08:15:17 +00:00
|
|
|
if (!(ExDestroyHandle(PspCidTable, Process->UniqueProcessId, NULL)))
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
|
|
|
/* Something wrong happened, bugcheck */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheck(CID_HANDLE_DELETION);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cleanup security information */
|
|
|
|
PspDeleteProcessSecurity(Process);
|
|
|
|
|
|
|
|
/* Check if we have kept information on the Working Set */
|
|
|
|
if (Process->WorkingSetWatch)
|
|
|
|
{
|
|
|
|
/* Free it */
|
|
|
|
ExFreePool(Process->WorkingSetWatch);
|
|
|
|
|
|
|
|
/* And return the quota it was taking up */
|
|
|
|
PsReturnProcessNonPagedPoolQuota(Process, 0x2000);
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Dereference the Device Map */
|
|
|
|
ObDereferenceDeviceMap(Process);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2021-12-30 20:03:42 +00:00
|
|
|
/*
|
|
|
|
* Dereference the quota block, the function
|
|
|
|
* will invoke a quota block cleanup if the
|
|
|
|
* block itself is no longer used by anybody.
|
|
|
|
*/
|
|
|
|
PspDereferenceQuotaBlock(Process, Process->QuotaBlock);
|
1999-12-18 17:48:23 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 01:38:29 +00:00
|
|
|
VOID
|
2006-07-09 18:54:13 +00:00
|
|
|
NTAPI
|
2006-07-20 16:30:07 +00:00
|
|
|
PspDeleteThread(IN PVOID ObjectBody)
|
1999-01-16 21:03:00 +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
|
|
|
PETHREAD Thread = (PETHREAD)ObjectBody;
|
|
|
|
PEPROCESS Process = Thread->ThreadsProcess;
|
2006-07-09 18:54:13 +00:00
|
|
|
PAGED_CODE();
|
2006-07-23 07:13:19 +00:00
|
|
|
PSTRACE(PS_KILL_DEBUG, "ObjectBody: %p\n", ObjectBody);
|
2006-07-23 19:45:16 +00:00
|
|
|
PSREFTRACE(Thread);
|
2006-07-20 15:46:10 +00:00
|
|
|
ASSERT(Thread->Tcb.Win32Thread == NULL);
|
2003-08-18 11:23:32 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if we have a stack */
|
|
|
|
if (Thread->Tcb.InitialStack)
|
|
|
|
{
|
|
|
|
/* Release it */
|
2008-09-12 11:13:15 +00:00
|
|
|
MmDeleteKernelStack((PVOID)Thread->Tcb.StackBase,
|
2006-07-09 18:54:13 +00:00
|
|
|
Thread->Tcb.LargeStack);
|
|
|
|
}
|
2005-02-23 18:43:25 +00:00
|
|
|
|
2006-07-20 15:46:10 +00:00
|
|
|
/* Check if we have a CID Handle */
|
|
|
|
if (Thread->Cid.UniqueThread)
|
2005-08-07 22:48:07 +00:00
|
|
|
{
|
2006-07-20 15:46:10 +00:00
|
|
|
/* Delete the CID Handle */
|
2007-01-22 08:15:17 +00:00
|
|
|
if (!(ExDestroyHandle(PspCidTable, Thread->Cid.UniqueThread, NULL)))
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
|
|
|
/* Something wrong happened, bugcheck */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheck(CID_HANDLE_DELETION);
|
2006-07-09 18:54:13 +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
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Cleanup impersionation information */
|
|
|
|
PspDeleteThreadSecurity(Thread);
|
|
|
|
|
|
|
|
/* Make sure the thread was inserted, before continuing */
|
|
|
|
if (!Process) return;
|
2003-12-30 00:12:47 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if the thread list is valid */
|
|
|
|
if (Thread->ThreadListEntry.Flink)
|
|
|
|
{
|
|
|
|
/* Lock the thread's process */
|
2006-07-20 17:44:30 +00:00
|
|
|
KeEnterCriticalRegion();
|
|
|
|
ExAcquirePushLockExclusive(&Process->ProcessLock);
|
2006-07-09 18:54:13 +00:00
|
|
|
|
|
|
|
/* Remove us from the list */
|
|
|
|
RemoveEntryList(&Thread->ThreadListEntry);
|
|
|
|
|
|
|
|
/* Release the lock */
|
2006-07-20 17:44:30 +00:00
|
|
|
ExReleasePushLockExclusive(&Process->ProcessLock);
|
|
|
|
KeLeaveCriticalRegion();
|
2006-07-09 18:54:13 +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
|
|
|
/* Dereference the Process */
|
|
|
|
ObDereferenceObject(Process);
|
|
|
|
}
|
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
|
|
|
/*
|
|
|
|
* FUNCTION: Terminates the current thread
|
|
|
|
* See "Windows Internals" - Chapter 13, Page 50-53
|
|
|
|
*/
|
|
|
|
VOID
|
2006-07-09 18:54:13 +00:00
|
|
|
NTAPI
|
2006-07-20 16:30:07 +00:00
|
|
|
PspExitThread(IN NTSTATUS ExitStatus)
|
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-09 18:54:13 +00:00
|
|
|
CLIENT_DIED_MSG TerminationMsg;
|
|
|
|
NTSTATUS Status;
|
2005-04-18 04:46:06 +00:00
|
|
|
PTEB Teb;
|
2006-07-09 18:54:13 +00:00
|
|
|
PEPROCESS CurrentProcess;
|
2007-01-18 09:44:49 +00:00
|
|
|
PETHREAD Thread, OtherThread, PreviousThread = NULL;
|
2006-07-09 18:54:13 +00:00
|
|
|
PVOID DeallocationStack;
|
[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
|
|
|
SIZE_T Dummy;
|
2006-07-09 18:54:13 +00:00
|
|
|
BOOLEAN Last = FALSE;
|
|
|
|
PTERMINATION_PORT TerminationPort, NextPort;
|
2005-08-16 00:01:42 +00:00
|
|
|
PLIST_ENTRY FirstEntry, CurrentEntry;
|
2005-07-23 17:40:48 +00:00
|
|
|
PKAPC Apc;
|
2006-07-09 18:54:13 +00:00
|
|
|
PTOKEN PrimaryToken;
|
|
|
|
PAGED_CODE();
|
2013-08-31 16:02:13 +00:00
|
|
|
PSTRACE(PS_KILL_DEBUG, "ExitStatus: %d\n", ExitStatus);
|
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 the Current Thread and Process */
|
2006-07-09 18:54:13 +00:00
|
|
|
Thread = PsGetCurrentThread();
|
|
|
|
CurrentProcess = Thread->ThreadsProcess;
|
|
|
|
ASSERT((Thread) == PsGetCurrentThread());
|
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
|
|
|
|
|
|
|
/* Can't terminate a thread if it attached another process */
|
2006-07-09 18:54:13 +00:00
|
|
|
if (KeIsAttachedProcess())
|
|
|
|
{
|
2006-07-20 15:46:10 +00:00
|
|
|
/* Bugcheck */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheckEx(INVALID_PROCESS_ATTACH_ATTEMPT,
|
2006-07-20 15:46:10 +00:00
|
|
|
(ULONG_PTR)CurrentProcess,
|
|
|
|
(ULONG_PTR)Thread->Tcb.ApcState.Process,
|
|
|
|
(ULONG_PTR)Thread->Tcb.ApcStateIndex,
|
|
|
|
(ULONG_PTR)Thread);
|
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
|
|
|
/* Lower to Passive Level */
|
2007-01-18 09:44:49 +00:00
|
|
|
KeLowerIrql(PASSIVE_LEVEL);
|
2006-07-09 18:54:13 +00:00
|
|
|
|
|
|
|
/* Can't be a worker thread */
|
|
|
|
if (Thread->ActiveExWorker)
|
|
|
|
{
|
2006-07-20 15:46:10 +00:00
|
|
|
/* Bugcheck */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheckEx(ACTIVE_EX_WORKER_THREAD_TERMINATION,
|
2006-07-20 15:46:10 +00:00
|
|
|
(ULONG_PTR)Thread,
|
2006-07-09 18:54:13 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Can't have pending APCs */
|
|
|
|
if (Thread->Tcb.CombinedApcDisable != 0)
|
|
|
|
{
|
2006-07-20 15:46:10 +00:00
|
|
|
/* Bugcheck */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheckEx(KERNEL_APC_PENDING_DURING_EXIT,
|
2006-07-09 18:54:13 +00:00
|
|
|
0,
|
2007-01-18 09:44:49 +00:00
|
|
|
Thread->Tcb.CombinedApcDisable,
|
|
|
|
0,
|
|
|
|
1);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
|
|
|
|
2006-07-20 15:46:10 +00:00
|
|
|
/* Lock the thread */
|
|
|
|
ExWaitForRundownProtectionRelease(&Thread->RundownProtect);
|
2006-07-09 18:54:13 +00:00
|
|
|
|
|
|
|
/* Cleanup the power state */
|
|
|
|
PopCleanupPowerState((PPOWER_STATE)&Thread->Tcb.PowerState);
|
|
|
|
|
|
|
|
/* Call the WMI Callback for Threads */
|
|
|
|
//WmiTraceThread(Thread, NULL, FALSE);
|
|
|
|
|
|
|
|
/* Run Thread Notify Routines before we desintegrate the thread */
|
|
|
|
PspRunCreateThreadNotifyRoutines(Thread, FALSE);
|
2003-12-30 03:27:52 +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 the Process before we modify its thread entries */
|
2006-07-20 17:44:30 +00:00
|
|
|
KeEnterCriticalRegion();
|
|
|
|
ExAcquirePushLockExclusive(&CurrentProcess->ProcessLock);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Decrease the active thread count, and check if it's 0 */
|
|
|
|
if (!(--CurrentProcess->ActiveThreads))
|
|
|
|
{
|
|
|
|
/* Set the delete flag */
|
2006-07-20 16:26:10 +00:00
|
|
|
InterlockedOr((PLONG)&CurrentProcess->Flags, PSF_PROCESS_DELETE_BIT);
|
2003-11-02 03:09:06 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Remember we are last */
|
|
|
|
Last = TRUE;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if this termination is due to the thread dying */
|
|
|
|
if (ExitStatus == STATUS_THREAD_IS_TERMINATING)
|
|
|
|
{
|
|
|
|
/* Check if the last thread was pending */
|
|
|
|
if (CurrentProcess->ExitStatus == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
/* Use the last exit status */
|
2006-07-20 15:46:10 +00:00
|
|
|
CurrentProcess->ExitStatus = CurrentProcess->
|
|
|
|
LastThreadExitStatus;
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Just a normal exit, write the code */
|
|
|
|
CurrentProcess->ExitStatus = ExitStatus;
|
|
|
|
}
|
|
|
|
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Loop all the current threads */
|
|
|
|
FirstEntry = &CurrentProcess->ThreadListHead;
|
|
|
|
CurrentEntry = FirstEntry->Flink;
|
|
|
|
while (FirstEntry != CurrentEntry)
|
|
|
|
{
|
|
|
|
/* Get the thread on the list */
|
|
|
|
OtherThread = CONTAINING_RECORD(CurrentEntry,
|
|
|
|
ETHREAD,
|
|
|
|
ThreadListEntry);
|
|
|
|
|
|
|
|
/* Check if it's a thread that's still alive */
|
|
|
|
if ((OtherThread != Thread) &&
|
|
|
|
!(KeReadStateThread(&OtherThread->Tcb)) &&
|
|
|
|
(ObReferenceObjectSafe(OtherThread)))
|
|
|
|
{
|
|
|
|
/* It's a live thread and we referenced it, unlock process */
|
|
|
|
ExReleasePushLockExclusive(&CurrentProcess->ProcessLock);
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
|
|
|
|
/* Wait on the thread */
|
|
|
|
KeWaitForSingleObject(OtherThread,
|
|
|
|
Executive,
|
|
|
|
KernelMode,
|
|
|
|
FALSE,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Check if we had a previous thread to dereference */
|
|
|
|
if (PreviousThread) ObDereferenceObject(PreviousThread);
|
|
|
|
|
|
|
|
/* Remember the thread and re-lock the process */
|
|
|
|
PreviousThread = OtherThread;
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
ExAcquirePushLockExclusive(&CurrentProcess->ProcessLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go to the next thread */
|
|
|
|
CurrentEntry = CurrentEntry->Flink;
|
|
|
|
}
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
|
|
|
else if (ExitStatus != STATUS_THREAD_IS_TERMINATING)
|
|
|
|
{
|
|
|
|
/* Write down the exit status of the last thread to get killed */
|
2006-07-20 15:46:10 +00:00
|
|
|
CurrentProcess->LastThreadExitStatus = ExitStatus;
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Unlock the Process */
|
2006-07-20 17:44:30 +00:00
|
|
|
ExReleasePushLockExclusive(&CurrentProcess->ProcessLock);
|
|
|
|
KeLeaveCriticalRegion();
|
2005-03-22 02:32:14 +00:00
|
|
|
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Check if we had a previous thread to dereference */
|
|
|
|
if (PreviousThread) ObDereferenceObject(PreviousThread);
|
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if the process has a debug port and if this is a user thread */
|
2006-07-20 15:46:10 +00:00
|
|
|
if ((CurrentProcess->DebugPort) && !(Thread->SystemThread))
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
|
|
|
/* Notify the Debug API. */
|
|
|
|
Last ? DbgkExitProcess(CurrentProcess->ExitStatus) :
|
|
|
|
DbgkExitThread(ExitStatus);
|
2005-03-22 02:32:14 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if this is a Critical Thread */
|
|
|
|
if ((KdDebuggerEnabled) && (Thread->BreakOnTermination))
|
|
|
|
{
|
2006-07-21 19:59:16 +00:00
|
|
|
/* Break to debugger */
|
|
|
|
PspCatchCriticalBreak("Critical thread 0x%p (in %s) exited\n",
|
|
|
|
Thread,
|
|
|
|
CurrentProcess->ImageFileName);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if it's the last thread and this is a Critical Process */
|
|
|
|
if ((Last) && (CurrentProcess->BreakOnTermination))
|
|
|
|
{
|
|
|
|
/* Check if a debugger is here to handle this */
|
|
|
|
if (KdDebuggerEnabled)
|
|
|
|
{
|
2006-07-21 19:59:16 +00:00
|
|
|
/* Break to debugger */
|
|
|
|
PspCatchCriticalBreak("Critical process 0x%p (in %s) exited\n",
|
|
|
|
CurrentProcess,
|
|
|
|
CurrentProcess->ImageFileName);
|
2006-07-20 15:46:10 +00:00
|
|
|
}
|
2006-07-09 18:54:13 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Bugcheck, we can't allow this */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheckEx(CRITICAL_PROCESS_DIED,
|
2006-07-09 18:54:13 +00:00
|
|
|
(ULONG_PTR)CurrentProcess,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(Thread->Tcb.CombinedApcDisable == 0);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
|
|
|
/* Process the Termination Ports */
|
2006-07-09 18:54:13 +00:00
|
|
|
TerminationPort = Thread->TerminationPort;
|
|
|
|
if (TerminationPort)
|
|
|
|
{
|
|
|
|
/* Setup the message header */
|
2009-12-12 15:21:56 +00:00
|
|
|
TerminationMsg.h.u2.ZeroInit = 0;
|
|
|
|
TerminationMsg.h.u2.s2.Type = LPC_CLIENT_DIED;
|
2006-07-09 18:54:13 +00:00
|
|
|
TerminationMsg.h.u1.s1.TotalLength = sizeof(TerminationMsg);
|
|
|
|
TerminationMsg.h.u1.s1.DataLength = sizeof(TerminationMsg) -
|
|
|
|
sizeof(PORT_MESSAGE);
|
|
|
|
|
|
|
|
/* Loop each port */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Save the Create Time */
|
|
|
|
TerminationMsg.CreateTime = Thread->CreateTime;
|
|
|
|
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Loop trying to send message */
|
|
|
|
while (TRUE)
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Send the LPC Message */
|
|
|
|
Status = LpcRequestPort(TerminationPort->Port,
|
|
|
|
&TerminationMsg.h);
|
|
|
|
if ((Status == STATUS_NO_MEMORY) ||
|
|
|
|
(Status == STATUS_INSUFFICIENT_RESOURCES))
|
|
|
|
{
|
|
|
|
/* Wait a bit and try again */
|
|
|
|
KeDelayExecutionThread(KernelMode, FALSE, &ShortTime);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
2005-05-31 15:01:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Dereference this LPC Port */
|
|
|
|
ObDereferenceObject(TerminationPort->Port);
|
2005-05-31 15:01:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Move to the next one */
|
|
|
|
NextPort = TerminationPort->Next;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Free the Termination Port Object */
|
2013-07-20 17:46:38 +00:00
|
|
|
ExFreePoolWithTag(TerminationPort, '=TsP');
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Keep looping as long as there is a port */
|
2007-01-18 09:44:49 +00:00
|
|
|
TerminationPort = NextPort;
|
|
|
|
} while (TerminationPort);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
|
|
|
else if (((ExitStatus == STATUS_THREAD_IS_TERMINATING) &&
|
|
|
|
(Thread->DeadThread)) ||
|
|
|
|
!(Thread->DeadThread))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This case is special and deserves some extra comments. What
|
|
|
|
* basically happens here is that this thread doesn't have a termination
|
|
|
|
* port, which means that it died before being fully created. Since we
|
|
|
|
* still have to notify an LPC Server, we'll use the exception port,
|
|
|
|
* which we know exists. However, we need to know how far the thread
|
2015-02-20 12:04:57 +00:00
|
|
|
* actually got created. We have three possibilities:
|
2006-07-09 18:54:13 +00:00
|
|
|
*
|
|
|
|
* - NtCreateThread returned an error really early: DeadThread is set.
|
|
|
|
* - NtCreateThread managed to create the thread: DeadThread is off.
|
2015-02-20 12:04:57 +00:00
|
|
|
* - NtCreateThread was creating the thread (with DeadThread set,
|
2006-07-09 18:54:13 +00:00
|
|
|
* but the thread got killed prematurely: STATUS_THREAD_IS_TERMINATING
|
|
|
|
* is our exit code.)
|
|
|
|
*
|
|
|
|
* For the 2 & 3rd scenarios, the thread has been created far enough to
|
|
|
|
* warrant notification to the LPC Server.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Setup the message header */
|
2015-02-20 12:04:57 +00:00
|
|
|
TerminationMsg.h.u2.ZeroInit = 0;
|
2006-07-09 18:54:13 +00:00
|
|
|
TerminationMsg.h.u2.s2.Type = LPC_CLIENT_DIED;
|
|
|
|
TerminationMsg.h.u1.s1.TotalLength = sizeof(TerminationMsg);
|
|
|
|
TerminationMsg.h.u1.s1.DataLength = sizeof(TerminationMsg) -
|
|
|
|
sizeof(PORT_MESSAGE);
|
|
|
|
|
|
|
|
/* Make sure the process has an exception port */
|
|
|
|
if (CurrentProcess->ExceptionPort)
|
|
|
|
{
|
|
|
|
/* Save the Create Time */
|
|
|
|
TerminationMsg.CreateTime = Thread->CreateTime;
|
|
|
|
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Loop trying to send message */
|
|
|
|
while (TRUE)
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Send the LPC Message */
|
|
|
|
Status = LpcRequestPort(CurrentProcess->ExceptionPort,
|
|
|
|
&TerminationMsg.h);
|
|
|
|
if ((Status == STATUS_NO_MEMORY) ||
|
|
|
|
(Status == STATUS_INSUFFICIENT_RESOURCES))
|
|
|
|
{
|
|
|
|
/* Wait a bit and try again */
|
|
|
|
KeDelayExecutionThread(KernelMode, FALSE, &ShortTime);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2006-07-09 18:54:13 +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
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Rundown Win32 Thread if there is one */
|
2006-07-20 15:46:10 +00:00
|
|
|
if (Thread->Tcb.Win32Thread) PspW32ThreadCallout(Thread,
|
|
|
|
PsW32ThreadCalloutExit);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* If we are the last thread and have a W32 Process */
|
|
|
|
if ((Last) && (CurrentProcess->Win32Process))
|
|
|
|
{
|
|
|
|
/* Run it down too */
|
|
|
|
PspW32ProcessCallout(CurrentProcess, FALSE);
|
|
|
|
}
|
|
|
|
|
2008-08-13 09:00:50 +00:00
|
|
|
/* Make sure Stack Swap is enabled */
|
|
|
|
if (!Thread->Tcb.EnableStackSwap)
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
2008-08-13 09:00:50 +00:00
|
|
|
/* Stack swap really shouldn't be disabled during exit! */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheckEx(KERNEL_STACK_LOCKED_AT_EXIT, 0, 0, 0, 0);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Cancel I/O for the thread. */
|
|
|
|
IoCancelThreadIo(Thread);
|
|
|
|
|
|
|
|
/* Rundown Timers */
|
|
|
|
ExTimerRundown();
|
|
|
|
|
|
|
|
/* FIXME: Rundown Registry Notifications (NtChangeNotify)
|
|
|
|
CmNotifyRunDown(Thread); */
|
|
|
|
|
|
|
|
/* Rundown Mutexes */
|
|
|
|
KeRundownThread();
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-20 15:46:10 +00:00
|
|
|
/* Check if we have a TEB */
|
|
|
|
Teb = Thread->Tcb.Teb;
|
2007-01-18 09:44:49 +00:00
|
|
|
if (Teb)
|
2005-07-12 01:56:14 +00:00
|
|
|
{
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Check if the thread is still alive */
|
|
|
|
if (!Thread->DeadThread)
|
2005-07-12 01:56:14 +00:00
|
|
|
{
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Check if we need to free its stack */
|
|
|
|
if (Teb->FreeStackOnTermination)
|
|
|
|
{
|
|
|
|
/* Set the TEB's Deallocation Stack as the Base Address */
|
|
|
|
Dummy = 0;
|
|
|
|
DeallocationStack = Teb->DeallocationStack;
|
|
|
|
|
|
|
|
/* Free the Thread's Stack */
|
|
|
|
ZwFreeVirtualMemory(NtCurrentProcess(),
|
|
|
|
&DeallocationStack,
|
|
|
|
&Dummy,
|
|
|
|
MEM_RELEASE);
|
|
|
|
}
|
2006-07-20 15:46:10 +00:00
|
|
|
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Free the debug handle */
|
|
|
|
if (Teb->DbgSsReserved[1]) ObCloseHandle(Teb->DbgSsReserved[1],
|
|
|
|
UserMode);
|
|
|
|
}
|
2006-07-20 15:46:10 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Decommit the TEB */
|
2006-05-18 20:32:17 +00:00
|
|
|
MmDeleteTeb(CurrentProcess, Teb);
|
2006-07-09 18:54:13 +00:00
|
|
|
Thread->Tcb.Teb = NULL;
|
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
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Free LPC Data */
|
|
|
|
LpcExitThread(Thread);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Save the exit status and exit time */
|
|
|
|
Thread->ExitStatus = ExitStatus;
|
|
|
|
KeQuerySystemTime(&Thread->ExitTime);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(Thread->Tcb.CombinedApcDisable == 0);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if this is the final thread or not */
|
|
|
|
if (Last)
|
|
|
|
{
|
|
|
|
/* Set the process exit time */
|
|
|
|
CurrentProcess->ExitTime = Thread->ExitTime;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Exit the process */
|
|
|
|
PspExitProcess(TRUE, CurrentProcess);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Get the process token and check if we need to audit */
|
|
|
|
PrimaryToken = PsReferencePrimaryToken(CurrentProcess);
|
|
|
|
if (SeDetailedAuditingWithToken(PrimaryToken))
|
|
|
|
{
|
|
|
|
/* Audit the exit */
|
|
|
|
SeAuditProcessExit(CurrentProcess);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dereference the process token */
|
|
|
|
ObFastDereferenceObject(&CurrentProcess->Token, PrimaryToken);
|
1999-01-16 21:03:00 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if this is a VDM Process and rundown the VDM DPCs if so */
|
2008-12-03 17:28:59 +00:00
|
|
|
if (CurrentProcess->VdmObjects) { /* VdmRundownDpcs(CurrentProcess); */ }
|
2006-07-09 18:54:13 +00:00
|
|
|
|
|
|
|
/* Kill the process in the Object Manager */
|
|
|
|
ObKillProcess(CurrentProcess);
|
|
|
|
|
|
|
|
/* Check if we have a section object */
|
|
|
|
if (CurrentProcess->SectionObject)
|
|
|
|
{
|
|
|
|
/* Dereference and clear the Section Object */
|
|
|
|
ObDereferenceObject(CurrentProcess->SectionObject);
|
|
|
|
CurrentProcess->SectionObject = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the process is part of a job */
|
|
|
|
if (CurrentProcess->Job)
|
|
|
|
{
|
|
|
|
/* Remove the process from the job */
|
|
|
|
PspExitProcessFromJob(CurrentProcess->Job, CurrentProcess);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable APCs */
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
|
|
|
|
/* Disable APC queueing, force a resumption */
|
|
|
|
Thread->Tcb.ApcQueueable = FALSE;
|
|
|
|
KeForceResumeThread(&Thread->Tcb);
|
|
|
|
|
|
|
|
/* Re-enable APCs */
|
|
|
|
KeLeaveCriticalRegion();
|
2005-07-23 17:40:48 +00:00
|
|
|
|
|
|
|
/* Flush the User APCs */
|
2006-07-09 18:54:13 +00:00
|
|
|
FirstEntry = KeFlushQueueApc(&Thread->Tcb, UserMode);
|
2006-07-20 15:46:10 +00:00
|
|
|
if (FirstEntry)
|
2005-07-23 17:40:48 +00:00
|
|
|
{
|
2007-01-18 09:44:49 +00:00
|
|
|
/* Start with the first entry */
|
2005-08-16 00:01:42 +00:00
|
|
|
CurrentEntry = FirstEntry;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Get the APC */
|
|
|
|
Apc = CONTAINING_RECORD(CurrentEntry, KAPC, ApcListEntry);
|
|
|
|
|
|
|
|
/* Move to the next one */
|
|
|
|
CurrentEntry = CurrentEntry->Flink;
|
|
|
|
|
|
|
|
/* Rundown the APC or de-allocate it */
|
|
|
|
if (Apc->RundownRoutine)
|
|
|
|
{
|
|
|
|
/* Call its own routine */
|
2007-01-18 09:44:49 +00:00
|
|
|
Apc->RundownRoutine(Apc);
|
2005-08-16 00:01:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Do it ourselves */
|
|
|
|
ExFreePool(Apc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (CurrentEntry != FirstEntry);
|
2005-07-23 17:40:48 +00:00
|
|
|
}
|
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Clean address space if this was the last thread */
|
|
|
|
if (Last) MmCleanProcessAddressSpace(CurrentProcess);
|
|
|
|
|
2005-07-23 17:40:48 +00:00
|
|
|
/* Call the Lego routine */
|
2006-07-09 18:54:13 +00:00
|
|
|
if (Thread->Tcb.LegoData) PspRunLegoRoutine(&Thread->Tcb);
|
2005-07-23 17:40:48 +00:00
|
|
|
|
|
|
|
/* Flush the APC queue, which should be empty */
|
2006-07-20 15:46:10 +00:00
|
|
|
FirstEntry = KeFlushQueueApc(&Thread->Tcb, KernelMode);
|
2007-01-18 09:44:49 +00:00
|
|
|
if ((FirstEntry) || (Thread->Tcb.CombinedApcDisable != 0))
|
2005-07-23 17:40:48 +00:00
|
|
|
{
|
|
|
|
/* Bugcheck time */
|
2008-08-24 15:48:05 +00:00
|
|
|
KeBugCheckEx(KERNEL_APC_PENDING_DURING_EXIT,
|
2005-08-16 00:01:42 +00:00
|
|
|
(ULONG_PTR)FirstEntry,
|
2007-01-18 09:44:49 +00:00
|
|
|
Thread->Tcb.CombinedApcDisable,
|
2006-07-09 18:54:13 +00:00
|
|
|
KeGetCurrentIrql(),
|
2005-07-23 17:40:48 +00:00
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Signal the process if this was the last thread */
|
|
|
|
if (Last) KeSetProcess(&CurrentProcess->Pcb, 0, FALSE);
|
|
|
|
|
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
|
|
|
/* Terminate the Thread from the Scheduler */
|
|
|
|
KeTerminateThread(0);
|
2001-02-06 00:11:20 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 01:38:29 +00:00
|
|
|
VOID
|
2006-07-09 18:54:13 +00:00
|
|
|
NTAPI
|
2006-07-20 16:30:07 +00:00
|
|
|
PsExitSpecialApc(IN PKAPC Apc,
|
|
|
|
IN OUT PKNORMAL_ROUTINE* NormalRoutine,
|
|
|
|
IN OUT PVOID* NormalContext,
|
|
|
|
IN OUT PVOID* SystemArgument1,
|
2006-07-23 07:13:19 +00:00
|
|
|
IN OUT PVOID* SystemArgument2)
|
2001-02-06 00:11:20 +00:00
|
|
|
{
|
2006-07-09 18:54:13 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PAGED_CODE();
|
2006-07-23 07:13:19 +00:00
|
|
|
PSTRACE(PS_KILL_DEBUG,
|
2021-09-12 17:49:54 +00:00
|
|
|
"Apc: %p SystemArgument2: %p\n", Apc, SystemArgument2);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-07-18 19:50:23 +00:00
|
|
|
/* Don't do anything unless we are in User-Mode */
|
|
|
|
if (Apc->SystemArgument2)
|
|
|
|
{
|
|
|
|
/* Free the APC */
|
2017-08-18 12:31:19 +00:00
|
|
|
Status = PtrToUlong(Apc->NormalContext);
|
2006-07-09 18:54:13 +00:00
|
|
|
PspExitApcRundown(Apc);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-07-18 19:50:23 +00:00
|
|
|
/* Terminate the Thread */
|
2006-07-09 18:54:13 +00:00
|
|
|
PspExitThread(Status);
|
2005-07-18 19:50:23 +00:00
|
|
|
}
|
2001-02-06 00:11:20 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 01:38:29 +00:00
|
|
|
VOID
|
2006-07-09 18:54:13 +00:00
|
|
|
NTAPI
|
2006-07-20 16:30:07 +00:00
|
|
|
PspExitNormalApc(IN PVOID NormalContext,
|
|
|
|
IN PVOID SystemArgument1,
|
|
|
|
IN PVOID SystemArgument2)
|
2001-02-06 00:11:20 +00:00
|
|
|
{
|
2005-07-18 19:50:23 +00:00
|
|
|
PKAPC Apc = (PKAPC)SystemArgument1;
|
|
|
|
PETHREAD Thread = PsGetCurrentThread();
|
2006-07-09 18:54:13 +00:00
|
|
|
PAGED_CODE();
|
2021-09-12 17:49:54 +00:00
|
|
|
PSTRACE(PS_KILL_DEBUG, "SystemArgument2: %p\n", SystemArgument2);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-07-18 19:50:23 +00:00
|
|
|
/* This should never happen */
|
2006-07-09 18:54:13 +00:00
|
|
|
ASSERT(!(((ULONG_PTR)SystemArgument2) & 1));
|
2005-07-18 19:50:23 +00:00
|
|
|
|
|
|
|
/* If we're here, this is not a System Thread, so kill it from User-Mode */
|
|
|
|
KeInitializeApc(Apc,
|
|
|
|
&Thread->Tcb,
|
|
|
|
OriginalApcEnvironment,
|
|
|
|
PsExitSpecialApc,
|
2006-07-09 18:54:13 +00:00
|
|
|
PspExitApcRundown,
|
2005-07-18 19:50:23 +00:00
|
|
|
PspExitNormalApc,
|
|
|
|
UserMode,
|
|
|
|
NormalContext);
|
|
|
|
|
|
|
|
/* Now insert the APC with the User-Mode Flag */
|
2006-07-09 18:54:13 +00:00
|
|
|
if (!(KeInsertQueueApc(Apc,
|
|
|
|
Apc,
|
|
|
|
(PVOID)((ULONG_PTR)SystemArgument2 | 1),
|
|
|
|
2)))
|
|
|
|
{
|
|
|
|
/* Failed to insert, free the APC */
|
|
|
|
PspExitApcRundown(Apc);
|
|
|
|
}
|
2005-07-18 19:50:23 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Set the APC Pending flag */
|
|
|
|
Thread->Tcb.ApcState.UserApcPending = TRUE;
|
2001-02-06 00:11:20 +00:00
|
|
|
}
|
|
|
|
|
1999-02-06 18:34:14 +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
|
|
|
* See "Windows Internals" - Chapter 13, Page 49
|
1999-02-06 18:34:14 +00:00
|
|
|
*/
|
2006-07-09 18:54:13 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2006-07-20 16:30:07 +00:00
|
|
|
PspTerminateThreadByPointer(IN PETHREAD Thread,
|
|
|
|
IN NTSTATUS ExitStatus,
|
|
|
|
IN BOOLEAN bSelf)
|
1999-01-16 21:03:00 +00:00
|
|
|
{
|
2005-05-09 01:38:29 +00:00
|
|
|
PKAPC Apc;
|
2006-07-09 18:54:13 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
ULONG Flags;
|
|
|
|
PAGED_CODE();
|
2013-08-31 16:02:13 +00:00
|
|
|
PSTRACE(PS_KILL_DEBUG, "Thread: %p ExitStatus: %d\n", Thread, ExitStatus);
|
2006-07-23 19:45:16 +00:00
|
|
|
PSREFTRACE(Thread);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if this is a Critical Thread, and Bugcheck */
|
|
|
|
if (Thread->BreakOnTermination)
|
|
|
|
{
|
2006-07-21 19:59:16 +00:00
|
|
|
/* Break to debugger */
|
|
|
|
PspCatchCriticalBreak("Terminating critical thread 0x%p (%s)\n",
|
|
|
|
Thread,
|
|
|
|
Thread->ThreadsProcess->ImageFileName);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we are already inside the thread */
|
2006-07-20 15:46:10 +00:00
|
|
|
if ((bSelf) || (PsGetCurrentThread() == Thread))
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
|
|
|
/* This should only happen at passive */
|
2007-01-17 20:44:37 +00:00
|
|
|
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Mark it as terminated */
|
2006-07-23 21:38:31 +00:00
|
|
|
PspSetCrossThreadFlag(Thread, CT_TERMINATED_BIT);
|
2005-03-22 02:32:14 +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
|
|
|
/* Directly terminate the thread */
|
|
|
|
PspExitThread(ExitStatus);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
2005-03-22 02:32:14 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* This shouldn't be a system thread */
|
2006-07-20 15:46:10 +00:00
|
|
|
if (Thread->SystemThread) return STATUS_ACCESS_DENIED;
|
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
|
|
|
/* Allocate the APC */
|
|
|
|
Apc = ExAllocatePoolWithTag(NonPagedPool, sizeof(KAPC), TAG_TERMINATE_APC);
|
2009-09-02 13:02:30 +00:00
|
|
|
if (!Apc) return STATUS_INSUFFICIENT_RESOURCES;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Set the Terminated Flag */
|
2007-01-18 09:44:49 +00:00
|
|
|
Flags = Thread->CrossThreadFlags | CT_TERMINATED_BIT;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Set it, and check if it was already set while we were running */
|
2007-01-18 09:44:49 +00:00
|
|
|
if (!(InterlockedExchange((PLONG)&Thread->CrossThreadFlags, Flags) &
|
|
|
|
CT_TERMINATED_BIT))
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
|
|
|
/* Initialize a Kernel Mode APC to Kill the Thread */
|
|
|
|
KeInitializeApc(Apc,
|
|
|
|
&Thread->Tcb,
|
|
|
|
OriginalApcEnvironment,
|
|
|
|
PsExitSpecialApc,
|
|
|
|
PspExitApcRundown,
|
|
|
|
PspExitNormalApc,
|
|
|
|
KernelMode,
|
2017-08-18 12:31:19 +00:00
|
|
|
UlongToPtr(ExitStatus));
|
2006-07-09 18:54:13 +00:00
|
|
|
|
|
|
|
/* Insert it into the APC Queue */
|
|
|
|
if (!KeInsertQueueApc(Apc, Apc, NULL, 2))
|
|
|
|
{
|
|
|
|
/* The APC was already in the queue, fail */
|
|
|
|
Status = STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Forcefully resume the thread and return */
|
|
|
|
KeForceResumeThread(&Thread->Tcb);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* We failed, free the APC */
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-27 17:16:31 +00:00
|
|
|
ExFreePoolWithTag(Apc, TAG_TERMINATE_APC);
|
2006-07-09 18:54:13 +00:00
|
|
|
|
|
|
|
/* Return Status */
|
|
|
|
return Status;
|
1999-01-16 21:03:00 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
[CACHE]
The cache manager rewrite I started years ago has finally appeared in
ReactOS' trunk and although at this point it's not quite perfectly
integrated, it's enough to boot up the bootcd or livecd. To check out
the more mature original, check out arty-newcc-reactos, branch
arty-newcc on bitbucket.org . Amine Khaldi encouraged me quite a bit
to not give up on it, and was able to reach out and be an advocate
when i really wasn't able to. Others agree that the time has come to
begin removing the old cache manager. I expect the remaining problems
in the version going to trunk will be taken care of relatively
quickly.
The motivation for this effort lies in the particularly hairy
relationship between ReactOS' cache manager and data sections. This
code completely removes page sharing between cache manager and section
and reimagines cache manager as being a facility layered on the memory
manager, not really caring about individual pages, but simply managing
data section objects where caching might occur.
It took me about 2 years to do the first pass of this rewrite and most
of this year to fix some lingering issues, properly implement demand
paging in ReactOS (code which didn't come with this patch in a
recognizable form), and finish getting the PrivateCacheMap and
SharedCacheMap relationship correct.
Currently, the new ntoskrnl/cache directory contains an own
implementation of data file sections. After things have settled down,
we can begin to deprecate and remove the parts of ReactOS' section
implementation that depend on a close relationship with cache
manager. Eventually, I think that the extra code added to
ntoskrnl/cache/section will be removed and ReactOS' own sections will
replace the use of the special MM_CACHE_SECTION_SEGMENT in the cache
path.
Note also, that this makes all cache manager (and new section parts)
use wide file offsets. If my section code were to take over other
parts of the ReactOS memory manager, they would also benefit from
these improvements.
I invite anyone who wants to to peek at this code and fix whatever
bugs can be found.
svn path=/trunk/; revision=49423
2010-11-02 02:32:39 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
PspIsProcessExiting(IN PEPROCESS Process)
|
|
|
|
{
|
2015-09-03 23:57:39 +00:00
|
|
|
return Process->Flags & PSF_PROCESS_EXITING_BIT;
|
[CACHE]
The cache manager rewrite I started years ago has finally appeared in
ReactOS' trunk and although at this point it's not quite perfectly
integrated, it's enough to boot up the bootcd or livecd. To check out
the more mature original, check out arty-newcc-reactos, branch
arty-newcc on bitbucket.org . Amine Khaldi encouraged me quite a bit
to not give up on it, and was able to reach out and be an advocate
when i really wasn't able to. Others agree that the time has come to
begin removing the old cache manager. I expect the remaining problems
in the version going to trunk will be taken care of relatively
quickly.
The motivation for this effort lies in the particularly hairy
relationship between ReactOS' cache manager and data sections. This
code completely removes page sharing between cache manager and section
and reimagines cache manager as being a facility layered on the memory
manager, not really caring about individual pages, but simply managing
data section objects where caching might occur.
It took me about 2 years to do the first pass of this rewrite and most
of this year to fix some lingering issues, properly implement demand
paging in ReactOS (code which didn't come with this patch in a
recognizable form), and finish getting the PrivateCacheMap and
SharedCacheMap relationship correct.
Currently, the new ntoskrnl/cache directory contains an own
implementation of data file sections. After things have settled down,
we can begin to deprecate and remove the parts of ReactOS' section
implementation that depend on a close relationship with cache
manager. Eventually, I think that the extra code added to
ntoskrnl/cache/section will be removed and ReactOS' own sections will
replace the use of the special MM_CACHE_SECTION_SEGMENT in the cache
path.
Note also, that this makes all cache manager (and new section parts)
use wide file offsets. If my section code were to take over other
parts of the ReactOS memory manager, they would also benefit from
these improvements.
I invite anyone who wants to to peek at this code and fix whatever
bugs can be found.
svn path=/trunk/; revision=49423
2010-11-02 02:32:39 +00:00
|
|
|
}
|
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
PspExitProcess(IN BOOLEAN LastThread,
|
|
|
|
IN PEPROCESS Process)
|
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-09 18:54:13 +00:00
|
|
|
ULONG Actual;
|
|
|
|
PAGED_CODE();
|
2006-07-23 07:13:19 +00:00
|
|
|
PSTRACE(PS_KILL_DEBUG,
|
2013-08-31 16:02:13 +00:00
|
|
|
"LastThread: %u Process: %p\n", LastThread, Process);
|
2006-07-23 19:45:16 +00:00
|
|
|
PSREFTRACE(Process);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-20 16:26:10 +00:00
|
|
|
/* Set Process Exit flag */
|
|
|
|
InterlockedOr((PLONG)&Process->Flags, PSF_PROCESS_EXITING_BIT);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if we are the last thread */
|
|
|
|
if (LastThread)
|
|
|
|
{
|
|
|
|
/* Notify the WMI Process Callback */
|
|
|
|
//WmiTraceProcess(Process, FALSE);
|
|
|
|
|
|
|
|
/* Run the Notification Routines */
|
|
|
|
PspRunCreateProcessNotifyRoutines(Process, FALSE);
|
|
|
|
}
|
2005-08-01 11:20:44 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Cleanup the power state */
|
|
|
|
PopCleanupPowerState((PPOWER_STATE)&Process->Pcb.PowerState);
|
|
|
|
|
|
|
|
/* Clear the security port */
|
|
|
|
if (!Process->SecurityPort)
|
|
|
|
{
|
|
|
|
/* So we don't double-dereference */
|
|
|
|
Process->SecurityPort = (PVOID)1;
|
|
|
|
}
|
|
|
|
else if (Process->SecurityPort != (PVOID)1)
|
|
|
|
{
|
|
|
|
/* Dereference it */
|
|
|
|
ObDereferenceObject(Process->SecurityPort);
|
|
|
|
Process->SecurityPort = (PVOID)1;
|
|
|
|
}
|
2005-03-21 21:33:31 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if we are the last thread */
|
|
|
|
if (LastThread)
|
|
|
|
{
|
|
|
|
/* Check if we have to set the Timer Resolution */
|
|
|
|
if (Process->SetTimerResolution)
|
|
|
|
{
|
|
|
|
/* Set it to default */
|
|
|
|
ZwSetTimerResolution(KeMaximumIncrement, 0, &Actual);
|
|
|
|
}
|
2006-07-20 15:46:10 +00:00
|
|
|
|
|
|
|
/* Check if we are part of a Job that has a completion port */
|
2006-07-09 18:54:13 +00:00
|
|
|
if ((Process->Job) && (Process->Job->CompletionPort))
|
|
|
|
{
|
|
|
|
/* FIXME: Check job status code and do I/O completion if needed */
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* FIXME: Notify the Prefetcher */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Clear process' address space here */
|
|
|
|
MmCleanProcessAddressSpace(Process);
|
|
|
|
}
|
1999-11-24 11:51:55 +00:00
|
|
|
}
|
1999-01-16 21:03:00 +00:00
|
|
|
|
2006-07-20 15:46:10 +00:00
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2006-07-20 16:30:07 +00:00
|
|
|
PsTerminateSystemThread(IN NTSTATUS ExitStatus)
|
2006-07-20 15:46:10 +00:00
|
|
|
{
|
|
|
|
PETHREAD Thread = PsGetCurrentThread();
|
|
|
|
|
|
|
|
/* Make sure this is a system thread */
|
2008-08-13 07:55:59 +00:00
|
|
|
if (!Thread->SystemThread) return STATUS_INVALID_PARAMETER;
|
2006-07-20 15:46:10 +00:00
|
|
|
|
|
|
|
/* Terminate it for real */
|
|
|
|
return PspTerminateThreadByPointer(Thread, ExitStatus, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2006-07-09 18:54:13 +00:00
|
|
|
NTAPI
|
2006-07-20 15:46:10 +00:00
|
|
|
NtTerminateProcess(IN HANDLE ProcessHandle OPTIONAL,
|
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
|
|
|
IN NTSTATUS ExitStatus)
|
1999-01-16 21:03:00 +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
|
|
|
NTSTATUS Status;
|
2006-07-09 18:54:13 +00:00
|
|
|
PEPROCESS Process, CurrentProcess = PsGetCurrentProcess();
|
|
|
|
PETHREAD Thread, CurrentThread = PsGetCurrentThread();
|
2005-03-22 17:32:15 +00:00
|
|
|
BOOLEAN KillByHandle;
|
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
|
|
|
PAGED_CODE();
|
2006-07-23 07:13:19 +00:00
|
|
|
PSTRACE(PS_KILL_DEBUG,
|
2013-08-31 16:02:13 +00:00
|
|
|
"ProcessHandle: %p ExitStatus: %d\n", ProcessHandle, ExitStatus);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-08-22 07:28:45 +00:00
|
|
|
/* Were we passed a process handle? */
|
|
|
|
if (ProcessHandle)
|
|
|
|
{
|
|
|
|
/* Yes we were, use it */
|
|
|
|
KillByHandle = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We weren't... we assume this is suicide */
|
|
|
|
KillByHandle = FALSE;
|
|
|
|
ProcessHandle = NtCurrentProcess();
|
|
|
|
}
|
2005-03-22 17:32:15 +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 the Process Object */
|
2007-08-22 07:28:45 +00:00
|
|
|
Status = ObReferenceObjectByHandle(ProcessHandle,
|
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
|
|
|
PROCESS_TERMINATE,
|
|
|
|
PsProcessType,
|
|
|
|
KeGetPreviousMode(),
|
|
|
|
(PVOID*)&Process,
|
|
|
|
NULL);
|
2006-07-20 15:46:10 +00:00
|
|
|
if (!NT_SUCCESS(Status)) return(Status);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if this is a Critical Process, and Bugcheck */
|
|
|
|
if (Process->BreakOnTermination)
|
2005-03-22 02:32:14 +00:00
|
|
|
{
|
2006-07-21 19:59:16 +00:00
|
|
|
/* Break to debugger */
|
|
|
|
PspCatchCriticalBreak("Terminating critical process 0x%p (%s)\n",
|
|
|
|
Process,
|
|
|
|
Process->ImageFileName);
|
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
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Lock the Process */
|
2007-01-18 09:44:49 +00:00
|
|
|
if (!ExAcquireRundownProtection(&Process->RundownProtect))
|
|
|
|
{
|
2008-08-22 14:29:01 +00:00
|
|
|
/* Failed to lock, fail */
|
2015-02-20 12:04:57 +00:00
|
|
|
ObDereferenceObject(Process);
|
2007-01-18 09:44:49 +00:00
|
|
|
return STATUS_PROCESS_IS_TERMINATING;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-08-22 07:28:45 +00:00
|
|
|
/* Set the delete flag, unless the process is comitting suicide */
|
|
|
|
if (KillByHandle) PspSetProcessFlag(Process, PSF_PROCESS_DELETE_BIT);
|
2005-03-22 17:32:15 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Get the first thread */
|
|
|
|
Status = STATUS_NOTHING_TO_TERMINATE;
|
2006-07-20 15:46:10 +00:00
|
|
|
Thread = PsGetNextProcessThread(Process, NULL);
|
|
|
|
if (Thread)
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
|
|
|
/* We know we have at least a thread */
|
|
|
|
Status = STATUS_SUCCESS;
|
2005-03-22 02:32:14 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Loop and kill the others */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Ensure it's not ours*/
|
|
|
|
if (Thread != CurrentThread)
|
|
|
|
{
|
|
|
|
/* Kill it */
|
|
|
|
PspTerminateThreadByPointer(Thread, ExitStatus, FALSE);
|
|
|
|
}
|
2005-03-22 17:32:15 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Move to the next thread */
|
2007-01-18 09:44:49 +00:00
|
|
|
Thread = PsGetNextProcessThread(Process, Thread);
|
|
|
|
} while (Thread);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
2005-03-22 17:32:15 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Unlock the process */
|
2006-07-20 15:46:10 +00:00
|
|
|
ExReleaseRundownProtection(&Process->RundownProtect);
|
2005-03-22 17:32:15 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if we are killing ourselves */
|
2007-08-22 07:28:45 +00:00
|
|
|
if (Process == CurrentProcess)
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
2007-08-22 07:28:45 +00:00
|
|
|
/* Also make sure the caller gave us our handle */
|
|
|
|
if (KillByHandle)
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
2008-08-22 14:29:01 +00:00
|
|
|
/* Dereference the process */
|
2007-08-22 07:28:45 +00:00
|
|
|
ObDereferenceObject(Process);
|
|
|
|
|
|
|
|
/* Terminate ourselves */
|
|
|
|
PspTerminateThreadByPointer(CurrentThread, ExitStatus, TRUE);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-22 07:28:45 +00:00
|
|
|
else if (ExitStatus == DBG_TERMINATE_PROCESS)
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
2007-08-22 07:28:45 +00:00
|
|
|
/* Disable debugging on this process */
|
|
|
|
DbgkClearProcessDebugObject(Process, NULL);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
2005-03-22 17:32:15 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Check if there was nothing to terminate, or if we have a Debug Port */
|
|
|
|
if ((Status == STATUS_NOTHING_TO_TERMINATE) ||
|
2006-07-20 15:46:10 +00:00
|
|
|
((Process->DebugPort) && (KillByHandle)))
|
2006-07-09 18:54:13 +00:00
|
|
|
{
|
|
|
|
/* Clear the handle table */
|
|
|
|
ObClearProcessHandleTable(Process);
|
2005-03-22 17:32:15 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Return status now */
|
|
|
|
Status = STATUS_SUCCESS;
|
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-03-22 17:32:15 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Decrease the reference count we added */
|
2005-03-22 17:32:15 +00:00
|
|
|
ObDereferenceObject(Process);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* Return status */
|
|
|
|
return Status;
|
1999-01-16 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2006-07-09 18:54:13 +00:00
|
|
|
NTAPI
|
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
|
|
|
NtTerminateThread(IN HANDLE ThreadHandle,
|
|
|
|
IN NTSTATUS ExitStatus)
|
1999-01-16 21:03:00 +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
|
|
|
PETHREAD Thread;
|
2006-07-09 18:54:13 +00:00
|
|
|
PETHREAD CurrentThread = PsGetCurrentThread();
|
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
|
|
|
NTSTATUS Status;
|
|
|
|
PAGED_CODE();
|
2006-07-23 07:13:19 +00:00
|
|
|
PSTRACE(PS_KILL_DEBUG,
|
2013-08-31 16:02:13 +00:00
|
|
|
"ThreadHandle: %p ExitStatus: %d\n", ThreadHandle, ExitStatus);
|
2006-07-20 15:46:10 +00:00
|
|
|
|
2005-07-12 01:56:14 +00:00
|
|
|
/* Handle the special NULL case */
|
|
|
|
if (!ThreadHandle)
|
|
|
|
{
|
|
|
|
/* Check if we're the only thread left */
|
2006-07-09 18:54:13 +00:00
|
|
|
if (PsGetCurrentProcess()->ActiveThreads == 1)
|
2005-07-12 01:56:14 +00:00
|
|
|
{
|
|
|
|
/* This is invalid */
|
|
|
|
return STATUS_CANT_TERMINATE_SELF;
|
|
|
|
}
|
2006-07-20 15:46:10 +00:00
|
|
|
|
|
|
|
/* Terminate us directly */
|
|
|
|
goto TerminateSelf;
|
2005-07-12 01:56:14 +00:00
|
|
|
}
|
2006-07-09 18:54:13 +00:00
|
|
|
else if (ThreadHandle == NtCurrentThread())
|
|
|
|
{
|
|
|
|
TerminateSelf:
|
|
|
|
/* Terminate this thread */
|
|
|
|
return PspTerminateThreadByPointer(CurrentThread,
|
|
|
|
ExitStatus,
|
|
|
|
TRUE);
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-07-09 18:54:13 +00:00
|
|
|
/* We are terminating another thread, get the Thread Object */
|
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
|
|
|
Status = ObReferenceObjectByHandle(ThreadHandle,
|
|
|
|
THREAD_TERMINATE,
|
|
|
|
PsThreadType,
|
|
|
|
KeGetPreviousMode(),
|
|
|
|
(PVOID*)&Thread,
|
|
|
|
NULL);
|
2006-07-20 15:46:10 +00:00
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
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
|
|
|
/* Check to see if we're running in the same thread */
|
2006-07-09 18:54:13 +00:00
|
|
|
if (Thread != CurrentThread)
|
|
|
|
{
|
2006-07-20 15:46:10 +00:00
|
|
|
/* Terminate it */
|
2006-07-09 18:54:13 +00:00
|
|
|
Status = PspTerminateThreadByPointer(Thread, ExitStatus, FALSE);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-22 17:32:15 +00:00
|
|
|
/* Dereference the Thread and return */
|
|
|
|
ObDereferenceObject(Thread);
|
2006-07-09 18:54:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Dereference the thread and terminate ourselves */
|
2005-03-19 09:14:21 +00:00
|
|
|
ObDereferenceObject(Thread);
|
2006-07-09 18:54:13 +00:00
|
|
|
goto TerminateSelf;
|
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
|
|
|
|
2006-07-20 15:46:10 +00:00
|
|
|
/* Return status */
|
2006-07-09 18:54:13 +00:00
|
|
|
return Status;
|
1999-01-16 21:03:00 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2006-07-09 18:54:13 +00:00
|
|
|
NTAPI
|
2006-07-20 15:46:10 +00:00
|
|
|
NtRegisterThreadTerminatePort(IN HANDLE PortHandle)
|
1999-01-16 21:03:00 +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
|
|
|
NTSTATUS Status;
|
|
|
|
PTERMINATION_PORT TerminationPort;
|
|
|
|
PVOID TerminationLpcPort;
|
2005-03-18 07:19:30 +00:00
|
|
|
PETHREAD Thread;
|
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
|
|
|
PAGED_CODE();
|
2006-07-23 07:13:19 +00:00
|
|
|
PSTRACE(PS_KILL_DEBUG, "PortHandle: %p\n", PortHandle);
|
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 the Port */
|
|
|
|
Status = ObReferenceObjectByHandle(PortHandle,
|
|
|
|
PORT_ALL_ACCESS,
|
|
|
|
LpcPortObjectType,
|
|
|
|
KeGetPreviousMode(),
|
|
|
|
&TerminationLpcPort,
|
2005-05-09 01:38:29 +00:00
|
|
|
NULL);
|
2006-07-20 15:46:10 +00:00
|
|
|
if (!NT_SUCCESS(Status)) return(Status);
|
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
|
|
|
/* Allocate the Port and make sure it suceeded */
|
2006-07-20 15:46:10 +00:00
|
|
|
TerminationPort = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
sizeof(TERMINATION_PORT),
|
2009-08-24 18:19:53 +00:00
|
|
|
'=TsP');
|
2006-07-20 15:46:10 +00:00
|
|
|
if(TerminationPort)
|
|
|
|
{
|
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
|
|
|
/* Associate the Port */
|
2005-03-18 07:19:30 +00:00
|
|
|
Thread = PsGetCurrentThread();
|
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
|
|
|
TerminationPort->Port = TerminationLpcPort;
|
2005-03-18 07:19:30 +00:00
|
|
|
TerminationPort->Next = Thread->TerminationPort;
|
|
|
|
Thread->TerminationPort = TerminationPort;
|
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 success */
|
2006-07-20 15:46:10 +00:00
|
|
|
return STATUS_SUCCESS;
|
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-20 15:46:10 +00:00
|
|
|
|
|
|
|
/* Dereference and Fail */
|
2015-02-20 12:04:57 +00:00
|
|
|
ObDereferenceObject(TerminationLpcPort);
|
2006-07-20 15:46:10 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
1999-01-16 21:03:00 +00:00
|
|
|
}
|