ReactOS 0.4.16-dev-2284-g3529151
probelib.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Small library with probing utilities for thread/process classes information
5 * COPYRIGHT: Copyright 2020 George Bișoc <george.bisoc@reactos.org>
6 */
7
8#include "precomp.h"
9#include <internal/ps_i.h>
10
11VOID
13 _In_ ALIGNMENT_PROBE_MODE ValidationMode,
14 _In_ ULONG InfoClassIndex,
15 _In_ PVOID InfoPointer,
16 _In_ ULONG InfoLength,
17 _In_ NTSTATUS ExpectedStatus)
18{
19 NTSTATUS Status, SpecialStatus = STATUS_SUCCESS;
20
21 if ((PsProcessInfoClass[InfoClassIndex].RequiredSizeQUERY == 0) &&
22 (PsProcessInfoClass[InfoClassIndex].RequiredSizeSET == 0))
23 {
24 skip("FIXME: Skipping test for InfoClass %lu, because PsProcessInfoClass[] doesn't have it.\n", InfoClassIndex);
25 return;
26 }
27
28 /* Before doing anything, check if we want query or set validation */
29 switch (ValidationMode)
30 {
31 case QUERY:
32 {
33 switch (InfoClassIndex)
34 {
36 {
37 SpecialStatus = STATUS_UNSUCCESSFUL;
38 break;
39 }
40
42 {
43 SpecialStatus = STATUS_INVALID_PARAMETER;
44 break;
45 }
46
47 /*
48 * This class returns an arbitrary size pointed by InformationLength
49 * which equates to the image filename of the process. Such status
50 * is returned in an invalid address query (STATUS_ACCESS_VIOLATION)
51 * where the function expects STATUS_INFO_LENGTH_MISMATCH instead.
52 */
54 {
55 SpecialStatus = STATUS_INFO_LENGTH_MISMATCH;
56 break;
57 }
58
59 /* This one works different from the others */
61 {
62 if (ExpectedStatus == STATUS_INFO_LENGTH_MISMATCH)
63 {
64 SpecialStatus = STATUS_ACCESS_VIOLATION;
65 }
66 else
67 {
68 SpecialStatus = STATUS_INVALID_INFO_CLASS;
69 }
70 break;
71 }
72
73 /* These classes don't belong in the query group */
78 case ProcessLdtSize:
82 {
83 SpecialStatus = STATUS_INVALID_INFO_CLASS;
84 break;
85 }
86
88 {
89 if (ExpectedStatus != STATUS_DATATYPE_MISALIGNMENT)
90 {
91 SpecialStatus = STATUS_INVALID_INFO_CLASS;
92 }
93 break;
94 }
95
96 /* These classes don't exist in Server 2003 */
98 {
99 /* Need to fix up the length */
100 if (InfoLength == sizeof(UNICODE_STRING))
101 {
102 InfoLength += MAX_PATH * sizeof(WCHAR);
103 }
104 /* Fall through */
105 }
108 case ProcessCycleTime:
116 {
118 {
119 SpecialStatus = STATUS_INVALID_INFO_CLASS;
120 }
121 break;
122 }
123
124#ifndef _M_IX86
126 {
127 SpecialStatus = STATUS_NOT_IMPLEMENTED;
128 break;
129 }
130#endif
131 }
132
133 /* Query the information */
135 InfoClassIndex,
136 InfoPointer,
137 InfoLength,
138 NULL);
139
140 /* And probe the results we've got */
141 ok(Status == ExpectedStatus || Status == SpecialStatus,
142 "0x%lx or special status (0x%lx) expected but got 0x%lx for class information %lu in query information process operation!\n", ExpectedStatus, SpecialStatus, Status, InfoClassIndex);
143 break;
144 }
145
146 case SET:
147 {
148 switch (InfoClassIndex)
149 {
151 {
152#ifndef _M_IX86
153 SpecialStatus = STATUS_NOT_IMPLEMENTED;
154#else
155 SpecialStatus = STATUS_INVALID_PARAMETER;
156#endif
157 break;
158 }
159
160 /*
161 * This class returns STATUS_SUCCESS when testing
162 * for STATUS_ACCESS_VIOLATION (setting an invalid address).
163 */
165 {
166 if (ExpectedStatus == STATUS_ACCESS_VIOLATION)
167 ExpectedStatus = STATUS_SUCCESS;
168 SpecialStatus = STATUS_PORT_ALREADY_SET;
169 break;
170 }
171
172 /* This one works different from the others */
174 {
175 if (ExpectedStatus == STATUS_INFO_LENGTH_MISMATCH)
176 {
177 SpecialStatus = STATUS_ACCESS_VIOLATION;
178 }
179 else
180 {
181 SpecialStatus = STATUS_PRIVILEGE_NOT_HELD;
182 }
183 break;
184 }
185
186 /* These classes don't belong in the set group */
190 case ProcessTimes:
191 case ProcessDebugPort:
198 case ProcessCookie:
200 {
201 SpecialStatus = STATUS_INVALID_INFO_CLASS;
202 break;
203 }
204
205 /* These classes don't exist in Server 2003 */
208 case ProcessCycleTime:
217 {
218 SpecialStatus = STATUS_INVALID_INFO_CLASS;
219 break;
220 }
221
222 /* Alignment probing is not performed for these classes */
226 {
227 SpecialStatus = STATUS_ACCESS_VIOLATION;
228 break;
229 }
230
231#ifndef _M_IX86
233 case ProcessLdtSize:
234 {
235 SpecialStatus = STATUS_NOT_IMPLEMENTED;
236 break;
237 }
238#endif
239 }
240
241 /* Set the information */
243 InfoClassIndex,
244 InfoPointer,
245 InfoLength);
246
247 /* And probe the results we've got */
248 ok(Status == ExpectedStatus || Status == SpecialStatus,
249 "0x%lx or special status (0x%lx) expected but got 0x%lx for class information %lu in set information process operation!\n", ExpectedStatus, SpecialStatus, Status, InfoClassIndex);
250 break;
251 }
252
253 default:
254 break;
255 }
256}
257
258VOID
260 _In_ ALIGNMENT_PROBE_MODE ValidationMode,
261 _In_ ULONG InfoClassIndex,
262 _In_ PVOID InfoPointer,
263 _In_ ULONG InfoLength,
264 _In_ NTSTATUS ExpectedStatus)
265{
266 NTSTATUS Status, SpecialStatus = STATUS_SUCCESS;
267
268 /* Before doing anything, check if we want query or set validation */
269 switch (ValidationMode)
270 {
271 case QUERY:
272 {
273 switch (InfoClassIndex)
274 {
275 /* These classes don't belong in the query group */
276 case ThreadPriority:
286 {
287 SpecialStatus = STATUS_INVALID_INFO_CLASS;
288 break;
289 }
290
291 /* These classes don't exist in Server 2003 SP2 */
294 case ThreadIoPriority:
295 case ThreadCycleTime:
299 case ThreadCSwitchMon:
300 {
301 SpecialStatus = STATUS_INVALID_INFO_CLASS;
302 break;
303 }
304 }
305
306 /* Query the information */
308 InfoClassIndex,
309 InfoPointer,
310 InfoLength,
311 NULL);
312
313 /* And probe the results we've got */
314 ok(Status == ExpectedStatus || Status == SpecialStatus || Status == STATUS_DATATYPE_MISALIGNMENT,
315 "0x%lx or special status (0x%lx) expected but got 0x%lx for class information %lu in query information thread operation!\n", ExpectedStatus, SpecialStatus, Status, InfoClassIndex);
316 break;
317 }
318
319 case SET:
320 {
321 switch (InfoClassIndex)
322 {
323 /* This class is not implemented in Windows Server 2003 SP2 */
325 {
326 SpecialStatus = STATUS_NOT_IMPLEMENTED;
327 break;
328 }
329
330 /*
331 * This class doesn't take a strict type for size length.
332 * The function happily succeds on an information length
333 * mismatch scenario with STATUS_SUCCESS.
334 */
336 {
337 SpecialStatus = STATUS_INFO_LENGTH_MISMATCH;
338 break;
339 }
340
341 /* These classes don't belong in the set group */
343 case ThreadTimes:
349 {
350 SpecialStatus = STATUS_INVALID_INFO_CLASS;
351 break;
352 }
353
354 /* These classes don't exist in Server 2003 SP2 */
357 case ThreadIoPriority:
358 case ThreadCycleTime:
362 case ThreadCSwitchMon:
363 {
364 SpecialStatus = STATUS_INVALID_INFO_CLASS;
365 break;
366 }
367
368 /* Alignment probing is not performed for this class */
370 {
371 SpecialStatus = STATUS_ACCESS_VIOLATION;
372 break;
373 }
374 }
375
376 /* Set the information */
378 InfoClassIndex,
379 InfoPointer,
380 InfoLength);
381
382 /* And probe the results we've got */
383 ok(Status == ExpectedStatus || Status == SpecialStatus || Status == STATUS_DATATYPE_MISALIGNMENT || Status == STATUS_SUCCESS,
384 "0x%lx or special status (0x%lx) expected but got 0x%lx for class information %lu in set information thread operation!\n", ExpectedStatus, SpecialStatus, Status, InfoClassIndex);
385 }
386
387 default:
388 break;
389 }
390}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define GetNTVersion()
Definition: apitest.h:17
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
LONG NTSTATUS
Definition: precomp.h:26
@ ProcessDebugPort
Definition: cicbase.cpp:64
@ ProcessBasicInformation
Definition: cicbase.cpp:63
@ ProcessWow64Information
Definition: cicbase.cpp:65
@ ProcessImageFileName
Definition: cicbase.cpp:66
#define SET(field, seg, reg)
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define NULL
Definition: types.h:112
@ ThreadEnableAlignmentFaultFixup
Definition: compat.h:942
@ ThreadDescriptorTableEntry
Definition: compat.h:941
@ ThreadEventPair_Reusable
Definition: compat.h:943
@ ThreadAmILastThread
Definition: compat.h:947
@ ThreadTimes
Definition: compat.h:936
@ ThreadPagePriority
Definition: compat.h:959
@ ThreadCSwitchMon
Definition: compat.h:962
@ ThreadPriority
Definition: compat.h:937
@ ThreadIdealProcessor
Definition: compat.h:948
@ ThreadActualBasePriority
Definition: compat.h:960
@ ThreadSwitchLegacyState
Definition: compat.h:954
@ ThreadIsTerminated
Definition: compat.h:955
@ ThreadLastSystemCall
Definition: compat.h:956
@ ThreadImpersonationToken
Definition: compat.h:940
@ ThreadSetTlsArrayAddress
Definition: compat.h:950
@ ThreadAffinityMask
Definition: compat.h:939
@ ThreadBasePriority
Definition: compat.h:938
@ ThreadTebInformation
Definition: compat.h:961
@ ThreadIoPriority
Definition: compat.h:957
@ ThreadCycleTime
Definition: compat.h:958
@ ThreadBasicInformation
Definition: compat.h:935
@ ThreadPerformanceCount
Definition: compat.h:946
@ ThreadIsIoPending
Definition: compat.h:951
@ ThreadZeroTlsCell
Definition: compat.h:945
@ ThreadHideFromDebugger
Definition: compat.h:952
#define MAX_PATH
Definition: compat.h:34
#define STATUS_ACCESS_VIOLATION
Status
Definition: gdiplustypes.h:25
@ ProcessPagePriority
Definition: winternl.h:1921
@ ProcessLUIDDeviceMapsEnabled
Definition: winternl.h:1910
@ ProcessMemoryAllocationMode
Definition: winternl.h:1928
@ ProcessTlsInformation
Definition: winternl.h:1917
@ ProcessWorkingSetWatchEx
Definition: winternl.h:1924
@ ProcessAffinityMask
Definition: winternl.h:1903
@ ProcessInstrumentationCallback
Definition: winternl.h:1922
@ ProcessImageFileMapping
Definition: winternl.h:1926
@ ProcessIoPortHandlers
Definition: winternl.h:1895
@ ProcessRaisePriority
Definition: winternl.h:1888
@ ProcessVmCounters
Definition: winternl.h:1885
@ ProcessPriorityClass
Definition: winternl.h:1900
@ ProcessImageInformation
Definition: winternl.h:1919
@ ProcessCookie
Definition: winternl.h:1918
@ ProcessPooledUsageAndLimits
Definition: winternl.h:1896
@ ProcessLdtSize
Definition: winternl.h:1893
@ ProcessIoCounters
Definition: winternl.h:1884
@ ProcessImageFileNameWin32
Definition: winternl.h:1925
@ ProcessAffinityUpdateMode
Definition: winternl.h:1927
@ ProcessEnableAlignmentFaultFixup
Definition: winternl.h:1899
@ ProcessBasePriority
Definition: winternl.h:1887
@ ProcessCycleTime
Definition: winternl.h:1920
@ ProcessAccessToken
Definition: winternl.h:1891
@ ProcessIoPriority
Definition: winternl.h:1915
@ ProcessHandleTracing
Definition: winternl.h:1914
@ ProcessThreadStackAllocation
Definition: winternl.h:1923
@ ProcessForegroundInformation
Definition: winternl.h:1907
@ ProcessTimes
Definition: winternl.h:1886
@ ProcessDebugObjectHandle
Definition: winternl.h:1912
@ ProcessExceptionPort
Definition: winternl.h:1890
@ ProcessWorkingSetWatch
Definition: winternl.h:1897
@ ProcessLdtInformation
Definition: winternl.h:1892
@ ProcessHandleCount
Definition: winternl.h:1902
@ ProcessUserModeIOPL
Definition: winternl.h:1898
#define NtCurrentThread()
Definition: winternl.h:5368
@ QUERY
Definition: precomp.h:18
enum _ALIGNMENT_PROBE_MODE ALIGNMENT_PROBE_MODE
#define _In_
Definition: no_sal2.h:158
#define NtCurrentProcess()
Definition: nt_native.h:1660
NTSTATUS NTAPI NtQueryInformationThread(_In_ HANDLE ThreadHandle, _In_ THREADINFOCLASS ThreadInformationClass, _Out_writes_bytes_to_opt_(ThreadInformationLength, *ReturnLength) PVOID ThreadInformation, _In_ ULONG ThreadInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:2881
NTSTATUS NTAPI NtSetInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _In_reads_bytes_(ProcessInformationLength) PVOID ProcessInformation, _In_ ULONG ProcessInformationLength)
Definition: query.c:1389
NTSTATUS NTAPI NtSetInformationThread(_In_ HANDLE ThreadHandle, _In_ THREADINFOCLASS ThreadInformationClass, _In_reads_bytes_(ThreadInformationLength) PVOID ThreadInformation, _In_ ULONG ThreadInformationLength)
Definition: query.c:2268
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_writes_bytes_to_opt_(ProcessInformationLength, *ReturnLength) PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:211
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:263
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:333
#define STATUS_PORT_ALREADY_SET
Definition: ntstatus.h:402
VOID QuerySetThreadValidator(_In_ ALIGNMENT_PROBE_MODE ValidationMode, _In_ ULONG InfoClassIndex, _In_ PVOID InfoPointer, _In_ ULONG InfoLength, _In_ NTSTATUS ExpectedStatus)
Definition: probelib.c:259
VOID QuerySetProcessValidator(_In_ ALIGNMENT_PROBE_MODE ValidationMode, _In_ ULONG InfoClassIndex, _In_ PVOID InfoPointer, _In_ ULONG InfoLength, _In_ NTSTATUS ExpectedStatus)
Definition: probelib.c:12
static const INFORMATION_CLASS_INFO PsProcessInfoClass[]
Definition: ps_i.h:15
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
__wchar_t WCHAR
Definition: xmlstorage.h:180