ReactOS  0.4.14-dev-114-gc8cbd56
kill.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for kill.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI PspCatchCriticalBreak (IN PCHAR Message, IN PVOID ProcessOrThread, IN PCHAR ImageName)
 
NTSTATUS NTAPI PspTerminateProcess (IN PEPROCESS Process, IN NTSTATUS ExitStatus)
 
NTSTATUS NTAPI PsTerminateProcess (IN PEPROCESS Process, IN NTSTATUS ExitStatus)
 
VOID NTAPI PspShutdownProcessManager (VOID)
 
VOID NTAPI PspExitApcRundown (IN PKAPC Apc)
 
VOID NTAPI PspReapRoutine (IN PVOID Context)
 
VOID NTAPI PspDeleteProcess (IN PVOID ObjectBody)
 
VOID NTAPI PspDeleteThread (IN PVOID ObjectBody)
 
VOID NTAPI PspExitThread (IN NTSTATUS ExitStatus)
 
VOID NTAPI PsExitSpecialApc (IN PKAPC Apc, IN OUT PKNORMAL_ROUTINE *NormalRoutine, IN OUT PVOID *NormalContext, IN OUT PVOID *SystemArgument1, IN OUT PVOID *SystemArgument2)
 
VOID NTAPI PspExitNormalApc (IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
NTSTATUS NTAPI PspTerminateThreadByPointer (IN PETHREAD Thread, IN NTSTATUS ExitStatus, IN BOOLEAN bSelf)
 
BOOLEAN NTAPI PspIsProcessExiting (IN PEPROCESS Process)
 
VOID NTAPI PspExitProcess (IN BOOLEAN LastThread, IN PEPROCESS Process)
 
NTSTATUS NTAPI PsTerminateSystemThread (IN NTSTATUS ExitStatus)
 
NTSTATUS NTAPI NtTerminateProcess (IN HANDLE ProcessHandle OPTIONAL, IN NTSTATUS ExitStatus)
 
NTSTATUS NTAPI NtTerminateThread (IN HANDLE ThreadHandle, IN NTSTATUS ExitStatus)
 
NTSTATUS NTAPI NtRegisterThreadTerminatePort (IN HANDLE PortHandle)
 

Variables

LIST_ENTRY PspReaperListHead = { NULL, NULL }
 
WORK_QUEUE_ITEM PspReaperWorkItem
 
LARGE_INTEGER ShortTime = {{-10 * 100 * 1000, -1}}
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file kill.c.

Function Documentation

◆ NtRegisterThreadTerminatePort()

NTSTATUS NTAPI NtRegisterThreadTerminatePort ( IN HANDLE  PortHandle)

Definition at line 1341 of file kill.c.

1342 {
1343  NTSTATUS Status;
1344  PTERMINATION_PORT TerminationPort;
1345  PVOID TerminationLpcPort;
1346  PETHREAD Thread;
1347  PAGED_CODE();
1348  PSTRACE(PS_KILL_DEBUG, "PortHandle: %p\n", PortHandle);
1349 
1350  /* Get the Port */
1351  Status = ObReferenceObjectByHandle(PortHandle,
1355  &TerminationLpcPort,
1356  NULL);
1357  if (!NT_SUCCESS(Status)) return(Status);
1358 
1359  /* Allocate the Port and make sure it suceeded */
1360  TerminationPort = ExAllocatePoolWithTag(NonPagedPool,
1361  sizeof(TERMINATION_PORT),
1362  '=TsP');
1363  if(TerminationPort)
1364  {
1365  /* Associate the Port */
1367  TerminationPort->Port = TerminationLpcPort;
1368  TerminationPort->Next = Thread->TerminationPort;
1369  Thread->TerminationPort = TerminationPort;
1370 
1371  /* Return success */
1372  return STATUS_SUCCESS;
1373  }
1374 
1375  /* Dereference and Fail */
1376  ObDereferenceObject(TerminationLpcPort);
1378 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define KeGetPreviousMode()
Definition: ketypes.h:1107
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
struct _TERMINATION_PORT * Next
Definition: pstypes.h:1011
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
smooth NULL
Definition: ftsmooth.c:416
struct _TERMINATION_PORT * TerminationPort
Definition: pstypes.h:1050
#define PS_KILL_DEBUG
Definition: ps.h:25
POBJECT_TYPE LpcPortObjectType
Definition: port.c:17
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
#define PORT_ALL_ACCESS
Definition: lpctypes.h:47
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by CsrNewThread().

◆ NtTerminateProcess()

NTSTATUS NTAPI NtTerminateProcess ( IN HANDLE ProcessHandle  OPTIONAL,
IN NTSTATUS  ExitStatus 
)

Definition at line 1160 of file kill.c.

1162 {
1163  NTSTATUS Status;
1165  PETHREAD Thread, CurrentThread = PsGetCurrentThread();
1166  BOOLEAN KillByHandle;
1167  PAGED_CODE();
1169  "ProcessHandle: %p ExitStatus: %d\n", ProcessHandle, ExitStatus);
1170 
1171  /* Were we passed a process handle? */
1172  if (ProcessHandle)
1173  {
1174  /* Yes we were, use it */
1175  KillByHandle = TRUE;
1176  }
1177  else
1178  {
1179  /* We weren't... we assume this is suicide */
1180  KillByHandle = FALSE;
1182  }
1183 
1184  /* Get the Process Object */
1187  PsProcessType,
1189  (PVOID*)&Process,
1190  NULL);
1191  if (!NT_SUCCESS(Status)) return(Status);
1192 
1193  /* Check if this is a Critical Process, and Bugcheck */
1194  if (Process->BreakOnTermination)
1195  {
1196  /* Break to debugger */
1197  PspCatchCriticalBreak("Terminating critical process 0x%p (%s)\n",
1198  Process,
1199  Process->ImageFileName);
1200  }
1201 
1202  /* Lock the Process */
1203  if (!ExAcquireRundownProtection(&Process->RundownProtect))
1204  {
1205  /* Failed to lock, fail */
1208  }
1209 
1210  /* Set the delete flag, unless the process is comitting suicide */
1211  if (KillByHandle) PspSetProcessFlag(Process, PSF_PROCESS_DELETE_BIT);
1212 
1213  /* Get the first thread */
1216  if (Thread)
1217  {
1218  /* We know we have at least a thread */
1220 
1221  /* Loop and kill the others */
1222  do
1223  {
1224  /* Ensure it's not ours*/
1225  if (Thread != CurrentThread)
1226  {
1227  /* Kill it */
1229  }
1230 
1231  /* Move to the next thread */
1233  } while (Thread);
1234  }
1235 
1236  /* Unlock the process */
1237  ExReleaseRundownProtection(&Process->RundownProtect);
1238 
1239  /* Check if we are killing ourselves */
1240  if (Process == CurrentProcess)
1241  {
1242  /* Also make sure the caller gave us our handle */
1243  if (KillByHandle)
1244  {
1245  /* Dereference the process */
1247 
1248  /* Terminate ourselves */
1249  PspTerminateThreadByPointer(CurrentThread, ExitStatus, TRUE);
1250  }
1251  }
1252  else if (ExitStatus == DBG_TERMINATE_PROCESS)
1253  {
1254  /* Disable debugging on this process */
1256  }
1257 
1258  /* Check if there was nothing to terminate, or if we have a Debug Port */
1260  ((Process->DebugPort) && (KillByHandle)))
1261  {
1262  /* Clear the handle table */
1264 
1265  /* Return status now */
1267  }
1268 
1269  /* Decrease the reference count we added */
1271 
1272  /* Return status */
1273  return Status;
1274 }
#define TRUE
Definition: types.h:120
#define DBG_TERMINATE_PROCESS
Definition: ntstatus.h:51
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
NTKERNELAPI VOID FASTCALL ExReleaseRundownProtection(_Inout_ PEX_RUNDOWN_REF RunRef)
#define KeGetPreviousMode()
Definition: ketypes.h:1107
LONG NTSTATUS
Definition: precomp.h:26
#define ExAcquireRundownProtection
Definition: ex.h:130
VOID NTAPI PspCatchCriticalBreak(IN PCHAR Message, IN PVOID ProcessOrThread, IN PCHAR ImageName)
Definition: kill.c:27
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define PsGetCurrentProcess
Definition: psfuncs.h:17
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_NOTHING_TO_TERMINATE
Definition: ntstatus.h:106
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define PS_KILL_DEBUG
Definition: ps.h:25
ULONG CurrentProcess
Definition: shell.c:125
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PROCESS_IS_TERMINATING
Definition: ntstatus.h:488
#define PSF_PROCESS_DELETE_BIT
Definition: pstypes.h:260
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
PETHREAD NTAPI PsGetNextProcessThread(IN PEPROCESS Process, IN PETHREAD Thread OPTIONAL)
Definition: process.c:75
NTSTATUS NTAPI DbgkClearProcessDebugObject(IN PEPROCESS Process, IN PDEBUG_OBJECT SourceDebugObject OPTIONAL)
Definition: dbgkobj.c:1410
Status
Definition: gdiplustypes.h:24
VOID NTAPI ObClearProcessHandleTable(IN PEPROCESS Process)
Definition: obhandle.c:2024
#define PROCESS_TERMINATE
Definition: pstypes.h:149
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:859
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define PspSetProcessFlag(Process, Flag)
Definition: ps_x.h:33
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
return STATUS_SUCCESS
Definition: btrfs.c:2966
POBJECT_TYPE PsProcessType
Definition: process.c:20
NTSTATUS NTAPI PspTerminateThreadByPointer(IN PETHREAD Thread, IN NTSTATUS ExitStatus, IN BOOLEAN bSelf)
Definition: kill.c:987

