ReactOS  0.4.15-dev-318-g99b52df
test.h File Reference
#include <ntos.h>
Include dependency graph for test.h:

Go to the source code of this file.

Classes

struct  tagFOO
 
struct  SOUND_DEVICE_INIT
 

Macros

#define NTOS_MODE_USER
 
#define FAILED_WITH_STATUS   DEFINE_DBG_MSG("%s() failed, status 0x%08X")
 
#define DEFINE_DBG_MSG(__str__)   "PSAPI: " __str__ "\n"
 

Typedefs

typedef struct tagFOO FOO
 
typedef struct tagFOOPFOO
 
typedef struct tagFOOLPFOO
 
typedef NTSTATUS NTAPI(* PPROC_ENUM_ROUTINE) (IN PSYSTEM_PROCESSES CurrentProcess, IN OUT PVOID CallbackContext)
 
typedef NTSTATUS NTAPI(* PTHREAD_ENUM_ROUTINE) (IN PSYSTEM_THREADS CurrentThread, IN OUT PVOID CallbackContext)
 
typedef NTSTATUS NTAPI(* PSYSMOD_ENUM_ROUTINE) (IN PSYSTEM_MODULE_INFORMATION_ENTRY CurrentModule, IN OUT PVOID CallbackContext)
 
typedef NTSTATUS NTAPI(* PPROCMOD_ENUM_ROUTINE) (IN HANDLE ProcessHandle, IN PLDR_DATA_TABLE_ENTRY CurrentModule, IN OUT PVOID CallbackContext)
 

Functions

void_lfind (const void *match, const void *start, unsigned int *array_size, unsigned int elem_size, int(*cf)(const void *, const void *))
 
static struct _TEBNtCurrentTeb (void)
 
NTSTATUS NTAPI PsaEnumerateProcessesAndThreads (IN PPROC_ENUM_ROUTINE ProcessCallback, IN OUT PVOID ProcessCallbackContext, IN PTHREAD_ENUM_ROUTINE ThreadCallback, IN OUT PVOID ThreadCallbackContext)
 
