#include <ntoskrnl.h>
#define NDEBUG
-#include <internal/debug.h>
+#include <debug.h>
/* GLOBALS *******************************************************************/
-LIST_ENTRY PspReaperListHead = {0};
+LIST_ENTRY PspReaperListHead = { NULL, NULL };
WORK_QUEUE_ITEM PspReaperWorkItem;
LARGE_INTEGER ShortTime = {{-10 * 100 * 1000, -1}};
Thread = CONTAINING_RECORD(NextEntry, ETHREAD, ReaperLink);
/* Delete this entry's kernel stack */
- MmDeleteKernelStack((PVOID)Thread->Tcb.StackLimit,
+ MmDeleteKernelStack((PVOID)Thread->Tcb.StackBase,
Thread->Tcb.LargeStack);
Thread->Tcb.InitialStack = NULL;
Process->SectionObject = NULL;
}
- /* Clean LDT and VDM_OBJECTS */
+#if defined(_X86_)
+ /* Clean Ldt and Vdm objects */
PspDeleteLdt(Process);
PspDeleteVdmObjects(Process);
+#endif
/* Delete the Object Table */
if (Process->ObjectTable)
KeUnstackDetachProcess(&ApcState);
}
- /* KDB hook */
- KDB_DELETEPROCESS_HOOK(Process);
-
/* Check if we have an address space, and clean it */
if (Process->HasAddressSpace)
{
if (!(ExDestroyHandle(PspCidTable, Process->UniqueProcessId, NULL)))
{
/* Something wrong happened, bugcheck */
- KEBUGCHECK(CID_HANDLE_DELETION);
+ KeBugCheck(CID_HANDLE_DELETION);
}
}
if (Thread->Tcb.InitialStack)
{
/* Release it */
- MmDeleteKernelStack((PVOID)Thread->Tcb.StackLimit,
+ MmDeleteKernelStack((PVOID)Thread->Tcb.StackBase,
Thread->Tcb.LargeStack);
}
if (!(ExDestroyHandle(PspCidTable, Thread->Cid.UniqueThread, NULL)))
{
/* Something wrong happened, bugcheck */
- KEBUGCHECK(CID_HANDLE_DELETION);
+ KeBugCheck(CID_HANDLE_DELETION);
}
}
if (KeIsAttachedProcess())
{
/* Bugcheck */
- KEBUGCHECKEX(INVALID_PROCESS_ATTACH_ATTEMPT,
+ KeBugCheckEx(INVALID_PROCESS_ATTACH_ATTEMPT,
(ULONG_PTR)CurrentProcess,
(ULONG_PTR)Thread->Tcb.ApcState.Process,
(ULONG_PTR)Thread->Tcb.ApcStateIndex,
if (Thread->ActiveExWorker)
{
/* Bugcheck */
- KEBUGCHECKEX(ACTIVE_EX_WORKER_THREAD_TERMINATION,
+ KeBugCheckEx(ACTIVE_EX_WORKER_THREAD_TERMINATION,
(ULONG_PTR)Thread,
0,
0,
if (Thread->Tcb.CombinedApcDisable != 0)
{
/* Bugcheck */
- KEBUGCHECKEX(KERNEL_APC_PENDING_DURING_EXIT,
+ KeBugCheckEx(KERNEL_APC_PENDING_DURING_EXIT,
0,
Thread->Tcb.CombinedApcDisable,
0,
else
{
/* Bugcheck, we can't allow this */
- KEBUGCHECKEX(CRITICAL_PROCESS_DIED,
+ KeBugCheckEx(CRITICAL_PROCESS_DIED,
(ULONG_PTR)CurrentProcess,
0,
0,
if (TerminationPort)
{
/* Setup the message header */
+ TerminationMsg.h.u2.ZeroInit = 0;
TerminationMsg.h.u2.s2.Type = LPC_CLIENT_DIED;
TerminationMsg.h.u1.s1.TotalLength = sizeof(TerminationMsg);
TerminationMsg.h.u1.s1.DataLength = sizeof(TerminationMsg) -
PspW32ProcessCallout(CurrentProcess, FALSE);
}
- /* Make sure Stack Swap isn't enabled */
- if (Thread->Tcb.EnableStackSwap)
+ /* Make sure Stack Swap is enabled */
+ if (!Thread->Tcb.EnableStackSwap)
{
- /* Stack swap really shouldn't be on during exit !*/
- KEBUGCHECKEX(KERNEL_STACK_LOCKED_AT_EXIT, 0, 0, 0, 0);
+ /* Stack swap really shouldn't be disabled during exit! */
+ KeBugCheckEx(KERNEL_STACK_LOCKED_AT_EXIT, 0, 0, 0, 0);
}
/* Cancel I/O for the thread. */
ObFastDereferenceObject(&CurrentProcess->Token, PrimaryToken);
/* Check if this is a VDM Process and rundown the VDM DPCs if so */
- if (CurrentProcess->VdmObjects);// VdmRundownDpcs(CurrentProcess);
+ if (CurrentProcess->VdmObjects) { /* VdmRundownDpcs(CurrentProcess); */ }
/* Kill the process in the Object Manager */
ObKillProcess(CurrentProcess);
if ((FirstEntry) || (Thread->Tcb.CombinedApcDisable != 0))
{
/* Bugcheck time */
- KEBUGCHECKEX(KERNEL_APC_PENDING_DURING_EXIT,
+ KeBugCheckEx(KERNEL_APC_PENDING_DURING_EXIT,
(ULONG_PTR)FirstEntry,
Thread->Tcb.CombinedApcDisable,
KeGetCurrentIrql(),
/* Allocate the APC */
Apc = ExAllocatePoolWithTag(NonPagedPool, sizeof(KAPC), TAG_TERMINATE_APC);
+ if (!Apc) return STATUS_INSUFFICIENT_RESOURCES;
/* Set the Terminated Flag */
Flags = Thread->CrossThreadFlags | CT_TERMINATED_BIT;
if (!KeInsertQueueApc(Apc, Apc, NULL, 2))
{
/* The APC was already in the queue, fail */
- ExFreePool(Apc);
Status = STATUS_UNSUCCESSFUL;
}
else
PETHREAD Thread = PsGetCurrentThread();
/* Make sure this is a system thread */
- if (Thread->SystemThread) return STATUS_INVALID_PARAMETER;
+ if (!Thread->SystemThread) return STATUS_INVALID_PARAMETER;
/* Terminate it for real */
return PspTerminateThreadByPointer(Thread, ExitStatus, TRUE);
PSTRACE(PS_KILL_DEBUG,
"ProcessHandle: %p ExitStatus: %p\n", ProcessHandle, ExitStatus);
- /* Remember how we will kill it */
- KillByHandle = (ProcessHandle != NULL);
+ /* 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();
+ }
/* Get the Process Object */
- Status = ObReferenceObjectByHandle((KillByHandle) ?
- ProcessHandle : NtCurrentProcess(),
+ Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_TERMINATE,
PsProcessType,
KeGetPreviousMode(),
/* Lock the Process */
if (!ExAcquireRundownProtection(&Process->RundownProtect))
{
- /* Failed to lock, fal */
+ /* Failed to lock, fail */
ObDereferenceObject (Process);
return STATUS_PROCESS_IS_TERMINATING;
}
- /* Set the delete flag */
- if (!KillByHandle) InterlockedOr((PLONG)&Process->Flags,
- PSF_PROCESS_DELETE_BIT);
+ /* Set the delete flag, unless the process is comitting suicide */
+ if (KillByHandle) PspSetProcessFlag(Process, PSF_PROCESS_DELETE_BIT);
/* Get the first thread */
Status = STATUS_NOTHING_TO_TERMINATE;
ExReleaseRundownProtection(&Process->RundownProtect);
/* Check if we are killing ourselves */
- if (Process != CurrentProcess)
+ if (Process == CurrentProcess)
{
- /* Check for the DBG_TERMINATE_PROCESS exit code */
- if (ExitStatus == DBG_TERMINATE_PROCESS)
+ /* Also make sure the caller gave us our handle */
+ if (KillByHandle)
{
- /* Disable debugging on this process */
- DbgkClearProcessDebugObject(Process, NULL);
+ /* Dereference the process */
+ ObDereferenceObject(Process);
+
+ /* Terminate ourselves */
+ PspTerminateThreadByPointer(CurrentThread, ExitStatus, TRUE);
}
}
- /* Make sure that we got a handle */
- else if (KillByHandle)
+ else if (ExitStatus == DBG_TERMINATE_PROCESS)
{
- /* Dereference the project */
- ObDereferenceObject(Process);
-
- /* Terminate ourselves */
- PspTerminateThreadByPointer(CurrentThread, ExitStatus, TRUE);
+ /* Disable debugging on this process */
+ DbgkClearProcessDebugObject(Process, NULL);
}
/* Check if there was nothing to terminate, or if we have a Debug Port */
/* Allocate the Port and make sure it suceeded */
TerminationPort = ExAllocatePoolWithTag(NonPagedPool,
sizeof(TERMINATION_PORT),
- TAG('P', 's', 'T', '='));
+ '=TsP');
if(TerminationPort)
{
/* Associate the Port */