push f47c376d7304fae45f226e699c8842fac9cae4ef
[wine/hacks.git] / dlls / ntdll / tests / info.c
blob55b449825c1053b545703e99071f13ffff2a1d0e
1 /* Unit test suite for *Information* Registry API functions
3 * Copyright 2005 Paul Vriens
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.
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.
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
21 #include "ntdll_test.h"
22 #include <winnls.h>
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 * pNtQueryInformationThread)(HANDLE, THREADINFOCLASS, PVOID, ULONG, PULONG);
27 static NTSTATUS (WINAPI * pNtSetInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG);
28 static NTSTATUS (WINAPI * pNtSetInformationThread)(HANDLE, THREADINFOCLASS, PVOID, ULONG);
29 static NTSTATUS (WINAPI * pNtReadVirtualMemory)(HANDLE, const void*, void*, SIZE_T, SIZE_T*);
31 /* one_before_last_pid is used to be able to compare values of a still running process
32 with the output of the test_query_process_times and test_query_process_handlecount tests.
34 static DWORD one_before_last_pid = 0;
36 #define NTDLL_GET_PROC(func) do { \
37 p ## func = (void*)GetProcAddress(hntdll, #func); \
38 if(!p ## func) { \
39 trace("GetProcAddress(%s) failed\n", #func); \
40 return FALSE; \
41 } \
42 } while(0)
44 static BOOL InitFunctionPtrs(void)
46 /* All needed functions are NT based, so using GetModuleHandle is a good check */
47 HMODULE hntdll = GetModuleHandle("ntdll");
48 if (!hntdll)
50 skip("Not running on NT\n");
51 return FALSE;
54 NTDLL_GET_PROC(NtQuerySystemInformation);
55 NTDLL_GET_PROC(NtQueryInformationProcess);
56 NTDLL_GET_PROC(NtQueryInformationThread);
57 NTDLL_GET_PROC(NtSetInformationProcess);
58 NTDLL_GET_PROC(NtSetInformationThread);
59 NTDLL_GET_PROC(NtReadVirtualMemory);
61 return TRUE;
64 static void test_query_basic(void)
66 NTSTATUS status;
67 ULONG ReturnLength;
68 SYSTEM_BASIC_INFORMATION sbi;
70 /* This test also covers some basic parameter testing that should be the same for
71 * every information class
74 /* Use a nonexistent info class */
75 trace("Check nonexistent info class\n");
76 status = pNtQuerySystemInformation(-1, NULL, 0, NULL);
77 ok( status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* vista */,
78 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status);
80 /* Use an existing class but with a zero-length buffer */
81 trace("Check zero-length buffer\n");
82 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, 0, NULL);
83 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
85 /* Use an existing class, correct length but no SystemInformation buffer */
86 trace("Check no SystemInformation buffer\n");
87 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, sizeof(sbi), NULL);
88 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_PARAMETER /* vista */,
89 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER, got %08x\n", status);
91 /* Use a existing class, correct length, a pointer to a buffer but no ReturnLength pointer */
92 trace("Check no ReturnLength pointer\n");
93 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), NULL);
94 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
96 /* Check a too large buffer size */
97 trace("Check a too large buffer size\n");
98 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi) * 2, &ReturnLength);
99 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
101 /* Finally some correct calls */
102 trace("Check with correct parameters\n");
103 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
104 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
105 ok( sizeof(sbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
107 /* Check if we have some return values */
108 trace("Number of Processors : %d\n", sbi.NumberOfProcessors);
109 ok( sbi.NumberOfProcessors > 0, "Expected more than 0 processors, got %d\n", sbi.NumberOfProcessors);
112 static void test_query_cpu(void)
114 DWORD status;
115 ULONG ReturnLength;
116 SYSTEM_CPU_INFORMATION sci;
118 status = pNtQuerySystemInformation(SystemCpuInformation, &sci, sizeof(sci), &ReturnLength);
119 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
120 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
122 /* Check if we have some return values */
123 trace("Processor FeatureSet : %08x\n", sci.FeatureSet);
124 ok( sci.FeatureSet != 0, "Expected some features for this processor, got %08x\n", sci.FeatureSet);
127 static void test_query_performance(void)
129 NTSTATUS status;
130 ULONG ReturnLength;
131 ULONGLONG buffer[sizeof(SYSTEM_PERFORMANCE_INFORMATION)/sizeof(ULONGLONG) + 1];
133 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, 0, &ReturnLength);
134 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
136 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer,
137 sizeof(SYSTEM_PERFORMANCE_INFORMATION), &ReturnLength);
138 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
139 ok( ReturnLength == sizeof(SYSTEM_PERFORMANCE_INFORMATION), "Inconsistent length %d\n", ReturnLength);
141 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer,
142 sizeof(SYSTEM_PERFORMANCE_INFORMATION) + 2, &ReturnLength);
143 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
144 ok( ReturnLength == sizeof(SYSTEM_PERFORMANCE_INFORMATION) ||
145 ReturnLength == sizeof(SYSTEM_PERFORMANCE_INFORMATION) + 2,
146 "Inconsistent length %d\n", ReturnLength);
148 /* Not return values yet, as struct members are unknown */
151 static void test_query_timeofday(void)
153 NTSTATUS status;
154 ULONG ReturnLength;
156 /* Copy of our winternl.h structure turned into a private one */
157 typedef struct _SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE {
158 LARGE_INTEGER liKeBootTime;
159 LARGE_INTEGER liKeSystemTime;
160 LARGE_INTEGER liExpTimeZoneBias;
161 ULONG uCurrentTimeZoneId;
162 DWORD dwUnknown1[5];
163 } SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE, *PSYSTEM_TIMEOFDAY_INFORMATION_PRIVATE;
165 SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE sti;
167 /* The struct size for NT (32 bytes) and Win2K/XP (48 bytes) differ.
169 * Windows 2000 and XP return STATUS_INFO_LENGTH_MISMATCH if the given buffer size is greater
170 * then 48 and 0 otherwise
171 * Windows NT returns STATUS_INFO_LENGTH_MISMATCH when the given buffer size is not correct
172 * and 0 otherwise
174 * Windows 2000 and XP copy the given buffer size into the provided buffer, if the return code is STATUS_SUCCESS
175 * NT only fills the buffer if the return code is STATUS_SUCCESS
179 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
181 if (status == STATUS_INFO_LENGTH_MISMATCH)
183 trace("Windows version is NT, we have to cater for differences with W2K/WinXP\n");
185 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
186 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
187 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
189 sti.uCurrentTimeZoneId = 0xdeadbeef;
190 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 28, &ReturnLength);
191 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
193 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
194 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
195 ok( 32 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
197 else
199 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
200 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
201 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
203 sti.uCurrentTimeZoneId = 0xdeadbeef;
204 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 24, &ReturnLength);
205 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
206 ok( 24 == ReturnLength, "ReturnLength should be 24, it is (%d)\n", ReturnLength);
207 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
209 sti.uCurrentTimeZoneId = 0xdeadbeef;
210 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
211 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
212 ok( 32 == ReturnLength, "ReturnLength should be 32, it is (%d)\n", ReturnLength);
213 ok( 0xdeadbeef != sti.uCurrentTimeZoneId, "Buffer should have been partially filled\n");
215 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 49, &ReturnLength);
216 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
217 ok( ReturnLength == 0 || ReturnLength == sizeof(sti) /* vista */,
218 "ReturnLength should be 0, it is (%d)\n", ReturnLength);
220 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
221 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
222 ok( sizeof(sti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
225 /* Check if we have some return values */
226 trace("uCurrentTimeZoneId : (%d)\n", sti.uCurrentTimeZoneId);
229 static void test_query_process(void)
231 NTSTATUS status;
232 DWORD last_pid;
233 ULONG ReturnLength;
234 int i = 0, k = 0;
235 int is_nt = 0;
236 SYSTEM_BASIC_INFORMATION sbi;
238 /* Copy of our winternl.h structure turned into a private one */
239 typedef struct _SYSTEM_PROCESS_INFORMATION_PRIVATE {
240 ULONG NextEntryOffset;
241 DWORD dwThreadCount;
242 DWORD dwUnknown1[6];
243 FILETIME ftCreationTime;
244 FILETIME ftUserTime;
245 FILETIME ftKernelTime;
246 UNICODE_STRING ProcessName;
247 DWORD dwBasePriority;
248 HANDLE UniqueProcessId;
249 HANDLE ParentProcessId;
250 ULONG HandleCount;
251 DWORD dwUnknown3;
252 DWORD dwUnknown4;
253 VM_COUNTERS vmCounters;
254 IO_COUNTERS ioCounters;
255 SYSTEM_THREAD_INFORMATION ti[1];
256 } SYSTEM_PROCESS_INFORMATION_PRIVATE, *PSYSTEM_PROCESS_INFORMATION_PRIVATE;
258 ULONG SystemInformationLength = sizeof(SYSTEM_PROCESS_INFORMATION_PRIVATE);
259 SYSTEM_PROCESS_INFORMATION_PRIVATE *spi, *spi_buf = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
261 /* Only W2K3 returns the needed length, the rest returns 0, so we have to loop */
263 for (;;)
265 status = pNtQuerySystemInformation(SystemProcessInformation, spi_buf, SystemInformationLength, &ReturnLength);
267 if (status != STATUS_INFO_LENGTH_MISMATCH) break;
269 spi_buf = HeapReAlloc(GetProcessHeap(), 0, spi_buf , SystemInformationLength *= 2);
271 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
272 spi = spi_buf;
274 /* Get the first NextEntryOffset, from this we can deduce the OS version we're running
276 * W2K/WinXP/W2K3:
277 * NextEntryOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
278 * NT:
279 * NextEntryOffset for a process is 136 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
280 * Wine (with every windows version):
281 * NextEntryOffset for a process is 0 if just this test is running
282 * NextEntryOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION) +
283 * ProcessName.MaximumLength
284 * if more wine processes are running
286 * Note : On windows the first process is in fact the Idle 'process' with a thread for every processor
289 pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
291 is_nt = ( spi->NextEntryOffset - (sbi.NumberOfProcessors * sizeof(SYSTEM_THREAD_INFORMATION)) == 136);
293 if (is_nt) skip("Windows version is NT, we will skip thread tests\n");
295 /* Check if we have some return values
297 * On windows there will be several processes running (Including the always present Idle and System)
298 * On wine we only have one (if this test is the only wine process running)
301 /* Loop through the processes */
303 for (;;)
305 i++;
307 last_pid = (DWORD_PTR)spi->UniqueProcessId;
309 ok( spi->dwThreadCount > 0, "Expected some threads for this process, got 0\n");
311 /* Loop through the threads, skip NT4 for now */
313 if (!is_nt)
315 DWORD j;
316 for ( j = 0; j < spi->dwThreadCount; j++)
318 k++;
319 ok ( spi->ti[j].ClientId.UniqueProcess == spi->UniqueProcessId,
320 "The owning pid of the thread (%p) doesn't equal the pid (%p) of the process\n",
321 spi->ti[j].ClientId.UniqueProcess, spi->UniqueProcessId);
325 if (!spi->NextEntryOffset) break;
327 one_before_last_pid = last_pid;
329 spi = (SYSTEM_PROCESS_INFORMATION_PRIVATE*)((char*)spi + spi->NextEntryOffset);
331 trace("Total number of running processes : %d\n", i);
332 if (!is_nt) trace("Total number of running threads : %d\n", k);
334 if (one_before_last_pid == 0) one_before_last_pid = last_pid;
336 HeapFree( GetProcessHeap(), 0, spi_buf);
339 static void test_query_procperf(void)
341 NTSTATUS status;
342 ULONG ReturnLength;
343 ULONG NeededLength;
344 SYSTEM_BASIC_INFORMATION sbi;
345 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi;
347 /* Find out the number of processors */
348 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
349 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
351 sppi = HeapAlloc(GetProcessHeap(), 0, NeededLength);
353 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, 0, &ReturnLength);
354 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
356 /* Try it for 1 processor */
357 sppi->KernelTime.QuadPart = 0xdeaddead;
358 sppi->UserTime.QuadPart = 0xdeaddead;
359 sppi->IdleTime.QuadPart = 0xdeaddead;
360 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi,
361 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION), &ReturnLength);
362 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
363 ok( sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) == ReturnLength,
364 "Inconsistent length %d\n", ReturnLength);
365 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
366 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
367 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
369 /* Try it for all processors */
370 sppi->KernelTime.QuadPart = 0xdeaddead;
371 sppi->UserTime.QuadPart = 0xdeaddead;
372 sppi->IdleTime.QuadPart = 0xdeaddead;
373 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength, &ReturnLength);
374 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
375 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
376 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
377 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
378 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
380 /* A too large given buffer size */
381 sppi = HeapReAlloc(GetProcessHeap(), 0, sppi , NeededLength + 2);
382 sppi->KernelTime.QuadPart = 0xdeaddead;
383 sppi->UserTime.QuadPart = 0xdeaddead;
384 sppi->IdleTime.QuadPart = 0xdeaddead;
385 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength + 2, &ReturnLength);
386 ok( status == STATUS_SUCCESS || status == STATUS_INFO_LENGTH_MISMATCH /* vista */,
387 "Expected STATUS_SUCCESS or STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
388 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
389 if (status == STATUS_SUCCESS)
391 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
392 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
393 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
395 else /* vista and 2008 */
397 ok (sppi->KernelTime.QuadPart == 0xdeaddead, "KernelTime changed\n");
398 ok (sppi->UserTime.QuadPart == 0xdeaddead, "UserTime changed\n");
399 ok (sppi->IdleTime.QuadPart == 0xdeaddead, "IdleTime changed\n");
402 HeapFree( GetProcessHeap(), 0, sppi);
405 static void test_query_module(void)
407 NTSTATUS status;
408 ULONG ReturnLength;
409 ULONG ModuleCount, i;
411 ULONG SystemInformationLength = sizeof(SYSTEM_MODULE_INFORMATION);
412 SYSTEM_MODULE_INFORMATION* smi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
413 SYSTEM_MODULE* sm;
415 /* Request the needed length */
416 status = pNtQuerySystemInformation(SystemModuleInformation, smi, 0, &ReturnLength);
417 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
418 ok( ReturnLength > 0, "Expected a ReturnLength to show the needed length\n");
420 SystemInformationLength = ReturnLength;
421 smi = HeapReAlloc(GetProcessHeap(), 0, smi , SystemInformationLength);
422 status = pNtQuerySystemInformation(SystemModuleInformation, smi, SystemInformationLength, &ReturnLength);
423 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
425 ModuleCount = smi->ModulesCount;
426 sm = &smi->Modules[0];
427 /* our implementation is a stub for now */
428 ok( ModuleCount > 0, "Expected some modules to be loaded\n");
430 /* Loop through all the modules/drivers, Wine doesn't get here (yet) */
431 for (i = 0; i < ModuleCount ; i++)
433 ok( i == sm->Id, "Id (%d) should have matched %u\n", sm->Id, i);
434 sm++;
437 HeapFree( GetProcessHeap(), 0, smi);
440 static void test_query_handle(void)
442 NTSTATUS status;
443 ULONG ReturnLength;
444 ULONG SystemInformationLength = sizeof(SYSTEM_HANDLE_INFORMATION);
445 SYSTEM_HANDLE_INFORMATION* shi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
447 /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
448 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
449 todo_wine ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
451 SystemInformationLength = ReturnLength;
452 shi = HeapReAlloc(GetProcessHeap(), 0, shi , SystemInformationLength);
453 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
454 if (status != STATUS_INFO_LENGTH_MISMATCH) /* vista */
456 ok( status == STATUS_SUCCESS,
457 "Expected STATUS_SUCCESS, got %08x\n", status);
459 /* Check if we have some return values */
460 trace("Number of Handles : %d\n", shi->Count);
461 todo_wine
463 /* our implementation is a stub for now */
464 ok( shi->Count > 1, "Expected more than 1 handles, got (%d)\n", shi->Count);
467 HeapFree( GetProcessHeap(), 0, shi);
470 static void test_query_cache(void)
472 NTSTATUS status;
473 ULONG ReturnLength;
474 SYSTEM_CACHE_INFORMATION sci;
476 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, 0, &ReturnLength);
477 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
479 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci), &ReturnLength);
480 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
481 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
483 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci) + 2, &ReturnLength);
484 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
485 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
488 static void test_query_interrupt(void)
490 NTSTATUS status;
491 ULONG ReturnLength;
492 ULONG NeededLength;
493 SYSTEM_BASIC_INFORMATION sbi;
494 SYSTEM_INTERRUPT_INFORMATION* sii;
496 /* Find out the number of processors */
497 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
498 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_INTERRUPT_INFORMATION);
500 sii = HeapAlloc(GetProcessHeap(), 0, NeededLength);
502 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, 0, &ReturnLength);
503 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
505 /* Try it for all processors */
506 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, NeededLength, &ReturnLength);
507 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
509 /* Windows XP and W2K3 (and others?) always return 0 for the ReturnLength
510 * No test added for this as it's highly unlikely that an app depends on this
513 HeapFree( GetProcessHeap(), 0, sii);
516 static void test_query_kerndebug(void)
518 NTSTATUS status;
519 ULONG ReturnLength;
520 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
522 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, 0, &ReturnLength);
523 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
525 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi), &ReturnLength);
526 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
527 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
529 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi) + 2, &ReturnLength);
530 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
531 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
534 static void test_query_regquota(void)
536 NTSTATUS status;
537 ULONG ReturnLength;
538 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
540 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, 0, &ReturnLength);
541 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
543 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi), &ReturnLength);
544 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
545 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
547 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi) + 2, &ReturnLength);
548 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
549 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
552 static void test_query_process_basic(void)
554 NTSTATUS status;
555 ULONG ReturnLength;
557 typedef struct _PROCESS_BASIC_INFORMATION_PRIVATE {
558 DWORD_PTR ExitStatus;
559 PPEB PebBaseAddress;
560 DWORD_PTR AffinityMask;
561 DWORD_PTR BasePriority;
562 ULONG_PTR UniqueProcessId;
563 ULONG_PTR InheritedFromUniqueProcessId;
564 } PROCESS_BASIC_INFORMATION_PRIVATE, *PPROCESS_BASIC_INFORMATION_PRIVATE;
566 PROCESS_BASIC_INFORMATION_PRIVATE pbi;
568 /* This test also covers some basic parameter testing that should be the same for
569 * every information class
572 /* Use a nonexistent info class */
573 trace("Check nonexistent info class\n");
574 status = pNtQueryInformationProcess(NULL, -1, NULL, 0, NULL);
575 ok( status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* vista */,
576 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status);
578 /* Do not give a handle and buffer */
579 trace("Check NULL handle and buffer and zero-length buffersize\n");
580 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, 0, NULL);
581 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
583 /* Use a correct info class and buffer size, but still no handle and buffer */
584 trace("Check NULL handle and buffer\n");
585 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, sizeof(pbi), NULL);
586 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
587 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
589 /* Use a correct info class and buffer size, but still no handle */
590 trace("Check NULL handle\n");
591 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
592 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
594 /* Use a greater buffer size */
595 trace("Check NULL handle and too large buffersize\n");
596 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi) * 2, NULL);
597 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
599 /* Use no ReturnLength */
600 trace("Check NULL ReturnLength\n");
601 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
602 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
604 /* Finally some correct calls */
605 trace("Check with correct parameters\n");
606 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), &ReturnLength);
607 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
608 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
610 /* Everything is correct except a too large buffersize */
611 trace("Too large buffersize\n");
612 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi) * 2, &ReturnLength);
613 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
614 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
616 /* Check if we have some return values */
617 trace("ProcessID : %lx\n", pbi.UniqueProcessId);
618 ok( pbi.UniqueProcessId > 0, "Expected a ProcessID > 0, got 0\n");
621 static void test_query_process_vm(void)
623 NTSTATUS status;
624 ULONG ReturnLength;
625 VM_COUNTERS pvi;
626 ULONG old_size = FIELD_OFFSET(VM_COUNTERS,PrivatePageCount);
628 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, NULL, sizeof(pvi), NULL);
629 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
630 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
632 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, &pvi, old_size, NULL);
633 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
635 /* Windows XP and W2K3 will report success for a size of 44 AND 48 !
636 Windows W2K will only report success for 44.
637 For now we only care for 44, which is FIELD_OFFSET(VM_COUNTERS,PrivatePageCount))
640 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 24, &ReturnLength);
641 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
643 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, old_size, &ReturnLength);
644 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
645 ok( old_size == ReturnLength, "Inconsistent length %d\n", ReturnLength);
647 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 46, &ReturnLength);
648 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
649 ok( ReturnLength == old_size || ReturnLength == sizeof(pvi), "Inconsistent length %d\n", ReturnLength);
651 /* Check if we have some return values */
652 trace("WorkingSetSize : %ld\n", pvi.WorkingSetSize);
653 todo_wine
655 ok( pvi.WorkingSetSize > 0, "Expected a WorkingSetSize > 0\n");
659 static void test_query_process_io(void)
661 NTSTATUS status;
662 ULONG ReturnLength;
663 IO_COUNTERS pii;
665 /* NT4 doesn't support this information class, so check for it */
666 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
667 if (status == STATUS_NOT_SUPPORTED)
669 skip("ProcessIoCounters information class is not supported\n");
670 return;
673 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, NULL, sizeof(pii), NULL);
674 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
675 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
677 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, &pii, sizeof(pii), NULL);
678 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
680 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, 24, &ReturnLength);
681 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
683 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
684 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
685 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
687 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii) * 2, &ReturnLength);
688 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
689 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
691 /* Check if we have some return values */
692 trace("OtherOperationCount : 0x%x%08x\n", (DWORD)(pii.OtherOperationCount >> 32), (DWORD)pii.OtherOperationCount);
693 todo_wine
695 ok( pii.OtherOperationCount > 0, "Expected an OtherOperationCount > 0\n");
699 static void test_query_process_times(void)
701 NTSTATUS status;
702 ULONG ReturnLength;
703 HANDLE process;
704 SYSTEMTIME UTC, Local;
705 KERNEL_USER_TIMES spti;
707 status = pNtQueryInformationProcess(NULL, ProcessTimes, NULL, sizeof(spti), NULL);
708 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
709 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
711 status = pNtQueryInformationProcess(NULL, ProcessTimes, &spti, sizeof(spti), NULL);
712 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
714 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, 24, &ReturnLength);
715 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
717 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
718 if (!process)
720 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
721 process = GetCurrentProcess();
722 trace("ProcessTimes for current process\n");
724 else
725 trace("ProcessTimes for process with ID : %d\n", one_before_last_pid);
727 status = pNtQueryInformationProcess( process, ProcessTimes, &spti, sizeof(spti), &ReturnLength);
728 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
729 ok( sizeof(spti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
730 CloseHandle(process);
732 FileTimeToSystemTime((const FILETIME *)&spti.CreateTime, &UTC);
733 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
734 trace("CreateTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
735 Local.wHour, Local.wMinute, Local.wSecond);
737 FileTimeToSystemTime((const FILETIME *)&spti.ExitTime, &UTC);
738 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
739 trace("ExitTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
740 Local.wHour, Local.wMinute, Local.wSecond);
742 FileTimeToSystemTime((const FILETIME *)&spti.KernelTime, &Local);
743 trace("KernelTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
745 FileTimeToSystemTime((const FILETIME *)&spti.UserTime, &Local);
746 trace("UserTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
748 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, sizeof(spti) * 2, &ReturnLength);
749 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
750 ok( sizeof(spti) == ReturnLength || ReturnLength == 0 /* vista */,
751 "Inconsistent length %d\n", ReturnLength);
754 static void test_query_process_handlecount(void)
756 NTSTATUS status;
757 ULONG ReturnLength;
758 DWORD handlecount;
759 BYTE buffer[2 * sizeof(DWORD)];
760 HANDLE process;
762 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, NULL, sizeof(handlecount), NULL);
763 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
764 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
766 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, &handlecount, sizeof(handlecount), NULL);
767 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
769 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, &handlecount, 2, &ReturnLength);
770 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
772 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
773 if (!process)
775 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
776 process = GetCurrentProcess();
777 trace("ProcessHandleCount for current process\n");
779 else
780 trace("ProcessHandleCount for process with ID : %d\n", one_before_last_pid);
782 status = pNtQueryInformationProcess( process, ProcessHandleCount, &handlecount, sizeof(handlecount), &ReturnLength);
783 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
784 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
785 CloseHandle(process);
787 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, buffer, sizeof(buffer), &ReturnLength);
788 ok( status == STATUS_INFO_LENGTH_MISMATCH || status == STATUS_SUCCESS,
789 "Expected STATUS_INFO_LENGTH_MISMATCH or STATUS_SUCCESS, got %08x\n", status);
790 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
792 /* Check if we have some return values */
793 trace("HandleCount : %d\n", handlecount);
794 todo_wine
796 ok( handlecount > 0, "Expected some handles, got 0\n");
800 static void test_query_process_image_file_name(void)
802 NTSTATUS status;
803 ULONG ReturnLength;
804 UNICODE_STRING image_file_name;
805 void *buffer;
806 char *file_nameA;
807 INT len;
809 status = pNtQueryInformationProcess(NULL, ProcessImageFileName, &image_file_name, sizeof(image_file_name), NULL);
810 if (status == STATUS_INVALID_INFO_CLASS)
812 skip("ProcessImageFileName is not supported\n");
813 return;
815 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
817 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, &image_file_name, 2, &ReturnLength);
818 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
820 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, &image_file_name, sizeof(image_file_name), &ReturnLength);
821 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
823 buffer = HeapAlloc(GetProcessHeap(), 0, ReturnLength);
824 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, buffer, ReturnLength, &ReturnLength);
825 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
826 memcpy(&image_file_name, buffer, sizeof(image_file_name));
827 len = WideCharToMultiByte(CP_ACP, 0, image_file_name.Buffer, image_file_name.Length/sizeof(WCHAR), NULL, 0, NULL, NULL);
828 file_nameA = HeapAlloc(GetProcessHeap(), 0, len + 1);
829 WideCharToMultiByte(CP_ACP, 0, image_file_name.Buffer, image_file_name.Length/sizeof(WCHAR), file_nameA, len, NULL, NULL);
830 file_nameA[len] = '\0';
831 HeapFree(GetProcessHeap(), 0, buffer);
832 trace("process image file name: %s\n", file_nameA);
833 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);
834 HeapFree(GetProcessHeap(), 0, file_nameA);
838 static void test_readvirtualmemory(void)
840 HANDLE process;
841 NTSTATUS status;
842 SIZE_T readcount;
843 static const char teststring[] = "test string";
844 char buffer[12];
846 process = OpenProcess(PROCESS_VM_READ, FALSE, GetCurrentProcessId());
847 ok(process != 0, "Expected to be able to open own process for reading memory\n");
849 /* normal operation */
850 status = pNtReadVirtualMemory(process, teststring, buffer, 12, &readcount);
851 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
852 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
853 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
855 /* no number of bytes */
856 memset(buffer, 0, 12);
857 status = pNtReadVirtualMemory(process, teststring, buffer, 12, NULL);
858 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
859 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
861 /* illegal remote address */
862 todo_wine{
863 status = pNtReadVirtualMemory(process, (void *) 0x1234, buffer, 12, &readcount);
864 ok( status == STATUS_PARTIAL_COPY || broken(status == STATUS_ACCESS_VIOLATION), "Expected STATUS_PARTIAL_COPY, got %08x\n", status);
865 if (status == STATUS_PARTIAL_COPY)
866 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
869 /* 0 handle */
870 status = pNtReadVirtualMemory(0, teststring, buffer, 12, &readcount);
871 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
872 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
874 /* pseudo handle for current process*/
875 memset(buffer, 0, 12);
876 status = pNtReadVirtualMemory((HANDLE)-1, teststring, buffer, 12, &readcount);
877 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
878 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
879 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
881 /* this test currently crashes wine with "wine client error:<process id>: read: Bad address"
882 * because the reply from wine server is directly read into the buffer and that fails with EFAULT
884 /* illegal local address */
885 /*status = pNtReadVirtualMemory(process, teststring, (void *)0x1234, 12, &readcount);
886 ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08lx\n", status);
887 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
890 CloseHandle(process);
893 static void test_affinity(void)
895 NTSTATUS status;
896 PROCESS_BASIC_INFORMATION pbi;
897 DWORD_PTR proc_affinity, thread_affinity;
898 THREAD_BASIC_INFORMATION tbi;
899 SYSTEM_INFO si;
901 GetSystemInfo(&si);
902 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL );
903 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
904 proc_affinity = (DWORD_PTR)pbi.Reserved2[0];
905 ok( proc_affinity == (1 << si.dwNumberOfProcessors) - 1, "Unexpected process affinity\n" );
906 proc_affinity = 1 << si.dwNumberOfProcessors;
907 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
908 ok( status == STATUS_INVALID_PARAMETER,
909 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
911 proc_affinity = 0;
912 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
913 ok( status == STATUS_INVALID_PARAMETER,
914 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
916 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
917 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
918 ok( tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1, "Unexpected thread affinity\n" );
919 thread_affinity = 1 << si.dwNumberOfProcessors;
920 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
921 ok( status == STATUS_INVALID_PARAMETER,
922 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
923 thread_affinity = 0;
924 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
925 ok( status == STATUS_INVALID_PARAMETER,
926 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
928 thread_affinity = 1;
929 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
930 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
931 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
932 ok( tbi.AffinityMask == 1, "Unexpected thread affinity\n" );
934 if (si.dwNumberOfProcessors <= 1)
936 skip("only one processor, skipping affinity testing\n");
937 return;
939 proc_affinity = 2;
940 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
941 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
942 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL );
943 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
944 proc_affinity = (DWORD_PTR)pbi.Reserved2[0];
945 ok( proc_affinity == 2, "Unexpected process affinity\n" );
946 /* Setting the process affinity changes the thread affinity to match */
947 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
948 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
949 ok( tbi.AffinityMask == 2, "Unexpected thread affinity\n" );
950 /* The thread affinity is restricted to the process affinity */
951 thread_affinity = 1;
952 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
953 ok( status == STATUS_INVALID_PARAMETER,
954 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
956 proc_affinity = (1 << si.dwNumberOfProcessors) - 1;
957 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
958 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
959 /* Resetting the process affinity also resets the thread affinity */
960 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
961 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
962 ok( tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1,
963 "Unexpected thread affinity" );
966 START_TEST(info)
968 if(!InitFunctionPtrs())
969 return;
971 /* NtQuerySystemInformation */
973 /* 0x0 SystemBasicInformation */
974 trace("Starting test_query_basic()\n");
975 test_query_basic();
977 /* 0x1 SystemCpuInformation */
978 trace("Starting test_query_cpu()\n");
979 test_query_cpu();
981 /* 0x2 SystemPerformanceInformation */
982 trace("Starting test_query_performance()\n");
983 test_query_performance();
985 /* 0x3 SystemTimeOfDayInformation */
986 trace("Starting test_query_timeofday()\n");
987 test_query_timeofday();
989 /* 0x5 SystemProcessInformation */
990 trace("Starting test_query_process()\n");
991 test_query_process();
993 /* 0x8 SystemProcessorPerformanceInformation */
994 trace("Starting test_query_procperf()\n");
995 test_query_procperf();
997 /* 0xb SystemModuleInformation */
998 trace("Starting test_query_module()\n");
999 test_query_module();
1001 /* 0x10 SystemHandleInformation */
1002 trace("Starting test_query_handle()\n");
1003 test_query_handle();
1005 /* 0x15 SystemCacheInformation */
1006 trace("Starting test_query_cache()\n");
1007 test_query_cache();
1009 /* 0x17 SystemInterruptInformation */
1010 trace("Starting test_query_interrupt()\n");
1011 test_query_interrupt();
1013 /* 0x23 SystemKernelDebuggerInformation */
1014 trace("Starting test_query_kerndebug()\n");
1015 test_query_kerndebug();
1017 /* 0x25 SystemRegistryQuotaInformation */
1018 trace("Starting test_query_regquota()\n");
1019 test_query_regquota();
1021 /* NtQueryInformationProcess */
1023 /* 0x0 ProcessBasicInformation */
1024 trace("Starting test_query_process_basic()\n");
1025 test_query_process_basic();
1027 /* 0x2 ProcessIoCounters */
1028 trace("Starting test_query_process_io()\n");
1029 test_query_process_io();
1031 /* 0x3 ProcessVmCounters */
1032 trace("Starting test_query_process_vm()\n");
1033 test_query_process_vm();
1035 /* 0x4 ProcessTimes */
1036 trace("Starting test_query_process_times()\n");
1037 test_query_process_times();
1039 /* 0x14 ProcessHandleCount */
1040 trace("Starting test_query_process_handlecount()\n");
1041 test_query_process_handlecount();
1043 /* 27 ProcessImageFileName */
1044 trace("Starting test_query_process_image_file_name()\n");
1045 test_query_process_image_file_name();
1047 /* belongs into it's own file */
1048 trace("Starting test_readvirtualmemory()\n");
1049 test_readvirtualmemory();
1051 trace("Starting test_affinity()\n");
1052 test_affinity();