◆ NtTerminateThread()

NTSTATUS NTAPI NtTerminateThread ( IN HANDLE ThreadHandle  ,
IN NTSTATUS  ExitStatus 
)

Definition at line 1278 of file kill.c.

1280 {
1281  PETHREAD Thread;
1282  PETHREAD CurrentThread = PsGetCurrentThread();
1283  NTSTATUS Status;
1284  PAGED_CODE();
1286  "ThreadHandle: %p ExitStatus: %d\n", ThreadHandle, ExitStatus);
1287 
1288  /* Handle the special NULL case */
1289  if (!ThreadHandle)
1290  {
1291  /* Check if we're the only thread left */
1292  if (PsGetCurrentProcess()->ActiveThreads == 1)
1293  {
1294  /* This is invalid */
1296  }
1297 
1298  /* Terminate us directly */
1299  goto TerminateSelf;
1300  }
1301  else if (ThreadHandle == NtCurrentThread())
1302  {
1303 TerminateSelf:
1304  /* Terminate this thread */
1305  return PspTerminateThreadByPointer(CurrentThread,
1306  ExitStatus,
1307  TRUE);
1308  }
1309 
1310  /* We are terminating another thread, get the Thread Object */
1311  Status = ObReferenceObjectByHandle(ThreadHandle,
1313  PsThreadType,
1315  (PVOID*)&Thread,
1316  NULL);
1317  if (!NT_SUCCESS(Status)) return Status;
1318 
1319  /* Check to see if we're running in the same thread */
1320  if (Thread != CurrentThread)
1321  {
1322  /* Terminate it */
1324 
1325  /* Dereference the Thread and return */
1327  }
1328  else
1329  {
1330  /* Dereference the thread and terminate ourselves */
1332  goto TerminateSelf;
1333  }
1334 
1335  /* Return status */
1336  return Status;
1337 }
#define TRUE
Definition: types.h:120
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define KeGetPreviousMode()
Definition: ketypes.h:1107
LONG NTSTATUS
Definition: precomp.h:26
#define NtCurrentThread()
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define PsGetCurrentProcess
Definition: psfuncs.h:17
smooth NULL
Definition: ftsmooth.c:416
#define PS_KILL_DEBUG
Definition: ps.h:25
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
POBJECT_TYPE PsThreadType
Definition: thread.c:20
Status
Definition: gdiplustypes.h:24
#define STATUS_CANT_TERMINATE_SELF
Definition: ntstatus.h:441
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:859
#define THREAD_TERMINATE
Definition: nt_native.h:1336
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
NTSTATUS NTAPI PspTerminateThreadByPointer(IN PETHREAD Thread, IN NTSTATUS ExitStatus, IN BOOLEAN bSelf)
Definition: kill.c:987

Referenced by _main(), BaseSrvBSMThread(), CreateRemoteThread(), CsrApiRequestThread(), CsrpCheckRequestThreads(), ExitThread(), InitializeUserModePnpManager(), PnpEventThread(), RtlExitUserThread(), RtlpExitThread(), TerminateThread(), TerminateUserModePnpManager(), and wWinMain().

◆ PsExitSpecialApc()

VOID NTAPI PsExitSpecialApc ( IN PKAPC  Apc,
IN OUT PKNORMAL_ROUTINE NormalRoutine,
IN OUT PVOID NormalContext,
IN OUT PVOID SystemArgument1,
IN OUT PVOID SystemArgument2 
)

Definition at line 921 of file kill.c.

926 {
928  PAGED_CODE();
930  "Apc: %p SystemArgument2: %p \n", Apc, SystemArgument2);
931 
932  /* Don't do anything unless we are in User-Mode */
933  if (Apc->SystemArgument2)
934  {
935  /* Free the APC */
936  Status = PtrToUlong(Apc->NormalContext);
937  PspExitApcRundown(Apc);
938 
939  /* Terminate the Thread */
941  }
942 }
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
#define PtrToUlong(u)
Definition: config.h:107
#define PS_KILL_DEBUG
Definition: ps.h:25
VOID NTAPI PspExitThread(IN NTSTATUS ExitStatus)
Definition: kill.c:449
VOID NTAPI PspExitApcRundown(IN PKAPC Apc)
Definition: kill.c:160
Status
Definition: gdiplustypes.h:24
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
#define PSTRACE(x, fmt,...)
Definition: ps.h:57

Referenced by PspExitNormalApc(), and PspTerminateThreadByPointer().

◆ PspCatchCriticalBreak()

VOID NTAPI PspCatchCriticalBreak ( IN PCHAR  Message,
IN PVOID  ProcessOrThread,
IN PCHAR  ImageName 
)

Definition at line 27 of file kill.c.

