2 * PROJECT: ReactOS API tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Tests for the NtSetInformationProcess API
5 * COPYRIGHT: Copyright 2020 George Bișoc <george.bisoc@reactos.org>
12 Test_ProcBasePriorityClass(void)
17 * Assign a priority of HIGH_PRIORITY (see pstypes.h).
18 * The function will fail with a status of STATUS_PRIVILEGE_NOT_HELD
19 * as the process who executed the caller doesn't have the requested
20 * privileges to perform the operation.
22 KPRIORITY BasePriority
= HIGH_PRIORITY
;
24 /* Everything is NULL */
25 Status
= NtSetInformationProcess(NULL
,
29 ok_hex(Status
, STATUS_INFO_LENGTH_MISMATCH
);
31 /* Set the base priority to an invalid process handle */
32 Status
= NtSetInformationProcess(NULL
,
36 ok_hex(Status
, STATUS_INVALID_HANDLE
);
38 /* Don't input anything to the caller but the length information is valid */
39 Status
= NtSetInformationProcess(NtCurrentProcess(),
43 ok_hex(Status
, STATUS_ACCESS_VIOLATION
);
45 /* Give the base priority input to the caller but length is invalid */
46 Status
= NtSetInformationProcess(NtCurrentProcess(),
50 ok_hex(Status
, STATUS_INFO_LENGTH_MISMATCH
);
52 /* The input buffer is misaligned and length information invalid */
53 Status
= NtSetInformationProcess(NtCurrentProcess(),
57 ok_hex(Status
, STATUS_INFO_LENGTH_MISMATCH
);
59 /* The input buffer is misaligned */
60 Status
= NtSetInformationProcess(NtCurrentProcess(),
64 ok_hex(Status
, STATUS_DATATYPE_MISALIGNMENT
);
66 /* The input buffer is misaligned (try with an alignment of 2) */
67 Status
= NtSetInformationProcess(NtCurrentProcess(),
71 ok_hex(Status
, STATUS_DATATYPE_MISALIGNMENT
);
73 /* Set the base priority but we have lack privileges to do so */
74 Status
= NtSetInformationProcess(NtCurrentProcess(),
78 ok_hex(Status
, STATUS_PRIVILEGE_NOT_HELD
);
81 * Assign a random priority value this time and
82 * set the base priority to the current process.
85 Status
= NtSetInformationProcess(NtCurrentProcess(),
89 ok_hex(Status
, STATUS_SUCCESS
);
94 Test_ProcRaisePriorityClass(void)
98 /* Raise the priority as much as possible */
99 ULONG RaisePriority
= MAXIMUM_PRIORITY
;
101 /* Everything is NULL */
102 Status
= NtSetInformationProcess(NULL
,
103 ProcessRaisePriority
,
106 ok_hex(Status
, STATUS_INFO_LENGTH_MISMATCH
);
108 /* A invalid handle to process is given */
109 Status
= NtSetInformationProcess(NULL
,
110 ProcessRaisePriority
,
113 ok_hex(Status
, STATUS_INVALID_HANDLE
);
115 /* The input buffer is misaligned and length information invalid */
116 Status
= NtSetInformationProcess(NtCurrentProcess(),
117 ProcessRaisePriority
,
120 ok_hex(Status
, STATUS_INFO_LENGTH_MISMATCH
);
122 /* A NULL buffer has been accessed */
123 Status
= NtSetInformationProcess(NtCurrentProcess(),
124 ProcessRaisePriority
,
127 ok_hex(Status
, STATUS_ACCESS_VIOLATION
);
129 /* The input buffer is misaligned */
130 Status
= NtSetInformationProcess(NtCurrentProcess(),
131 ProcessRaisePriority
,
134 ok_hex(Status
, STATUS_DATATYPE_MISALIGNMENT
);
136 /* The input buffer is misaligned -- try with an alignment size of 2 */
137 Status
= NtSetInformationProcess(NtCurrentProcess(),
138 ProcessRaisePriority
,
141 ok_hex(Status
, STATUS_DATATYPE_MISALIGNMENT
);
143 /* Raise the priority of the given current process */
144 Status
= NtSetInformationProcess(NtCurrentProcess(),
145 ProcessRaisePriority
,
148 ok_hex(Status
, STATUS_SUCCESS
);
153 Test_ProcForegroundBackgroundClass(void)
156 PPROCESS_FOREGROUND_BACKGROUND ProcForeground
;
158 ProcForeground
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(PROCESS_FOREGROUND_BACKGROUND
));
159 if (ProcForeground
== NULL
)
161 skip("Failed to allocate memory block from heap for PROCESS_FOREGROUND_BACKGROUND!\n");
165 /* As a test, set the foreground of the retrieved current process to FALSE */
166 ProcForeground
->Foreground
= FALSE
;
168 /* Set everything NULL for the caller */
169 Status
= NtSetInformationProcess(NULL
,
170 ProcessForegroundInformation
,
173 ok_hex(Status
, STATUS_INFO_LENGTH_MISMATCH
);
175 /* Give an invalid process handle (but the input buffer and length are correct) */
176 Status
= NtSetInformationProcess(NULL
,
177 ProcessForegroundInformation
,
179 sizeof(PROCESS_FOREGROUND_BACKGROUND
));
180 ok_hex(Status
, STATUS_INVALID_HANDLE
);
182 /* Give a buffer data to the argument input as NULL */
183 Status
= NtSetInformationProcess(NtCurrentProcess(),
184 ProcessForegroundInformation
,
186 sizeof(PROCESS_FOREGROUND_BACKGROUND
));
187 ok_hex(Status
, STATUS_ACCESS_VIOLATION
);
189 /* Set the information process foreground with an incorrect buffer alignment and zero buffer length */
190 Status
= NtSetInformationProcess(NtCurrentProcess(),
191 ProcessForegroundInformation
,
194 ok_hex(Status
, STATUS_INFO_LENGTH_MISMATCH
);
197 * Set the information process foreground with an incorrect buffer alignment but correct size length.
198 * The function will return STATUS_ACCESS_VIOLATION as the alignment probe requirement is not performed
201 Status
= NtSetInformationProcess(NtCurrentProcess(),
202 ProcessForegroundInformation
,
204 sizeof(PROCESS_FOREGROUND_BACKGROUND
));
205 ok_hex(Status
, STATUS_ACCESS_VIOLATION
);
207 /* Set the foreground information to the current given process, we must expect the function should succeed */
208 Status
= NtSetInformationProcess(NtCurrentProcess(),
209 ProcessForegroundInformation
,
211 sizeof(PROCESS_FOREGROUND_BACKGROUND
));
212 ok_hex(Status
, STATUS_SUCCESS
);
214 /* Clear all the stuff */
215 HeapFree(GetProcessHeap(), 0, ProcForeground
);
220 Test_ProcessWx86InformationClass(void)
225 /* Everything is NULL */
226 Status
= NtSetInformationProcess(NULL
,
227 ProcessWx86Information
,
230 ok_hex(Status
, STATUS_INFO_LENGTH_MISMATCH
);
232 /* Don't set anything to the process */
233 Status
= NtSetInformationProcess(NtCurrentProcess(),
234 ProcessWx86Information
,
237 ok_hex(Status
, STATUS_ACCESS_VIOLATION
);
239 /* The buffer is misaligned and information length is wrong */
240 Status
= NtSetInformationProcess(NtCurrentProcess(),
241 ProcessWx86Information
,
244 ok_hex(Status
, STATUS_INFO_LENGTH_MISMATCH
);
246 /* The buffer is misaligned */
247 Status
= NtSetInformationProcess(NtCurrentProcess(),
248 ProcessWx86Information
,
251 ok_hex(Status
, STATUS_DATATYPE_MISALIGNMENT
);
253 /* The buffer is misaligned -- try with an alignment size of 2 */
254 Status
= NtSetInformationProcess(NtCurrentProcess(),
255 ProcessWx86Information
,
258 ok_hex(Status
, STATUS_DATATYPE_MISALIGNMENT
);
260 /* We do not have privileges to set the VDM power */
261 Status
= NtSetInformationProcess(NtCurrentProcess(),
262 ProcessWx86Information
,
265 ok_hex(Status
, STATUS_PRIVILEGE_NOT_HELD
);
268 START_TEST(NtSetInformationProcess
)
270 Test_ProcForegroundBackgroundClass();
271 Test_ProcBasePriorityClass();
272 Test_ProcRaisePriorityClass();
273 Test_ProcessWx86InformationClass();