ReactOS 0.4.15-dev-5666-gc548b97
SystemInfo.c File Reference
#include "precomp.h"
#include <versionhelpers.h>
Include dependency graph for SystemInfo.c:

Go to the source code of this file.

Macros

#define ntv6(x)   (LOBYTE(LOWORD(GetVersion())) >= 6 ? (x) : 0)
 

Functions

static void Test_Flags (void)
 
static void Test_TimeAdjustment (void)
 
static void Test_KernelDebugger (void)
 
 START_TEST (NtSystemInformation)
 

Macro Definition Documentation

◆ ntv6

#define ntv6 (   x)    (LOBYTE(LOWORD(GetVersion())) >= 6 ? (x) : 0)

Definition at line 12 of file SystemInfo.c.

Function Documentation

◆ START_TEST()

START_TEST ( NtSystemInformation  )

Definition at line 326 of file SystemInfo.c.

327{
330
332 ok(Status == STATUS_INVALID_INFO_CLASS, "NtQuerySystemInformation returned %lx\n", Status);
333
336 ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
337
338 ReturnLength = 0x55555555;
340 ok(Status == STATUS_INVALID_INFO_CLASS, "NtQuerySystemInformation returned %lx\n", Status);
341 ok(ReturnLength == 0 ||
342 ntv6(ReturnLength == 0x55555555), "ReturnLength = %lu\n", ReturnLength);
343
344 ReturnLength = 0x55555555;
347 ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
348 ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
349
350 ReturnLength = 0x55555555;
353 ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
354 ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
355
358 ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
359
360 Status = NtQuerySystemInformation(9999, (PVOID)1, 1, (PVOID)1);
362 ntv6(Status == STATUS_INVALID_INFO_CLASS), "NtQuerySystemInformation returned %lx\n", Status);
363
364 Test_Flags();
367}
static void Test_Flags(void)
Definition: SystemInfo.c:16
static void Test_TimeAdjustment(void)
Definition: SystemInfo.c:183
static void Test_KernelDebugger(void)
Definition: SystemInfo.c:278
#define ntv6(x)
Definition: SystemInfo.c:12
#define ok(value,...)
Definition: atltest.h:57
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
Status
Definition: gdiplustypes.h:25
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:183
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:240
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)

◆ Test_Flags()

static void Test_Flags ( void  )
static

Definition at line 16 of file SystemInfo.c.

