[NTDLL_WINETEST]: Sync with Wine 1.5.19.
[reactos.git] / rostests / winetests / ntdll / info.c
1 /* Unit test suite for *Information* Registry API functions
2 *
3 * Copyright 2005 Paul Vriens
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 *
19 */
20
21 #include "ntdll_test.h"
22 #include <winnls.h>
23 #include <stdio.h>
24
25 static NTSTATUS (WINAPI * pNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG);
26 static NTSTATUS (WINAPI * pNtPowerInformation)(POWER_INFORMATION_LEVEL, PVOID, ULONG, PVOID, ULONG);
27 static NTSTATUS (WINAPI * pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
28 static NTSTATUS (WINAPI * pNtQueryInformationThread)(HANDLE, THREADINFOCLASS, PVOID, ULONG, PULONG);
29 static NTSTATUS (WINAPI * pNtSetInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG);
30 static NTSTATUS (WINAPI * pNtSetInformationThread)(HANDLE, THREADINFOCLASS, PVOID, ULONG);
31 static NTSTATUS (WINAPI * pNtReadVirtualMemory)(HANDLE, const void*, void*, SIZE_T, SIZE_T*);
32 static NTSTATUS (WINAPI * pNtQueryVirtualMemory)(HANDLE, LPCVOID, MEMORY_INFORMATION_CLASS , PVOID , SIZE_T , SIZE_T *);
33 static NTSTATUS (WINAPI * pNtCreateSection)(HANDLE*,ACCESS_MASK,const OBJECT_ATTRIBUTES*,const LARGE_INTEGER*,ULONG,ULONG,HANDLE);
34 static NTSTATUS (WINAPI * pNtMapViewOfSection)(HANDLE,HANDLE,PVOID*,ULONG,SIZE_T,const LARGE_INTEGER*,SIZE_T*,SECTION_INHERIT,ULONG,ULONG);
35 static NTSTATUS (WINAPI * pNtUnmapViewOfSection)(HANDLE,PVOID);
36 static NTSTATUS (WINAPI * pNtClose)(HANDLE);
37 static ULONG (WINAPI * pNtGetCurrentProcessorNumber)(void);
38 static BOOL (WINAPI * pIsWow64Process)(HANDLE, PBOOL);
39
40 static BOOL is_wow64;
41
42 /* one_before_last_pid is used to be able to compare values of a still running process
43 with the output of the test_query_process_times and test_query_process_handlecount tests.
44 */
45 static DWORD one_before_last_pid = 0;
46
47 #define NTDLL_GET_PROC(func) do { \
48 p ## func = (void*)GetProcAddress(hntdll, #func); \
49 if(!p ## func) { \
50 trace("GetProcAddress(%s) failed\n", #func); \
51 return FALSE; \
52 } \
53 } while(0)
54
55 static BOOL InitFunctionPtrs(void)
56 {
57 /* All needed functions are NT based, so using GetModuleHandle is a good check */
58 HMODULE hntdll = GetModuleHandle("ntdll");
59 if (!hntdll)
60 {
61 win_skip("Not running on NT\n");
62 return FALSE;
63 }
64
65 NTDLL_GET_PROC(NtQuerySystemInformation);
66 NTDLL_GET_PROC(NtPowerInformation);
67 NTDLL_GET_PROC(NtQueryInformationProcess);
68 NTDLL_GET_PROC(NtQueryInformationThread);
69 NTDLL_GET_PROC(NtSetInformationProcess);
70 NTDLL_GET_PROC(NtSetInformationThread);
71 NTDLL_GET_PROC(NtReadVirtualMemory);
72 NTDLL_GET_PROC(NtQueryVirtualMemory);
73 NTDLL_GET_PROC(NtClose);
74 NTDLL_GET_PROC(NtCreateSection);
75 NTDLL_GET_PROC(NtMapViewOfSection);
76 NTDLL_GET_PROC(NtUnmapViewOfSection);
77
78 /* not present before XP */
79 pNtGetCurrentProcessorNumber = (void *) GetProcAddress(hntdll, "NtGetCurrentProcessorNumber");
80
81 pIsWow64Process = (void *)GetProcAddress(GetModuleHandle("kernel32.dll"), "IsWow64Process");
82 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
83 return TRUE;
84 }
85
86 static void test_query_basic(void)
87 {
88 NTSTATUS status;
89 ULONG ReturnLength;
90 SYSTEM_BASIC_INFORMATION sbi;
91
92 /* This test also covers some basic parameter testing that should be the same for
93 * every information class
94 */
95
96 /* Use a nonexistent info class */
97 trace("Check nonexistent info class\n");
98 status = pNtQuerySystemInformation(-1, NULL, 0, NULL);
99 ok( status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* vista */,
100 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status);
101
102 /* Use an existing class but with a zero-length buffer */
103 trace("Check zero-length buffer\n");
104 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, 0, NULL);
105 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
106
107 /* Use an existing class, correct length but no SystemInformation buffer */
108 trace("Check no SystemInformation buffer\n");
109 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, sizeof(sbi), NULL);
110 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_PARAMETER /* vista */,
111 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER, got %08x\n", status);
112
113 /* Use a existing class, correct length, a pointer to a buffer but no ReturnLength pointer */
114 trace("Check no ReturnLength pointer\n");
115 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), NULL);
116 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
117
118 /* Check a too large buffer size */
119 trace("Check a too large buffer size\n");
120 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi) * 2, &ReturnLength);
121 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
122
123 /* Finally some correct calls */
124 trace("Check with correct parameters\n");
125 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
126 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
127 ok( sizeof(sbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
128
129 /* Check if we have some return values */
130 trace("Number of Processors : %d\n", sbi.NumberOfProcessors);
131 ok( sbi.NumberOfProcessors > 0, "Expected more than 0 processors, got %d\n", sbi.NumberOfProcessors);
132 }
133
134 static void test_query_cpu(void)
135 {
136 DWORD status;
137 ULONG ReturnLength;
138 SYSTEM_CPU_INFORMATION sci;
139
140 status = pNtQuerySystemInformation(SystemCpuInformation, &sci, sizeof(sci), &ReturnLength);
141 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
142 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
143
144 /* Check if we have some return values */
145 trace("Processor FeatureSet : %08x\n", sci.FeatureSet);
146 ok( sci.FeatureSet != 0, "Expected some features for this processor, got %08x\n", sci.FeatureSet);
147 }
148
149 static void test_query_performance(void)
150 {
151 NTSTATUS status;
152 ULONG ReturnLength;
153 ULONGLONG buffer[sizeof(SYSTEM_PERFORMANCE_INFORMATION)/sizeof(ULONGLONG) + 5];
154 DWORD size = sizeof(SYSTEM_PERFORMANCE_INFORMATION);
155
156 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, 0, &ReturnLength);
157 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
158
159 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, size, &ReturnLength);
160 if (status == STATUS_INFO_LENGTH_MISMATCH && is_wow64)
161 {
162 /* size is larger on wow64 under w2k8/win7 */
163 size += 16;
164 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, size, &ReturnLength);
165 }
166 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
167 ok( ReturnLength == size, "Inconsistent length %d\n", ReturnLength);
168
169 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, size + 2, &ReturnLength);
170 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
171 ok( ReturnLength == size || ReturnLength == size + 2,
172 "Inconsistent length %d\n", ReturnLength);
173
174 /* Not return values yet, as struct members are unknown */
175 }
176
177 static void test_query_timeofday(void)
178 {
179 NTSTATUS status;
180 ULONG ReturnLength;
181
182 /* Copy of our winternl.h structure turned into a private one */
183 typedef struct _SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE {
184 LARGE_INTEGER liKeBootTime;
185 LARGE_INTEGER liKeSystemTime;
186 LARGE_INTEGER liExpTimeZoneBias;
187 ULONG uCurrentTimeZoneId;
188 DWORD dwUnknown1[5];
189 } SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE;
190
191 SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE sti;
192
193 /* The struct size for NT (32 bytes) and Win2K/XP (48 bytes) differ.
194 *
195 * Windows 2000 and XP return STATUS_INFO_LENGTH_MISMATCH if the given buffer size is greater
196 * then 48 and 0 otherwise
197 * Windows NT returns STATUS_INFO_LENGTH_MISMATCH when the given buffer size is not correct
198 * and 0 otherwise
199 *
200 * Windows 2000 and XP copy the given buffer size into the provided buffer, if the return code is STATUS_SUCCESS
201 * NT only fills the buffer if the return code is STATUS_SUCCESS
202 *
203 */
204
205 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
206
207 if (status == STATUS_INFO_LENGTH_MISMATCH)
208 {
209 trace("Windows version is NT, we have to cater for differences with W2K/WinXP\n");
210
211 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
212 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
213 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
214
215 sti.uCurrentTimeZoneId = 0xdeadbeef;
216 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 28, &ReturnLength);
217 ok(status == STATUS_SUCCESS || broken(status == STATUS_INFO_LENGTH_MISMATCH /* NT4 */), "Expected STATUS_SUCCESS, got %08x\n", status);
218 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
219
220 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
221 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
222 ok( 32 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
223 }
224 else
225 {
226 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
227 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
228 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
229
230 sti.uCurrentTimeZoneId = 0xdeadbeef;
231 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 24, &ReturnLength);
232 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
233 ok( 24 == ReturnLength, "ReturnLength should be 24, it is (%d)\n", ReturnLength);
234 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
235
236 sti.uCurrentTimeZoneId = 0xdeadbeef;
237 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
238 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
239 ok( 32 == ReturnLength, "ReturnLength should be 32, it is (%d)\n", ReturnLength);
240 ok( 0xdeadbeef != sti.uCurrentTimeZoneId, "Buffer should have been partially filled\n");
241
242 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 49, &ReturnLength);
243 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
244 ok( ReturnLength == 0 || ReturnLength == sizeof(sti) /* vista */,
245 "ReturnLength should be 0, it is (%d)\n", ReturnLength);
246
247 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
248 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
249 ok( sizeof(sti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
250 }
251
252 /* Check if we have some return values */
253 trace("uCurrentTimeZoneId : (%d)\n", sti.uCurrentTimeZoneId);
254 }
255
256 static void test_query_process(void)
257 {
258 NTSTATUS status;
259 DWORD last_pid;
260 ULONG ReturnLength;
261 int i = 0, k = 0;
262 int is_nt = 0;
263 SYSTEM_BASIC_INFORMATION sbi;
264
265 /* Copy of our winternl.h structure turned into a private one */
266 typedef struct _SYSTEM_PROCESS_INFORMATION_PRIVATE {
267 ULONG NextEntryOffset;
268 DWORD dwThreadCount;
269 DWORD dwUnknown1[6];
270 FILETIME ftCreationTime;
271 FILETIME ftUserTime;
272 FILETIME ftKernelTime;
273 UNICODE_STRING ProcessName;
274 DWORD dwBasePriority;
275 HANDLE UniqueProcessId;
276 HANDLE ParentProcessId;
277 ULONG HandleCount;
278 DWORD dwUnknown3;
279 DWORD dwUnknown4;
280 VM_COUNTERS vmCounters;
281 IO_COUNTERS ioCounters;
282 SYSTEM_THREAD_INFORMATION ti[1];
283 } SYSTEM_PROCESS_INFORMATION_PRIVATE;
284
285 ULONG SystemInformationLength = sizeof(SYSTEM_PROCESS_INFORMATION_PRIVATE);
286 SYSTEM_PROCESS_INFORMATION_PRIVATE *spi, *spi_buf = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
287
288 /* test ReturnLength */
289 ReturnLength = 0;
290 status = pNtQuerySystemInformation(SystemProcessInformation, NULL, 0, &ReturnLength);
291 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_LENGTH_MISMATCH got %08x\n", status);
292 ok( ReturnLength > 0 || broken(ReturnLength == 0) /* NT4, Win2K */,
293 "Expected a ReturnLength to show the needed length\n");
294
295 /* W2K3 and later returns the needed length, the rest returns 0, so we have to loop */
296 for (;;)
297 {
298 status = pNtQuerySystemInformation(SystemProcessInformation, spi_buf, SystemInformationLength, &ReturnLength);
299
300 if (status != STATUS_INFO_LENGTH_MISMATCH) break;
301
302 spi_buf = HeapReAlloc(GetProcessHeap(), 0, spi_buf , SystemInformationLength *= 2);
303 }
304 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
305 spi = spi_buf;
306
307 /* Get the first NextEntryOffset, from this we can deduce the OS version we're running
308 *
309 * W2K/WinXP/W2K3:
310 * NextEntryOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
311 * NT:
312 * NextEntryOffset for a process is 136 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
313 * Wine (with every windows version):
314 * NextEntryOffset for a process is 0 if just this test is running
315 * NextEntryOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION) +
316 * ProcessName.MaximumLength
317 * if more wine processes are running
318 *
319 * Note : On windows the first process is in fact the Idle 'process' with a thread for every processor
320 */
321
322 pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
323
324 is_nt = ( spi->NextEntryOffset - (sbi.NumberOfProcessors * sizeof(SYSTEM_THREAD_INFORMATION)) == 136);
325
326 if (is_nt) win_skip("Windows version is NT, we will skip thread tests\n");
327
328 /* Check if we have some return values
329 *
330 * On windows there will be several processes running (Including the always present Idle and System)
331 * On wine we only have one (if this test is the only wine process running)
332 */
333
334 /* Loop through the processes */
335
336 for (;;)
337 {
338 i++;
339
340 last_pid = (DWORD_PTR)spi->UniqueProcessId;
341
342 ok( spi->dwThreadCount > 0, "Expected some threads for this process, got 0\n");
343
344 /* Loop through the threads, skip NT4 for now */
345
346 if (!is_nt)
347 {
348 DWORD j;
349 for ( j = 0; j < spi->dwThreadCount; j++)
350 {
351 k++;
352 ok ( spi->ti[j].ClientId.UniqueProcess == spi->UniqueProcessId,
353 "The owning pid of the thread (%p) doesn't equal the pid (%p) of the process\n",
354 spi->ti[j].ClientId.UniqueProcess, spi->UniqueProcessId);
355 }
356 }
357
358 if (!spi->NextEntryOffset) break;
359
360 one_before_last_pid = last_pid;
361
362 spi = (SYSTEM_PROCESS_INFORMATION_PRIVATE*)((char*)spi + spi->NextEntryOffset);
363 }
364 trace("Total number of running processes : %d\n", i);
365 if (!is_nt) trace("Total number of running threads : %d\n", k);
366
367 if (one_before_last_pid == 0) one_before_last_pid = last_pid;
368
369 HeapFree( GetProcessHeap(), 0, spi_buf);
370 }
371
372 static void test_query_procperf(void)
373 {
374 NTSTATUS status;
375 ULONG ReturnLength;
376 ULONG NeededLength;
377 SYSTEM_BASIC_INFORMATION sbi;
378 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi;
379
380 /* Find out the number of processors */
381 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
382 ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
383 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
384
385 sppi = HeapAlloc(GetProcessHeap(), 0, NeededLength);
386
387 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, 0, &ReturnLength);
388 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
389
390 /* Try it for 1 processor */
391 sppi->KernelTime.QuadPart = 0xdeaddead;
392 sppi->UserTime.QuadPart = 0xdeaddead;
393 sppi->IdleTime.QuadPart = 0xdeaddead;
394 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi,
395 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION), &ReturnLength);
396 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
397 ok( sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) == ReturnLength,
398 "Inconsistent length %d\n", ReturnLength);
399 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
400 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
401 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
402
403 /* Try it for all processors */
404 sppi->KernelTime.QuadPart = 0xdeaddead;
405 sppi->UserTime.QuadPart = 0xdeaddead;
406 sppi->IdleTime.QuadPart = 0xdeaddead;
407 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength, &ReturnLength);
408 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
409 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
410 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
411 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
412 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
413
414 /* A too large given buffer size */
415 sppi = HeapReAlloc(GetProcessHeap(), 0, sppi , NeededLength + 2);
416 sppi->KernelTime.QuadPart = 0xdeaddead;
417 sppi->UserTime.QuadPart = 0xdeaddead;
418 sppi->IdleTime.QuadPart = 0xdeaddead;
419 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength + 2, &ReturnLength);
420 ok( status == STATUS_SUCCESS || status == STATUS_INFO_LENGTH_MISMATCH /* vista */,
421 "Expected STATUS_SUCCESS or STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
422 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
423 if (status == STATUS_SUCCESS)
424 {
425 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
426 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
427 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
428 }
429 else /* vista and 2008 */
430 {
431 ok (sppi->KernelTime.QuadPart == 0xdeaddead, "KernelTime changed\n");
432 ok (sppi->UserTime.QuadPart == 0xdeaddead, "UserTime changed\n");
433 ok (sppi->IdleTime.QuadPart == 0xdeaddead, "IdleTime changed\n");
434 }
435
436 HeapFree( GetProcessHeap(), 0, sppi);
437 }
438
439 static void test_query_module(void)
440 {
441 NTSTATUS status;
442 ULONG ReturnLength;
443 ULONG ModuleCount, i;
444
445 ULONG SystemInformationLength = sizeof(SYSTEM_MODULE_INFORMATION);
446 SYSTEM_MODULE_INFORMATION* smi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
447 SYSTEM_MODULE* sm;
448
449 /* Request the needed length */
450 status = pNtQuerySystemInformation(SystemModuleInformation, smi, 0, &ReturnLength);
451 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
452 ok( ReturnLength > 0, "Expected a ReturnLength to show the needed length\n");
453
454 SystemInformationLength = ReturnLength;
455 smi = HeapReAlloc(GetProcessHeap(), 0, smi , SystemInformationLength);
456 status = pNtQuerySystemInformation(SystemModuleInformation, smi, SystemInformationLength, &ReturnLength);
457 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
458
459 ModuleCount = smi->ModulesCount;
460 sm = &smi->Modules[0];
461 /* our implementation is a stub for now */
462 ok( ModuleCount > 0, "Expected some modules to be loaded\n");
463
464 /* Loop through all the modules/drivers, Wine doesn't get here (yet) */
465 for (i = 0; i < ModuleCount ; i++)
466 {
467 ok( i == sm->Id, "Id (%d) should have matched %u\n", sm->Id, i);
468 sm++;
469 }
470
471 HeapFree( GetProcessHeap(), 0, smi);
472 }
473
474 static void test_query_handle(void)
475 {
476 NTSTATUS status;
477 ULONG ReturnLength;
478 ULONG SystemInformationLength = sizeof(SYSTEM_HANDLE_INFORMATION);
479 SYSTEM_HANDLE_INFORMATION* shi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
480
481 /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
482 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
483 todo_wine ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
484
485 SystemInformationLength = ReturnLength;
486 shi = HeapReAlloc(GetProcessHeap(), 0, shi , SystemInformationLength);
487 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
488 if (status != STATUS_INFO_LENGTH_MISMATCH) /* vista */
489 {
490 ok( status == STATUS_SUCCESS,
491 "Expected STATUS_SUCCESS, got %08x\n", status);
492
493 /* Check if we have some return values */
494 trace("Number of Handles : %d\n", shi->Count);
495 todo_wine
496 {
497 /* our implementation is a stub for now */
498 ok( shi->Count > 1, "Expected more than 1 handles, got (%d)\n", shi->Count);
499 }
500 }
501 HeapFree( GetProcessHeap(), 0, shi);
502 }
503
504 static void test_query_cache(void)
505 {
506 NTSTATUS status;
507 ULONG ReturnLength;
508 SYSTEM_CACHE_INFORMATION sci;
509
510 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, 0, &ReturnLength);
511 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
512
513 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci), &ReturnLength);
514 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
515 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
516
517 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci) + 2, &ReturnLength);
518 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
519 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
520 }
521
522 static void test_query_interrupt(void)
523 {
524 NTSTATUS status;
525 ULONG ReturnLength;
526 ULONG NeededLength;
527 SYSTEM_BASIC_INFORMATION sbi;
528 SYSTEM_INTERRUPT_INFORMATION* sii;
529
530 /* Find out the number of processors */
531 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
532 ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
533 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_INTERRUPT_INFORMATION);
534
535 sii = HeapAlloc(GetProcessHeap(), 0, NeededLength);
536
537 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, 0, &ReturnLength);
538 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
539
540 /* Try it for all processors */
541 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, NeededLength, &ReturnLength);
542 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
543
544 /* Windows XP and W2K3 (and others?) always return 0 for the ReturnLength
545 * No test added for this as it's highly unlikely that an app depends on this
546 */
547
548 HeapFree( GetProcessHeap(), 0, sii);
549 }
550
551 static void test_query_kerndebug(void)
552 {
553 NTSTATUS status;
554 ULONG ReturnLength;
555 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
556
557 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, 0, &ReturnLength);
558 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
559
560 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi), &ReturnLength);
561 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
562 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
563
564 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi) + 2, &ReturnLength);
565 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
566 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
567 }
568
569 static void test_query_regquota(void)
570 {
571 NTSTATUS status;
572 ULONG ReturnLength;
573 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
574
575 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, 0, &ReturnLength);
576 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
577
578 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi), &ReturnLength);
579 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
580 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
581
582 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi) + 2, &ReturnLength);
583 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
584 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
585 }
586
587 static void test_query_logicalproc(void)
588 {
589 NTSTATUS status;
590 ULONG len, i, proc_no;
591 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *slpi;
592 SYSTEM_INFO si;
593
594 GetSystemInfo(&si);
595
596 status = pNtQuerySystemInformation(SystemLogicalProcessorInformation, NULL, 0, &len);
597 if(status == STATUS_INVALID_INFO_CLASS)
598 {
599 win_skip("SystemLogicalProcessorInformation is not supported\n");
600 return;
601 }
602 if(status == STATUS_NOT_IMPLEMENTED)
603 {
604 todo_wine ok(0, "SystemLogicalProcessorInformation is not implemented\n");
605 return;
606 }
607 ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
608 ok(len%sizeof(*slpi) == 0, "Incorrect length %d\n", len);
609
610 slpi = HeapAlloc(GetProcessHeap(), 0, len);
611 status = pNtQuerySystemInformation(SystemLogicalProcessorInformation, slpi, len, &len);
612 ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
613
614 proc_no = 0;
615 for(i=0; i<len/sizeof(*slpi); i++) {
616 switch(slpi[i].Relationship) {
617 case RelationProcessorCore:
618 /* Get number of logical processors */
619 for(; slpi[i].ProcessorMask; slpi[i].ProcessorMask /= 2)
620 proc_no += slpi[i].ProcessorMask%2;
621 break;
622 default:
623 break;
624 }
625 }
626 ok(proc_no > 0, "No processors were found\n");
627 if(si.dwNumberOfProcessors <= 32)
628 ok(proc_no == si.dwNumberOfProcessors, "Incorrect number of logical processors: %d, expected %d\n",
629 proc_no, si.dwNumberOfProcessors);
630
631 HeapFree(GetProcessHeap(), 0, slpi);
632 }
633
634 static void test_query_processor_power_info(void)
635 {
636 NTSTATUS status;
637 PROCESSOR_POWER_INFORMATION* ppi;
638 ULONG size;
639 SYSTEM_INFO si;
640 int i;
641
642 GetSystemInfo(&si);
643 size = si.dwNumberOfProcessors * sizeof(PROCESSOR_POWER_INFORMATION);
644 ppi = HeapAlloc(GetProcessHeap(), 0, size);
645
646 /* If size < (sizeof(PROCESSOR_POWER_INFORMATION) * NumberOfProcessors), Win7 returns
647 * STATUS_BUFFER_TOO_SMALL. WinXP returns STATUS_SUCCESS for any value of size. It copies as
648 * many whole PROCESSOR_POWER_INFORMATION structures that there is room for. Even if there is
649 * not enough room for one structure, WinXP still returns STATUS_SUCCESS having done nothing.
650 *
651 * If ppi == NULL, Win7 returns STATUS_INVALID_PARAMETER while WinXP returns STATUS_SUCCESS
652 * and does nothing.
653 *
654 * The same behavior is seen with CallNtPowerInformation (in powrprof.dll).
655 */
656
657 if (si.dwNumberOfProcessors > 1)
658 {
659 for(i = 0; i < si.dwNumberOfProcessors; i++)
660 ppi[i].Number = 0xDEADBEEF;
661
662 /* Call with a buffer size that is large enough to hold at least one but not large
663 * enough to hold them all. This will be STATUS_SUCCESS on WinXP but not on Win7 */
664 status = pNtPowerInformation(ProcessorInformation, 0, 0, ppi, size - sizeof(PROCESSOR_POWER_INFORMATION));
665 if (status == STATUS_SUCCESS)
666 {
667 /* lax version found on older Windows like WinXP */
668 ok( (ppi[si.dwNumberOfProcessors - 2].Number != 0xDEADBEEF) &&
669 (ppi[si.dwNumberOfProcessors - 1].Number == 0xDEADBEEF),
670 "Expected all but the last record to be overwritten.\n");
671
672 status = pNtPowerInformation(ProcessorInformation, 0, 0, 0, size);
673 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
674
675 for(i = 0; i < si.dwNumberOfProcessors; i++)
676 ppi[i].Number = 0xDEADBEEF;
677 status = pNtPowerInformation(ProcessorInformation, 0, 0, ppi, sizeof(PROCESSOR_POWER_INFORMATION) - 1);
678 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
679 for(i = 0; i < si.dwNumberOfProcessors; i++)
680 if (ppi[i].Number != 0xDEADBEEF) break;
681 ok( i == si.dwNumberOfProcessors, "Expected untouched buffer\n");
682 }
683 else
684 {
685 /* picky version found on newer Windows like Win7 */
686 ok( ppi[1].Number == 0xDEADBEEF, "Expected untouched buffer.\n");
687 ok( status == STATUS_BUFFER_TOO_SMALL, "Expected STATUS_BUFFER_TOO_SMALL, got %08x\n", status);
688
689 status = pNtPowerInformation(ProcessorInformation, 0, 0, 0, size);
690 ok( status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER, "Got %08x\n", status);
691
692 status = pNtPowerInformation(ProcessorInformation, 0, 0, ppi, 0);
693 ok( status == STATUS_BUFFER_TOO_SMALL || status == STATUS_INVALID_PARAMETER, "Got %08x\n", status);
694 }
695 }
696 else
697 {
698 skip("Test needs more than one processor.\n");
699 }
700
701 status = pNtPowerInformation(ProcessorInformation, 0, 0, ppi, size);
702 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
703
704 HeapFree(GetProcessHeap(), 0, ppi);
705 }
706
707 static void test_query_process_basic(void)
708 {
709 NTSTATUS status;
710 ULONG ReturnLength;
711
712 typedef struct _PROCESS_BASIC_INFORMATION_PRIVATE {
713 DWORD_PTR ExitStatus;
714 PPEB PebBaseAddress;
715 DWORD_PTR AffinityMask;
716 DWORD_PTR BasePriority;
717 ULONG_PTR UniqueProcessId;
718 ULONG_PTR InheritedFromUniqueProcessId;
719 } PROCESS_BASIC_INFORMATION_PRIVATE;
720
721 PROCESS_BASIC_INFORMATION_PRIVATE pbi;
722
723 /* This test also covers some basic parameter testing that should be the same for
724 * every information class
725 */
726
727 /* Use a nonexistent info class */
728 trace("Check nonexistent info class\n");
729 status = pNtQueryInformationProcess(NULL, -1, NULL, 0, NULL);
730 ok( status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* vista */,
731 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status);
732
733 /* Do not give a handle and buffer */
734 trace("Check NULL handle and buffer and zero-length buffersize\n");
735 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, 0, NULL);
736 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
737
738 /* Use a correct info class and buffer size, but still no handle and buffer */
739 trace("Check NULL handle and buffer\n");
740 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, sizeof(pbi), NULL);
741 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
742 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
743
744 /* Use a correct info class and buffer size, but still no handle */
745 trace("Check NULL handle\n");
746 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
747 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
748
749 /* Use a greater buffer size */
750 trace("Check NULL handle and too large buffersize\n");
751 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi) * 2, NULL);
752 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
753
754 /* Use no ReturnLength */
755 trace("Check NULL ReturnLength\n");
756 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
757 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
758
759 /* Finally some correct calls */
760 trace("Check with correct parameters\n");
761 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), &ReturnLength);
762 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
763 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
764
765 /* Everything is correct except a too large buffersize */
766 trace("Too large buffersize\n");
767 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi) * 2, &ReturnLength);
768 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
769 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
770
771 /* Check if we have some return values */
772 trace("ProcessID : %lx\n", pbi.UniqueProcessId);
773 ok( pbi.UniqueProcessId > 0, "Expected a ProcessID > 0, got 0\n");
774 }
775
776 static void test_query_process_vm(void)
777 {
778 NTSTATUS status;
779 ULONG ReturnLength;
780 VM_COUNTERS pvi;
781 ULONG old_size = FIELD_OFFSET(VM_COUNTERS,PrivatePageCount);
782
783 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, NULL, sizeof(pvi), NULL);
784 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
785 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
786
787 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, &pvi, old_size, NULL);
788 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
789
790 /* Windows XP and W2K3 will report success for a size of 44 AND 48 !
791 Windows W2K will only report success for 44.
792 For now we only care for 44, which is FIELD_OFFSET(VM_COUNTERS,PrivatePageCount))
793 */
794
795 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 24, &ReturnLength);
796 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
797
798 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, old_size, &ReturnLength);
799 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
800 ok( old_size == ReturnLength, "Inconsistent length %d\n", ReturnLength);
801
802 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 46, &ReturnLength);
803 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
804 ok( ReturnLength == old_size || ReturnLength == sizeof(pvi), "Inconsistent length %d\n", ReturnLength);
805
806 /* Check if we have some return values */
807 trace("WorkingSetSize : %ld\n", pvi.WorkingSetSize);
808 todo_wine
809 {
810 ok( pvi.WorkingSetSize > 0, "Expected a WorkingSetSize > 0\n");
811 }
812 }
813
814 static void test_query_process_io(void)
815 {
816 NTSTATUS status;
817 ULONG ReturnLength;
818 IO_COUNTERS pii;
819
820 /* NT4 doesn't support this information class, so check for it */
821 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
822 if (status == STATUS_NOT_SUPPORTED)
823 {
824 win_skip("ProcessIoCounters information class is not supported\n");
825 return;
826 }
827
828 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, NULL, sizeof(pii), NULL);
829 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
830 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
831
832 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, &pii, sizeof(pii), NULL);
833 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
834
835 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, 24, &ReturnLength);
836 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
837
838 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
839 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
840 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
841
842 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii) * 2, &ReturnLength);
843 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
844 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
845
846 /* Check if we have some return values */
847 trace("OtherOperationCount : 0x%x%08x\n", (DWORD)(pii.OtherOperationCount >> 32), (DWORD)pii.OtherOperationCount);
848 todo_wine
849 {
850 ok( pii.OtherOperationCount > 0, "Expected an OtherOperationCount > 0\n");
851 }
852 }
853
854 static void test_query_process_times(void)
855 {
856 NTSTATUS status;
857 ULONG ReturnLength;
858 HANDLE process;
859 SYSTEMTIME UTC, Local;
860 KERNEL_USER_TIMES spti;
861
862 status = pNtQueryInformationProcess(NULL, ProcessTimes, NULL, sizeof(spti), NULL);
863 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
864 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
865
866 status = pNtQueryInformationProcess(NULL, ProcessTimes, &spti, sizeof(spti), NULL);
867 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
868
869 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, 24, &ReturnLength);
870 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
871
872 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
873 if (!process)
874 {
875 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
876 process = GetCurrentProcess();
877 trace("ProcessTimes for current process\n");
878 }
879 else
880 trace("ProcessTimes for process with ID : %d\n", one_before_last_pid);
881
882 status = pNtQueryInformationProcess( process, ProcessTimes, &spti, sizeof(spti), &ReturnLength);
883 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
884 ok( sizeof(spti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
885 CloseHandle(process);
886
887 FileTimeToSystemTime((const FILETIME *)&spti.CreateTime, &UTC);
888 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
889 trace("CreateTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
890 Local.wHour, Local.wMinute, Local.wSecond);
891
892 FileTimeToSystemTime((const FILETIME *)&spti.ExitTime, &UTC);
893 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
894 trace("ExitTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
895 Local.wHour, Local.wMinute, Local.wSecond);
896
897 FileTimeToSystemTime((const FILETIME *)&spti.KernelTime, &Local);
898 trace("KernelTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
899
900 FileTimeToSystemTime((const FILETIME *)&spti.UserTime, &Local);
901 trace("UserTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
902
903 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, sizeof(spti) * 2, &ReturnLength);
904 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
905 ok( sizeof(spti) == ReturnLength ||
906 ReturnLength == 0 /* vista */ ||
907 broken(is_wow64), /* returns garbage on wow64 */
908 "Inconsistent length %d\n", ReturnLength);
909 }
910
911 static void test_query_process_debug_port(int argc, char **argv)
912 {
913 DWORD_PTR debug_port = 0xdeadbeef;
914 char cmdline[MAX_PATH];
915 PROCESS_INFORMATION pi;
916 STARTUPINFO si = { 0 };
917 NTSTATUS status;
918 BOOL ret;
919
920 sprintf(cmdline, "%s %s %s", argv[0], argv[1], "debuggee");
921
922 si.cb = sizeof(si);
923 ret = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &si, &pi);
924 ok(ret, "CreateProcess failed, last error %#x.\n", GetLastError());
925 if (!ret) return;
926
927 status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
928 NULL, 0, NULL);
929 ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
930
931 status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
932 NULL, sizeof(debug_port), NULL);
933 ok(status == STATUS_INVALID_HANDLE || status == STATUS_ACCESS_VIOLATION,
934 "Expected STATUS_INVALID_HANDLE, got %#x.\n", status);
935
936 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
937 NULL, sizeof(debug_port), NULL);
938 ok(status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
939
940 status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
941 &debug_port, sizeof(debug_port), NULL);
942 ok(status == STATUS_INVALID_HANDLE, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
943
944 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
945 &debug_port, sizeof(debug_port) - 1, NULL);
946 ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
947
948 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
949 &debug_port, sizeof(debug_port) + 1, NULL);
950 ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
951
952 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
953 &debug_port, sizeof(debug_port), NULL);
954 ok(!status, "NtQueryInformationProcess failed, status %#x.\n", status);
955 ok(debug_port == 0, "Expected port 0, got %#lx.\n", debug_port);
956
957 status = pNtQueryInformationProcess(pi.hProcess, ProcessDebugPort,
958 &debug_port, sizeof(debug_port), NULL);
959 ok(!status, "NtQueryInformationProcess failed, status %#x.\n", status);
960 ok(debug_port == ~(DWORD_PTR)0, "Expected port %#lx, got %#lx.\n", ~(DWORD_PTR)0, debug_port);
961
962 for (;;)
963 {
964 DEBUG_EVENT ev;
965
966 ret = WaitForDebugEvent(&ev, INFINITE);
967 ok(ret, "WaitForDebugEvent failed, last error %#x.\n", GetLastError());
968 if (!ret) break;
969
970 if (ev.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break;
971
972 ret = ContinueDebugEvent(ev.dwProcessId, ev.dwThreadId, DBG_CONTINUE);
973 ok(ret, "ContinueDebugEvent failed, last error %#x.\n", GetLastError());
974 if (!ret) break;
975 }
976
977 ret = CloseHandle(pi.hThread);
978 ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
979 ret = CloseHandle(pi.hProcess);
980 ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
981 }
982
983 static void test_query_process_handlecount(void)
984 {
985 NTSTATUS status;
986 ULONG ReturnLength;
987 DWORD handlecount;
988 BYTE buffer[2 * sizeof(DWORD)];
989 HANDLE process;
990
991 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, NULL, sizeof(handlecount), NULL);
992 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
993 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
994
995 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, &handlecount, sizeof(handlecount), NULL);
996 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
997
998 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, &handlecount, 2, &ReturnLength);
999 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
1000
1001 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
1002 if (!process)
1003 {
1004 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
1005 process = GetCurrentProcess();
1006 trace("ProcessHandleCount for current process\n");
1007 }
1008 else
1009 trace("ProcessHandleCount for process with ID : %d\n", one_before_last_pid);
1010
1011 status = pNtQueryInformationProcess( process, ProcessHandleCount, &handlecount, sizeof(handlecount), &ReturnLength);
1012 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1013 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
1014 CloseHandle(process);
1015
1016 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, buffer, sizeof(buffer), &ReturnLength);
1017 ok( status == STATUS_INFO_LENGTH_MISMATCH || status == STATUS_SUCCESS,
1018 "Expected STATUS_INFO_LENGTH_MISMATCH or STATUS_SUCCESS, got %08x\n", status);
1019 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
1020
1021 /* Check if we have some return values */
1022 trace("HandleCount : %d\n", handlecount);
1023 todo_wine
1024 {
1025 ok( handlecount > 0, "Expected some handles, got 0\n");
1026 }
1027 }
1028
1029 static void test_query_process_image_file_name(void)
1030 {
1031 NTSTATUS status;
1032 ULONG ReturnLength;
1033 UNICODE_STRING image_file_name;
1034 void *buffer;
1035 char *file_nameA;
1036 INT len;
1037
1038 status = pNtQueryInformationProcess(NULL, ProcessImageFileName, &image_file_name, sizeof(image_file_name), NULL);
1039 if (status == STATUS_INVALID_INFO_CLASS)
1040 {
1041 win_skip("ProcessImageFileName is not supported\n");
1042 return;
1043 }
1044 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
1045
1046 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, &image_file_name, 2, &ReturnLength);
1047 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
1048
1049 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, &image_file_name, sizeof(image_file_name), &ReturnLength);
1050 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
1051
1052 buffer = HeapAlloc(GetProcessHeap(), 0, ReturnLength);
1053 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, buffer, ReturnLength, &ReturnLength);
1054 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1055 memcpy(&image_file_name, buffer, sizeof(image_file_name));
1056 len = WideCharToMultiByte(CP_ACP, 0, image_file_name.Buffer, image_file_name.Length/sizeof(WCHAR), NULL, 0, NULL, NULL);
1057 file_nameA = HeapAlloc(GetProcessHeap(), 0, len + 1);
1058 WideCharToMultiByte(CP_ACP, 0, image_file_name.Buffer, image_file_name.Length/sizeof(WCHAR), file_nameA, len, NULL, NULL);
1059 file_nameA[len] = '\0';
1060 HeapFree(GetProcessHeap(), 0, buffer);
1061 trace("process image file name: %s\n", file_nameA);
1062 todo_wine ok(strncmp(file_nameA, "\\Device\\", 8) == 0, "Process image name should be an NT path beginning with \\Device\\ (is %s)\n", file_nameA);
1063 HeapFree(GetProcessHeap(), 0, file_nameA);
1064 }
1065
1066 static void test_query_process_debug_object_handle(int argc, char **argv)
1067 {
1068 char cmdline[MAX_PATH];
1069 STARTUPINFO si = {0};
1070 PROCESS_INFORMATION pi;
1071 BOOL ret;
1072 HANDLE debug_object;
1073 NTSTATUS status;
1074
1075 sprintf(cmdline, "%s %s %s", argv[0], argv[1], "debuggee");
1076
1077 si.cb = sizeof(si);
1078 ret = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, DEBUG_PROCESS, NULL,
1079 NULL, &si, &pi);
1080 ok(ret, "CreateProcess failed with last error %u\n", GetLastError());
1081 if (!ret) return;
1082
1083 status = pNtQueryInformationProcess(NULL, ProcessDebugObjectHandle, NULL,
1084 0, NULL);
1085 if (status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED)
1086 {
1087 win_skip("ProcessDebugObjectHandle is not supported\n");
1088 return;
1089 }
1090 ok(status == STATUS_INFO_LENGTH_MISMATCH,
1091 "Expected NtQueryInformationProcess to return STATUS_INFO_LENGTH_MISMATCH, got 0x%08x\n",
1092 status);
1093
1094 status = pNtQueryInformationProcess(NULL, ProcessDebugObjectHandle, NULL,
1095 sizeof(debug_object), NULL);
1096 ok(status == STATUS_INVALID_HANDLE ||
1097 status == STATUS_ACCESS_VIOLATION, /* XP */
1098 "Expected NtQueryInformationProcess to return STATUS_INVALID_HANDLE, got 0x%08x\n", status);
1099
1100 status = pNtQueryInformationProcess(GetCurrentProcess(),
1101 ProcessDebugObjectHandle, NULL, sizeof(debug_object), NULL);
1102 ok(status == STATUS_ACCESS_VIOLATION,
1103 "Expected NtQueryInformationProcess to return STATUS_ACCESS_VIOLATION, got 0x%08x\n", status);
1104
1105 status = pNtQueryInformationProcess(NULL, ProcessDebugObjectHandle,
1106 &debug_object, sizeof(debug_object), NULL);
1107 ok(status == STATUS_INVALID_HANDLE,
1108 "Expected NtQueryInformationProcess to return STATUS_ACCESS_VIOLATION, got 0x%08x\n", status);
1109
1110 status = pNtQueryInformationProcess(GetCurrentProcess(),
1111 ProcessDebugObjectHandle, &debug_object,
1112 sizeof(debug_object) - 1, NULL);
1113 ok(status == STATUS_INFO_LENGTH_MISMATCH,
1114 "Expected NtQueryInformationProcess to return STATUS_INFO_LENGTH_MISMATCH, got 0x%08x\n", status);
1115
1116 status = pNtQueryInformationProcess(GetCurrentProcess(),
1117 ProcessDebugObjectHandle, &debug_object,
1118 sizeof(debug_object) + 1, NULL);
1119 ok(status == STATUS_INFO_LENGTH_MISMATCH,
1120 "Expected NtQueryInformationProcess to return STATUS_INFO_LENGTH_MISMATCH, got 0x%08x\n", status);
1121
1122 debug_object = (HANDLE)0xdeadbeef;
1123 status = pNtQueryInformationProcess(GetCurrentProcess(),
1124 ProcessDebugObjectHandle, &debug_object,
1125 sizeof(debug_object), NULL);
1126 ok(status == STATUS_PORT_NOT_SET,
1127 "Expected NtQueryInformationProcess to return STATUS_PORT_NOT_SET, got 0x%08x\n", status);
1128 ok(debug_object == NULL ||
1129 broken(debug_object == (HANDLE)0xdeadbeef), /* Wow64 */
1130 "Expected debug object handle to be NULL, got %p\n", debug_object);
1131
1132 debug_object = (HANDLE)0xdeadbeef;
1133 status = pNtQueryInformationProcess(pi.hProcess, ProcessDebugObjectHandle,
1134 &debug_object, sizeof(debug_object), NULL);
1135 todo_wine
1136 ok(status == STATUS_SUCCESS,
1137 "Expected NtQueryInformationProcess to return STATUS_SUCCESS, got 0x%08x\n", status);
1138 todo_wine
1139 ok(debug_object != NULL,
1140 "Expected debug object handle to be non-NULL, got %p\n", debug_object);
1141
1142 for (;;)
1143 {
1144 DEBUG_EVENT ev;
1145
1146 ret = WaitForDebugEvent(&ev, INFINITE);
1147 ok(ret, "WaitForDebugEvent failed with last error %u\n", GetLastError());
1148 if (!ret) break;
1149
1150 if (ev.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break;
1151
1152 ret = ContinueDebugEvent(ev.dwProcessId, ev.dwThreadId, DBG_CONTINUE);
1153 ok(ret, "ContinueDebugEvent failed with last error %u\n", GetLastError());
1154 if (!ret) break;
1155 }
1156
1157 ret = CloseHandle(pi.hThread);
1158 ok(ret, "CloseHandle failed with last error %u\n", GetLastError());
1159 ret = CloseHandle(pi.hProcess);
1160 ok(ret, "CloseHandle failed with last error %u\n", GetLastError());
1161 }
1162
1163 static void test_query_process_debug_flags(int argc, char **argv)
1164 {
1165 DWORD debug_flags = 0xdeadbeef;
1166 char cmdline[MAX_PATH];
1167 PROCESS_INFORMATION pi;
1168 STARTUPINFO si = { 0 };
1169 NTSTATUS status;
1170 BOOL ret;
1171
1172 sprintf(cmdline, "%s %s %s", argv[0], argv[1], "debuggee");
1173
1174 si.cb = sizeof(si);
1175 ret = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS, NULL, NULL, &si, &pi);
1176 ok(ret, "CreateProcess failed, last error %#x.\n", GetLastError());
1177 if (!ret) return;
1178
1179 status = pNtQueryInformationProcess(NULL, ProcessDebugFlags,
1180 NULL, 0, NULL);
1181 ok(status == STATUS_INFO_LENGTH_MISMATCH || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
1182
1183 status = pNtQueryInformationProcess(NULL, ProcessDebugFlags,
1184 NULL, sizeof(debug_flags), NULL);
1185 ok(status == STATUS_INVALID_HANDLE || status == STATUS_ACCESS_VIOLATION || broken(status == STATUS_INVALID_INFO_CLASS) /* W7PROX64 (32-bit) */,
1186 "Expected STATUS_INVALID_HANDLE, got %#x.\n", status);
1187
1188 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugFlags,
1189 NULL, sizeof(debug_flags), NULL);
1190 ok(status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
1191
1192 status = pNtQueryInformationProcess(NULL, ProcessDebugFlags,
1193 &debug_flags, sizeof(debug_flags), NULL);
1194 ok(status == STATUS_INVALID_HANDLE || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
1195
1196 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugFlags,
1197 &debug_flags, sizeof(debug_flags) - 1, NULL);
1198 ok(status == STATUS_INFO_LENGTH_MISMATCH || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
1199
1200 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugFlags,
1201 &debug_flags, sizeof(debug_flags) + 1, NULL);
1202 ok(status == STATUS_INFO_LENGTH_MISMATCH || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
1203
1204 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugFlags,
1205 &debug_flags, sizeof(debug_flags), NULL);
1206 ok(!status || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "NtQueryInformationProcess failed, status %#x.\n", status);
1207 ok(debug_flags == TRUE|| broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "Expected flag TRUE, got %x.\n", debug_flags);
1208
1209 status = pNtQueryInformationProcess(pi.hProcess, ProcessDebugFlags,
1210 &debug_flags, sizeof(debug_flags), NULL);
1211 ok(!status || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "NtQueryInformationProcess failed, status %#x.\n", status);
1212 ok(debug_flags == FALSE || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "Expected flag FALSE, got %x.\n", debug_flags);
1213
1214 for (;;)
1215 {
1216 DEBUG_EVENT ev;
1217
1218 ret = WaitForDebugEvent(&ev, INFINITE);
1219 ok(ret, "WaitForDebugEvent failed, last error %#x.\n", GetLastError());
1220 if (!ret) break;
1221
1222 if (ev.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break;
1223
1224 ret = ContinueDebugEvent(ev.dwProcessId, ev.dwThreadId, DBG_CONTINUE);
1225 ok(ret, "ContinueDebugEvent failed, last error %#x.\n", GetLastError());
1226 if (!ret) break;
1227 }
1228
1229 ret = CloseHandle(pi.hThread);
1230 ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
1231 ret = CloseHandle(pi.hProcess);
1232 ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
1233 }
1234
1235 static void test_readvirtualmemory(void)
1236 {
1237 HANDLE process;
1238 NTSTATUS status;
1239 SIZE_T readcount;
1240 static const char teststring[] = "test string";
1241 char buffer[12];
1242
1243 process = OpenProcess(PROCESS_VM_READ, FALSE, GetCurrentProcessId());
1244 ok(process != 0, "Expected to be able to open own process for reading memory\n");
1245
1246 /* normal operation */
1247 status = pNtReadVirtualMemory(process, teststring, buffer, 12, &readcount);
1248 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1249 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
1250 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
1251
1252 /* no number of bytes */
1253 memset(buffer, 0, 12);
1254 status = pNtReadVirtualMemory(process, teststring, buffer, 12, NULL);
1255 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1256 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
1257
1258 /* illegal remote address */
1259 todo_wine{
1260 status = pNtReadVirtualMemory(process, (void *) 0x1234, buffer, 12, &readcount);
1261 ok( status == STATUS_PARTIAL_COPY || broken(status == STATUS_ACCESS_VIOLATION), "Expected STATUS_PARTIAL_COPY, got %08x\n", status);
1262 if (status == STATUS_PARTIAL_COPY)
1263 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
1264 }
1265
1266 /* 0 handle */
1267 status = pNtReadVirtualMemory(0, teststring, buffer, 12, &readcount);
1268 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
1269 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
1270
1271 /* pseudo handle for current process*/
1272 memset(buffer, 0, 12);
1273 status = pNtReadVirtualMemory((HANDLE)-1, teststring, buffer, 12, &readcount);
1274 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1275 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
1276 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
1277
1278 /* illegal local address */
1279 status = pNtReadVirtualMemory(process, teststring, (void *)0x1234, 12, &readcount);
1280 ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
1281 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
1282
1283 CloseHandle(process);
1284 }
1285
1286 static void test_mapprotection(void)
1287 {
1288 HANDLE h;
1289 void* addr;
1290 MEMORY_BASIC_INFORMATION info;
1291 ULONG oldflags, flagsize, flags = MEM_EXECUTE_OPTION_ENABLE;
1292 LARGE_INTEGER size, offset;
1293 NTSTATUS status;
1294 SIZE_T retlen, count;
1295 void (*f)(void);
1296
1297 if (!pNtClose) {
1298 skip("No NtClose ... Win98\n");
1299 return;
1300 }
1301 /* Switch to being a noexec unaware process */
1302 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &oldflags, sizeof (oldflags), &flagsize);
1303 if (status == STATUS_INVALID_PARAMETER) {
1304 skip("Invalid Parameter on ProcessExecuteFlags query?\n");
1305 return;
1306 }
1307 ok( (status == STATUS_SUCCESS) || (status == STATUS_INVALID_INFO_CLASS), "Expected STATUS_SUCCESS, got %08x\n", status);
1308 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &flags, sizeof(flags) );
1309 ok( (status == STATUS_SUCCESS) || (status == STATUS_INVALID_INFO_CLASS), "Expected STATUS_SUCCESS, got %08x\n", status);
1310
1311 size.u.LowPart = 0x1000;
1312 size.u.HighPart = 0;
1313 status = pNtCreateSection ( &h,
1314 STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE | SECTION_MAP_EXECUTE,
1315 NULL,
1316 &size,
1317 PAGE_READWRITE,
1318 SEC_COMMIT | SEC_NOCACHE,
1319 0
1320 );
1321 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1322
1323 offset.u.LowPart = 0;
1324 offset.u.HighPart = 0;
1325 count = 0x1000;
1326 addr = NULL;
1327 status = pNtMapViewOfSection ( h, GetCurrentProcess(), &addr, 0, 0, &offset, &count, ViewShare, 0, PAGE_READWRITE);
1328 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1329 #if defined(__x86_64__) || defined(__i386__)
1330 memset (addr, 0xc3, 1); /* lret ... in both i386 and x86_64 */
1331 trace("trying to execute code in the readwrite only mapped anon file...\n");
1332 f = addr;f();
1333 trace("...done.\n");
1334 #endif
1335
1336 status = pNtQueryVirtualMemory( GetCurrentProcess(), addr, MemoryBasicInformation, &info, sizeof(info), &retlen );
1337 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1338 ok( retlen == sizeof(info), "Expected STATUS_SUCCESS, got %08x\n", status);
1339 ok((info.Protect & ~PAGE_NOCACHE) == PAGE_READWRITE, "addr.Protect is not PAGE_READWRITE, but 0x%x\n", info.Protect);
1340
1341 status = pNtUnmapViewOfSection (GetCurrentProcess(), addr);
1342 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1343 pNtClose (h);
1344
1345 /* Switch back */
1346 pNtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &oldflags, sizeof(oldflags) );
1347 }
1348
1349 static void test_queryvirtualmemory(void)
1350 {
1351 NTSTATUS status;
1352 SIZE_T readcount;
1353 static const char teststring[] = "test string";
1354 static char datatestbuf[42] = "abc";
1355 static char rwtestbuf[42];
1356 MEMORY_BASIC_INFORMATION mbi;
1357 char stackbuf[42];
1358 HMODULE module;
1359
1360 module = GetModuleHandle( "ntdll.dll" );
1361 trace("Check flags of the PE header of NTDLL.DLL at %p\n", module);
1362 status = pNtQueryVirtualMemory(NtCurrentProcess(), module, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1363 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1364 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1365 ok (mbi.AllocationBase == module, "mbi.AllocationBase is 0x%p, expected 0x%p\n", mbi.AllocationBase, module);
1366 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1367 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%x\n", mbi.State, MEM_COMMIT);
1368 ok (mbi.Protect == PAGE_READONLY, "mbi.Protect is 0x%x, expected 0x%x\n", mbi.Protect, PAGE_READONLY);
1369 ok (mbi.Type == MEM_IMAGE, "mbi.Type is 0x%x, expected 0x%x\n", mbi.Type, MEM_IMAGE);
1370
1371 trace("Check flags of a function entry in NTDLL.DLL at %p\n", pNtQueryVirtualMemory);
1372 module = GetModuleHandle( "ntdll.dll" );
1373 status = pNtQueryVirtualMemory(NtCurrentProcess(), pNtQueryVirtualMemory, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1374 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1375 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1376 ok (mbi.AllocationBase == module, "mbi.AllocationBase is 0x%p, expected 0x%p\n", mbi.AllocationBase, module);
1377 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1378 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%x\n", mbi.State, MEM_COMMIT);
1379 ok (mbi.Protect == PAGE_EXECUTE_READ, "mbi.Protect is 0x%x, expected 0x%x\n", mbi.Protect, PAGE_EXECUTE_READ);
1380
1381 trace("Check flags of heap at %p\n", GetProcessHeap());
1382 status = pNtQueryVirtualMemory(NtCurrentProcess(), GetProcessHeap(), MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1383 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1384 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1385 ok (mbi.AllocationProtect == PAGE_READWRITE || mbi.AllocationProtect == PAGE_EXECUTE_READWRITE,
1386 "mbi.AllocationProtect is 0x%x\n", mbi.AllocationProtect);
1387 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%x\n", mbi.State, MEM_COMMIT);
1388 ok (mbi.Protect == PAGE_READWRITE || mbi.Protect == PAGE_EXECUTE_READWRITE,
1389 "mbi.Protect is 0x%x\n", mbi.Protect);
1390
1391 trace("Check flags of stack at %p\n", stackbuf);
1392 status = pNtQueryVirtualMemory(NtCurrentProcess(), stackbuf, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1393 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1394 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1395 ok (mbi.AllocationProtect == PAGE_READWRITE, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_READWRITE);
1396 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%x\n", mbi.State, MEM_COMMIT);
1397 ok (mbi.Protect == PAGE_READWRITE, "mbi.Protect is 0x%x, expected 0x%x\n", mbi.Protect, PAGE_READWRITE);
1398
1399 trace("Check flags of read-only data at %p\n", teststring);
1400 module = GetModuleHandle( NULL );
1401 status = pNtQueryVirtualMemory(NtCurrentProcess(), teststring, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1402 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1403 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1404 ok (mbi.AllocationBase == module, "mbi.AllocationBase is 0x%p, expected 0x%p\n", mbi.AllocationBase, module);
1405 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1406 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%X\n", mbi.State, MEM_COMMIT);
1407 if (mbi.Protect != PAGE_READONLY)
1408 todo_wine ok( mbi.Protect == PAGE_READONLY, "mbi.Protect is 0x%x, expected 0x%X\n", mbi.Protect, PAGE_READONLY);
1409
1410 trace("Check flags of read-write data at %p\n", datatestbuf);
1411 status = pNtQueryVirtualMemory(NtCurrentProcess(), datatestbuf, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1412 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1413 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1414 ok (mbi.AllocationBase == module, "mbi.AllocationBase is 0x%p, expected 0x%p\n", mbi.AllocationBase, module);
1415 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1416 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%X\n", mbi.State, MEM_COMMIT);
1417 ok (mbi.Protect == PAGE_READWRITE || mbi.Protect == PAGE_WRITECOPY,
1418 "mbi.Protect is 0x%x\n", mbi.Protect);
1419
1420 trace("Check flags of read-write uninitialized data (.bss) at %p\n", rwtestbuf);
1421 status = pNtQueryVirtualMemory(NtCurrentProcess(), rwtestbuf, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1422 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1423 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1424 if (mbi.AllocationBase == module)
1425 {
1426 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1427 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%X\n", mbi.State, MEM_COMMIT);
1428 ok (mbi.Protect == PAGE_READWRITE || mbi.Protect == PAGE_WRITECOPY,
1429 "mbi.Protect is 0x%x\n", mbi.Protect);
1430 }
1431 else skip( "bss is outside of module\n" ); /* this can happen on Mac OS */
1432 }
1433
1434 static void test_affinity(void)
1435 {
1436 NTSTATUS status;
1437 PROCESS_BASIC_INFORMATION pbi;
1438 DWORD_PTR proc_affinity, thread_affinity;
1439 THREAD_BASIC_INFORMATION tbi;
1440 SYSTEM_INFO si;
1441
1442 GetSystemInfo(&si);
1443 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL );
1444 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1445 proc_affinity = (DWORD_PTR)pbi.Reserved2[0];
1446 ok( proc_affinity == (1 << si.dwNumberOfProcessors) - 1, "Unexpected process affinity\n" );
1447 proc_affinity = 1 << si.dwNumberOfProcessors;
1448 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1449 ok( status == STATUS_INVALID_PARAMETER,
1450 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1451
1452 proc_affinity = 0;
1453 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1454 ok( status == STATUS_INVALID_PARAMETER,
1455 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1456
1457 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1458 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1459 ok( tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1, "Unexpected thread affinity\n" );
1460 thread_affinity = 1 << si.dwNumberOfProcessors;
1461 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1462 ok( status == STATUS_INVALID_PARAMETER,
1463 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1464 thread_affinity = 0;
1465 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1466 ok( status == STATUS_INVALID_PARAMETER,
1467 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1468
1469 thread_affinity = 1;
1470 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1471 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1472 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1473 ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1474 ok( tbi.AffinityMask == 1, "Unexpected thread affinity\n" );
1475
1476 /* NOTE: Pre-Vista does not recognize the "all processors" flag (all bits set) */
1477 thread_affinity = ~(DWORD_PTR)0;
1478 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1479 ok( broken(status == STATUS_INVALID_PARAMETER) || status == STATUS_SUCCESS,
1480 "Expected STATUS_SUCCESS, got %08x\n", status);
1481
1482 if (si.dwNumberOfProcessors <= 1)
1483 {
1484 skip("only one processor, skipping affinity testing\n");
1485 return;
1486 }
1487
1488 /* Test thread affinity mask resulting from "all processors" flag */
1489 if (status == STATUS_SUCCESS)
1490 {
1491 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1492 ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1493 ok( broken(tbi.AffinityMask == 1) || tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1,
1494 "Unexpected thread affinity\n" );
1495 }
1496 else
1497 skip("Cannot test thread affinity mask for 'all processors' flag\n");
1498
1499 proc_affinity = 2;
1500 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1501 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1502 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL );
1503 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1504 proc_affinity = (DWORD_PTR)pbi.Reserved2[0];
1505 ok( proc_affinity == 2, "Unexpected process affinity\n" );
1506 /* Setting the process affinity changes the thread affinity to match */
1507 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1508 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1509 ok( tbi.AffinityMask == 2, "Unexpected thread affinity\n" );
1510 /* The thread affinity is restricted to the process affinity */
1511 thread_affinity = 1;
1512 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1513 ok( status == STATUS_INVALID_PARAMETER,
1514 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1515
1516 proc_affinity = (1 << si.dwNumberOfProcessors) - 1;
1517 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1518 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1519 /* Resetting the process affinity also resets the thread affinity */
1520 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1521 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1522 ok( tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1,
1523 "Unexpected thread affinity\n" );
1524 }
1525
1526 static void test_NtGetCurrentProcessorNumber(void)
1527 {
1528 NTSTATUS status;
1529 SYSTEM_INFO si;
1530 PROCESS_BASIC_INFORMATION pbi;
1531 THREAD_BASIC_INFORMATION tbi;
1532 DWORD_PTR old_process_mask;
1533 DWORD_PTR old_thread_mask;
1534 DWORD_PTR new_mask;
1535 ULONG current_cpu;
1536 ULONG i;
1537
1538 if (!pNtGetCurrentProcessorNumber) {
1539 win_skip("NtGetCurrentProcessorNumber not available\n");
1540 return;
1541 }
1542
1543 GetSystemInfo(&si);
1544 current_cpu = pNtGetCurrentProcessorNumber();
1545 trace("dwNumberOfProcessors: %d, current processor: %d\n", si.dwNumberOfProcessors, current_cpu);
1546
1547 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
1548 old_process_mask = (DWORD_PTR)pbi.Reserved2[0];
1549 ok(status == STATUS_SUCCESS, "got 0x%x (expected STATUS_SUCCESS)\n", status);
1550
1551 status = pNtQueryInformationThread(GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL);
1552 old_thread_mask = tbi.AffinityMask;
1553 ok(status == STATUS_SUCCESS, "got 0x%x (expected STATUS_SUCCESS)\n", status);
1554
1555 /* allow the test to run on all processors */
1556 new_mask = (1 << si.dwNumberOfProcessors) - 1;
1557 status = pNtSetInformationProcess(GetCurrentProcess(), ProcessAffinityMask, &new_mask, sizeof(new_mask));
1558 ok(status == STATUS_SUCCESS, "got 0x%x (expected STATUS_SUCCESS)\n", status);
1559
1560 for (i = 0; i < si.dwNumberOfProcessors; i++)
1561 {
1562 new_mask = 1 << i;
1563 status = pNtSetInformationThread(GetCurrentThread(), ThreadAffinityMask, &new_mask, sizeof(new_mask));
1564 ok(status == STATUS_SUCCESS, "%d: got 0x%x (expected STATUS_SUCCESS)\n", i, status);
1565
1566 status = pNtQueryInformationThread(GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL);
1567 ok(status == STATUS_SUCCESS, "%d: got 0x%x (expected STATUS_SUCCESS)\n", i, status);
1568
1569 current_cpu = pNtGetCurrentProcessorNumber();
1570 ok((current_cpu == i), "%d (new_mask 0x%lx): running on processor %d (AffinityMask: 0x%lx)\n",
1571 i, new_mask, current_cpu, tbi.AffinityMask);
1572 }
1573
1574 /* restore old values */
1575 status = pNtSetInformationProcess(GetCurrentProcess(), ProcessAffinityMask, &old_process_mask, sizeof(old_process_mask));
1576 ok(status == STATUS_SUCCESS, "got 0x%x (expected STATUS_SUCCESS)\n", status);
1577
1578 status = pNtSetInformationThread(GetCurrentThread(), ThreadAffinityMask, &old_thread_mask, sizeof(old_thread_mask));
1579 ok(status == STATUS_SUCCESS, "got 0x%x (expected STATUS_SUCCESS)\n", status);
1580 }
1581
1582 START_TEST(info)
1583 {
1584 char **argv;
1585 int argc;
1586
1587 if(!InitFunctionPtrs())
1588 return;
1589
1590 argc = winetest_get_mainargs(&argv);
1591 if (argc >= 3) return; /* Child */
1592
1593 /* NtQuerySystemInformation */
1594
1595 /* 0x0 SystemBasicInformation */
1596 trace("Starting test_query_basic()\n");
1597 test_query_basic();
1598
1599 /* 0x1 SystemCpuInformation */
1600 trace("Starting test_query_cpu()\n");
1601 test_query_cpu();
1602
1603 /* 0x2 SystemPerformanceInformation */
1604 trace("Starting test_query_performance()\n");
1605 test_query_performance();
1606
1607 /* 0x3 SystemTimeOfDayInformation */
1608 trace("Starting test_query_timeofday()\n");
1609 test_query_timeofday();
1610
1611 /* 0x5 SystemProcessInformation */
1612 trace("Starting test_query_process()\n");
1613 test_query_process();
1614
1615 /* 0x8 SystemProcessorPerformanceInformation */
1616 trace("Starting test_query_procperf()\n");
1617 test_query_procperf();
1618
1619 /* 0xb SystemModuleInformation */
1620 trace("Starting test_query_module()\n");
1621 test_query_module();
1622
1623 /* 0x10 SystemHandleInformation */
1624 trace("Starting test_query_handle()\n");
1625 test_query_handle();
1626
1627 /* 0x15 SystemCacheInformation */
1628 trace("Starting test_query_cache()\n");
1629 test_query_cache();
1630
1631 /* 0x17 SystemInterruptInformation */
1632 trace("Starting test_query_interrupt()\n");
1633 test_query_interrupt();
1634
1635 /* 0x23 SystemKernelDebuggerInformation */
1636 trace("Starting test_query_kerndebug()\n");
1637 test_query_kerndebug();
1638
1639 /* 0x25 SystemRegistryQuotaInformation */
1640 trace("Starting test_query_regquota()\n");
1641 test_query_regquota();
1642
1643 /* 0x49 SystemLogicalProcessorInformation */
1644 trace("Starting test_query_logicalproc()\n");
1645 test_query_logicalproc();
1646
1647 /* NtPowerInformation */
1648
1649 /* 0xb ProcessorInformation */
1650 trace("Starting test_query_processor_power_info()\n");
1651 test_query_processor_power_info();
1652
1653 /* NtQueryInformationProcess */
1654
1655 /* 0x0 ProcessBasicInformation */
1656 trace("Starting test_query_process_basic()\n");
1657 test_query_process_basic();
1658
1659 /* 0x2 ProcessIoCounters */
1660 trace("Starting test_query_process_io()\n");
1661 test_query_process_io();
1662
1663 /* 0x3 ProcessVmCounters */
1664 trace("Starting test_query_process_vm()\n");
1665 test_query_process_vm();
1666
1667 /* 0x4 ProcessTimes */
1668 trace("Starting test_query_process_times()\n");
1669 test_query_process_times();
1670
1671 /* 0x7 ProcessDebugPort */
1672 trace("Starting test_process_debug_port()\n");
1673 test_query_process_debug_port(argc, argv);
1674
1675 /* 0x14 ProcessHandleCount */
1676 trace("Starting test_query_process_handlecount()\n");
1677 test_query_process_handlecount();
1678
1679 /* 0x1B ProcessImageFileName */
1680 trace("Starting test_query_process_image_file_name()\n");
1681 test_query_process_image_file_name();
1682
1683 /* 0x1E ProcessDebugObjectHandle */
1684 trace("Starting test_query_process_debug_object_handle()\n");
1685 test_query_process_debug_object_handle(argc, argv);
1686
1687 /* 0x1F ProcessDebugFlags */
1688 trace("Starting test_process_debug_flags()\n");
1689 test_query_process_debug_flags(argc, argv);
1690
1691 /* belongs into it's own file */
1692 trace("Starting test_readvirtualmemory()\n");
1693 test_readvirtualmemory();
1694
1695 trace("Starting test_queryvirtualmemory()\n");
1696 test_queryvirtualmemory();
1697
1698 trace("Starting test_mapprotection()\n");
1699 test_mapprotection();
1700
1701 trace("Starting test_affinity()\n");
1702 test_affinity();
1703 test_NtGetCurrentProcessorNumber();
1704 }