ReactOS 0.4.16-dev-2613-g9533ad7
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 differently from the others */
61 {
62 if (ExpectedStatus == STATUS_INFO_LENGTH_MISMATCH)
63 SpecialStatus = STATUS_ACCESS_VIOLATION;
64 else
65 SpecialStatus = STATUS_INVALID_INFO_CLASS;
66 break;
67 }
68
69 /* These classes don't belong in the query group */
74 case ProcessLdtSize:
78 {
79 SpecialStatus = STATUS_INVALID_INFO_CLASS;
80 break;
81 }
82
84 {
85 if (ExpectedStatus != STATUS_DATATYPE_MISALIGNMENT)
86 SpecialStatus = STATUS_INVALID_INFO_CLASS;
87 break;
88 }
89
90 /* These classes don't exist in Server 2003 */
92 {
93 /* Need to fix up the length */
94 if (InfoLength == sizeof(UNICODE_STRING))
95 InfoLength += MAX_PATH * sizeof(WCHAR);
96 /* Fall through */
97 }
100 case ProcessCycleTime:
108 {
110 SpecialStatus = STATUS_INVALID_INFO_CLASS;
111 break;
112 }
113
114#ifndef _M_IX86
116 {
117 SpecialStatus = STATUS_NOT_IMPLEMENTED;
118 break;
119 }
120#endif
121 }
122
123 /* Query the information */
125 InfoClassIndex,
126 InfoPointer,
127 InfoLength,
128 NULL);
129
130 /* And probe the results we've got */
131 ok(Status == ExpectedStatus || Status == SpecialStatus,
132 "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);
133 break;
134 }
135
136 case SET:
137 {
138 switch (InfoClassIndex)
139 {
141 {
142#ifndef _M_IX86
143 SpecialStatus = STATUS_NOT_IMPLEMENTED;
144#else
145 SpecialStatus = STATUS_INVALID_PARAMETER;
146#endif
147 break;
148 }
149
150 /*
151 * This class returns STATUS_SUCCESS when testing
152 * for STATUS_ACCESS_VIOLATION (setting an invalid address).
153 */
155 {
156 if (ExpectedStatus == STATUS_ACCESS_VIOLATION)
157 ExpectedStatus = STATUS_SUCCESS;
158 SpecialStatus = STATUS_PORT_ALREADY_SET;
159 break;
160 }
161
162 /* This one works differently from the others */
164 {
165 if (ExpectedStatus == STATUS_INFO_LENGTH_MISMATCH)
166 SpecialStatus = STATUS_ACCESS_VIOLATION;
167 else
168 SpecialStatus = STATUS_PRIVILEGE_NOT_HELD;
169 break;
170 }
171
172 /* These classes don't belong in the set group */
176 case ProcessTimes:
177 case ProcessDebugPort:
184 case ProcessCookie:
186 {
187 SpecialStatus = STATUS_INVALID_INFO_CLASS;
188 break;
189 }
190
191 /* These classes don't exist in Server 2003 */
194 case ProcessCycleTime:
203 {
204 SpecialStatus = STATUS_INVALID_INFO_CLASS;
205 break;
206 }
207
208 /* Alignment probing is not performed for these classes */
212 {
213 SpecialStatus = STATUS_ACCESS_VIOLATION;
214 break;
215 }
216
217#ifndef _M_IX86
219 case ProcessLdtSize:
220 {
221 SpecialStatus = STATUS_NOT_IMPLEMENTED;
222 break;
223 }
224#endif
225 }
226
227 /* Set the information */
229 InfoClassIndex,
230 InfoPointer,
231 InfoLength);
232
233 /* And probe the results we've got */
234 ok(Status == ExpectedStatus || Status == SpecialStatus,
235 "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);
236 break;
237 }
238
239 default:
240 break;
241 }
242}
243
244VOID
246 _In_ ALIGNMENT_PROBE_MODE ValidationMode,
247 _In_ ULONG InfoClassIndex,
248 _In_ PVOID InfoPointer,
249 _In_ ULONG InfoLength,
250 _In_ NTSTATUS ExpectedStatus)
251{
252 NTSTATUS Status, SpecialStatus = STATUS_SUCCESS;
253
254 /* Before doing anything, check if we want query or set validation */
255 switch (ValidationMode)
256 {
257 case QUERY:
258 {
259 switch (InfoClassIndex)
260 {
261 /* These classes don't belong in the query group */
262 case ThreadPriority:
271 {
272 SpecialStatus = STATUS_INVALID_INFO_CLASS;
273 break;
274 }
275
276 /* This class supports queries only on Vista and above */
278 {
280 SpecialStatus = STATUS_INVALID_INFO_CLASS;
281 break;
282 }
283
284 /* These classes don't exist in Server 2003 SP2 */
287 case ThreadIoPriority:
288 case ThreadCycleTime:
292 case ThreadCSwitchMon:
293 {
294 SpecialStatus = STATUS_INVALID_INFO_CLASS;
295 break;
296 }
297
298 /* ThreadNameInformation is Windows 10+, but
299 * ReactOS supports this class, so don't exclude it */
301 {
302#ifndef __REACTOS__
304 SpecialStatus = STATUS_INVALID_INFO_CLASS;
305#else
306 /* This one works differently from the others */
307 if (ExpectedStatus == STATUS_INFO_LENGTH_MISMATCH)
308 ExpectedStatus = STATUS_BUFFER_TOO_SMALL;
309#endif
310 break;
311 }
312
313 default:
314 {
315 /* All of these classes only exist on Windows 7 and above */
316 if ( ((InfoClassIndex >= ThreadCSwitchPmu) &&
318 ((InfoClassIndex >= ThreadCpuAccountingInformation) &&
320 ((InfoClassIndex >= ThreadSuspendCount) &&
322 ((InfoClassIndex >= ThreadHeterogeneousCpuPolicy) &&
324 {
325 SpecialStatus = STATUS_INVALID_INFO_CLASS;
326 }
327 }
328 }
329
330 /* Query the information */
332 InfoClassIndex,
333 InfoPointer,
334 InfoLength,
335 NULL);
336
337 /* And probe the results we've got */
338 ok(Status == ExpectedStatus || Status == SpecialStatus || Status == STATUS_DATATYPE_MISALIGNMENT,
339 "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);
340 break;
341 }
342
343 case SET:
344 {
345 switch (InfoClassIndex)
346 {
347 /* This class is not implemented in Windows Server 2003 SP2 */
349 {
350 SpecialStatus = STATUS_NOT_IMPLEMENTED;
351 break;
352 }
353
354 /*
355 * This class doesn't take a strict type for size length.
356 * The function happily succeeds on an information length
357 * mismatch scenario with STATUS_SUCCESS.
358 */
360 {
361 SpecialStatus = STATUS_INFO_LENGTH_MISMATCH;
362 break;
363 }
364
365 /* These classes don't belong in the set group */
367 case ThreadTimes:
373 {
374 SpecialStatus = STATUS_INVALID_INFO_CLASS;
375 break;
376 }
377
378 /* These classes don't exist in Server 2003 SP2 */
381 case ThreadIoPriority:
382 case ThreadCycleTime:
386 case ThreadCSwitchMon:
387 {
388 SpecialStatus = STATUS_INVALID_INFO_CLASS;
389 break;
390 }
391
392 /* Alignment probing is not performed for this class */
394 {
395 SpecialStatus = STATUS_ACCESS_VIOLATION;
396 break;
397 }
398
399 /* ThreadNameInformation is Windows 10+, but
400 * ReactOS supports this class, so don't exclude it */
402 {
403#ifndef __REACTOS__
405 SpecialStatus = STATUS_INVALID_INFO_CLASS;
406#endif
407 break;
408 }
409
410 default:
411 {
412 /* All of these classes only exist on Windows 7 and above */
413 if ( ((InfoClassIndex >= ThreadCSwitchPmu) &&
415 ((InfoClassIndex >= ThreadCpuAccountingInformation) &&
417 ((InfoClassIndex >= ThreadSuspendCount) &&
419 ((InfoClassIndex >= ThreadHeterogeneousCpuPolicy) &&
421 {
422 SpecialStatus = STATUS_INVALID_INFO_CLASS;
423 }
424 }
425 }
426
427 /* Set the information */
429 InfoClassIndex,
430 InfoPointer,
431 InfoLength);
432
433 /* And probe the results we've got */
434 ok(Status == ExpectedStatus || Status == SpecialStatus || Status == STATUS_DATATYPE_MISALIGNMENT || Status == STATUS_SUCCESS,
435 "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);
436 }
437
438 default:
439 break;
440 }
441}
#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
@ ThreadCSwitchPmu
Definition: compat.h:963
@ 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
@ 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:2985
NTSTATUS NTAPI NtSetInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _In_reads_bytes_(ProcessInformationLength) PVOID ProcessInformation, _In_ ULONG ProcessInformationLength)
Definition: query.c:1390
NTSTATUS NTAPI NtSetInformationThread(_In_ HANDLE ThreadHandle, _In_ THREADINFOCLASS ThreadInformationClass, _In_reads_bytes_(ThreadInformationLength) PVOID ThreadInformation, _In_ ULONG ThreadInformationLength)
Definition: query.c:2269
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
short WCHAR
Definition: pedump.c:58
VOID QuerySetThreadValidator(_In_ ALIGNMENT_PROBE_MODE ValidationMode, _In_ ULONG InfoClassIndex, _In_ PVOID InfoPointer, _In_ ULONG InfoLength, _In_ NTSTATUS ExpectedStatus)
Definition: probelib.c:245
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_WIN10
Definition: sdkddkver.h:32
#define _WIN32_WINNT_WINBLUE
Definition: sdkddkver.h:30
#define _WIN32_WINNT_WIN8
Definition: sdkddkver.h:29
#define _WIN32_WINNT_WIN7
Definition: sdkddkver.h:28
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
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
@ ThreadSuspendCount
Definition: winternl.h:2316
@ ThreadCpuAccountingInformation
Definition: winternl.h:2315
@ ThreadHeterogeneousCpuPolicy
Definition: winternl.h:2317
@ ThreadNameInformation
Definition: winternl.h:2319
@ 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