30 {
31  CHAR Action[2];
33  PAGED_CODE();
34 
35  /* Check if a debugger is enabled */
37  {
38  /* Print out the message */
39  DbgPrint(Message, ProcessOrThread, ImageName);
40  do
41  {
42  /* If a debugger isn't present, don't prompt */
43  if (KdDebuggerNotPresent) break;
44 
45  /* A debuger is active, prompt for action */
46  DbgPrompt("Break, or Ignore (bi)?", Action, sizeof(Action));
47  switch (Action[0])
48  {
49  /* Break */
50  case 'B': case 'b':
51 
52  /* Do a breakpoint */
53  DbgBreakPoint();
54 
55  /* Ignore */
56  case 'I': case 'i':
57 
58  /* Handle it */
59  Handled = TRUE;
60 
61  /* Unrecognized */
62  default:
63  break;
64  }
65  } while (!Handled);
66  }
67 
68  /* Did we ultimately handle this? */
69  if (!Handled)
70  {
71  /* We didn't, bugcheck */
72  KeBugCheckEx(CRITICAL_OBJECT_TERMINATION,
73  ((PKPROCESS)ProcessOrThread)->Header.Type,
74  (ULONG_PTR)ProcessOrThread,
77  }
78 }
#define TRUE
Definition: types.h:120
#define DbgPrint
Definition: loader.c:25
NTSYSAPI ULONG NTAPI DbgPrompt(_In_z_ PCCH Prompt, _Out_writes_bytes_(MaximumResponseLength) PCH Response, _In_ ULONG MaximumResponseLength)
char CHAR
Definition: xmlstorage.h:175
void DbgBreakPoint()
Definition: mach.c:553
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
Definition: Header.h:8
unsigned char BOOLEAN
BOOLEAN KdDebuggerEnabled
Definition: kdmain.c:16
_In_ BOOLEAN Handled
Definition: ketypes.h:337
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG Action
Definition: fsrtlfuncs.h:738
CHAR Message[80]
Definition: alive.c:5
static const char * ImageName
Definition: image.c:34
BOOLEAN KdDebuggerNotPresent
Definition: kdmain.c:18
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107

Referenced by NtTerminateProcess(), PspExitThread(), PspTerminateProcess(), and PspTerminateThreadByPointer().

◆ PspDeleteProcess()

VOID NTAPI PspDeleteProcess ( IN PVOID  ObjectBody)

Definition at line 256 of file kill.c.

257 {
258  PEPROCESS Process = (PEPROCESS)ObjectBody;
260  PAGED_CODE();
261  PSTRACE(PS_KILL_DEBUG, "ObjectBody: %p\n", ObjectBody);
263 
264  /* Check if it has an Active Process Link */
265  if (Process->ActiveProcessLinks.Flink)
266  {
267  /* Remove it from the Active List */
269  RemoveEntryList(&Process->ActiveProcessLinks);
270  Process->ActiveProcessLinks.Flink = NULL;
271  Process->ActiveProcessLinks.Blink = NULL;
273  }
274 
275  /* Check for Auditing information */
276  if (Process->SeAuditProcessCreationInfo.ImageFileName)
277  {
278  /* Free it */
279  ExFreePoolWithTag(Process->SeAuditProcessCreationInfo.ImageFileName,
280  TAG_SEPA);
281  Process->SeAuditProcessCreationInfo.ImageFileName = NULL;
282  }
283 
284  /* Check if we have a job */
285  if (Process->Job)
286  {
287  /* Remove the process from the job */
289 
290  /* Dereference it */
292  Process->Job = NULL;
293  }
294 
295  /* Increase the stack count */
296  Process->Pcb.StackCount++;
297 
298  /* Check if we have a debug port */
299  if (Process->DebugPort)
300  {
301  /* Deference the Debug Port */
302  ObDereferenceObject(Process->DebugPort);
303  Process->DebugPort = NULL;
304  }
305 
306  /* Check if we have an exception port */
307  if (Process->ExceptionPort)
308  {
309  /* Deference the Exception Port */
310  ObDereferenceObject(Process->ExceptionPort);
311  Process->ExceptionPort = NULL;
312  }
313 
314  /* Check if we have a section object */
315  if (Process->SectionObject)
316  {
317  /* Deference the Section Object */
318  ObDereferenceObject(Process->SectionObject);
319  Process->SectionObject = NULL;
320  }
321 
322 #if defined(_X86_)
323  /* Clean Ldt and Vdm objects */
326 #endif
327 
328  /* Delete the Object Table */
329  if (Process->ObjectTable)
330  {
331  /* Attach to the process */
333 
334  /* Kill the Object Info */
336 
337  /* Detach */
339  }
340 
341  /* Check if we have an address space, and clean it */
342  if (Process->HasAddressSpace)
343  {
344  /* Attach to the process */
346 
347  /* Clean the Address Space */
349 
350  /* Detach */
352 
353  /* Completely delete the Address Space */
355  }
356 
357  /* See if we have a PID */
358  if (Process->UniqueProcessId)
359  {
360  /* Delete the PID */
361  if (!(ExDestroyHandle(PspCidTable, Process->UniqueProcessId, NULL)))
362  {
363  /* Something wrong happened, bugcheck */
364  KeBugCheck(CID_HANDLE_DELETION);
365  }
366  }
367 
368  /* Cleanup security information */
370 
371  /* Check if we have kept information on the Working Set */
372  if (Process->WorkingSetWatch)
373  {
374  /* Free it */
375  ExFreePool(Process->WorkingSetWatch);
376 
377  /* And return the quota it was taking up */
379  }
380 
381  /* Dereference the Device Map */
383 
384  /* Destroy the Quota Block */
386 }
VOID NTAPI ObKillProcess(IN PEPROCESS Process)
Definition: obhandle.c:2157
KAPC_STATE
Definition: ketypes.h:1273
VOID NTAPI PspDeleteVdmObjects(PEPROCESS Process)
Definition: psldt.c:27
BOOLEAN NTAPI ExDestroyHandle(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle, IN PHANDLE_TABLE_ENTRY HandleTableEntry OPTIONAL)
Definition: handle.c:948
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
struct _EPROCESS * PEPROCESS
Definition: nt_native.h:30
VOID NTAPI PspExitProcess(IN BOOLEAN LastThread, IN PEPROCESS Process)
Definition: kill.c:1074
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PHANDLE_TABLE PspCidTable
Definition: psmgr.c:48
#define PAGED_CODE()
Definition: video.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
VOID NTAPI KeStackAttachProcess(IN PKPROCESS Process, OUT PRKAPC_STATE ApcState)
Definition: procobj.c:701
#define PSREFTRACE(x)
Definition: ps.h:58
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1507
#define PS_KILL_DEBUG
Definition: ps.h:25
VOID NTAPI PspDeleteLdt(PEPROCESS Process)
Definition: psldt.c:19
VOID NTAPI ObDereferenceDeviceMap(IN PEPROCESS Process)
Definition: devicemap.c:456
VOID NTAPI PspDeleteProcessSecurity(IN PEPROCESS Process)
Definition: security.c:30
VOID NTAPI PsReturnProcessNonPagedPoolQuota(IN PEPROCESS Process, IN SIZE_T Amount)
Definition: quota.c:253
VOID NTAPI PspRemoveProcessFromJob(IN PEPROCESS Process, IN PEJOB Job)
Definition: job.c:138
NTSTATUS NTAPI MmDeleteProcessAddressSpace(IN PEPROCESS Process)
VOID NTAPI PspDestroyQuotaBlock(IN PEPROCESS Process)
VOID NTAPI KeUnstackDetachProcess(IN PRKAPC_STATE ApcState)
Definition: procobj.c:753
KGUARDED_MUTEX PspActiveProcessMutex
Definition: process.c:23
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1492
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
#define TAG_SEPA
Definition: tag.h:189
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by PspInitPhase0().

◆ PspDeleteThread()

VOID NTAPI PspDeleteThread ( IN PVOID  ObjectBody)

Definition at line 390 of file kill.c.

391 {
392  PETHREAD Thread = (PETHREAD)ObjectBody;
393  PEPROCESS Process = Thread->ThreadsProcess;
394  PAGED_CODE();
395  PSTRACE(PS_KILL_DEBUG, "ObjectBody: %p\n", ObjectBody);
398 
399  /* Check if we have a stack */
400  if (Thread->Tcb.InitialStack)
401  {
402  /* Release it */
404  Thread->Tcb.LargeStack);
405  }
406 
407  /* Check if we have a CID Handle */
408  if (Thread->Cid.UniqueThread)
409  {
410  /* Delete the CID Handle */
412  {
413  /* Something wrong happened, bugcheck */
414  KeBugCheck(CID_HANDLE_DELETION);
415  }
416  }
417 
418  /* Cleanup impersionation information */
420 
421  /* Make sure the thread was inserted, before continuing */
422  if (!Process) return;
423 
424  /* Check if the thread list is valid */
426  {
427  /* Lock the thread's process */
429  ExAcquirePushLockExclusive(&Process->ProcessLock);
430 
431  /* Remove us from the list */
433 
434  /* Release the lock */
435  ExReleasePushLockExclusive(&Process->ProcessLock);
437  }
438 
439  /* Dereference the Process */
441 }
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1022
LIST_ENTRY ThreadListEntry
Definition: pstypes.h:1089
BOOLEAN NTAPI ExDestroyHandle(IN PHANDLE_TABLE HandleTable, IN HANDLE Handle, IN PHANDLE_TABLE_ENTRY HandleTableEntry OPTIONAL)
Definition: handle.c:948
VOID NTAPI MmDeleteKernelStack(PVOID Stack, BOOLEAN GuiStack)
KTHREAD Tcb
Definition: pstypes.h:1034
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PHANDLE_TABLE PspCidTable
Definition: psmgr.c:48
#define PAGED_CODE()
Definition: video.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
FORCEINLINE VOID ExReleasePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1238
#define PSREFTRACE(x)
Definition: ps.h:58
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1507
#define PS_KILL_DEBUG
Definition: ps.h:25
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
CLIENT_ID Cid
Definition: pstypes.h:1059
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
HANDLE UniqueThread
Definition: compat.h:475
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
VOID NTAPI PspDeleteThreadSecurity(IN PETHREAD Thread)
Definition: security.c:46
PVOID StackBase
Definition: ketypes.h:1556
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
PVOID Win32Thread
Definition: ketypes.h:1756
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
struct _ETHREAD * PETHREAD
Definition: nt_native.h:29
PVOID InitialStack
Definition: ketypes.h:1554

