ReactOS 0.4.15-dev-5667-ged97270
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 /* Before doing anything, check if we want query or set validation */
22 switch (ValidationMode)
23 {
24 case QUERY:
25 {
26 switch (InfoClassIndex)
27 {
29 {
30 SpecialStatus = STATUS_UNSUCCESSFUL;
31 break;
32 }
33
35 {
36 SpecialStatus = STATUS_INVALID_PARAMETER;
37 break;
38 }
39
40 /*
41 * This class returns an arbitrary size pointed by InformationLength
42 * which equates to the image filename of the process. Such status
43 * is returned in an invalid address query (STATUS_ACCESS_VIOLATION)
44 * where the function expects STATUS_INFO_LENGTH_MISMATCH instead.
45 */
47 {
48 SpecialStatus = STATUS_INFO_LENGTH_MISMATCH;
49 break;
50 }
51
52 /* This one works different from the others */
54 {
55 if (ExpectedStatus == STATUS_INFO_LENGTH_MISMATCH)
56 {
57 SpecialStatus = STATUS_ACCESS_VIOLATION;
58 }
59 else
60 {
61 SpecialStatus = STATUS_INVALID_INFO_CLASS;
62 }
63 break;
64 }
65
66 /* These classes don't belong in the query group */
71 case ProcessLdtSize:
76 {
77 SpecialStatus = STATUS_INVALID_INFO_CLASS;
78 break;
79 }
80
81 /* These classes don't exist in Server 2003 */
93 {
94 SpecialStatus = STATUS_INVALID_INFO_CLASS;
95 break;
96 }
97 }
98
99 /* Query the information */
101 InfoClassIndex,
102 InfoPointer,
103 InfoLength,
104 NULL);
105
106 /* And probe the results we've got */
107 ok(Status == ExpectedStatus || Status == SpecialStatus || Status == STATUS_DATATYPE_MISALIGNMENT,
108 "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);
109 break;
110 }
111
112 case SET:
113 {
114 switch (InfoClassIndex)
115 {
117 {
118 SpecialStatus = STATUS_INVALID_PARAMETER;
119 break;
120 }
121
122 /*
123 * This class returns STATUS_SUCCESS when testing
124 * for STATUS_ACCESS_VIOLATION (setting an invalid address).
125 */
127 {
128 SpecialStatus = STATUS_PORT_ALREADY_SET;
129 break;
130 }
131
132 /* This one works different from the others */
134 {
135 if (ExpectedStatus == STATUS_INFO_LENGTH_MISMATCH)
136 {
137 SpecialStatus = STATUS_ACCESS_VIOLATION;
138 }
139 else
140 {
141 SpecialStatus = STATUS_PRIVILEGE_NOT_HELD;
142 }
143 break;
144 }
145
146 /* These classes don't belong in the set group */
150 case ProcessTimes:
151 case ProcessDebugPort:
158 case ProcessCookie:
160 {
161 SpecialStatus = STATUS_INVALID_INFO_CLASS;
162 break;
163 }
164
165 /* These classes don't exist in Server 2003 */
168 case ProcessCycleTime:
177 {
178 SpecialStatus = STATUS_INVALID_INFO_CLASS;
179 break;
180 }
181
182 /* Alignment probing is not performed for these classes */
186 {
187 SpecialStatus = STATUS_ACCESS_VIOLATION;
188 break;
189 }
190 }
191
192 /* Set the information */
194 InfoClassIndex,
195 InfoPointer,
196 InfoLength);
197
198 /* And probe the results we've got */
199 ok(Status == ExpectedStatus || Status == SpecialStatus || Status == STATUS_DATATYPE_MISALIGNMENT || Status == STATUS_SUCCESS,
200 "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);
201 break;
202 }
203
204 default:
205 break;
206 }
207}
208
209VOID
211 _In_ ALIGNMENT_PROBE_MODE ValidationMode,
212 _In_ ULONG InfoClassIndex,
213 _In_ PVOID InfoPointer,
214 _In_ ULONG InfoLength,
215 _In_ NTSTATUS ExpectedStatus)
216{
217 NTSTATUS Status, SpecialStatus = STATUS_SUCCESS;
218
219 /* Before doing anything, check if we want query or set validation */
220 switch (ValidationMode)
221 {
222 case QUERY:
223 {
224 switch (InfoClassIndex)
225 {
226 /* These classes don't belong in the query group */
227 case ThreadPriority:
237 {
238 SpecialStatus = STATUS_INVALID_INFO_CLASS;
239 break;
240 }
241
242 /* These classes don't exist in Server 2003 SP2 */
245 case ThreadIoPriority:
246 case ThreadCycleTime:
250 case ThreadCSwitchMon:
251 {
252 SpecialStatus = STATUS_INVALID_INFO_CLASS;
253 break;
254 }
255 }
256
257 /* Query the information */
259 InfoClassIndex,
260 InfoPointer,
261 InfoLength,
262 NULL);
263
264 /* And probe the results we've got */
265 ok(Status == ExpectedStatus || Status == SpecialStatus || Status == STATUS_DATATYPE_MISALIGNMENT,
266 "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);
267 break;
268 }
269
270 case SET:
271 {
272 switch (InfoClassIndex)
273 {
274 /* This class is not implemented in Windows Server 2003 SP2 */
276 {
277 SpecialStatus = STATUS_NOT_IMPLEMENTED;
278 break;
279 }
280
281 /*
282 * This class doesn't take a strict type for size length.
283 * The function happily succeds on an information length
284 * mismatch scenario with STATUS_SUCCESS.
285 */
287 {
288 SpecialStatus = STATUS_INFO_LENGTH_MISMATCH;
289 break;
290 }
291
292 /* These classes don't belong in the set group */
294 case ThreadTimes:
300 {
301 SpecialStatus = STATUS_INVALID_INFO_CLASS;
302 break;
303 }
304
305 /* These classes don't exist in Server 2003 SP2 */
308 case ThreadIoPriority:
309 case ThreadCycleTime:
313 case ThreadCSwitchMon:
314 {
315 SpecialStatus = STATUS_INVALID_INFO_CLASS;
316 break;
317 }
318
319 /* Alignment probing is not performed for this class */
321 {
322 SpecialStatus = STATUS_ACCESS_VIOLATION;
323 break;
324 }
325 }
326
327 /* Set the information */
329 InfoClassIndex,
330 InfoPointer,
331 InfoLength);
332
333 /* And probe the results we've got */
334 ok(Status == ExpectedStatus || Status == SpecialStatus || Status == STATUS_DATATYPE_MISALIGNMENT || Status == STATUS_SUCCESS,
335 "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);
336 }
337
338 default:
339 break;
340 }
341}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define ok(value,...)
Definition: atltest.h:57
LONG NTSTATUS
Definition: precomp.h:26
#define SET(field, seg, reg)
#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
Status
Definition: gdiplustypes.h:25
@ ProcessDebugPort
Definition: winternl.h:395
@ ProcessBasicInformation
Definition: winternl.h:394
@ ProcessWow64Information
Definition: winternl.h:396
@ ProcessImageFileName
Definition: winternl.h:397
@ ProcessPagePriority
Definition: winternl.h:894
@ ProcessLUIDDeviceMapsEnabled
Definition: winternl.h:884
@ ProcessMemoryAllocationMode
Definition: winternl.h:901
@ ProcessTlsInformation
Definition: winternl.h:890
@ ProcessWorkingSetWatchEx
Definition: winternl.h:897
@ ProcessAffinityMask
Definition: winternl.h:877
@ ProcessInstrumentationCallback
Definition: winternl.h:895
@ ProcessImageFileMapping
Definition: winternl.h:899
@ ProcessIoPortHandlers
Definition: winternl.h:869
@ ProcessRaisePriority
Definition: winternl.h:862
@ ProcessVmCounters
Definition: winternl.h:859
@ ProcessPriorityClass
Definition: winternl.h:874
@ ProcessImageInformation
Definition: winternl.h:892
@ ProcessCookie
Definition: winternl.h:891
@ ProcessPooledUsageAndLimits
Definition: winternl.h:870
@ ProcessLdtSize
Definition: winternl.h:867
@ ProcessIoCounters
Definition: winternl.h:858
@ ProcessImageFileNameWin32
Definition: winternl.h:898
@ ProcessAffinityUpdateMode
Definition: winternl.h:900
@ ProcessEnableAlignmentFaultFixup
Definition: winternl.h:873
@ ProcessBasePriority
Definition: winternl.h:861
@ ProcessCycleTime
Definition: winternl.h:893
@ ProcessAccessToken
Definition: winternl.h:865
@ ProcessHandleTracing
Definition: winternl.h:888
@ ProcessThreadStackAllocation
Definition: winternl.h:896
@ ProcessForegroundInformation
Definition: winternl.h:881
@ ProcessTimes
Definition: winternl.h:860
@ ProcessDebugObjectHandle
Definition: winternl.h:886
@ ProcessExceptionPort
Definition: winternl.h:864
@ ProcessWorkingSetWatch
Definition: winternl.h:871
@ ProcessHandleCount
Definition: winternl.h:876
@ ProcessUserModeIOPL
Definition: winternl.h:872
@ ProcessIoPriority
Definition: pstypes.h:266
@ QUERY
Definition: precomp.h:18
enum _ALIGNMENT_PROBE_MODE ALIGNMENT_PROBE_MODE
#define _In_
Definition: ms_sal.h:308
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtQueryInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, OUT PVOID ThreadInformation, IN ULONG ThreadInformationLength, OUT PULONG ReturnLength OPTIONAL)
Definition: query.c:2624
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1105
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
Definition: query.c:2018
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:183
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:240
#define STATUS_PORT_ALREADY_SET
Definition: ntstatus.h:308
VOID QuerySetThreadValidator(_In_ ALIGNMENT_PROBE_MODE ValidationMode, _In_ ULONG InfoClassIndex, _In_ PVOID InfoPointer, _In_ ULONG InfoLength, _In_ NTSTATUS ExpectedStatus)
Definition: probelib.c:210
VOID QuerySetProcessValidator(_In_ ALIGNMENT_PROBE_MODE ValidationMode, _In_ ULONG InfoClassIndex, _In_ PVOID InfoPointer, _In_ ULONG InfoLength, _In_ NTSTATUS ExpectedStatus)
Definition: probelib.c:12
#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
#define NtCurrentThread()