17{
21 ULONG Buffer[2];
22 ULONG Buffer2[2];
24 BOOLEAN PrivilegeEnabled;
25
26 /* Make sure we don't have debug privileges initially, otherwise WHS testbot fails */
28 ok(Status == STATUS_SUCCESS, "RtlAdjustPrivilege returned %lx\n", Status);
29
30 /* Query */
31 ReturnLength = 0x55555555;
33 ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
34 ok(ReturnLength == 0 ||
35 ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
36
37 ReturnLength = 0x55555555;
39 ok(Status == STATUS_ACCESS_VIOLATION, "NtQuerySystemInformation returned %lx\n", Status);
40 ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
41
42 ReturnLength = 0x55555555;
44 ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
45 ok(ReturnLength == 0 ||
46 ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
47
48 ReturnLength = 0x55555555;
50 ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
51 ok(ReturnLength == 0 ||
52 ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
53
54 ReturnLength = 0x55555555;
55 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
57 ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtQuerySystemInformation returned %lx\n", Status);
58 ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
59 ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
60 ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
61
62 ReturnLength = 0x55555555;
63 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
65 ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtQuerySystemInformation returned %lx\n", Status);
66 ok(ReturnLength == 0x55555555, "ReturnLength = %lu\n", ReturnLength);
67 ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
68 ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
69
70 ReturnLength = 0x55555555;
71 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
73 ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
74 ok(ReturnLength == 0 ||
75 ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
76 ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
77 ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
78
79 ReturnLength = 0x55555555;
80 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
82 ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
83 ok(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION), "ReturnLength = %lu\n", ReturnLength);
84 ok(FlagsInfo->Flags != 0x55555555, "Flags = %lx\n", FlagsInfo->Flags);
85 ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
86 Flags = FlagsInfo->Flags;
87
88 ReturnLength = 0x55555555;
89 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
91 ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
92 ok(ReturnLength == 0 ||
93 ntv6(ReturnLength == sizeof(SYSTEM_FLAGS_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
94 ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
95 ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
96
97 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
99 ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
100 ok(FlagsInfo->Flags == Flags, "Flags = %lx, expected %lx\n", FlagsInfo->Flags, Flags);
101 ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
102
103 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
105 ok(Status == STATUS_ACCESS_VIOLATION, "NtQuerySystemInformation returned %lx\n", Status);
106 ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
107 ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
108
109 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
111 ok(Status == STATUS_ACCESS_VIOLATION, "NtQuerySystemInformation returned %lx\n", Status);
112 ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
113 ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
114
115 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
117 ok(Status == STATUS_ACCESS_VIOLATION, "NtQuerySystemInformation returned %lx\n", Status);
118 ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
119 ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
120
121 RtlFillMemory(Buffer2, sizeof(Buffer2), 0x55);
122 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
124 ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
125 ok(FlagsInfo->Flags == Flags, "Flags = %lx, expected %lx\n", FlagsInfo->Flags, Flags);
126 ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
127 ok(Buffer2[0] == 0x00000455, "Buffer2[0] = %lx\n", Buffer2[0]);
128 ok(Buffer2[1] == 0x55555500, "Buffer2[1] = %lx\n", Buffer2[1]);
129
130 /* Set */
132 ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtSetSystemInformation returned %lx\n", Status);
133
135 ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtSetSystemInformation returned %lx\n", Status);
136
138 ok(Status == (IsWindows7OrGreater() ? STATUS_ACCESS_DENIED : STATUS_ACCESS_VIOLATION), "NtSetSystemInformation returned %lx\n", Status);
139
141 ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtSetSystemInformation returned %lx\n", Status);
142
143 Status = RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE, TRUE, FALSE, &PrivilegeEnabled);
144 if (!NT_SUCCESS(Status))
145 {
146 skip("Cannot acquire SeDebugPrivilege\n");
147 return;
148 }
149
151 ok(Status == STATUS_ACCESS_VIOLATION, "NtSetSystemInformation returned %lx\n", Status);
152
154 ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtSetSystemInformation returned %lx\n", Status);
155
157 ok(Status == STATUS_ACCESS_VIOLATION, "NtSetSystemInformation returned %lx\n", Status);
158
159 FlagsInfo->Flags = Flags;
161 ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtSetSystemInformation returned %lx\n", Status);
162
164 ok(Status == STATUS_DATATYPE_MISALIGNMENT, "NtSetSystemInformation returned %lx\n", Status);
165
167 ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtSetSystemInformation returned %lx\n", Status);
168
170 ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtSetSystemInformation returned %lx\n", Status);
171
173 ok(Status == STATUS_SUCCESS, "NtSetSystemInformation returned %lx\n", Status);
174
175 ok(FlagsInfo->Flags == Flags, "Flags = %lx, expected %lu\n", FlagsInfo->Flags, Flags);
176
177 Status = RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE, PrivilegeEnabled, FALSE, &PrivilegeEnabled);
178 ok(Status == STATUS_SUCCESS, "RtlAdjustPrivilege returned %lx\n", Status);
179}
NTSYSAPI NTSTATUS NTAPI NtSetSystemInformation(IN INT SystemInformationClass, IN PVOID SystemInformation, IN ULONG SystemInformationLength)
unsigned char BOOLEAN
#define skip(...)
Definition: atltest.h:64
Definition: bufpool.h:45
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
@ SystemFlagsInformation
Definition: ntddk_ex.h:20
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
unsigned int * PULONG
Definition: retypes.h:1
void * PVOID
Definition: retypes.h:9
unsigned char * PUCHAR
Definition: retypes.h:3
#define SE_DEBUG_PRIVILEGE
Definition: security.c:674
#define SE_SYSTEMTIME_PRIVILEGE
Definition: security.c:666
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
VERSIONHELPERAPI IsWindows7OrGreater()
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by START_TEST().

◆ Test_KernelDebugger()

static void Test_KernelDebugger ( void  )
static

Definition at line 278 of file SystemInfo.c.

279{
282 ULONG Buffer[2];
284
285 /* Query */
286 ReturnLength = 0x55555555;
288 ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
289 ok(ReturnLength == 0 ||
290 ntv6(ReturnLength == sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
291
292 ReturnLength = 0x55555555;
293 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
295 ok(Status == STATUS_INFO_LENGTH_MISMATCH, "NtQuerySystemInformation returned %lx\n", Status);
296 ok(ReturnLength == 0 ||
297 ntv6(ReturnLength == sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION)), "ReturnLength = %lu\n", ReturnLength);
298 ok(Buffer[0] == 0x55555555, "Buffer[0] = %lx\n", Buffer[0]);
299 ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
300
301 ReturnLength = 0x55555555;
302 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
304 ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
305 ok(ReturnLength == sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION), "ReturnLength = %lu\n", ReturnLength);
306 ok((Buffer[0] & 0x55fefe55) == 0x55000055, "Buffer[0] = %lx\n", Buffer[0]);
307 ok(Buffer[1] == 0x55555555, "Buffer[1] = %lx\n", Buffer[1]);
308
309 ReturnLength = 0x55555555;
310 RtlFillMemory(Buffer, sizeof(Buffer), 0x55);
312 ok(Status == STATUS_SUCCESS, "NtQuerySystemInformation returned %lx\n", Status);
313 ok(ReturnLength == sizeof(SYSTEM_KERNEL_DEBUGGER_INFORMATION), "ReturnLength = %lu\n", ReturnLength);
314 ok(DebuggerInfo->KernelDebuggerEnabled == FALSE ||
315 DebuggerInfo->KernelDebuggerEnabled == TRUE, "KernelDebuggerEnabled = %u\n", DebuggerInfo->KernelDebuggerEnabled);
316 ok(DebuggerInfo->KernelDebuggerNotPresent == FALSE ||
317 DebuggerInfo->KernelDebuggerNotPresent == TRUE, "KernelDebuggerNotPresent = %u\n", DebuggerInfo->KernelDebuggerNotPresent);
318
319 /* Set - not supported */
320 DebuggerInfo->KernelDebuggerEnabled = FALSE;
321 DebuggerInfo->KernelDebuggerNotPresent = TRUE;
323 ok(Status == STATUS_INVALID_INFO_CLASS, "NtSetSystemInformation returned %lx\n", Status);
324}
@ SystemKernelDebuggerInformation
Definition: ntddk_ex.h:46

Referenced by START_TEST().

◆ Test_TimeAdjustment()

static void Test_TimeAdjustment ( void  )
static

Definition at line 183 of file SystemInfo.c.

184{
185 SYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfoOrg, GetTimeInfo;
189 BOOLEAN PrivilegeEnabled;
190
191 /* Make sure we don't have debug privileges initially, otherwise WHS testbot fails */
193 ok(Status == STATUS_SUCCESS, "RtlAdjustPrivilege returned %lx\n", Status);
194
195 SetTimeInfo.TimeAdjustment = 0;
196 SetTimeInfo.Enable = 0;
197
198 /* Query original values */
200 &TimeInfoOrg,
201 sizeof(TimeInfoOrg),
202 &ReturnLength);
203
204 /* Test without privilege */
206 &SetTimeInfo,
207 sizeof(SetTimeInfo));
209
210 /* Get the required privilege */
212 if (!NT_SUCCESS(Status))
213 {
214 skip("Cannot acquire SeSystemTimePrivilege\n");
215 return;
216 }
217
218 /* Test wrong length */
220 &SetTimeInfo,
221 sizeof(SetTimeInfo) + 1);
223
224 /* Test both members 0 */
226 &SetTimeInfo,
227 sizeof(SetTimeInfo));
229
230 /* Set huge value */
231 SetTimeInfo.TimeAdjustment = -1;
232 SetTimeInfo.Enable = 0;
234 &SetTimeInfo,
235 sizeof(SetTimeInfo));
237
238 /* Query the result */
240 &GetTimeInfo,
241 sizeof(GetTimeInfo),
242 &ReturnLength);
244 ok_long(GetTimeInfo.TimeAdjustment, IsWindows7OrGreater() ? 0x7076cc : -1);
245 ok_long(GetTimeInfo.Enable, 0);
246
247 /* set Enable to 1 */
248 SetTimeInfo.TimeAdjustment = -1;
249 SetTimeInfo.Enable = 1;
251 &SetTimeInfo,
252 sizeof(SetTimeInfo));
254
255 /* Query the result */
257 &GetTimeInfo,
258 sizeof(GetTimeInfo),
259 &ReturnLength);
261 ok_long(GetTimeInfo.TimeAdjustment, GetTimeInfo.TimeIncrement);
262 ok_long(GetTimeInfo.Enable, 1);
263
264 /* Restore original values */
265 SetTimeInfo.TimeAdjustment = TimeInfoOrg.TimeAdjustment;
266 SetTimeInfo.Enable = TimeInfoOrg.Enable;
268 &SetTimeInfo,
269 sizeof(SetTimeInfo));
271
272 Status = RtlAdjustPrivilege(SE_SYSTEMTIME_PRIVILEGE, PrivilegeEnabled, FALSE, &PrivilegeEnabled);
273 ok(Status == STATUS_SUCCESS, "RtlAdjustPrivilege returned %lx\n", Status);
274}
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
#define ok_long(expression, result)
Definition: atltest.h:133
@ SystemTimeAdjustmentInformation
Definition: ntddk_ex.h:39
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
#define STATUS_INTEGER_DIVIDE_BY_ZERO
Definition: ntstatus.h:384

Referenced by START_TEST().