Referenced by PspInitPhase0().

◆ PspExitApcRundown()

VOID NTAPI PspExitApcRundown ( IN PKAPC  Apc)

Definition at line 160 of file kill.c.

161 {
162  PAGED_CODE();
163 
164  /* Free the APC */
165  ExFreePool(Apc);
166 }
#define PAGED_CODE()
Definition: video.h:57
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by PsExitSpecialApc(), PspExitNormalApc(), and PspTerminateThreadByPointer().

◆ PspExitNormalApc()

VOID NTAPI PspExitNormalApc ( IN PVOID  NormalContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 946 of file kill.c.

949 {
950  PKAPC Apc = (PKAPC)SystemArgument1;
952  PAGED_CODE();
953  PSTRACE(PS_KILL_DEBUG, "SystemArgument2: %p \n", SystemArgument2);
954 
955  /* This should never happen */
956  ASSERT(!(((ULONG_PTR)SystemArgument2) & 1));
957 
958  /* If we're here, this is not a System Thread, so kill it from User-Mode */
959  KeInitializeApc(Apc,
960  &Thread->Tcb,
965  UserMode,
966  NormalContext);
967 
968  /* Now insert the APC with the User-Mode Flag */
969  if (!(KeInsertQueueApc(Apc,
970  Apc,
972  2)))
973  {
974  /* Failed to insert, free the APC */
975  PspExitApcRundown(Apc);
976  }
977 
978  /* Set the APC Pending flag */
979  Thread->Tcb.ApcState.UserApcPending = TRUE;
980 }
VOID NTAPI KeInitializeApc(IN PKAPC Apc, IN PKTHREAD Thread, IN KAPC_ENVIRONMENT TargetEnvironment, IN PKKERNEL_ROUTINE KernelRoutine, IN PKRUNDOWN_ROUTINE RundownRoutine OPTIONAL, IN PKNORMAL_ROUTINE NormalRoutine, IN KPROCESSOR_MODE Mode, IN PVOID Context)
Definition: apc.c:651
#define TRUE
Definition: types.h:120
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
KTHREAD Tcb
Definition: pstypes.h:1034
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
KAPC_STATE ApcState
Definition: ketypes.h:1668
#define PS_KILL_DEBUG
Definition: ps.h:25
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:675
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI PspExitApcRundown(IN PKAPC Apc)
Definition: kill.c:160
Definition: ketypes.h:535
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
VOID NTAPI PspExitNormalApc(IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: kill.c:946
BOOLEAN NTAPI KeInsertQueueApc(IN PKAPC Apc, IN PVOID SystemArgument1, IN PVOID SystemArgument2, IN KPRIORITY PriorityBoost)
Definition: apc.c:735
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
VOID NTAPI PsExitSpecialApc(IN PKAPC Apc, IN OUT PKNORMAL_ROUTINE *NormalRoutine, IN OUT PVOID *NormalContext, IN OUT PVOID *SystemArgument1, IN OUT PVOID *SystemArgument2)
Definition: kill.c:921
struct _KAPC * PKAPC

Referenced by PspTerminateThreadByPointer().

◆ PspExitProcess()

VOID NTAPI PspExitProcess ( IN BOOLEAN  LastThread,
IN PEPROCESS  Process 
)

Definition at line 1074 of file kill.c.

1076 {
1077  ULONG Actual;
1078  PAGED_CODE();
1080  "LastThread: %u Process: %p\n", LastThread, Process);
1082 
1083  /* Set Process Exit flag */
1085 
1086  /* Check if we are the last thread */
1087  if (LastThread)
1088  {
1089  /* Notify the WMI Process Callback */
1090  //WmiTraceProcess(Process, FALSE);
1091 
1092  /* Run the Notification Routines */
1094  }
1095 
1096  /* Cleanup the power state */
1097  PopCleanupPowerState((PPOWER_STATE)&Process->Pcb.PowerState);
1098 
1099  /* Clear the security port */
1100  if (!Process->SecurityPort)
1101  {
1102  /* So we don't double-dereference */
1103  Process->SecurityPort = (PVOID)1;
1104  }
1105  else if (Process->SecurityPort != (PVOID)1)
1106  {
1107  /* Dereference it */
1108  ObDereferenceObject(Process->SecurityPort);
1109  Process->SecurityPort = (PVOID)1;
1110  }
1111 
1112  /* Check if we are the last thread */
1113  if (LastThread)
1114  {
1115  /* Check if we have to set the Timer Resolution */
1116  if (Process->SetTimerResolution)
1117  {
1118  /* Set it to default */
1120  }
1121 
1122  /* Check if we are part of a Job that has a completion port */
1123  if ((Process->Job) && (Process->Job->CompletionPort))
1124  {
1125  /* FIXME: Check job status code and do I/O completion if needed */
1126  }
1127 
1128  /* FIXME: Notify the Prefetcher */
1129  }
1130  else
1131  {
1132  /* Clear process' address space here */
1134  }
1135 }
ULONG KeMaximumIncrement
Definition: clock.c:20
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define PSF_PROCESS_EXITING_BIT
Definition: pstypes.h:259
#define PAGED_CODE()
Definition: video.h:57
#define PSREFTRACE(x)
Definition: ps.h:58
void * PVOID
Definition: retypes.h:9
#define PS_KILL_DEBUG
Definition: ps.h:25
VOID NTAPI MmCleanProcessAddressSpace(IN PEPROCESS Process)
Definition: procsup.c:1235
NTSYSAPI NTSTATUS NTAPI ZwSetTimerResolution(_In_ ULONG RequestedResolution, _In_ BOOLEAN SetOrUnset, _Out_ PULONG ActualResolution)
FORCEINLINE VOID PspRunCreateProcessNotifyRoutines(IN PEPROCESS CurrentProcess, IN BOOLEAN Create)
Definition: ps_x.h:62
VOID NTAPI PopCleanupPowerState(IN PPOWER_STATE PowerState)
Definition: power.c:63
#define InterlockedOr
Definition: interlocked.h:224
PETHREAD LastThread
Definition: pinsup.c:109
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
signed int * PLONG
Definition: retypes.h:5

Referenced by PspDeleteProcess(), and PspExitThread().

◆ PspExitThread()

VOID NTAPI PspExitThread ( IN NTSTATUS  ExitStatus)

Definition at line 449 of file kill.c.

450 {
451  CLIENT_DIED_MSG TerminationMsg;
453  PTEB Teb;
455  PETHREAD Thread, OtherThread, PreviousThread = NULL;
456  PVOID DeallocationStack;
457  SIZE_T Dummy;
458  BOOLEAN Last = FALSE;
459  PTERMINATION_PORT TerminationPort, NextPort;
460  PLIST_ENTRY FirstEntry, CurrentEntry;
461  PKAPC Apc;
462  PTOKEN PrimaryToken;
463  PAGED_CODE();
464  PSTRACE(PS_KILL_DEBUG, "ExitStatus: %d\n", ExitStatus);
465 
466  /* Get the Current Thread and Process */
468  CurrentProcess = Thread->ThreadsProcess;
470 
471  /* Can't terminate a thread if it attached another process */
472  if (KeIsAttachedProcess())
473  {
474  /* Bugcheck */
475  KeBugCheckEx(INVALID_PROCESS_ATTACH_ATTEMPT,
477  (ULONG_PTR)Thread->Tcb.ApcState.Process,
479  (ULONG_PTR)Thread);
480  }
481 
482  /* Lower to Passive Level */
484 
485  /* Can't be a worker thread */
486  if (Thread->ActiveExWorker)
487  {
488  /* Bugcheck */
489  KeBugCheckEx(ACTIVE_EX_WORKER_THREAD_TERMINATION,
490  (ULONG_PTR)Thread,
491  0,
492  0,
493  0);
494  }
495 
496  /* Can't have pending APCs */
497  if (Thread->Tcb.CombinedApcDisable != 0)
498  {
499  /* Bugcheck */
500  KeBugCheckEx(KERNEL_APC_PENDING_DURING_EXIT,
501  0,
503  0,
504  1);
505  }
506 
507  /* Lock the thread */
509 
510  /* Cleanup the power state */
512 
513  /* Call the WMI Callback for Threads */
514  //WmiTraceThread(Thread, NULL, FALSE);
515 
516  /* Run Thread Notify Routines before we desintegrate the thread */
518 
519  /* Lock the Process before we modify its thread entries */
522 
523  /* Decrease the active thread count, and check if it's 0 */
524  if (!(--CurrentProcess->ActiveThreads))
525  {
526  /* Set the delete flag */
528 
529  /* Remember we are last */
530  Last = TRUE;
531 
532  /* Check if this termination is due to the thread dying */
534  {
535  /* Check if the last thread was pending */
536  if (CurrentProcess->ExitStatus == STATUS_PENDING)
537  {
538  /* Use the last exit status */
539  CurrentProcess->ExitStatus = CurrentProcess->
540  LastThreadExitStatus;
541  }
542  }
543  else
544  {
545  /* Just a normal exit, write the code */
546  CurrentProcess->ExitStatus = ExitStatus;
547  }
548 
549  /* Loop all the current threads */
550  FirstEntry = &CurrentProcess->ThreadListHead;
551  CurrentEntry = FirstEntry->Flink;
552  while (FirstEntry != CurrentEntry)
553  {
554  /* Get the thread on the list */
555  OtherThread = CONTAINING_RECORD(CurrentEntry,
556  ETHREAD,
557  ThreadListEntry);
558 
559  /* Check if it's a thread that's still alive */
560  if ((OtherThread != Thread) &&
561  !(KeReadStateThread(&OtherThread->Tcb)) &&
562  (ObReferenceObjectSafe(OtherThread)))
563  {
564  /* It's a live thread and we referenced it, unlock process */
567 
568  /* Wait on the thread */
569  KeWaitForSingleObject(OtherThread,
570  Executive,
571  KernelMode,
572  FALSE,
573  NULL);
574 
575  /* Check if we had a previous thread to dereference */
576  if (PreviousThread) ObDereferenceObject(PreviousThread);
577 
578  /* Remember the thread and re-lock the process */
579  PreviousThread = OtherThread;
582  }
583 
584  /* Go to the next thread */
585  CurrentEntry = CurrentEntry->Flink;
586  }
587  }
589  {
590  /* Write down the exit status of the last thread to get killed */
591  CurrentProcess->LastThreadExitStatus = ExitStatus;
592  }
593 
594  /* Unlock the Process */
597 
598  /* Check if we had a previous thread to dereference */
599  if (PreviousThread) ObDereferenceObject(PreviousThread);
600 
601  /* Check if the process has a debug port and if this is a user thread */
602  if ((CurrentProcess->DebugPort) && !(Thread->SystemThread))
603  {
604  /* Notify the Debug API. */
605  Last ? DbgkExitProcess(CurrentProcess->ExitStatus) :
607  }
608 
609  /* Check if this is a Critical Thread */
611  {
612  /* Break to debugger */
613  PspCatchCriticalBreak("Critical thread 0x%p (in %s) exited\n",
614  Thread,
615  CurrentProcess->ImageFileName);
616  }
617 
618  /* Check if it's the last thread and this is a Critical Process */
619  if ((Last) && (CurrentProcess->BreakOnTermination))
620  {
621  /* Check if a debugger is here to handle this */
622  if (KdDebuggerEnabled)
623  {
624  /* Break to debugger */
625  PspCatchCriticalBreak("Critical process 0x%p (in %s) exited\n",
627  CurrentProcess->ImageFileName);
628  }
629  else
630  {
631  /* Bugcheck, we can't allow this */
632  KeBugCheckEx(CRITICAL_PROCESS_DIED,
634  0,
635  0,
636  0);
637  }
638  }
639 
640  /* Sanity check */
642 
643  /* Process the Termination Ports */
644  TerminationPort = Thread->TerminationPort;
645  if (TerminationPort)
646  {
647  /* Setup the message header */
648  TerminationMsg.h.u2.ZeroInit = 0;
649  TerminationMsg.h.u2.s2.Type = LPC_CLIENT_DIED;
650  TerminationMsg.h.u1.s1.TotalLength = sizeof(TerminationMsg);
651  TerminationMsg.h.u1.s1.DataLength = sizeof(TerminationMsg) -
652  sizeof(PORT_MESSAGE);
653 
654  /* Loop each port */
655  do
656  {
657  /* Save the Create Time */
658  TerminationMsg.CreateTime = Thread->CreateTime;
659 
660  /* Loop trying to send message */
661  while (TRUE)
662  {
663  /* Send the LPC Message */
664  Status = LpcRequestPort(TerminationPort->Port,
665  &TerminationMsg.h);
666  if ((Status == STATUS_NO_MEMORY) ||
668  {
669  /* Wait a bit and try again */
671  continue;
672  }
673  break;
674  }
675 
676  /* Dereference this LPC Port */
677  ObDereferenceObject(TerminationPort->Port);
678 
679  /* Move to the next one */
680  NextPort = TerminationPort->Next;
681 
682  /* Free the Termination Port Object */
683  ExFreePoolWithTag(TerminationPort, '=TsP');
684 
685  /* Keep looping as long as there is a port */
686  TerminationPort = NextPort;
687  } while (TerminationPort);
688  }
689  else if (((ExitStatus == STATUS_THREAD_IS_TERMINATING) &&
690  (Thread->DeadThread)) ||
691  !(Thread->DeadThread))
692  {
693  /*
694  * This case is special and deserves some extra comments. What
695  * basically happens here is that this thread doesn't have a termination
696  * port, which means that it died before being fully created. Since we
697  * still have to notify an LPC Server, we'll use the exception port,
698  * which we know exists. However, we need to know how far the thread
699  * actually got created. We have three possibilities:
700  *
701  * - NtCreateThread returned an error really early: DeadThread is set.
702  * - NtCreateThread managed to create the thread: DeadThread is off.
703  * - NtCreateThread was creating the thread (with DeadThread set,
704  * but the thread got killed prematurely: STATUS_THREAD_IS_TERMINATING
705  * is our exit code.)
706  *
707  * For the 2 & 3rd scenarios, the thread has been created far enough to
708  * warrant notification to the LPC Server.
709  */
710 
711  /* Setup the message header */
712  TerminationMsg.h.u2.ZeroInit = 0;
713  TerminationMsg.h.u2.s2.Type = LPC_CLIENT_DIED;
714  TerminationMsg.h.u1.s1.TotalLength = sizeof(TerminationMsg);
715  TerminationMsg.h.u1.s1.DataLength = sizeof(TerminationMsg) -
716  sizeof(PORT_MESSAGE);
717 
718  /* Make sure the process has an exception port */
719  if (CurrentProcess->ExceptionPort)
720  {
721  /* Save the Create Time */
722  TerminationMsg.CreateTime = Thread->CreateTime;
723 
724  /* Loop trying to send message */
725  while (TRUE)
726  {
727  /* Send the LPC Message */
728  Status = LpcRequestPort(CurrentProcess->ExceptionPort,
729  &TerminationMsg.h);
730  if ((Status == STATUS_NO_MEMORY) ||
732  {
733  /* Wait a bit and try again */
735  continue;
736  }
737  break;
738  }
739  }
740  }
741 
742  /* Rundown Win32 Thread if there is one */
745 
746  /* If we are the last thread and have a W32 Process */
747  if ((Last) && (CurrentProcess->Win32Process))
748  {
749  /* Run it down too */
751  }
752 
753  /* Make sure Stack Swap is enabled */
754  if (!Thread->Tcb.EnableStackSwap)
755  {
756  /* Stack swap really shouldn't be disabled during exit! */
757  KeBugCheckEx(KERNEL_STACK_LOCKED_AT_EXIT, 0, 0, 0, 0);
758  }
759 
760  /* Cancel I/O for the thread. */
762 
763  /* Rundown Timers */
764  ExTimerRundown();
765 
766  /* FIXME: Rundown Registry Notifications (NtChangeNotify)
767  CmNotifyRunDown(Thread); */
768 
769  /* Rundown Mutexes */
770  KeRundownThread();
771 
772  /* Check if we have a TEB */
773  Teb = Thread->Tcb.Teb;
774  if (Teb)
775  {
776  /* Check if the thread is still alive */
777  if (!Thread->DeadThread)
778  {
779  /* Check if we need to free its stack */
780  if (Teb->FreeStackOnTermination)
781  {
782  /* Set the TEB's Deallocation Stack as the Base Address */
783  Dummy = 0;
784  DeallocationStack = Teb->DeallocationStack;
785 
786  /* Free the Thread's Stack */
787  ZwFreeVirtualMemory(NtCurrentProcess(),
788  &DeallocationStack,
789  &Dummy,
790  MEM_RELEASE);
791  }
792 
793  /* Free the debug handle */
794  if (Teb->DbgSsReserved[1]) ObCloseHandle(Teb->DbgSsReserved[1],
795  UserMode);
796  }
797 
798  /* Decommit the TEB */
800  Thread->Tcb.Teb = NULL;
801  }
802 
803  /* Free LPC Data */
805 
806  /* Save the exit status and exit time */
809 
810  /* Sanity check */
812 
813  /* Check if this is the final thread or not */
814  if (Last)
815  {
816  /* Set the process exit time */
817  CurrentProcess->ExitTime = Thread->ExitTime;
818 
819  /* Exit the process */
821 
822  /* Get the process token and check if we need to audit */
823  PrimaryToken = PsReferencePrimaryToken(CurrentProcess);
824  if (SeDetailedAuditingWithToken(PrimaryToken))
825  {
826  /* Audit the exit */
828  }
829 
830  /* Dereference the process token */
831  ObFastDereferenceObject(&CurrentProcess->Token, PrimaryToken);
832 
833  /* Check if this is a VDM Process and rundown the VDM DPCs if so */
834  if (CurrentProcess->VdmObjects) { /* VdmRundownDpcs(CurrentProcess); */ }
835 
836  /* Kill the process in the Object Manager */
838 
839  /* Check if we have a section object */
840  if (CurrentProcess->SectionObject)
841  {
842  /* Dereference and clear the Section Object */
843  ObDereferenceObject(CurrentProcess->SectionObject);
844  CurrentProcess->SectionObject = NULL;
845  }
846 
847  /* Check if the process is part of a job */
848  if (CurrentProcess->Job)
849  {
850  /* Remove the process from the job */
852  }
853  }
854 
855  /* Disable APCs */
857 
858  /* Disable APC queueing, force a resumption */
861 
862  /* Re-enable APCs */
864 
865  /* Flush the User APCs */
866  FirstEntry = KeFlushQueueApc(&Thread->Tcb, UserMode);
867  if (FirstEntry)
868  {
869  /* Start with the first entry */
870  CurrentEntry = FirstEntry;
871  do
872  {
873  /* Get the APC */
874  Apc = CONTAINING_RECORD(CurrentEntry, KAPC, ApcListEntry);
875 
876  /* Move to the next one */
877  CurrentEntry = CurrentEntry->Flink;
878 
879  /* Rundown the APC or de-allocate it */
880  if (Apc->RundownRoutine)
881  {
882  /* Call its own routine */
883  Apc->RundownRoutine(Apc);
884  }
885  else
886  {
887  /* Do it ourselves */
888  ExFreePool(Apc);
889  }
890  }
891  while (CurrentEntry != FirstEntry);
892  }
893 
894  /* Clean address space if this was the last thread */
896 
897  /* Call the Lego routine */
899 
900  /* Flush the APC queue, which should be empty */
901  FirstEntry = KeFlushQueueApc(&Thread->Tcb, KernelMode);
902  if ((FirstEntry) || (Thread->Tcb.CombinedApcDisable != 0))
903  {
904  /* Bugcheck time */
905  KeBugCheckEx(KERNEL_APC_PENDING_DURING_EXIT,
906  (ULONG_PTR)FirstEntry,
909  0);
910  }
911 
912  /* Signal the process if this was the last thread */
913  if (Last) KeSetProcess(&CurrentProcess->Pcb, 0, FALSE);
914 
915  /* Terminate the Thread from the Scheduler */
917 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
VOID NTAPI ObKillProcess(IN PEPROCESS Process)
Definition: obhandle.c:2157
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
PLIST_ENTRY NTAPI KeFlushQueueApc(IN PKTHREAD Thread, IN KPROCESSOR_MODE PreviousMode)
Definition: apc.c:793
VOID NTAPI KeRundownThread(VOID)
Definition: thrdobj.c:439
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1022
LARGE_INTEGER ExitTime
Definition: pstypes.h:1038
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
VOID NTAPI IoCancelThreadIo(IN PETHREAD Thread)
Definition: irp.c:1146
ULONG EnableStackSwap
Definition: ketypes.h:1619
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
VOID NTAPI ExTimerRundown(VOID)
Definition: timer.c:43
ULONG CombinedApcDisable
Definition: ketypes.h:1773
LARGE_INTEGER CreateTime
Definition: lpctypes.h:270
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:297
LARGE_INTEGER CreateTime
Definition: pstypes.h:1035
LONG NTSTATUS
Definition: precomp.h:26
EX_RUNDOWN_REF RundownProtect
Definition: pstypes.h:1090
KTHREAD Tcb
Definition: pstypes.h:1034
PKWIN32_PROCESS_CALLOUT PspW32ProcessCallout
Definition: win32.c:18
VOID NTAPI PspCatchCriticalBreak(IN PCHAR Message, IN PVOID ProcessOrThread, IN PCHAR ImageName)
Definition: kill.c:27
VOID NTAPI PspExitProcess(IN BOOLEAN LastThread, IN PEPROCESS Process)
Definition: kill.c:1074
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
VOID NTAPI SeAuditProcessExit(IN PEPROCESS Process)
Definition: audit.c:40
struct _TERMINATION_PORT * Next
Definition: pstypes.h:1011
VOID NTAPI MmDeleteTeb(struct _EPROCESS *Process, PTEB Teb)
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
BOOLEAN FASTCALL ObReferenceObjectSafe(IN PVOID Object)
Definition: obref.c:24
uint32_t ULONG_PTR
Definition: typedefs.h:63
ULONG NTAPI KeSetProcess(struct _KPROCESS *Process, KPRIORITY Increment, BOOLEAN InWait)
PKWIN32_THREAD_CALLOUT PspW32ThreadCallout
Definition: win32.c:19
KAPC_STATE ApcState
Definition: ketypes.h:1668
ULONG ActiveExWorker
Definition: pstypes.h:1131
NTSTATUS NTAPI KeDelayExecutionThread(IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Interval OPTIONAL)
Definition: wait.c:283
BOOLEAN NTAPI KeIsAttachedProcess(VOID)
Definition: procobj.c:690
BOOLEAN NTAPI KeReadStateThread(IN PKTHREAD Thread)
Definition: thrdobj.c:51
VOID NTAPI PspExitProcessFromJob(IN PEJOB Job, IN PEPROCESS Process)
Definition: job.c:146
FORCEINLINE VOID ExReleasePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1238
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN KdDebuggerEnabled
Definition: kdmain.c:16
NTKERNELAPI VOID FASTCALL ExWaitForRundownProtectionRelease(_Inout_ PEX_RUNDOWN_REF RunRef)
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _TERMINATION_PORT * TerminationPort
Definition: pstypes.h:1050
#define NtCurrentProcess()
Definition: nt_native.h:1657
VOID NTAPI KeTerminateThread(IN KPRIORITY Increment)
Definition: thrdobj.c:1375
NTSTATUS NTAPI LpcRequestPort(IN PVOID PortObject, IN PPORT_MESSAGE LpcMessage)
Definition: send.c:22
#define PS_KILL_DEBUG
Definition: ps.h:25
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
VOID NTAPI MmCleanProcessAddressSpace(IN PEPROCESS Process)
Definition: procsup.c:1235
ULONG CurrentProcess
Definition: shell.c:125
LARGE_INTEGER ShortTime
Definition: kill.c:21
PVOID DeallocationStack
Definition: compat.h:527
#define STATUS_PENDING
Definition: ntstatus.h:82
PVOID DbgSsReserved[2]
Definition: compat.h:532
#define PSF_PROCESS_DELETE_BIT
Definition: pstypes.h:260
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
ULONG BreakOnTermination
Definition: pstypes.h:1115
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI PopCleanupPowerState(IN PPOWER_STATE PowerState)
Definition: power.c:63
VOID NTAPI DbgkExitProcess(IN NTSTATUS ExitStatus)
Definition: dbgkutil.c:304
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3376
PORT_MESSAGE h
Definition: lpctypes.h:269
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
Definition: ketypes.h:535
#define InterlockedOr
Definition: interlocked.h:224
Definition: typedefs.h:117
PACCESS_TOKEN NTAPI PsReferencePrimaryToken(PEPROCESS Process)
Definition: security.c:440
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
ULONG SystemThread
Definition: pstypes.h:1113
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
Definition: compat.h:484
FORCEINLINE VOID PspRunCreateThreadNotifyRoutines(IN PETHREAD CurrentThread, IN BOOLEAN Create)
Definition: ps_x.h:40
NTSTATUS ExitStatus
Definition: pstypes.h:1044
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:859
FORCEINLINE VOID PspRunLegoRoutine(IN PKTHREAD Thread)
Definition: ps_x.h:103
PVOID Teb
Definition: ketypes.h:1697
VOID FASTCALL ObFastDereferenceObject(IN PEX_FAST_REF FastRef, IN PVOID Object)
Definition: obref.c:169
#define MEM_RELEASE
Definition: nt_native.h:1316
PVOID LegoData
Definition: ketypes.h:1887
ULONG NTAPI KeForceResumeThread(IN PKTHREAD Thread)
Definition: thrdobj.c:276
PVOID Win32Thread
Definition: ketypes.h:1756
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
UCHAR ApcStateIndex
Definition: ketypes.h:1832
VOID NTAPI LpcExitThread(IN PETHREAD Thread)
Definition: close.c:19
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
ULONG ApcQueueable
Definition: ketypes.h:1601
BOOLEAN NTAPI SeDetailedAuditingWithToken(IN PTOKEN Token)
Definition: audit.c:25
signed int * PLONG
Definition: retypes.h:5
VOID NTAPI DbgkExitThread(IN NTSTATUS ExitStatus)
Definition: dbgkutil.c:340
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by PsExitSpecialApc(), and PspTerminateThreadByPointer().

◆ PspIsProcessExiting()

BOOLEAN NTAPI PspIsProcessExiting ( IN PEPROCESS  Process)

Definition at line 1067 of file kill.c.

1068 {
1069  return Process->Flags & PSF_PROCESS_EXITING_BIT;
1070 }
#define PSF_PROCESS_EXITING_BIT
Definition: pstypes.h:259
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by MmpPageOutPhysicalAddress().

◆ PspReapRoutine()

VOID NTAPI PspReapRoutine ( IN PVOID  Context)

Definition at line 170 of file kill.c.

171 {
172  PSINGLE_LIST_ENTRY NextEntry;
174  PSTRACE(PS_KILL_DEBUG, "Context: %p\n", Context);
175 
176  /* Start main loop */
177  do
178  {
179  /* Write magic value and return the next entry to process */
181  (PVOID)1);
182  ASSERT((NextEntry != NULL) && (NextEntry != (PVOID)1));
183 
184  /* Start inner loop */
185  do
186  {
187  /* Get the first Thread Entry */
188  Thread = CONTAINING_RECORD(NextEntry, ETHREAD, ReaperLink);
189 
190  /* Delete this entry's kernel stack */
192  Thread->Tcb.LargeStack);
194 
195  /* Move to the next entry */
196  NextEntry = NextEntry->Next;
197 
198  /* Dereference this thread */
200  } while ((NextEntry != NULL) && (NextEntry != (PVOID)1));
201 
202  /* Remove magic value, keep looping if it got changed */
204  NULL,
205  (PVOID)1) != (PVOID)1);
206 }
Definition: ntbasedef.h:635
VOID NTAPI MmDeleteKernelStack(PVOID Stack, BOOLEAN GuiStack)
KTHREAD Tcb
Definition: pstypes.h:1034
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define PS_KILL_DEBUG
Definition: ps.h:25
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:636
PVOID StackBase
Definition: ketypes.h:1556
LIST_ENTRY PspReaperListHead
Definition: kill.c:19
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
PVOID InitialStack
Definition: ketypes.h:1554

Referenced by PspInitPhase0().

◆ PspShutdownProcessManager()

VOID NTAPI PspShutdownProcessManager ( VOID  )

Definition at line 138 of file kill.c.

139 {
141 
142  /* Loop every process */
144  while (Process)
145  {
146  /* Make sure this isn't the idle or initial process */
148  {
149  /* Kill it */
151  }
152 
153  /* Get the next process */
155  }
156 }
PEPROCESS PsIdleProcess
Definition: psmgr.c:51
PEPROCESS PsInitialSystemProcess
Definition: psmgr.c:50
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI PspTerminateProcess(IN PEPROCESS Process, IN NTSTATUS ExitStatus)
Definition: kill.c:82
PEPROCESS NTAPI PsGetNextProcess(IN PEPROCESS OldProcess OPTIONAL)
Definition: process.c:128
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define STATUS_SYSTEM_SHUTDOWN
Definition: ntstatus.h:841

◆ PspTerminateProcess()

NTSTATUS NTAPI PspTerminateProcess ( IN PEPROCESS  Process,
IN NTSTATUS  ExitStatus 
)

Definition at line 82 of file kill.c.

84 {
87  PAGED_CODE();
89  "Process: %p ExitStatus: %d\n", Process, ExitStatus);
91 
92  /* Check if this is a Critical Process */
93  if (Process->BreakOnTermination)
94  {
95  /* Break to debugger */
96  PspCatchCriticalBreak("Terminating critical process 0x%p (%s)\n",
97  Process,
98  Process->ImageFileName);
99  }
100 
101  /* Set the delete flag */
103 
104  /* Get the first thread */
106  while (Thread)
107  {
108  /* Kill it */
111 
112  /* We had at least one thread, so termination is OK */
114  }
115 
116  /* Check if there was nothing to terminate or if we have a debug port */
117  if ((Status == STATUS_NOTHING_TO_TERMINATE) || (Process->DebugPort))
118  {
119  /* Clear the handle table anyway */
121  }
122 
123  /* Return status */
124  return Status;
125 }
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI PspCatchCriticalBreak(IN PCHAR Message, IN PVOID ProcessOrThread, IN PCHAR ImageName)
Definition: kill.c:27
#define PAGED_CODE()
Definition: video.h:57
#define PSREFTRACE(x)
Definition: ps.h:58
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_NOTHING_TO_TERMINATE
Definition: ntstatus.h:106
#define PS_KILL_DEBUG
Definition: ps.h:25
#define PSF_PROCESS_DELETE_BIT
Definition: pstypes.h:260
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
PETHREAD NTAPI PsGetNextProcessThread(IN PEPROCESS Process, IN PETHREAD Thread OPTIONAL)
Definition: process.c:75
#define InterlockedOr
Definition: interlocked.h:224
Status
Definition: gdiplustypes.h:24
VOID NTAPI ObClearProcessHandleTable(IN PEPROCESS Process)
Definition: obhandle.c:2024
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:859
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
return STATUS_SUCCESS
Definition: btrfs.c:2966
signed int * PLONG
Definition: retypes.h:5
NTSTATUS NTAPI PspTerminateThreadByPointer(IN PETHREAD Thread, IN NTSTATUS ExitStatus, IN BOOLEAN bSelf)
Definition: kill.c:987

