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