Merge trunk head (46467)
[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
24 static NTSTATUS (WINAPI * pNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG);
25 static NTSTATUS (WINAPI * pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
26 static NTSTATUS (WINAPI * pNtReadVirtualMemory)(HANDLE, const void*, void*, SIZE_T, SIZE_T*);
27
28 /* one_before_last_pid is used to be able to compare values of a still running process
29 with the output of the test_query_process_times and test_query_process_handlecount tests.
30 */
31 static DWORD one_before_last_pid = 0;
32
33 #define NTDLL_GET_PROC(func) do { \
34 p ## func = (void*)GetProcAddress(hntdll, #func); \
35 if(!p ## func) { \
36 trace("GetProcAddress(%s) failed\n", #func); \
37 return FALSE; \
38 } \
39 } while(0)
40
41 static BOOL InitFunctionPtrs(void)
42 {
43 /* All needed functions are NT based, so using GetModuleHandle is a good check */
44 HMODULE hntdll = GetModuleHandle("ntdll");
45 if (!hntdll)
46 {
47 skip("Not running on NT\n");
48 return FALSE;
49 }
50
51 NTDLL_GET_PROC(NtQuerySystemInformation);
52 NTDLL_GET_PROC(NtQueryInformationProcess);
53 NTDLL_GET_PROC(NtReadVirtualMemory);
54
55 return TRUE;
56 }
57
58 static void test_query_basic(void)
59 {
60 NTSTATUS status;
61 ULONG ReturnLength;
62 SYSTEM_BASIC_INFORMATION sbi;
63
64 /* This test also covers some basic parameter testing that should be the same for
65 * every information class
66 */
67
68 /* Use a nonexistent info class */
69 trace("Check nonexistent info class\n");
70 status = pNtQuerySystemInformation(-1, NULL, 0, NULL);
71 ok( status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* vista */,
72 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status);
73
74 /* Use an existing class but with a zero-length buffer */
75 trace("Check zero-length buffer\n");
76 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, 0, NULL);
77 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
78
79 /* Use an existing class, correct length but no SystemInformation buffer */
80 trace("Check no SystemInformation buffer\n");
81 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, sizeof(sbi), NULL);
82 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_PARAMETER /* vista */,
83 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER, got %08x\n", status);
84
85 /* Use a existing class, correct length, a pointer to a buffer but no ReturnLength pointer */
86 trace("Check no ReturnLength pointer\n");
87 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), NULL);
88 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
89
90 /* Check a too large buffer size */
91 trace("Check a too large buffer size\n");
92 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi) * 2, &ReturnLength);
93 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
94
95 /* Finally some correct calls */
96 trace("Check with correct parameters\n");
97 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
98 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
99 ok( sizeof(sbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
100
101 /* Check if we have some return values */
102 trace("Number of Processors : %d\n", sbi.NumberOfProcessors);
103 ok( sbi.NumberOfProcessors > 0, "Expected more than 0 processors, got %d\n", sbi.NumberOfProcessors);
104 }
105
106 static void test_query_cpu(void)
107 {
108 DWORD status;
109 ULONG ReturnLength;
110 SYSTEM_CPU_INFORMATION sci;
111
112 status = pNtQuerySystemInformation(SystemCpuInformation, &sci, sizeof(sci), &ReturnLength);
113 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
114 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
115
116 /* Check if we have some return values */
117 trace("Processor FeatureSet : %08x\n", sci.FeatureSet);
118 ok( sci.FeatureSet != 0, "Expected some features for this processor, got %08x\n", sci.FeatureSet);
119 }
120
121 static void test_query_performance(void)
122 {
123 NTSTATUS status;
124 ULONG ReturnLength;
125 SYSTEM_PERFORMANCE_INFORMATION spi;
126
127 status = pNtQuerySystemInformation(SystemPerformanceInformation, &spi, 0, &ReturnLength);
128 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
129
130 status = pNtQuerySystemInformation(SystemPerformanceInformation, &spi, sizeof(spi), &ReturnLength);
131 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
132 ok( sizeof(spi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
133
134 status = pNtQuerySystemInformation(SystemPerformanceInformation, &spi, sizeof(spi) + 2, &ReturnLength);
135 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
136 ok( sizeof(spi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
137
138 /* Not return values yet, as struct members are unknown */
139 }
140
141 static void test_query_timeofday(void)
142 {
143 NTSTATUS status;
144 ULONG ReturnLength;
145
146 /* Copy of our winternl.h structure turned into a private one */
147 typedef struct _SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE {
148 LARGE_INTEGER liKeBootTime;
149 LARGE_INTEGER liKeSystemTime;
150 LARGE_INTEGER liExpTimeZoneBias;
151 ULONG uCurrentTimeZoneId;
152 DWORD dwUnknown1[5];
153 } SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE, *PSYSTEM_TIMEOFDAY_INFORMATION_PRIVATE;
154
155 SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE sti;
156
157 /* The struct size for NT (32 bytes) and Win2K/XP (48 bytes) differ.
158 *
159 * Windows 2000 and XP return STATUS_INFO_LENGTH_MISMATCH if the given buffer size is greater
160 * then 48 and 0 otherwise
161 * Windows NT returns STATUS_INFO_LENGTH_MISMATCH when the given buffer size is not correct
162 * and 0 otherwise
163 *
164 * Windows 2000 and XP copy the given buffer size into the provided buffer, if the return code is STATUS_SUCCESS
165 * NT only fills the buffer if the return code is STATUS_SUCCESS
166 *
167 */
168
169 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
170
171 if (status == STATUS_INFO_LENGTH_MISMATCH)
172 {
173 trace("Windows version is NT, we have to cater for differences with W2K/WinXP\n");
174
175 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
176 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
177 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
178
179 sti.uCurrentTimeZoneId = 0xdeadbeef;
180 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 28, &ReturnLength);
181 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
182
183 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
184 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
185 ok( 32 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
186 }
187 else
188 {
189 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
190 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
191 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
192
193 sti.uCurrentTimeZoneId = 0xdeadbeef;
194 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 24, &ReturnLength);
195 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
196 ok( 24 == ReturnLength, "ReturnLength should be 24, it is (%d)\n", ReturnLength);
197 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
198
199 sti.uCurrentTimeZoneId = 0xdeadbeef;
200 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
201 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
202 ok( 32 == ReturnLength, "ReturnLength should be 32, it is (%d)\n", ReturnLength);
203 ok( 0xdeadbeef != sti.uCurrentTimeZoneId, "Buffer should have been partially filled\n");
204
205 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 49, &ReturnLength);
206 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
207 ok( ReturnLength == 0 || ReturnLength == sizeof(sti) /* vista */,
208 "ReturnLength should be 0, it is (%d)\n", ReturnLength);
209
210 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
211 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
212 ok( sizeof(sti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
213 }
214
215 /* Check if we have some return values */
216 trace("uCurrentTimeZoneId : (%d)\n", sti.uCurrentTimeZoneId);
217 }
218
219 static void test_query_process(void)
220 {
221 NTSTATUS status;
222 DWORD last_pid;
223 ULONG ReturnLength;
224 int i = 0, k = 0;
225 int is_nt = 0;
226 SYSTEM_BASIC_INFORMATION sbi;
227
228 /* Copy of our winternl.h structure turned into a private one */
229 typedef struct _SYSTEM_PROCESS_INFORMATION_PRIVATE {
230 DWORD dwOffset;
231 DWORD dwThreadCount;
232 DWORD dwUnknown1[6];
233 FILETIME ftCreationTime;
234 FILETIME ftUserTime;
235 FILETIME ftKernelTime;
236 UNICODE_STRING ProcessName;
237 DWORD dwBasePriority;
238 DWORD dwProcessID;
239 DWORD dwParentProcessID;
240 DWORD dwHandleCount;
241 DWORD dwUnknown3;
242 DWORD dwUnknown4;
243 VM_COUNTERS vmCounters;
244 IO_COUNTERS ioCounters;
245 SYSTEM_THREAD_INFORMATION ti[1];
246 } SYSTEM_PROCESS_INFORMATION_PRIVATE, *PSYSTEM_PROCESS_INFORMATION_PRIVATE;
247
248 ULONG SystemInformationLength = sizeof(SYSTEM_PROCESS_INFORMATION_PRIVATE);
249 SYSTEM_PROCESS_INFORMATION_PRIVATE *spi, *spi_buf = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
250
251 /* Only W2K3 returns the needed length, the rest returns 0, so we have to loop */
252
253 for (;;)
254 {
255 status = pNtQuerySystemInformation(SystemProcessInformation, spi_buf, SystemInformationLength, &ReturnLength);
256
257 if (status != STATUS_INFO_LENGTH_MISMATCH) break;
258
259 spi_buf = HeapReAlloc(GetProcessHeap(), 0, spi_buf , SystemInformationLength *= 2);
260 }
261 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
262 spi = spi_buf;
263
264 /* Get the first dwOffset, from this we can deduce the OS version we're running
265 *
266 * W2K/WinXP/W2K3:
267 * dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
268 * NT:
269 * dwOffset for a process is 136 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
270 * Wine (with every windows version):
271 * dwOffset for a process is 0 if just this test is running
272 * dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION) +
273 * ProcessName.MaximumLength
274 * if more wine processes are running
275 *
276 * Note : On windows the first process is in fact the Idle 'process' with a thread for every processor
277 */
278
279 pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
280
281 is_nt = ( spi->dwOffset - (sbi.NumberOfProcessors * sizeof(SYSTEM_THREAD_INFORMATION)) == 136);
282
283 if (is_nt) skip("Windows version is NT, we will skip thread tests\n");
284
285 /* Check if we have some return values
286 *
287 * On windows there will be several processes running (Including the always present Idle and System)
288 * On wine we only have one (if this test is the only wine process running)
289 */
290
291 /* Loop through the processes */
292
293 for (;;)
294 {
295 i++;
296
297 last_pid = spi->dwProcessID;
298
299 ok( spi->dwThreadCount > 0, "Expected some threads for this process, got 0\n");
300
301 /* Loop through the threads, skip NT4 for now */
302
303 if (!is_nt)
304 {
305 DWORD j;
306 for ( j = 0; j < spi->dwThreadCount; j++)
307 {
308 k++;
309 ok ( spi->ti[j].dwOwningPID == spi->dwProcessID,
310 "The owning pid of the thread (%d) doesn't equal the pid (%d) of the process\n",
311 spi->ti[j].dwOwningPID, spi->dwProcessID);
312 }
313 }
314
315 if (!spi->dwOffset) break;
316
317 one_before_last_pid = last_pid;
318
319 spi = (SYSTEM_PROCESS_INFORMATION_PRIVATE*)((char*)spi + spi->dwOffset);
320 }
321 trace("Total number of running processes : %d\n", i);
322 if (!is_nt) trace("Total number of running threads : %d\n", k);
323
324 if (one_before_last_pid == 0) one_before_last_pid = last_pid;
325
326 HeapFree( GetProcessHeap(), 0, spi_buf);
327 }
328
329 static void test_query_procperf(void)
330 {
331 NTSTATUS status;
332 ULONG ReturnLength;
333 ULONG NeededLength;
334 SYSTEM_BASIC_INFORMATION sbi;
335 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi;
336
337 /* Find out the number of processors */
338 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
339 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
340
341 sppi = HeapAlloc(GetProcessHeap(), 0, NeededLength);
342
343 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, 0, &ReturnLength);
344 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
345
346 /* Try it for 1 processor */
347 sppi->KernelTime.QuadPart = 0xdeaddead;
348 sppi->UserTime.QuadPart = 0xdeaddead;
349 sppi->IdleTime.QuadPart = 0xdeaddead;
350 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi,
351 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION), &ReturnLength);
352 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
353 ok( sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) == ReturnLength,
354 "Inconsistent length %d\n", ReturnLength);
355 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
356 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
357 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
358
359 /* Try it for all processors */
360 sppi->KernelTime.QuadPart = 0xdeaddead;
361 sppi->UserTime.QuadPart = 0xdeaddead;
362 sppi->IdleTime.QuadPart = 0xdeaddead;
363 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength, &ReturnLength);
364 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
365 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
366 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
367 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
368 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
369
370 /* A too large given buffer size */
371 sppi = HeapReAlloc(GetProcessHeap(), 0, sppi , NeededLength + 2);
372 sppi->KernelTime.QuadPart = 0xdeaddead;
373 sppi->UserTime.QuadPart = 0xdeaddead;
374 sppi->IdleTime.QuadPart = 0xdeaddead;
375 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength + 2, &ReturnLength);
376 ok( status == STATUS_SUCCESS || status == STATUS_INFO_LENGTH_MISMATCH /* vista */,
377 "Expected STATUS_SUCCESS or STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
378 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
379 if (status == STATUS_SUCCESS)
380 {
381 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
382 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
383 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
384 }
385 else /* vista and 2008 */
386 {
387 ok (sppi->KernelTime.QuadPart == 0xdeaddead, "KernelTime changed\n");
388 ok (sppi->UserTime.QuadPart == 0xdeaddead, "UserTime changed\n");
389 ok (sppi->IdleTime.QuadPart == 0xdeaddead, "IdleTime changed\n");
390 }
391
392 HeapFree( GetProcessHeap(), 0, sppi);
393 }
394
395 static void test_query_module(void)
396 {
397 NTSTATUS status;
398 ULONG ReturnLength;
399 ULONG ModuleCount, i;
400
401 ULONG SystemInformationLength = sizeof(SYSTEM_MODULE_INFORMATION);
402 SYSTEM_MODULE_INFORMATION* smi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
403 SYSTEM_MODULE* sm;
404
405 /* Request the needed length */
406 status = pNtQuerySystemInformation(SystemModuleInformation, smi, 0, &ReturnLength);
407 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
408 ok( ReturnLength > 0, "Expected a ReturnLength to show the needed length\n");
409
410 SystemInformationLength = ReturnLength;
411 smi = HeapReAlloc(GetProcessHeap(), 0, smi , SystemInformationLength);
412 status = pNtQuerySystemInformation(SystemModuleInformation, smi, SystemInformationLength, &ReturnLength);
413 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
414
415 ModuleCount = smi->ModulesCount;
416 sm = &smi->Modules[0];
417 /* our implementation is a stub for now */
418 ok( ModuleCount > 0, "Expected some modules to be loaded\n");
419
420 /* Loop through all the modules/drivers, Wine doesn't get here (yet) */
421 for (i = 0; i < ModuleCount ; i++)
422 {
423 ok( i == sm->Id, "Id (%d) should have matched %u\n", sm->Id, i);
424 sm++;
425 }
426
427 HeapFree( GetProcessHeap(), 0, smi);
428 }
429
430 static void test_query_handle(void)
431 {
432 NTSTATUS status;
433 ULONG ReturnLength;
434 ULONG SystemInformationLength = sizeof(SYSTEM_HANDLE_INFORMATION);
435 SYSTEM_HANDLE_INFORMATION* shi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
436
437 /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
438 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
439 todo_wine ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
440
441 SystemInformationLength = ReturnLength;
442 shi = HeapReAlloc(GetProcessHeap(), 0, shi , SystemInformationLength);
443 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
444 if (status != STATUS_INFO_LENGTH_MISMATCH) /* vista */
445 {
446 ok( status == STATUS_SUCCESS,
447 "Expected STATUS_SUCCESS, got %08x\n", status);
448
449 /* Check if we have some return values */
450 trace("Number of Handles : %d\n", shi->Count);
451 todo_wine
452 {
453 /* our implementation is a stub for now */
454 ok( shi->Count > 1, "Expected more than 1 handles, got (%d)\n", shi->Count);
455 }
456 }
457 HeapFree( GetProcessHeap(), 0, shi);
458 }
459
460 static void test_query_cache(void)
461 {
462 NTSTATUS status;
463 ULONG ReturnLength;
464 SYSTEM_CACHE_INFORMATION sci;
465
466 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, 0, &ReturnLength);
467 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
468
469 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci), &ReturnLength);
470 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
471 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
472
473 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci) + 2, &ReturnLength);
474 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
475 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
476 }
477
478 static void test_query_interrupt(void)
479 {
480 NTSTATUS status;
481 ULONG ReturnLength;
482 ULONG NeededLength;
483 SYSTEM_BASIC_INFORMATION sbi;
484 SYSTEM_INTERRUPT_INFORMATION* sii;
485
486 /* Find out the number of processors */
487 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
488 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_INTERRUPT_INFORMATION);
489
490 sii = HeapAlloc(GetProcessHeap(), 0, NeededLength);
491
492 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, 0, &ReturnLength);
493 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
494
495 /* Try it for all processors */
496 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, NeededLength, &ReturnLength);
497 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
498
499 /* Windows XP and W2K3 (and others?) always return 0 for the ReturnLength
500 * No test added for this as it's highly unlikely that an app depends on this
501 */
502
503 HeapFree( GetProcessHeap(), 0, sii);
504 }
505
506 static void test_query_kerndebug(void)
507 {
508 NTSTATUS status;
509 ULONG ReturnLength;
510 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
511
512 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, 0, &ReturnLength);
513 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
514
515 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi), &ReturnLength);
516 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
517 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
518
519 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi) + 2, &ReturnLength);
520 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
521 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
522 }
523
524 static void test_query_regquota(void)
525 {
526 NTSTATUS status;
527 ULONG ReturnLength;
528 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
529
530 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, 0, &ReturnLength);
531 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
532
533 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi), &ReturnLength);
534 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
535 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
536
537 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi) + 2, &ReturnLength);
538 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
539 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
540 }
541
542 static void test_query_process_basic(void)
543 {
544 NTSTATUS status;
545 ULONG ReturnLength;
546
547 typedef struct _PROCESS_BASIC_INFORMATION_PRIVATE {
548 DWORD ExitStatus;
549 DWORD PebBaseAddress;
550 DWORD AffinityMask;
551 DWORD BasePriority;
552 ULONG UniqueProcessId;
553 ULONG InheritedFromUniqueProcessId;
554 } PROCESS_BASIC_INFORMATION_PRIVATE, *PPROCESS_BASIC_INFORMATION_PRIVATE;
555
556 PROCESS_BASIC_INFORMATION_PRIVATE pbi;
557
558 /* This test also covers some basic parameter testing that should be the same for
559 * every information class
560 */
561
562 /* Use a nonexistent info class */
563 trace("Check nonexistent info class\n");
564 status = pNtQueryInformationProcess(NULL, -1, NULL, 0, NULL);
565 ok( status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* vista */,
566 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status);
567
568 /* Do not give a handle and buffer */
569 trace("Check NULL handle and buffer and zero-length buffersize\n");
570 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, 0, NULL);
571 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
572
573 /* Use a correct info class and buffer size, but still no handle and buffer */
574 trace("Check NULL handle and buffer\n");
575 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, sizeof(pbi), NULL);
576 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
577 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
578
579 /* Use a correct info class and buffer size, but still no handle */
580 trace("Check NULL handle\n");
581 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
582 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
583
584 /* Use a greater buffer size */
585 trace("Check NULL handle and too large buffersize\n");
586 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi) * 2, NULL);
587 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
588
589 /* Use no ReturnLength */
590 trace("Check NULL ReturnLength\n");
591 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
592 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
593
594 /* Finally some correct calls */
595 trace("Check with correct parameters\n");
596 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), &ReturnLength);
597 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
598 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
599
600 /* Everything is correct except a too large buffersize */
601 trace("Too large buffersize\n");
602 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi) * 2, &ReturnLength);
603 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
604 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
605
606 /* Check if we have some return values */
607 trace("ProcessID : %d\n", pbi.UniqueProcessId);
608 ok( pbi.UniqueProcessId > 0, "Expected a ProcessID > 0, got 0\n");
609 }
610
611 static void test_query_process_vm(void)
612 {
613 NTSTATUS status;
614 ULONG ReturnLength;
615 VM_COUNTERS pvi;
616
617 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, NULL, sizeof(pvi), NULL);
618 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
619 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
620
621 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, &pvi, sizeof(pvi), NULL);
622 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
623
624 /* Windows XP and W2K3 will report success for a size of 44 AND 48 !
625 Windows W2K will only report success for 44.
626 For now we only care for 44, which is sizeof(VM_COUNTERS)
627 If an app depends on it, we have to implement this in ntdll/process.c
628 */
629
630 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 24, &ReturnLength);
631 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
632
633 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, sizeof(pvi), &ReturnLength);
634 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
635 ok( sizeof(pvi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
636
637 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 46, &ReturnLength);
638 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
639 ok( sizeof(pvi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
640
641 /* Check if we have some return values */
642 trace("WorkingSetSize : %ld\n", pvi.WorkingSetSize);
643 todo_wine
644 {
645 ok( pvi.WorkingSetSize > 0, "Expected a WorkingSetSize > 0\n");
646 }
647 }
648
649 static void test_query_process_io(void)
650 {
651 NTSTATUS status;
652 ULONG ReturnLength;
653 IO_COUNTERS pii;
654
655 /* NT4 doesn't support this information class, so check for it */
656 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
657 if (status == STATUS_NOT_SUPPORTED)
658 {
659 skip("ProcessIoCounters information class is not supported\n");
660 return;
661 }
662
663 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, NULL, sizeof(pii), NULL);
664 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
665 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
666
667 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, &pii, sizeof(pii), NULL);
668 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
669
670 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, 24, &ReturnLength);
671 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
672
673 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
674 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
675 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
676
677 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii) * 2, &ReturnLength);
678 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
679 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
680
681 /* Check if we have some return values */
682 trace("OtherOperationCount : 0x%x%08x\n", (DWORD)(pii.OtherOperationCount >> 32), (DWORD)pii.OtherOperationCount);
683 todo_wine
684 {
685 ok( pii.OtherOperationCount > 0, "Expected an OtherOperationCount > 0\n");
686 }
687 }
688
689 static void test_query_process_times(void)
690 {
691 NTSTATUS status;
692 ULONG ReturnLength;
693 HANDLE process;
694 SYSTEMTIME UTC, Local;
695 KERNEL_USER_TIMES spti;
696
697 status = pNtQueryInformationProcess(NULL, ProcessTimes, NULL, sizeof(spti), NULL);
698 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
699 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
700
701 status = pNtQueryInformationProcess(NULL, ProcessTimes, &spti, sizeof(spti), NULL);
702 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
703
704 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, 24, &ReturnLength);
705 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
706
707 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
708 if (!process)
709 {
710 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
711 process = GetCurrentProcess();
712 trace("ProcessTimes for current process\n");
713 }
714 else
715 trace("ProcessTimes for process with ID : %d\n", one_before_last_pid);
716
717 status = pNtQueryInformationProcess( process, ProcessTimes, &spti, sizeof(spti), &ReturnLength);
718 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
719 ok( sizeof(spti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
720 CloseHandle(process);
721
722 FileTimeToSystemTime((const FILETIME *)&spti.CreateTime, &UTC);
723 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
724 trace("CreateTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
725 Local.wHour, Local.wMinute, Local.wSecond);
726
727 FileTimeToSystemTime((const FILETIME *)&spti.ExitTime, &UTC);
728 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
729 trace("ExitTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
730 Local.wHour, Local.wMinute, Local.wSecond);
731
732 FileTimeToSystemTime((const FILETIME *)&spti.KernelTime, &Local);
733 trace("KernelTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
734
735 FileTimeToSystemTime((const FILETIME *)&spti.UserTime, &Local);
736 trace("UserTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
737
738 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, sizeof(spti) * 2, &ReturnLength);
739 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
740 ok( sizeof(spti) == ReturnLength || ReturnLength == 0 /* vista */,
741 "Inconsistent length %d\n", ReturnLength);
742 }
743
744 static void test_query_process_handlecount(void)
745 {
746 NTSTATUS status;
747 ULONG ReturnLength;
748 DWORD handlecount;
749 HANDLE process;
750
751 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, NULL, sizeof(handlecount), NULL);
752 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
753 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
754
755 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, &handlecount, sizeof(handlecount), NULL);
756 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
757
758 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, &handlecount, 2, &ReturnLength);
759 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
760
761 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
762 if (!process)
763 {
764 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
765 process = GetCurrentProcess();
766 trace("ProcessHandleCount for current process\n");
767 }
768 else
769 trace("ProcessHandleCount for process with ID : %d\n", one_before_last_pid);
770
771 status = pNtQueryInformationProcess( process, ProcessHandleCount, &handlecount, sizeof(handlecount), &ReturnLength);
772 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
773 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
774 CloseHandle(process);
775
776 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, &handlecount, sizeof(handlecount) * 2, &ReturnLength);
777 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
778 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
779
780 /* Check if we have some return values */
781 trace("HandleCount : %d\n", handlecount);
782 todo_wine
783 {
784 ok( handlecount > 0, "Expected some handles, got 0\n");
785 }
786 }
787
788 static void test_query_process_image_file_name(void)
789 {
790 NTSTATUS status;
791 ULONG ReturnLength;
792 UNICODE_STRING image_file_name;
793 void *buffer;
794 char *file_nameA;
795 INT len;
796
797 status = pNtQueryInformationProcess(NULL, ProcessImageFileName, &image_file_name, sizeof(image_file_name), NULL);
798 if (status == STATUS_INVALID_INFO_CLASS)
799 {
800 skip("ProcessImageFileName is not supported\n");
801 return;
802 }
803 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
804
805 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, &image_file_name, 2, &ReturnLength);
806 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
807
808 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, &image_file_name, sizeof(image_file_name), &ReturnLength);
809 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
810
811 buffer = HeapAlloc(GetProcessHeap(), 0, ReturnLength);
812 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, buffer, ReturnLength, &ReturnLength);
813 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
814 memcpy(&image_file_name, buffer, sizeof(image_file_name));
815 len = WideCharToMultiByte(CP_ACP, 0, image_file_name.Buffer, image_file_name.Length/sizeof(WCHAR), NULL, 0, NULL, NULL);
816 file_nameA = HeapAlloc(GetProcessHeap(), 0, len + 1);
817 WideCharToMultiByte(CP_ACP, 0, image_file_name.Buffer, image_file_name.Length/sizeof(WCHAR), file_nameA, len, NULL, NULL);
818 file_nameA[len] = '\0';
819 HeapFree(GetProcessHeap(), 0, buffer);
820 trace("process image file name: %s\n", file_nameA);
821 HeapFree(GetProcessHeap(), 0, file_nameA);
822 }
823
824
825 static void test_readvirtualmemory(void)
826 {
827 HANDLE process;
828 NTSTATUS status;
829 SIZE_T readcount;
830 static const char teststring[] = "test string";
831 char buffer[12];
832
833 process = OpenProcess(PROCESS_VM_READ, FALSE, GetCurrentProcessId());
834 ok(process != 0, "Expected to be able to open own process for reading memory\n");
835
836 /* normal operation */
837 status = pNtReadVirtualMemory(process, teststring, buffer, 12, &readcount);
838 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
839 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
840 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
841
842 /* no number of bytes */
843 memset(buffer, 0, 12);
844 status = pNtReadVirtualMemory(process, teststring, buffer, 12, NULL);
845 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
846 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
847
848 /* illegal remote address */
849 todo_wine{
850 status = pNtReadVirtualMemory(process, (void *) 0x1234, buffer, 12, &readcount);
851 ok( status == STATUS_PARTIAL_COPY || broken(status == STATUS_ACCESS_VIOLATION), "Expected STATUS_PARTIAL_COPY, got %08x\n", status);
852 if (status == STATUS_PARTIAL_COPY)
853 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
854 }
855
856 /* 0 handle */
857 status = pNtReadVirtualMemory(0, teststring, buffer, 12, &readcount);
858 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
859 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
860
861 /* pseudo handle for current process*/
862 memset(buffer, 0, 12);
863 status = pNtReadVirtualMemory((HANDLE)-1, teststring, buffer, 12, &readcount);
864 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
865 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
866 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
867
868 /* this test currently crashes wine with "wine client error:<process id>: read: Bad address"
869 * because the reply from wine server is directly read into the buffer and that fails with EFAULT
870 */
871 /* illegal local address */
872 /*status = pNtReadVirtualMemory(process, teststring, (void *)0x1234, 12, &readcount);
873 ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08lx\n", status);
874 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
875 */
876
877 CloseHandle(process);
878 }
879
880 START_TEST(info)
881 {
882 if(!InitFunctionPtrs())
883 return;
884
885 /* NtQuerySystemInformation */
886
887 /* 0x0 SystemBasicInformation */
888 trace("Starting test_query_basic()\n");
889 test_query_basic();
890
891 /* 0x1 SystemCpuInformation */
892 trace("Starting test_query_cpu()\n");
893 test_query_cpu();
894
895 /* 0x2 SystemPerformanceInformation */
896 trace("Starting test_query_performance()\n");
897 test_query_performance();
898
899 /* 0x3 SystemTimeOfDayInformation */
900 trace("Starting test_query_timeofday()\n");
901 test_query_timeofday();
902
903 /* 0x5 SystemProcessInformation */
904 trace("Starting test_query_process()\n");
905 test_query_process();
906
907 /* 0x8 SystemProcessorPerformanceInformation */
908 trace("Starting test_query_procperf()\n");
909 test_query_procperf();
910
911 /* 0xb SystemModuleInformation */
912 trace("Starting test_query_module()\n");
913 test_query_module();
914
915 /* 0x10 SystemHandleInformation */
916 trace("Starting test_query_handle()\n");
917 test_query_handle();
918
919 /* 0x15 SystemCacheInformation */
920 trace("Starting test_query_cache()\n");
921 test_query_cache();
922
923 /* 0x17 SystemInterruptInformation */
924 trace("Starting test_query_interrupt()\n");
925 test_query_interrupt();
926
927 /* 0x23 SystemKernelDebuggerInformation */
928 trace("Starting test_query_kerndebug()\n");
929 test_query_kerndebug();
930
931 /* 0x25 SystemRegistryQuotaInformation */
932 trace("Starting test_query_regquota()\n");
933 test_query_regquota();
934
935 /* NtQueryInformationProcess */
936
937 /* 0x0 ProcessBasicInformation */
938 trace("Starting test_query_process_basic()\n");
939 test_query_process_basic();
940
941 /* 0x2 ProcessIoCounters */
942 trace("Starting test_query_process_io()\n");
943 test_query_process_io();
944
945 /* 0x3 ProcessVmCounters */
946 trace("Starting test_query_process_vm()\n");
947 test_query_process_vm();
948
949 /* 0x4 ProcessTimes */
950 trace("Starting test_query_process_times()\n");
951 test_query_process_times();
952
953 /* 0x14 ProcessHandleCount */
954 trace("Starting test_query_process_handlecount()\n");
955 test_query_process_handlecount();
956
957 /* 27 ProcessImageFileName */
958 trace("Starting test_query_process_image_file_name()\n");
959 test_query_process_image_file_name();
960
961 /* belongs into it's own file */
962 trace("Starting test_readvirtualmemory()\n");
963 test_readvirtualmemory();
964 }