NTSTATUS NTAPI PsaEnumerateProcesses (IN PPROC_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 
NTSTATUS NTAPI PsaEnumerateThreads (IN PTHREAD_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 
NTSTATUS NTAPI PsaCaptureProcessesAndThreads (OUT PSYSTEM_PROCESSES *ProcessesAndThreads)
 
NTSTATUS NTAPI PsaWalkProcessesAndThreads (IN PSYSTEM_PROCESSES ProcessesAndThreads, IN PPROC_ENUM_ROUTINE ProcessCallback, IN OUT PVOID ProcessCallbackContext, IN PTHREAD_ENUM_ROUTINE ThreadCallback, IN OUT PVOID ThreadCallbackContext)
 
NTSTATUS NTAPI PsaWalkProcesses (IN PSYSTEM_PROCESSES ProcessesAndThreads, IN PPROC_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 
NTSTATUS NTAPI PsaWalkThreads (IN PSYSTEM_PROCESSES ProcessesAndThreads, IN PTHREAD_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 
PSYSTEM_PROCESSES FASTCALL PsaWalkFirstProcess (IN PSYSTEM_PROCESSES ProcessesAndThreads)
 
PSYSTEM_PROCESSES FASTCALL PsaWalkNextProcess (IN PSYSTEM_PROCESSES CurrentProcess)
 
PSYSTEM_THREADS FASTCALL PsaWalkFirstThread (IN PSYSTEM_PROCESSES CurrentProcess)
 
PSYSTEM_THREADS FASTCALL PsaWalkNextThread (IN PSYSTEM_THREADS CurrentThread)
 
NTSTATUS NTAPI PsaEnumerateSystemModules (IN PSYSMOD_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 
NTSTATUS NTAPI PsaCaptureSystemModules (OUT PSYSTEM_MODULE_INFORMATION *SystemModules)
 
NTSTATUS NTAPI PsaWalkSystemModules (IN PSYSTEM_MODULE_INFORMATION SystemModules, IN PSYSMOD_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 
PSYSTEM_MODULE_INFORMATION_ENTRY FASTCALL PsaWalkFirstSystemModule (IN PSYSTEM_MODULE_INFORMATION SystemModules)
 
PSYSTEM_MODULE_INFORMATION_ENTRY FASTCALL PsaWalkNextSystemModule (IN PSYSTEM_MODULE_INFORMATION CurrentSystemModule)
 
NTSTATUS NTAPI PsaEnumerateProcessModules (IN HANDLE ProcessHandle, IN PPROCMOD_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 
VOID NTAPI PsaFreeCapture (IN PVOID Capture)
 
voidPsaiMalloc (SIZE_T size)
 
voidPsaiRealloc (void *ptr, SIZE_T size)
 
void PsaiFree (void *ptr)
 

Macro Definition Documentation

◆ DEFINE_DBG_MSG

#define DEFINE_DBG_MSG (   __str__)    "PSAPI: " __str__ "\n"

Definition at line 257 of file test.h.

◆ FAILED_WITH_STATUS

#define FAILED_WITH_STATUS   DEFINE_DBG_MSG("%s() failed, status 0x%08X")

Definition at line 95 of file test.h.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 47 of file test.h.

Typedef Documentation

◆ FOO

typedef struct tagFOO FOO

◆ LPFOO

typedef struct tagFOO* LPFOO

◆ PFOO

typedef struct tagFOO * PFOO

◆ PPROC_ENUM_ROUTINE

Definition at line 70 of file test.h.

◆ PPROCMOD_ENUM_ROUTINE

Definition at line 88 of file test.h.

◆ PSYSMOD_ENUM_ROUTINE

typedef NTSTATUS NTAPI(* PSYSMOD_ENUM_ROUTINE) (IN PSYSTEM_MODULE_INFORMATION_ENTRY CurrentModule, IN OUT PVOID CallbackContext)

Definition at line 82 of file test.h.

◆ PTHREAD_ENUM_ROUTINE

typedef NTSTATUS NTAPI(* PTHREAD_ENUM_ROUTINE) (IN PSYSTEM_THREADS CurrentThread, IN OUT PVOID CallbackContext)

Definition at line 76 of file test.h.

Function Documentation

◆ _lfind()

void* _lfind ( const void match,
const void start,
unsigned int array_size,
unsigned int  elem_size,
int(*)(const void *, const void *)  cf 
)

Referenced by _lsearch().

◆ NtCurrentTeb()

static struct _TEB* NtCurrentTeb ( void  )
inlinestatic

Definition at line 25 of file test.h.

26 {
27  struct _TEB * pTeb;
28 
29  /* FIXME: instead of hardcoded offsets, use offsetof() - if possible */
30  __asm__ __volatile__
31  (
32  "movl %%fs:0x18, %0\n" /* fs:18h == Teb->Tib.Self */
33  : "=r" (pTeb) /* can't have two memory operands */
34  : /* no inputs */
35  );
36 
37  return pTeb;
38 }
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
Definition: compat.h:493

◆ PsaCaptureProcessesAndThreads()

NTSTATUS NTAPI PsaCaptureProcessesAndThreads ( OUT PSYSTEM_PROCESSES ProcessesAndThreads)

◆ PsaCaptureSystemModules()

NTSTATUS NTAPI PsaCaptureSystemModules ( OUT PSYSTEM_MODULE_INFORMATION SystemModules)

◆ 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 }
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:55
smooth NULL
Definition: ftsmooth.c:416
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
LPFNPSPCALLBACK Callback
Definition: desk.c:112

◆ 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 */
167  Status = PsaCaptureProcessesAndThreads(&pInfoBuffer);
168 
169  if(!NT_SUCCESS(Status))
170  {
171  goto Bail;
172  }
173 
174  /* walk the processes and threads list */
175  Status = PsaWalkProcessesAndThreads(pInfoBuffer,
176  ProcessCallback,
177  ProcessCallbackContext,
179  ThreadCallbackContext);
180 
181 Bail:
182  PsaFreeCapture(pInfoBuffer);
183 
184  return Status;
185 }
VOID NTAPI PsaFreeCapture(IN PVOID Capture)
Definition: processes.c:188
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
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
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI PsaCaptureProcessesAndThreads(OUT PSYSTEM_PROCESS_INFORMATION *ProcessesAndThreads)
Definition: processes.c:38

◆ PsaEnumerateProcessModules()

NTSTATUS NTAPI PsaEnumerateProcessModules ( IN HANDLE  ProcessHandle,
IN PPROCMOD_ENUM_ROUTINE  Callback,
IN OUT PVOID  CallbackContext 
)

Definition at line 30 of file modules.c.

33 {
35 
36  /* current process - use direct memory copy */
37  /* FIXME - compare process id instead of a handle */
39  {
40  PLIST_ENTRY ListHead, Current;
41 
42 #if 0
43  __try
44  {
45 #endif
46  ListHead = &(NtCurrentPeb()->Ldr->InLoadOrderModuleList);
47  Current = ListHead->Flink;
48 
49  while(Current != ListHead)
50  {
51  PLDR_DATA_TABLE_ENTRY LoaderModule = CONTAINING_RECORD(Current, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
52 
53  /* return the current module to the callback */
54  Status = Callback(ProcessHandle, LoaderModule, CallbackContext);
55 
56  if(!NT_SUCCESS(Status))
57  {
58  goto Failure;
59  }
60 
61  Current = LoaderModule->InLoadOrderLinks.Flink;
62  }
63 #if 0
64  }
66  {
67  return GetExceptionCode();
68  }
69 #endif
70  }
71  else
72  {
73  PROCESS_BASIC_INFORMATION BasicInformation;
74  PPEB_LDR_DATA LoaderData;
75  LDR_DATA_TABLE_ENTRY LoaderModule;
76  PLIST_ENTRY ListHead, Current;
77 
78  /* query the process basic information (includes the PEB address) */
81  &BasicInformation,
82  sizeof(BasicInformation),
83  NULL);
84 
85  if(!NT_SUCCESS(Status))
86  {
87  DPRINT(FAILED_WITH_STATUS, "NtQueryInformationProcess", Status);
88  goto Failure;
89  }
90 
91  /* get the address of the PE Loader data */
93  &(BasicInformation.PebBaseAddress->Ldr),
94  &LoaderData,
95  sizeof(LoaderData),
96  NULL);
97 
98  if(!NT_SUCCESS(Status))
99  {
100  DPRINT(FAILED_WITH_STATUS, "NtReadVirtualMemory", Status);
101  goto Failure;
102  }
103 
104  /* head of the module list: the last element in the list will point to this */
105  ListHead = &LoaderData->InLoadOrderModuleList;
106 
107  /* get the address of the first element in the list */
109  &(LoaderData->InLoadOrderModuleList.Flink),
110  &Current,
111  sizeof(Current),
112  NULL);
113 
114  while(Current != ListHead)
115  {
116  /* read the current module */
118  CONTAINING_RECORD(Current, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks),
119  &LoaderModule,
120  sizeof(LoaderModule),
121  NULL);
122 
123  if(!NT_SUCCESS(Status))
124  {
125  DPRINT(FAILED_WITH_STATUS, "NtReadVirtualMemory", Status);
126  goto Failure;
127  }
128 
129  /* return the current module to the callback */
130  Status = Callback(ProcessHandle, &LoaderModule, CallbackContext);
131 
132  if(!NT_SUCCESS(Status))
133  {
134  goto Failure;
135  }
136 
137  /* address of the next module in the list */
138  Current = LoaderModule.InLoadOrderLinks.Flink;
139  }
140  }
141 
142  return STATUS_SUCCESS;
143 
144 Failure:
145  return Status;
146 }
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:55
LIST_ENTRY InLoadOrderModuleList
Definition: ldrtypes.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:59
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
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 NtCurrentProcess()
Definition: nt_native.h:1657
#define GetExceptionCode()
Definition: exception.h:69
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtReadVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, OUT PVOID Buffer, IN SIZE_T NumberOfBytesToRead, OUT PSIZE_T NumberOfBytesRead OPTIONAL)
Definition: virtual.c:2691
Definition: btrfs_drv.h:1922
Definition: typedefs.h:118
Status
Definition: gdiplustypes.h:24
LIST_ENTRY InLoadOrderLinks
Definition: ldrtypes.h:138
#define NtCurrentPeb()
Definition: FLS.c:20
PPEB_LDR_DATA Ldr
Definition: btrfs_drv.h:1958
#define FAILED_WITH_STATUS
Definition: test.h:95
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
return STATUS_SUCCESS
Definition: btrfs.c:3014
LPFNPSPCALLBACK Callback
Definition: desk.c:112

◆ PsaEnumerateSystemModules()

NTSTATUS NTAPI PsaEnumerateSystemModules ( IN PSYSMOD_ENUM_ROUTINE  Callback,
IN OUT PVOID  CallbackContext 
)

Definition at line 21 of file drivers.c.

23 {
24  PRTL_PROCESS_MODULES psmModules;
26 
27 #if 0
28  __try
29  {
30 #else
31  do
32  {
33 #endif
34  /* capture the system modules */
35  Status = PsaCaptureSystemModules(&psmModules);
36 
37  if(!NT_SUCCESS(Status))
38  {
39  break;
40  }
41 
42  /* walk the system modules */
44 #if 0
45  }
46  __finally
47  {
48 #else
49  } while(0);
50 #endif
51  /* free the capture */
52  PsaFreeCapture(psmModules);
53 #if 0
54  }
55 #endif
56 
57  return Status;
58 }
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:55
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI PsaWalkSystemModules(IN PRTL_PROCESS_MODULES SystemModules, IN PSYSMOD_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
Definition: drivers.c:154
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI PsaFreeCapture(IN PVOID Capture)
Definition: processes.c:188
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:3014
LPFNPSPCALLBACK Callback
Definition: desk.c:112
NTSTATUS NTAPI PsaCaptureSystemModules(OUT PRTL_PROCESS_MODULES *SystemModules)
Definition: drivers.c:61

◆ 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 }
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:55
smooth NULL
Definition: ftsmooth.c:416
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
LPFNPSPCALLBACK Callback
Definition: desk.c:112

◆ PsaFreeCapture()

VOID NTAPI PsaFreeCapture ( IN PVOID  Capture)

Definition at line 188 of file processes.c.

189 {
190  PsaiFree(Capture);
191 }
void PsaiFree(void *ptr)
Definition: ctm.c:103
struct _Capture Capture
Definition: capture.h:24

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

◆ PsaiFree()

void PsaiFree ( void ptr)

Definition at line 103 of file ctm.c.

103 { free(ptr); }
#define free
Definition: debug_ros.c:5
static PVOID ptr
Definition: dispmode.c:27

◆ PsaiMalloc()

void* PsaiMalloc ( SIZE_T  size)

Definition at line 101 of file ctm.c.

101 { return malloc(size); }
GLsizeiptr size
Definition: glext.h:5919
#define malloc
Definition: debug_ros.c:4

◆ PsaiRealloc()

void* PsaiRealloc ( void ptr,
SIZE_T  size 
)

Definition at line 102 of file ctm.c.

102 { return realloc(ptr, size); }
#define realloc
Definition: debug_ros.c:6
static PVOID ptr
Definition: dispmode.c:27
GLsizeiptr size
Definition: glext.h:5919

◆ PsaWalkFirstProcess()

PSYSTEM_PROCESSES FASTCALL PsaWalkFirstProcess ( IN PSYSTEM_PROCESSES  ProcessesAndThreads)

◆ PsaWalkFirstSystemModule()

PSYSTEM_MODULE_INFORMATION_ENTRY FASTCALL PsaWalkFirstSystemModule ( IN PSYSTEM_MODULE_INFORMATION  SystemModules)

◆ PsaWalkFirstThread()

PSYSTEM_THREADS FASTCALL PsaWalkFirstThread ( IN PSYSTEM_PROCESSES  CurrentProcess)

Referenced by PrintThreads().

◆ PsaWalkNextProcess()

PSYSTEM_PROCESSES FASTCALL PsaWalkNextProcess ( IN PSYSTEM_PROCESSES  CurrentProcess)

◆ PsaWalkNextSystemModule()

PSYSTEM_MODULE_INFORMATION_ENTRY FASTCALL PsaWalkNextSystemModule ( IN PSYSTEM_MODULE_INFORMATION  CurrentSystemModule)

◆ PsaWalkNextThread()

PSYSTEM_THREADS FASTCALL PsaWalkNextThread ( IN PSYSTEM_THREADS  CurrentThread)

Referenced by PrintThreads().

◆ PsaWalkProcesses()

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

◆ PsaWalkProcessesAndThreads()

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

◆ PsaWalkSystemModules()

NTSTATUS NTAPI PsaWalkSystemModules ( IN PSYSTEM_MODULE_INFORMATION  SystemModules,
IN PSYSMOD_ENUM_ROUTINE  Callback,
IN OUT PVOID  CallbackContext 
)

◆ PsaWalkThreads()

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