ReactOS 0.4.16-dev-303-g11d5cb8
processes.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for processes.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI PsaCaptureProcessesAndThreads (OUT PSYSTEM_PROCESS_INFORMATION *ProcessesAndThreads)
 
NTSTATUS NTAPI PsaWalkProcessesAndThreads (IN PSYSTEM_PROCESS_INFORMATION ProcessesAndThreads, IN PPROC_ENUM_ROUTINE ProcessCallback, IN OUT PVOID ProcessCallbackContext, IN PTHREAD_ENUM_ROUTINE ThreadCallback, IN OUT PVOID ThreadCallbackContext)
 
NTSTATUS NTAPI PsaEnumerateProcessesAndThreads (IN PPROC_ENUM_ROUTINE ProcessCallback, IN OUT PVOID ProcessCallbackContext, IN PTHREAD_ENUM_ROUTINE ThreadCallback, IN OUT PVOID ThreadCallbackContext)
 
VOID NTAPI PsaFreeCapture (IN PVOID Capture)
 
NTSTATUS NTAPI PsaWalkProcesses (IN PSYSTEM_PROCESS_INFORMATION ProcessesAndThreads, IN PPROC_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 
NTSTATUS NTAPI PsaWalkThreads (IN PSYSTEM_PROCESS_INFORMATION ProcessesAndThreads, IN PTHREAD_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 
NTSTATUS NTAPI PsaEnumerateProcesses (IN PPROC_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 
NTSTATUS NTAPI PsaEnumerateThreads (IN PTHREAD_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 
PSYSTEM_PROCESS_INFORMATION FASTCALL PsaWalkFirstProcess (IN PSYSTEM_PROCESS_INFORMATION ProcessesAndThreads)
 
PSYSTEM_PROCESS_INFORMATION FASTCALL PsaWalkNextProcess (IN PSYSTEM_PROCESS_INFORMATION CurrentProcess)
 
PSYSTEM_THREAD_INFORMATION FASTCALL PsaWalkFirstThread (IN PSYSTEM_PROCESS_INFORMATION CurrentProcess)
 
PSYSTEM_THREAD_INFORMATION FASTCALL PsaWalkNextThread (IN PSYSTEM_THREAD_INFORMATION CurrentThread)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 34 of file processes.c.

Function Documentation

◆ PsaCaptureProcessesAndThreads()

NTSTATUS NTAPI PsaCaptureProcessesAndThreads ( OUT PSYSTEM_PROCESS_INFORMATION ProcessesAndThreads)

Definition at line 38 of file processes.c.

39{
41 SIZE_T nSize = 0x8000;
43
44 if(ProcessesAndThreads == NULL)
45 {
47 }
48
49 /* FIXME: if the system has loaded several processes and threads, the buffer
50 could get really big. But if there's several processes and threads, the
51 system is already under stress, and a huge buffer could only make things
52 worse. The function should be profiled to see what's the average minimum
53 buffer size, to succeed on the first shot */
54 do
55 {
56 PVOID pTmp;
57
58 /* free the buffer, and reallocate it to the new size. RATIONALE: since we
59 ignore the buffer's contents at this point, there's no point in a realloc()
60 that could end up copying a large chunk of data we'd discard anyway */
61 PsaiFree(pInfoBuffer);
62 pTmp = PsaiMalloc(nSize);
63
64 if(pTmp == NULL)
65 {
68 break;
69 }
70
71 pInfoBuffer = pTmp;
72
73 /* query the information */
75 pInfoBuffer,
76 nSize,
77 NULL);
78
79 /* double the buffer size */
80 nSize *= 2;
82
83 if(!NT_SUCCESS(Status))
84 {
85 DPRINT(FAILED_WITH_STATUS, "NtQuerySystemInformation", Status);
86 return Status;
87 }
88
89 *ProcessesAndThreads = pInfoBuffer;
90 return STATUS_SUCCESS;
91}
LONG NTSTATUS
Definition: precomp.h:26
void PsaiFree(void *ptr)
Definition: ctm.c:103
void * PsaiMalloc(SIZE_T size)
Definition: ctm.c:101
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
@ SystemProcessInformation
Definition: ntddk_ex.h:16
Status
Definition: gdiplustypes.h:25
#define FAILED_WITH_STATUS
Definition: test.h:95
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2109

Referenced by PsaEnumerateProcessesAndThreads().

◆ PsaEnumerateProcesses()

NTSTATUS NTAPI PsaEnumerateProcesses ( IN PPROC_ENUM_ROUTINE  Callback,
IN OUT PVOID  CallbackContext 
)

Definition at line 218 of file processes.c.

220{
223 NULL,
224 NULL);
225}
NTSTATUS NTAPI PsaEnumerateProcessesAndThreads(IN PPROC_ENUM_ROUTINE ProcessCallback, IN OUT PVOID ProcessCallbackContext, IN PTHREAD_ENUM_ROUTINE ThreadCallback, IN OUT PVOID ThreadCallbackContext)
Definition: processes.c:153
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:60

◆ PsaEnumerateProcessesAndThreads()

NTSTATUS NTAPI PsaEnumerateProcessesAndThreads ( IN PPROC_ENUM_ROUTINE  ProcessCallback,
IN OUT PVOID  ProcessCallbackContext,
IN PTHREAD_ENUM_ROUTINE  ThreadCallback,
IN OUT PVOID  ThreadCallbackContext 
)

Definition at line 153 of file processes.c.

157{
158 PSYSTEM_PROCESS_INFORMATION pInfoBuffer = NULL;
160
161 if(ProcessCallback == NULL && ThreadCallback == NULL)
162 {
164 }
165
166 /* get the processes and threads list */
168
169 if(!NT_SUCCESS(Status))
170 {
171 goto Bail;
172 }
173
174 /* walk the processes and threads list */
176 ProcessCallback,
177 ProcessCallbackContext,
179 ThreadCallbackContext);
180
181Bail:
182 PsaFreeCapture(pInfoBuffer);
183
184 return Status;
185}
@ ThreadCallback
Definition: dbghelp.h:626
VOID NTAPI PsaFreeCapture(IN PVOID Capture)
Definition: processes.c:188
NTSTATUS NTAPI PsaWalkProcessesAndThreads(IN PSYSTEM_PROCESS_INFORMATION ProcessesAndThreads, IN PPROC_ENUM_ROUTINE ProcessCallback, IN OUT PVOID ProcessCallbackContext, IN PTHREAD_ENUM_ROUTINE ThreadCallback, IN OUT PVOID ThreadCallbackContext)
Definition: processes.c:94
NTSTATUS NTAPI PsaCaptureProcessesAndThreads(OUT PSYSTEM_PROCESS_INFORMATION *ProcessesAndThreads)
Definition: processes.c:38
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

Referenced by PsaEnumerateProcesses(), and PsaEnumerateThreads().

◆ PsaEnumerateThreads()

NTSTATUS NTAPI PsaEnumerateThreads ( IN PTHREAD_ENUM_ROUTINE  Callback,
IN OUT PVOID  CallbackContext 
)

Definition at line 228 of file processes.c.

230{
232 NULL,
233 Callback,
235}

◆ PsaFreeCapture()

VOID NTAPI PsaFreeCapture ( IN PVOID  Capture)

Definition at line 188 of file processes.c.

189{
191}
struct _Capture Capture
Definition: capture.h:24

Referenced by PerfDataRefresh(), PrintProcess(), PrintProcessList(), PsaEnumerateProcessesAndThreads(), and PsaEnumerateSystemModules().

◆ PsaWalkFirstProcess()

PSYSTEM_PROCESS_INFORMATION FASTCALL PsaWalkFirstProcess ( IN PSYSTEM_PROCESS_INFORMATION  ProcessesAndThreads)

Definition at line 238 of file processes.c.

239{
240 return ProcessesAndThreads;
241}

Referenced by PsaWalkProcessesAndThreads().

◆ PsaWalkFirstThread()

PSYSTEM_THREAD_INFORMATION FASTCALL PsaWalkFirstThread ( IN PSYSTEM_PROCESS_INFORMATION  CurrentProcess)

Definition at line 257 of file processes.c.

258{
259 static SIZE_T nOffsetOfThreads = 0;
260
261 /* get the offset of the Threads field */
262 nOffsetOfThreads = sizeof(SYSTEM_PROCESS_INFORMATION);
263
264 return (PSYSTEM_THREAD_INFORMATION)((ULONG_PTR)CurrentProcess + nOffsetOfThreads);
265}
#define ULONG_PTR
Definition: config.h:101
struct _SYSTEM_PROCESS_INFORMATION SYSTEM_PROCESS_INFORMATION

Referenced by PsaWalkProcessesAndThreads().

◆ PsaWalkNextProcess()

PSYSTEM_PROCESS_INFORMATION FASTCALL PsaWalkNextProcess ( IN PSYSTEM_PROCESS_INFORMATION  CurrentProcess)

Definition at line 244 of file processes.c.

245{
246 if(CurrentProcess->NextEntryOffset == 0)
247 {
248 return NULL;
249 }
250 else
251 {
252 return (PSYSTEM_PROCESS_INFORMATION)((ULONG_PTR)CurrentProcess + CurrentProcess->NextEntryOffset);
253 }
254}

Referenced by PsaWalkProcessesAndThreads().

◆ PsaWalkNextThread()

PSYSTEM_THREAD_INFORMATION FASTCALL PsaWalkNextThread ( IN PSYSTEM_THREAD_INFORMATION  CurrentThread)

Definition at line 268 of file processes.c.

269{
270 return (PSYSTEM_THREAD_INFORMATION)((ULONG_PTR)CurrentThread +
273}

Referenced by PsaWalkProcessesAndThreads().

◆ PsaWalkProcesses()

NTSTATUS NTAPI PsaWalkProcesses ( IN PSYSTEM_PROCESS_INFORMATION  ProcessesAndThreads,
IN PPROC_ENUM_ROUTINE  Callback,
IN OUT PVOID  CallbackContext 
)

Definition at line 194 of file processes.c.

197{
198 return PsaWalkProcessesAndThreads(ProcessesAndThreads,
199 Callback,
201 NULL,
202 NULL);
203}

◆ PsaWalkProcessesAndThreads()

NTSTATUS NTAPI PsaWalkProcessesAndThreads ( IN PSYSTEM_PROCESS_INFORMATION  ProcessesAndThreads,
IN PPROC_ENUM_ROUTINE  ProcessCallback,
IN OUT PVOID  ProcessCallbackContext,
IN PTHREAD_ENUM_ROUTINE  ThreadCallback,
IN OUT PVOID  ThreadCallbackContext 
)

Definition at line 94 of file processes.c.

99{
101
102 if(ProcessCallback == NULL && ThreadCallback == NULL)
103 {
105 }
106
108
109 ProcessesAndThreads = PsaWalkFirstProcess(ProcessesAndThreads);
110
111 /* scan the process list */
112 do
113 {
114 if(ProcessCallback)
115 {
116 Status = ProcessCallback(ProcessesAndThreads, ProcessCallbackContext);
117
118 if(!NT_SUCCESS(Status))
119 {
120 break;
121 }
122 }
123
124 /* if the caller provided a thread callback */
126 {
127 ULONG i;
129
130 /* scan the current process's thread list */
131 for(i = 0, pCurThread = PsaWalkFirstThread(ProcessesAndThreads);
132 i < ProcessesAndThreads->NumberOfThreads;
133 i++, pCurThread = PsaWalkNextThread(pCurThread))
134 {
135 Status = ThreadCallback(pCurThread, ThreadCallbackContext);
136
137 if(!NT_SUCCESS(Status))
138 {
139 goto Bail;
140 }
141 }
142 }
143
144 /* move to the next process */
145 ProcessesAndThreads = PsaWalkNextProcess(ProcessesAndThreads);
146 } while(ProcessesAndThreads);
147
148Bail:
149 return Status;
150}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PSYSTEM_PROCESS_INFORMATION FASTCALL PsaWalkNextProcess(IN PSYSTEM_PROCESS_INFORMATION CurrentProcess)
Definition: processes.c:244
PSYSTEM_THREAD_INFORMATION FASTCALL PsaWalkFirstThread(IN PSYSTEM_PROCESS_INFORMATION CurrentProcess)
Definition: processes.c:257
PSYSTEM_PROCESS_INFORMATION FASTCALL PsaWalkFirstProcess(IN PSYSTEM_PROCESS_INFORMATION ProcessesAndThreads)
Definition: processes.c:238
PSYSTEM_THREAD_INFORMATION FASTCALL PsaWalkNextThread(IN PSYSTEM_THREAD_INFORMATION CurrentThread)
Definition: processes.c:268
uint32_t ULONG
Definition: typedefs.h:59

Referenced by PsaEnumerateProcessesAndThreads(), PsaWalkProcesses(), and PsaWalkThreads().

◆ PsaWalkThreads()

NTSTATUS NTAPI PsaWalkThreads ( IN PSYSTEM_PROCESS_INFORMATION  ProcessesAndThreads,
IN PTHREAD_ENUM_ROUTINE  Callback,
IN OUT PVOID  CallbackContext 
)

Definition at line 206 of file processes.c.

209{
210 return PsaWalkProcessesAndThreads(ProcessesAndThreads,
211 NULL,
212 NULL,
213 Callback,
215}