1 /*
2  * test.h
3  *
4  * This file is a combination of a couple different headers
5  * from ReactOS's include/ folder, and a little bit of custom
6  * hacking as well for the purpose of testing sdkparse.
7  *
8  *  THIS SOFTWARE IS NOT COPYRIGHTED
9  *
10  *  This source code is offered for use in the public domain. You may
11  *  use, modify or distribute it freely.
12  *
13  *  This code is distributed in the hope that it will be useful but
14  *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
15  *  DISCLAMED. This includes but is not limited to warranties of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17  *
18  */
19 
20 #ifndef __INTERNAL_PSAPI_H_INCLUDED__
21 #define __INTERNAL_PSAPI_H_INCLUDED__
22 
23 void  *_lfind(const void* match, const void* start,unsigned int* array_size, unsigned int elem_size,int (*cf)(const void*,const void*));
24 
NtCurrentTeb(void)25 static inline struct _TEB * NtCurrentTeb(void)
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 }
39 
40 typedef struct tagFOO
41 {
42 	INT lonibble : 4;
43 	INT hinibble : 4;
44 } FOO, *PFOO, FAR *LPFOO;
45 
46 /* INCLUDES */
47 #define NTOS_MODE_USER
48 #include <ntos.h>
49 
50 /* OBJECTS */
51 typedef struct
52 {
53 	LPSTR LeftVolumeName;
54 	LPSTR RightVolumeName;
55 	ULONG DefaultVolume;
56 	ULONG Type;
57 	ULONG DeviceType;
58 	char Key[4];
59 	LPSTR PrototypeName;
60 	PVOID DeferredRoutine;
61 	PVOID ExclusionRoutine;
62 	PVOID DispatchRoutine;
63 	PVOID DevCapsRoutine;
64 	PVOID HwSetVolume;
65 	ULONG IoMethod;
66 }SOUND_DEVICE_INIT;
67 
68 /* TYPES */
69 typedef NTSTATUS NTAPI (*PPROC_ENUM_ROUTINE)
70 (
71  IN PSYSTEM_PROCESSES CurrentProcess,
72  IN OUT PVOID CallbackContext
73 );
74 
75 typedef NTSTATUS NTAPI (*PTHREAD_ENUM_ROUTINE)
76 (
77  IN PSYSTEM_THREADS CurrentThread,
78  IN OUT PVOID CallbackContext
79 );
80 
81 typedef NTSTATUS NTAPI (*PSYSMOD_ENUM_ROUTINE)
82 (
83  IN PSYSTEM_MODULE_INFORMATION_ENTRY CurrentModule,
84  IN OUT PVOID CallbackContext
85 );
86 
87 typedef NTSTATUS NTAPI (*PPROCMOD_ENUM_ROUTINE)
88 (
89  IN HANDLE ProcessHandle,
90  IN PLDR_DATA_TABLE_ENTRY CurrentModule,
91  IN OUT PVOID CallbackContext
92 );
93 
94 /* CONSTANTS */
95 #define FAILED_WITH_STATUS DEFINE_DBG_MSG("%s() failed, status 0x%08X")
96 
97 /* PROTOTYPES */
98 /* Processes and threads */
99 /* enumeration */
100 NTSTATUS
101 NTAPI
102 PsaEnumerateProcessesAndThreads
103 (
104  IN PPROC_ENUM_ROUTINE ProcessCallback,
105  IN OUT PVOID ProcessCallbackContext,
106  IN PTHREAD_ENUM_ROUTINE ThreadCallback,
107  IN OUT PVOID ThreadCallbackContext
108 );
109 
110 NTSTATUS
111 NTAPI
112 PsaEnumerateProcesses
113 (
114  IN PPROC_ENUM_ROUTINE Callback,
115  IN OUT PVOID CallbackContext
116 );
117 
118 NTSTATUS
119 NTAPI
120 PsaEnumerateThreads
121 (
122  IN PTHREAD_ENUM_ROUTINE Callback,
123  IN OUT PVOID CallbackContext
124 );
125 
126 /* capturing & walking */
127 NTSTATUS
128 NTAPI
129 PsaCaptureProcessesAndThreads
130 (
131  OUT PSYSTEM_PROCESSES * ProcessesAndThreads
132 );
133 
134 NTSTATUS
135 NTAPI
136 PsaWalkProcessesAndThreads
137 (
138  IN PSYSTEM_PROCESSES ProcessesAndThreads,
139  IN PPROC_ENUM_ROUTINE ProcessCallback,
140  IN OUT PVOID ProcessCallbackContext,
141  IN PTHREAD_ENUM_ROUTINE ThreadCallback,
142  IN OUT PVOID ThreadCallbackContext
143 );
144 
145 NTSTATUS
146 NTAPI
147 PsaWalkProcesses
148 (
149  IN PSYSTEM_PROCESSES ProcessesAndThreads,
150  IN PPROC_ENUM_ROUTINE Callback,
151  IN OUT PVOID CallbackContext
152 );
153 
154 NTSTATUS
155 NTAPI
156 PsaWalkThreads
157 (
158  IN PSYSTEM_PROCESSES ProcessesAndThreads,
159  IN PTHREAD_ENUM_ROUTINE Callback,
160  IN OUT PVOID CallbackContext
161 );
162 
163 PSYSTEM_PROCESSES
164 FASTCALL
165 PsaWalkFirstProcess
166 (
167  IN PSYSTEM_PROCESSES ProcessesAndThreads
168 );
169 
170 PSYSTEM_PROCESSES
171 FASTCALL
172 PsaWalkNextProcess
173 (
174  IN PSYSTEM_PROCESSES CurrentProcess
175 );
176 
177 PSYSTEM_THREADS
178 FASTCALL
179 PsaWalkFirstThread
180 (
181  IN PSYSTEM_PROCESSES CurrentProcess
182 );
183 
184 PSYSTEM_THREADS
185 FASTCALL
186 PsaWalkNextThread
187 (
188  IN PSYSTEM_THREADS CurrentThread
189 );
190 
191 /* System modules */
192 /* enumeration */
193 NTSTATUS
194 NTAPI
195 PsaEnumerateSystemModules
196 (
197  IN PSYSMOD_ENUM_ROUTINE Callback,
198  IN OUT PVOID CallbackContext
199 );
200 
201 /* capturing & walking */
202 NTSTATUS
203 NTAPI
204 PsaCaptureSystemModules
205 (
206  OUT PSYSTEM_MODULE_INFORMATION * SystemModules
207 );
208 
209 NTSTATUS
210 NTAPI
211 PsaWalkSystemModules
212 (
213  IN PSYSTEM_MODULE_INFORMATION SystemModules,
214  IN PSYSMOD_ENUM_ROUTINE Callback,
215  IN OUT PVOID CallbackContext
216 );
217 
218 PSYSTEM_MODULE_INFORMATION_ENTRY
219 FASTCALL
220 PsaWalkFirstSystemModule
221 (
222  IN PSYSTEM_MODULE_INFORMATION SystemModules
223 );
224 
225 PSYSTEM_MODULE_INFORMATION_ENTRY
226 FASTCALL
227 PsaWalkNextSystemModule
228 (
229  IN PSYSTEM_MODULE_INFORMATION CurrentSystemModule
230 );
231 
232 /* Process modules */
233 NTSTATUS
234 NTAPI
235 PsaEnumerateProcessModules
236 (
237  IN HANDLE ProcessHandle,
238  IN PPROCMOD_ENUM_ROUTINE Callback,
239  IN OUT PVOID CallbackContext
240 );
241 
242 /* Miscellaneous */
243 VOID
244 NTAPI
245 PsaFreeCapture
246 (
247  IN PVOID Capture
248 );
249 
250 /* The user must define these functions. They are called by PSAPI to allocate
251    memory. This allows PSAPI to be called from any environment */
252 void *PsaiMalloc(SIZE_T size);
253 void *PsaiRealloc(void *ptr, SIZE_T size);
254 void PsaiFree(void *ptr);
255 
256 /* MACROS */
257 #define DEFINE_DBG_MSG(__str__) "PSAPI: " __str__ "\n"
258 
259 #endif /* __INTERNAL_PSAPI_H_INCLUDED__ */
260 
261 /* EOF */
262