Referenced by PspShutdownProcessManager(), and PsTerminateProcess().

◆ PspTerminateThreadByPointer()

NTSTATUS NTAPI PspTerminateThreadByPointer ( IN PETHREAD  Thread,
IN NTSTATUS  ExitStatus,
IN BOOLEAN  bSelf 
)

Definition at line 987 of file kill.c.

990 {
991  PKAPC Apc;
993  ULONG Flags;
994  PAGED_CODE();
995  PSTRACE(PS_KILL_DEBUG, "Thread: %p ExitStatus: %d\n", Thread, ExitStatus);
997 
998  /* Check if this is a Critical Thread, and Bugcheck */
1000  {
1001  /* Break to debugger */
1002  PspCatchCriticalBreak("Terminating critical thread 0x%p (%s)\n",
1003  Thread,
1004  Thread->ThreadsProcess->ImageFileName);
1005  }
1006 
1007  /* Check if we are already inside the thread */
1008  if ((bSelf) || (PsGetCurrentThread() == Thread))
1009  {
1010  /* This should only happen at passive */
1012 
1013  /* Mark it as terminated */
1015 
1016  /* Directly terminate the thread */
1018  }
1019 
1020  /* This shouldn't be a system thread */
1022 
1023  /* Allocate the APC */
1025  if (!Apc) return STATUS_INSUFFICIENT_RESOURCES;
1026 
1027  /* Set the Terminated Flag */
1029 
1030  /* Set it, and check if it was already set while we were running */
1033  {
1034  /* Initialize a Kernel Mode APC to Kill the Thread */
1035  KeInitializeApc(Apc,
1036  &Thread->Tcb,
1041  KernelMode,
1043 
1044  /* Insert it into the APC Queue */
1045  if (!KeInsertQueueApc(Apc, Apc, NULL, 2))
1046  {
1047  /* The APC was already in the queue, fail */
1049  }
1050  else
1051  {
1052  /* Forcefully resume the thread and return */
1054  return Status;
1055  }
1056  }
1057 
1058  /* We failed, free the APC */
1060 
1061  /* Return Status */
1062  return Status;
1063 }
VOID NTAPI KeInitializeApc(IN PKAPC Apc, IN PKTHREAD Thread, IN KAPC_ENVIRONMENT TargetEnvironment, IN PKKERNEL_ROUTINE KernelRoutine, IN PKRUNDOWN_ROUTINE RundownRoutine OPTIONAL, IN PKNORMAL_ROUTINE NormalRoutine, IN KPROCESSOR_MODE Mode, IN PVOID Context)
Definition: apc.c:651
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define ASSERT_IRQL_EQUAL(x)
Definition: debug.h:43
LONG NTSTATUS
Definition: precomp.h:26
KTHREAD Tcb
Definition: pstypes.h:1034
VOID NTAPI PspCatchCriticalBreak(IN PCHAR Message, IN PVOID ProcessOrThread, IN PCHAR ImageName)
Definition: kill.c:27
#define PAGED_CODE()
Definition: video.h:57
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define PSREFTRACE(x)
Definition: ps.h:58
smooth NULL
Definition: ftsmooth.c:416
#define UlongToPtr(u)
Definition: config.h:106
#define PS_KILL_DEBUG
Definition: ps.h:25
#define CT_TERMINATED_BIT
Definition: pstypes.h:222
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
ULONG BreakOnTermination
Definition: pstypes.h:1115
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID NTAPI PspExitThread(IN NTSTATUS ExitStatus)
Definition: kill.c:449
VOID NTAPI PspExitApcRundown(IN PKAPC Apc)
Definition: kill.c:160
ULONG CrossThreadFlags
Definition: pstypes.h:1125
#define PspSetCrossThreadFlag(Thread, Flag)
Definition: ps_x.h:25
Definition: ketypes.h:535
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
ULONG SystemThread
Definition: pstypes.h:1113
#define InterlockedExchange
Definition: armddk.h:54
Status
Definition: gdiplustypes.h:24
VOID NTAPI PspExitNormalApc(IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: kill.c:946
#define TAG_TERMINATE_APC
Definition: tag.h:163
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:859
BOOLEAN NTAPI KeInsertQueueApc(IN PKAPC Apc, IN PVOID SystemArgument1, IN PVOID SystemArgument2, IN KPRIORITY PriorityBoost)
Definition: apc.c:735
ULONG NTAPI KeForceResumeThread(IN PKTHREAD Thread)
Definition: thrdobj.c:276
unsigned int ULONG
Definition: retypes.h:1
#define PSTRACE(x, fmt,...)
Definition: ps.h:57
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2966
signed int * PLONG
Definition: retypes.h:5
VOID NTAPI PsExitSpecialApc(IN PKAPC Apc, IN OUT PKNORMAL_ROUTINE *NormalRoutine, IN OUT PVOID *NormalContext, IN OUT PVOID *SystemArgument1, IN OUT PVOID *SystemArgument2)
Definition: kill.c:921

Referenced by KiThreadStartup(), NtTerminateProcess(), NtTerminateThread(), PspSystemThreadStartup(), PspTerminateProcess(), PspUserThreadStartup(), and PsTerminateSystemThread().

◆ PsTerminateProcess()

NTSTATUS NTAPI PsTerminateProcess ( IN PEPROCESS  Process,
IN NTSTATUS  ExitStatus 
)

Definition at line 129 of file kill.c.

131 {
132  /* Call the internal API */
134 }
NTSTATUS NTAPI PspTerminateProcess(IN PEPROCESS Process, IN NTSTATUS ExitStatus)
Definition: kill.c:82
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:859
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219

Referenced by DbgkpCloseObject(), and ExpDebuggerWorker().

◆ PsTerminateSystemThread()

NTSTATUS NTAPI PsTerminateSystemThread ( IN NTSTATUS  ExitStatus)

Definition at line 1144 of file kill.c.

1145 {
1147 
1148  /* Make sure this is a system thread */
1150 
1151  /* Terminate it for real */
1153 }
#define TRUE
Definition: types.h:120
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
ULONG SystemThread
Definition: pstypes.h:1113
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:859
NTSTATUS NTAPI PspTerminateThreadByPointer(IN PETHREAD Thread, IN NTSTATUS ExitStatus, IN BOOLEAN bSelf)
Definition: kill.c:987

Referenced by _Function_class_(), ExpWorkerThreadBalanceManager(), ExpWorkerThreadEntryPoint(), Ext2bhReaperThread(), Ext2FcbReaperThread(), Ext2McbReaperThread(), InbvRotationThread(), KeyboardDeviceWorker(), LwipThreadMain(), MonitorThread(), RxpWorkerThreadDispatcher(), RxSpinUpRequestsDispatcher(), SermouseDeviceWorker(), sys_arch_mbox_fetch(), sys_arch_sem_wait(), SystemProcessTestWorker(), SystemProcessWorker(), TdiReceiveThread(), TdiSendThread(), USBPORT_WorkerThread(), and VfdDeviceThread().

Variable Documentation

◆ PspReaperListHead

LIST_ENTRY PspReaperListHead = { NULL, NULL }

Definition at line 19 of file kill.c.

Referenced by KeTerminateThread(), and PspReapRoutine().

◆ PspReaperWorkItem

WORK_QUEUE_ITEM PspReaperWorkItem

Definition at line 20 of file kill.c.

Referenced by KeTerminateThread(), and PspInitPhase0().

◆ ShortTime

LARGE_INTEGER ShortTime = {{-10 * 100 * 1000, -1}}

Definition at line 21 of file kill.c.

Referenced by PspExitThread().