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"
25 static NTSTATUS (WINAPI * pNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG);
26 static NTSTATUS (WINAPI * pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
27 static NTSTATUS (WINAPI * pNtQueryInformationThread)(HANDLE, THREADINFOCLASS, PVOID, ULONG, PULONG);
28 static NTSTATUS (WINAPI * pNtSetInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG);
29 static NTSTATUS (WINAPI * pNtSetInformationThread)(HANDLE, THREADINFOCLASS, PVOID, ULONG);
30 static NTSTATUS (WINAPI * pNtReadVirtualMemory)(HANDLE, const void*, void*, SIZE_T, SIZE_T*);
32 /* one_before_last_pid is used to be able to compare values of a still running process
33 with the output of the test_query_process_times and test_query_process_handlecount tests.
35 static DWORD one_before_last_pid = 0;
37 #define NTDLL_GET_PROC(func) do { \
38 p ## func = (void*)GetProcAddress(hntdll, #func); \
40 trace("GetProcAddress(%s) failed\n", #func); \
45 static BOOL InitFunctionPtrs(void)
47 /* All needed functions are NT based, so using GetModuleHandle is a good check */
48 HMODULE hntdll = GetModuleHandle("ntdll");
51 win_skip("Not running on NT\n");
55 NTDLL_GET_PROC(NtQuerySystemInformation);
56 NTDLL_GET_PROC(NtQueryInformationProcess);
57 NTDLL_GET_PROC(NtQueryInformationThread);
58 NTDLL_GET_PROC(NtSetInformationProcess);
59 NTDLL_GET_PROC(NtSetInformationThread);
60 NTDLL_GET_PROC(NtReadVirtualMemory);
65 static void test_query_basic(void)
69 SYSTEM_BASIC_INFORMATION sbi;
71 /* This test also covers some basic parameter testing that should be the same for
72 * every information class
75 /* Use a nonexistent info class */
76 trace("Check nonexistent info class\n");
77 status = pNtQuerySystemInformation(-1, NULL, 0, NULL);
78 ok( status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* vista */,
79 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status);
81 /* Use an existing class but with a zero-length buffer */
82 trace("Check zero-length buffer\n");
83 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, 0, NULL);
84 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
86 /* Use an existing class, correct length but no SystemInformation buffer */
87 trace("Check no SystemInformation buffer\n");
88 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, sizeof(sbi), NULL);
89 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_PARAMETER /* vista */,
90 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER, got %08x\n", status);
92 /* Use a existing class, correct length, a pointer to a buffer but no ReturnLength pointer */
93 trace("Check no ReturnLength pointer\n");
94 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), NULL);
95 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
97 /* Check a too large buffer size */
98 trace("Check a too large buffer size\n");
99 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi) * 2, &ReturnLength);
100 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
102 /* Finally some correct calls */
103 trace("Check with correct parameters\n");
104 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
105 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
106 ok( sizeof(sbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
108 /* Check if we have some return values */
109 trace("Number of Processors : %d\n", sbi.NumberOfProcessors);
110 ok( sbi.NumberOfProcessors > 0, "Expected more than 0 processors, got %d\n", sbi.NumberOfProcessors);
113 static void test_query_cpu(void)
117 SYSTEM_CPU_INFORMATION sci;
119 status = pNtQuerySystemInformation(SystemCpuInformation, &sci, sizeof(sci), &ReturnLength);
120 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
121 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
123 /* Check if we have some return values */
124 trace("Processor FeatureSet : %08x\n", sci.FeatureSet);
125 ok( sci.FeatureSet != 0, "Expected some features for this processor, got %08x\n", sci.FeatureSet);
128 static void test_query_performance(void)
132 ULONGLONG buffer[sizeof(SYSTEM_PERFORMANCE_INFORMATION)/sizeof(ULONGLONG) + 1];
134 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, 0, &ReturnLength);
135 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
137 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer,
138 sizeof(SYSTEM_PERFORMANCE_INFORMATION), &ReturnLength);
139 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
140 ok( ReturnLength == sizeof(SYSTEM_PERFORMANCE_INFORMATION), "Inconsistent length %d\n", ReturnLength);
142 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer,
143 sizeof(SYSTEM_PERFORMANCE_INFORMATION) + 2, &ReturnLength);
144 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
145 ok( ReturnLength == sizeof(SYSTEM_PERFORMANCE_INFORMATION) ||
146 ReturnLength == sizeof(SYSTEM_PERFORMANCE_INFORMATION) + 2,
147 "Inconsistent length %d\n", ReturnLength);
149 /* Not return values yet, as struct members are unknown */
152 static void test_query_timeofday(void)
157 /* Copy of our winternl.h structure turned into a private one */
158 typedef struct _SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE {
159 LARGE_INTEGER liKeBootTime;
160 LARGE_INTEGER liKeSystemTime;
161 LARGE_INTEGER liExpTimeZoneBias;
162 ULONG uCurrentTimeZoneId;
164 } SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE, *PSYSTEM_TIMEOFDAY_INFORMATION_PRIVATE;
166 SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE sti;
168 /* The struct size for NT (32 bytes) and Win2K/XP (48 bytes) differ.
170 * Windows 2000 and XP return STATUS_INFO_LENGTH_MISMATCH if the given buffer size is greater
171 * then 48 and 0 otherwise
172 * Windows NT returns STATUS_INFO_LENGTH_MISMATCH when the given buffer size is not correct
175 * Windows 2000 and XP copy the given buffer size into the provided buffer, if the return code is STATUS_SUCCESS
176 * NT only fills the buffer if the return code is STATUS_SUCCESS
180 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
182 if (status == STATUS_INFO_LENGTH_MISMATCH)
184 trace("Windows version is NT, we have to cater for differences with W2K/WinXP\n");
186 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
187 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
188 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
190 sti.uCurrentTimeZoneId = 0xdeadbeef;
191 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 28, &ReturnLength);
192 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
194 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
195 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
196 ok( 32 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
200 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
201 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
202 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
204 sti.uCurrentTimeZoneId = 0xdeadbeef;
205 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 24, &ReturnLength);
206 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
207 ok( 24 == ReturnLength, "ReturnLength should be 24, it is (%d)\n", ReturnLength);
208 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
210 sti.uCurrentTimeZoneId = 0xdeadbeef;
211 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
212 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
213 ok( 32 == ReturnLength, "ReturnLength should be 32, it is (%d)\n", ReturnLength);
214 ok( 0xdeadbeef != sti.uCurrentTimeZoneId, "Buffer should have been partially filled\n");
216 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 49, &ReturnLength);
217 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
218 ok( ReturnLength == 0 || ReturnLength == sizeof(sti) /* vista */,
219 "ReturnLength should be 0, it is (%d)\n", ReturnLength);
221 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
222 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
223 ok( sizeof(sti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
226 /* Check if we have some return values */
227 trace("uCurrentTimeZoneId : (%d)\n", sti.uCurrentTimeZoneId);
230 static void test_query_process(void)
237 SYSTEM_BASIC_INFORMATION sbi;
239 /* Copy of our winternl.h structure turned into a private one */
240 typedef struct _SYSTEM_PROCESS_INFORMATION_PRIVATE {
241 ULONG NextEntryOffset;
244 FILETIME ftCreationTime;
246 FILETIME ftKernelTime;
247 UNICODE_STRING ProcessName;
248 DWORD dwBasePriority;
249 HANDLE UniqueProcessId;
250 HANDLE ParentProcessId;
254 VM_COUNTERS vmCounters;
255 IO_COUNTERS ioCounters;
256 SYSTEM_THREAD_INFORMATION ti[1];
257 } SYSTEM_PROCESS_INFORMATION_PRIVATE, *PSYSTEM_PROCESS_INFORMATION_PRIVATE;
259 ULONG SystemInformationLength = sizeof(SYSTEM_PROCESS_INFORMATION_PRIVATE);
260 SYSTEM_PROCESS_INFORMATION_PRIVATE *spi, *spi_buf = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
262 /* Only W2K3 returns the needed length, the rest returns 0, so we have to loop */
266 status = pNtQuerySystemInformation(SystemProcessInformation, spi_buf, SystemInformationLength, &ReturnLength);
268 if (status != STATUS_INFO_LENGTH_MISMATCH) break;
270 spi_buf = HeapReAlloc(GetProcessHeap(), 0, spi_buf , SystemInformationLength *= 2);
272 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
275 /* Get the first NextEntryOffset, from this we can deduce the OS version we're running
278 * NextEntryOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
280 * NextEntryOffset for a process is 136 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
281 * Wine (with every windows version):
282 * NextEntryOffset for a process is 0 if just this test is running
283 * NextEntryOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION) +
284 * ProcessName.MaximumLength
285 * if more wine processes are running
287 * Note : On windows the first process is in fact the Idle 'process' with a thread for every processor
290 pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
292 is_nt = ( spi->NextEntryOffset - (sbi.NumberOfProcessors * sizeof(SYSTEM_THREAD_INFORMATION)) == 136);
294 if (is_nt) win_skip("Windows version is NT, we will skip thread tests\n");
296 /* Check if we have some return values
298 * On windows there will be several processes running (Including the always present Idle and System)
299 * On wine we only have one (if this test is the only wine process running)
302 /* Loop through the processes */
308 last_pid = (DWORD_PTR)spi->UniqueProcessId;
310 ok( spi->dwThreadCount > 0, "Expected some threads for this process, got 0\n");
312 /* Loop through the threads, skip NT4 for now */
317 for ( j = 0; j < spi->dwThreadCount; j++)
320 ok ( spi->ti[j].ClientId.UniqueProcess == spi->UniqueProcessId,
321 "The owning pid of the thread (%p) doesn't equal the pid (%p) of the process\n",
322 spi->ti[j].ClientId.UniqueProcess, spi->UniqueProcessId);
326 if (!spi->NextEntryOffset) break;
328 one_before_last_pid = last_pid;
330 spi = (SYSTEM_PROCESS_INFORMATION_PRIVATE*)((char*)spi + spi->NextEntryOffset);
332 trace("Total number of running processes : %d\n", i);
333 if (!is_nt) trace("Total number of running threads : %d\n", k);
335 if (one_before_last_pid == 0) one_before_last_pid = last_pid;
337 HeapFree( GetProcessHeap(), 0, spi_buf);
340 static void test_query_procperf(void)
345 SYSTEM_BASIC_INFORMATION sbi;
346 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi;
348 /* Find out the number of processors */
349 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
350 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
352 sppi = HeapAlloc(GetProcessHeap(), 0, NeededLength);
354 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, 0, &ReturnLength);
355 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
357 /* Try it for 1 processor */
358 sppi->KernelTime.QuadPart = 0xdeaddead;
359 sppi->UserTime.QuadPart = 0xdeaddead;
360 sppi->IdleTime.QuadPart = 0xdeaddead;
361 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi,
362 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION), &ReturnLength);
363 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
364 ok( sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) == ReturnLength,
365 "Inconsistent length %d\n", 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");
370 /* Try it for all processors */
371 sppi->KernelTime.QuadPart = 0xdeaddead;
372 sppi->UserTime.QuadPart = 0xdeaddead;
373 sppi->IdleTime.QuadPart = 0xdeaddead;
374 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength, &ReturnLength);
375 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
376 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
377 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
378 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
379 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
381 /* A too large given buffer size */
382 sppi = HeapReAlloc(GetProcessHeap(), 0, sppi , NeededLength + 2);
383 sppi->KernelTime.QuadPart = 0xdeaddead;
384 sppi->UserTime.QuadPart = 0xdeaddead;
385 sppi->IdleTime.QuadPart = 0xdeaddead;
386 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength + 2, &ReturnLength);
387 ok( status == STATUS_SUCCESS || status == STATUS_INFO_LENGTH_MISMATCH /* vista */,
388 "Expected STATUS_SUCCESS or STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
389 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
390 if (status == STATUS_SUCCESS)
392 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
393 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
394 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
396 else /* vista and 2008 */
398 ok (sppi->KernelTime.QuadPart == 0xdeaddead, "KernelTime changed\n");
399 ok (sppi->UserTime.QuadPart == 0xdeaddead, "UserTime changed\n");
400 ok (sppi->IdleTime.QuadPart == 0xdeaddead, "IdleTime changed\n");
403 HeapFree( GetProcessHeap(), 0, sppi);
406 static void test_query_module(void)
410 ULONG ModuleCount, i;
412 ULONG SystemInformationLength = sizeof(SYSTEM_MODULE_INFORMATION);
413 SYSTEM_MODULE_INFORMATION* smi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
416 /* Request the needed length */
417 status = pNtQuerySystemInformation(SystemModuleInformation, smi, 0, &ReturnLength);
418 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
419 ok( ReturnLength > 0, "Expected a ReturnLength to show the needed length\n");
421 SystemInformationLength = ReturnLength;
422 smi = HeapReAlloc(GetProcessHeap(), 0, smi , SystemInformationLength);
423 status = pNtQuerySystemInformation(SystemModuleInformation, smi, SystemInformationLength, &ReturnLength);
424 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
426 ModuleCount = smi->ModulesCount;
427 sm = &smi->Modules[0];
428 /* our implementation is a stub for now */
429 ok( ModuleCount > 0, "Expected some modules to be loaded\n");
431 /* Loop through all the modules/drivers, Wine doesn't get here (yet) */
432 for (i = 0; i < ModuleCount ; i++)
434 ok( i == sm->Id, "Id (%d) should have matched %u\n", sm->Id, i);
438 HeapFree( GetProcessHeap(), 0, smi);
441 static void test_query_handle(void)
445 ULONG SystemInformationLength = sizeof(SYSTEM_HANDLE_INFORMATION);
446 SYSTEM_HANDLE_INFORMATION* shi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
448 /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
449 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
450 todo_wine ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
452 SystemInformationLength = ReturnLength;
453 shi = HeapReAlloc(GetProcessHeap(), 0, shi , SystemInformationLength);
454 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
455 if (status != STATUS_INFO_LENGTH_MISMATCH) /* vista */
457 ok( status == STATUS_SUCCESS,
458 "Expected STATUS_SUCCESS, got %08x\n", status);
460 /* Check if we have some return values */
461 trace("Number of Handles : %d\n", shi->Count);
464 /* our implementation is a stub for now */
465 ok( shi->Count > 1, "Expected more than 1 handles, got (%d)\n", shi->Count);
468 HeapFree( GetProcessHeap(), 0, shi);
471 static void test_query_cache(void)
475 SYSTEM_CACHE_INFORMATION sci;
477 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, 0, &ReturnLength);
478 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
480 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci), &ReturnLength);
481 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
482 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
484 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci) + 2, &ReturnLength);
485 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
486 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
489 static void test_query_interrupt(void)
494 SYSTEM_BASIC_INFORMATION sbi;
495 SYSTEM_INTERRUPT_INFORMATION* sii;
497 /* Find out the number of processors */
498 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
499 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_INTERRUPT_INFORMATION);
501 sii = HeapAlloc(GetProcessHeap(), 0, NeededLength);
503 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, 0, &ReturnLength);
504 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
506 /* Try it for all processors */
507 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, NeededLength, &ReturnLength);
508 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
510 /* Windows XP and W2K3 (and others?) always return 0 for the ReturnLength
511 * No test added for this as it's highly unlikely that an app depends on this
514 HeapFree( GetProcessHeap(), 0, sii);
517 static void test_query_kerndebug(void)
521 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
523 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, 0, &ReturnLength);
524 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
526 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi), &ReturnLength);
527 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
528 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
530 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi) + 2, &ReturnLength);
531 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
532 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
535 static void test_query_regquota(void)
539 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
541 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, 0, &ReturnLength);
542 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
544 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi), &ReturnLength);
545 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
546 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
548 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi) + 2, &ReturnLength);
549 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
550 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
553 static void test_query_process_basic(void)
558 typedef struct _PROCESS_BASIC_INFORMATION_PRIVATE {
559 DWORD_PTR ExitStatus;
561 DWORD_PTR AffinityMask;
562 DWORD_PTR BasePriority;
563 ULONG_PTR UniqueProcessId;
564 ULONG_PTR InheritedFromUniqueProcessId;
565 } PROCESS_BASIC_INFORMATION_PRIVATE, *PPROCESS_BASIC_INFORMATION_PRIVATE;
567 PROCESS_BASIC_INFORMATION_PRIVATE pbi;
569 /* This test also covers some basic parameter testing that should be the same for
570 * every information class
573 /* Use a nonexistent info class */
574 trace("Check nonexistent info class\n");
575 status = pNtQueryInformationProcess(NULL, -1, NULL, 0, NULL);
576 ok( status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* vista */,
577 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status);
579 /* Do not give a handle and buffer */
580 trace("Check NULL handle and buffer and zero-length buffersize\n");
581 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, 0, NULL);
582 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
584 /* Use a correct info class and buffer size, but still no handle and buffer */
585 trace("Check NULL handle and buffer\n");
586 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, sizeof(pbi), NULL);
587 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
588 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
590 /* Use a correct info class and buffer size, but still no handle */
591 trace("Check NULL handle\n");
592 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
593 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
595 /* Use a greater buffer size */
596 trace("Check NULL handle and too large buffersize\n");
597 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi) * 2, NULL);
598 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
600 /* Use no ReturnLength */
601 trace("Check NULL ReturnLength\n");
602 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
603 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
605 /* Finally some correct calls */
606 trace("Check with correct parameters\n");
607 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), &ReturnLength);
608 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
609 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
611 /* Everything is correct except a too large buffersize */
612 trace("Too large buffersize\n");
613 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi) * 2, &ReturnLength);
614 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
615 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
617 /* Check if we have some return values */
618 trace("ProcessID : %lx\n", pbi.UniqueProcessId);
619 ok( pbi.UniqueProcessId > 0, "Expected a ProcessID > 0, got 0\n");
622 static void test_query_process_vm(void)
627 ULONG old_size = FIELD_OFFSET(VM_COUNTERS,PrivatePageCount);
629 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, NULL, sizeof(pvi), NULL);
630 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
631 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
633 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, &pvi, old_size, NULL);
634 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
636 /* Windows XP and W2K3 will report success for a size of 44 AND 48 !
637 Windows W2K will only report success for 44.
638 For now we only care for 44, which is FIELD_OFFSET(VM_COUNTERS,PrivatePageCount))
641 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 24, &ReturnLength);
642 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
644 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, old_size, &ReturnLength);
645 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
646 ok( old_size == ReturnLength, "Inconsistent length %d\n", ReturnLength);
648 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 46, &ReturnLength);
649 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
650 ok( ReturnLength == old_size || ReturnLength == sizeof(pvi), "Inconsistent length %d\n", ReturnLength);
652 /* Check if we have some return values */
653 trace("WorkingSetSize : %ld\n", pvi.WorkingSetSize);
656 ok( pvi.WorkingSetSize > 0, "Expected a WorkingSetSize > 0\n");
660 static void test_query_process_io(void)
666 /* NT4 doesn't support this information class, so check for it */
667 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
668 if (status == STATUS_NOT_SUPPORTED)
670 win_skip("ProcessIoCounters information class is not supported\n");
674 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, NULL, sizeof(pii), NULL);
675 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
676 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
678 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, &pii, sizeof(pii), NULL);
679 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
681 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, 24, &ReturnLength);
682 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
684 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
685 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
686 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
688 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii) * 2, &ReturnLength);
689 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
690 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
692 /* Check if we have some return values */
693 trace("OtherOperationCount : 0x%x%08x\n", (DWORD)(pii.OtherOperationCount >> 32), (DWORD)pii.OtherOperationCount);
696 ok( pii.OtherOperationCount > 0, "Expected an OtherOperationCount > 0\n");
700 static void test_query_process_times(void)
705 SYSTEMTIME UTC, Local;
706 KERNEL_USER_TIMES spti;
708 status = pNtQueryInformationProcess(NULL, ProcessTimes, NULL, sizeof(spti), NULL);
709 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
710 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
712 status = pNtQueryInformationProcess(NULL, ProcessTimes, &spti, sizeof(spti), NULL);
713 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
715 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, 24, &ReturnLength);
716 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
718 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
721 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
722 process = GetCurrentProcess();
723 trace("ProcessTimes for current process\n");
726 trace("ProcessTimes for process with ID : %d\n", one_before_last_pid);
728 status = pNtQueryInformationProcess( process, ProcessTimes, &spti, sizeof(spti), &ReturnLength);
729 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
730 ok( sizeof(spti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
731 CloseHandle(process);
733 FileTimeToSystemTime((const FILETIME *)&spti.CreateTime, &UTC);
734 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
735 trace("CreateTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
736 Local.wHour, Local.wMinute, Local.wSecond);
738 FileTimeToSystemTime((const FILETIME *)&spti.ExitTime, &UTC);
739 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
740 trace("ExitTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
741 Local.wHour, Local.wMinute, Local.wSecond);
743 FileTimeToSystemTime((const FILETIME *)&spti.KernelTime, &Local);
744 trace("KernelTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
746 FileTimeToSystemTime((const FILETIME *)&spti.UserTime, &Local);
747 trace("UserTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
749 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, sizeof(spti) * 2, &ReturnLength);
750 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
751 ok( sizeof(spti) == ReturnLength || ReturnLength == 0 /* vista */,
752 "Inconsistent length %d\n", ReturnLength);
755 static void test_query_process_debug_port(int argc, char **argv)
757 DWORD_PTR debug_port = 0xdeadbeef;
758 char cmdline[MAX_PATH];
759 PROCESS_INFORMATION pi;
760 STARTUPINFO si = { 0 };
764 sprintf(cmdline, "%s %s %s", argv[0], argv[1], "debuggee");
767 ret = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &si, &pi);
768 ok(ret, "CreateProcess failed, last error %#x.\n", GetLastError());
771 status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
773 ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
775 status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
776 NULL, sizeof(debug_port), NULL);
777 ok(status == STATUS_INVALID_HANDLE || status == STATUS_ACCESS_VIOLATION,
778 "Expected STATUS_INVALID_HANDLE, got %#x.\n", status);
780 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
781 NULL, sizeof(debug_port), NULL);
782 ok(status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
784 status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
785 &debug_port, sizeof(debug_port), NULL);
786 ok(status == STATUS_INVALID_HANDLE, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
788 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
789 &debug_port, sizeof(debug_port) - 1, NULL);
790 ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
792 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
793 &debug_port, sizeof(debug_port) + 1, NULL);
794 ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
796 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
797 &debug_port, sizeof(debug_port), NULL);
798 ok(!status, "NtQueryInformationProcess failed, status %#x.\n", status);
799 ok(debug_port == 0, "Expected port 0, got %#lx.\n", debug_port);
801 status = pNtQueryInformationProcess(pi.hProcess, ProcessDebugPort,
802 &debug_port, sizeof(debug_port), NULL);
803 ok(!status, "NtQueryInformationProcess failed, status %#x.\n", status);
804 ok(debug_port == ~(DWORD_PTR)0, "Expected port %#lx, got %#lx.\n", ~(DWORD_PTR)0, debug_port);
810 ret = WaitForDebugEvent(&ev, INFINITE);
811 ok(ret, "WaitForDebugEvent failed, last error %#x.\n", GetLastError());
814 if (ev.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break;
816 ret = ContinueDebugEvent(ev.dwProcessId, ev.dwThreadId, DBG_CONTINUE);
817 ok(ret, "ContinueDebugEvent failed, last error %#x.\n", GetLastError());
821 ret = CloseHandle(pi.hThread);
822 ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
823 ret = CloseHandle(pi.hProcess);
824 ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
827 static void test_query_process_handlecount(void)
832 BYTE buffer[2 * sizeof(DWORD)];
835 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, NULL, sizeof(handlecount), NULL);
836 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
837 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
839 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, &handlecount, sizeof(handlecount), NULL);
840 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
842 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, &handlecount, 2, &ReturnLength);
843 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
845 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
848 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
849 process = GetCurrentProcess();
850 trace("ProcessHandleCount for current process\n");
853 trace("ProcessHandleCount for process with ID : %d\n", one_before_last_pid);
855 status = pNtQueryInformationProcess( process, ProcessHandleCount, &handlecount, sizeof(handlecount), &ReturnLength);
856 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
857 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
858 CloseHandle(process);
860 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, buffer, sizeof(buffer), &ReturnLength);
861 ok( status == STATUS_INFO_LENGTH_MISMATCH || status == STATUS_SUCCESS,
862 "Expected STATUS_INFO_LENGTH_MISMATCH or STATUS_SUCCESS, got %08x\n", status);
863 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
865 /* Check if we have some return values */
866 trace("HandleCount : %d\n", handlecount);
869 ok( handlecount > 0, "Expected some handles, got 0\n");
873 static void test_query_process_image_file_name(void)
877 UNICODE_STRING image_file_name;
882 status = pNtQueryInformationProcess(NULL, ProcessImageFileName, &image_file_name, sizeof(image_file_name), NULL);
883 if (status == STATUS_INVALID_INFO_CLASS)
885 win_skip("ProcessImageFileName is not supported\n");
888 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
890 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, &image_file_name, 2, &ReturnLength);
891 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
893 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, &image_file_name, sizeof(image_file_name), &ReturnLength);
894 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
896 buffer = HeapAlloc(GetProcessHeap(), 0, ReturnLength);
897 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, buffer, ReturnLength, &ReturnLength);
898 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
899 memcpy(&image_file_name, buffer, sizeof(image_file_name));
900 len = WideCharToMultiByte(CP_ACP, 0, image_file_name.Buffer, image_file_name.Length/sizeof(WCHAR), NULL, 0, NULL, NULL);
901 file_nameA = HeapAlloc(GetProcessHeap(), 0, len + 1);
902 WideCharToMultiByte(CP_ACP, 0, image_file_name.Buffer, image_file_name.Length/sizeof(WCHAR), file_nameA, len, NULL, NULL);
903 file_nameA[len] = '\0';
904 HeapFree(GetProcessHeap(), 0, buffer);
905 trace("process image file name: %s\n", file_nameA);
906 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);
907 HeapFree(GetProcessHeap(), 0, file_nameA);
911 static void test_readvirtualmemory(void)
916 static const char teststring[] = "test string";
919 process = OpenProcess(PROCESS_VM_READ, FALSE, GetCurrentProcessId());
920 ok(process != 0, "Expected to be able to open own process for reading memory\n");
922 /* normal operation */
923 status = pNtReadVirtualMemory(process, teststring, buffer, 12, &readcount);
924 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
925 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
926 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
928 /* no number of bytes */
929 memset(buffer, 0, 12);
930 status = pNtReadVirtualMemory(process, teststring, buffer, 12, NULL);
931 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
932 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
934 /* illegal remote address */
936 status = pNtReadVirtualMemory(process, (void *) 0x1234, buffer, 12, &readcount);
937 ok( status == STATUS_PARTIAL_COPY || broken(status == STATUS_ACCESS_VIOLATION), "Expected STATUS_PARTIAL_COPY, got %08x\n", status);
938 if (status == STATUS_PARTIAL_COPY)
939 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
943 status = pNtReadVirtualMemory(0, teststring, buffer, 12, &readcount);
944 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
945 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
947 /* pseudo handle for current process*/
948 memset(buffer, 0, 12);
949 status = pNtReadVirtualMemory((HANDLE)-1, teststring, buffer, 12, &readcount);
950 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
951 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
952 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
954 /* illegal local address */
955 status = pNtReadVirtualMemory(process, teststring, (void *)0x1234, 12, &readcount);
956 ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
957 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
959 CloseHandle(process);
962 static void test_affinity(void)
965 PROCESS_BASIC_INFORMATION pbi;
966 DWORD_PTR proc_affinity, thread_affinity;
967 THREAD_BASIC_INFORMATION tbi;
971 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL );
972 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
973 proc_affinity = (DWORD_PTR)pbi.Reserved2[0];
974 ok( proc_affinity == (1 << si.dwNumberOfProcessors) - 1, "Unexpected process affinity\n" );
975 proc_affinity = 1 << si.dwNumberOfProcessors;
976 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
977 ok( status == STATUS_INVALID_PARAMETER,
978 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
981 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
982 ok( status == STATUS_INVALID_PARAMETER,
983 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
985 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
986 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
987 ok( tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1, "Unexpected thread affinity\n" );
988 thread_affinity = 1 << si.dwNumberOfProcessors;
989 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
990 ok( status == STATUS_INVALID_PARAMETER,
991 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
993 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
994 ok( status == STATUS_INVALID_PARAMETER,
995 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
998 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
999 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1000 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1001 ok( tbi.AffinityMask == 1, "Unexpected thread affinity\n" );
1003 /* NOTE: Pre-Vista does not recognize the "all processors" flag (all bits set) */
1004 thread_affinity = ~0UL;
1005 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1006 ok( broken(status == STATUS_INVALID_PARAMETER) || status == STATUS_SUCCESS,
1007 "Expected STATUS_SUCCESS, got %08x\n", status);
1009 if (si.dwNumberOfProcessors <= 1)
1011 skip("only one processor, skipping affinity testing\n");
1015 /* Test thread affinity mask resulting from "all processors" flag */
1016 if (status == STATUS_SUCCESS)
1018 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1019 ok( broken(tbi.AffinityMask == 1) || tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1,
1020 "Unexpected thread affinity\n" );
1023 skip("Cannot test thread affinity mask for 'all processors' flag\n");
1026 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1027 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1028 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL );
1029 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1030 proc_affinity = (DWORD_PTR)pbi.Reserved2[0];
1031 ok( proc_affinity == 2, "Unexpected process affinity\n" );
1032 /* Setting the process affinity changes the thread affinity to match */
1033 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1034 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1035 ok( tbi.AffinityMask == 2, "Unexpected thread affinity\n" );
1036 /* The thread affinity is restricted to the process affinity */
1037 thread_affinity = 1;
1038 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1039 ok( status == STATUS_INVALID_PARAMETER,
1040 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1042 proc_affinity = (1 << si.dwNumberOfProcessors) - 1;
1043 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1044 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1045 /* Resetting the process affinity also resets the thread affinity */
1046 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1047 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1048 ok( tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1,
1049 "Unexpected thread affinity\n" );
1057 if(!InitFunctionPtrs())
1060 argc = winetest_get_mainargs(&argv);
1061 if (argc >= 3) return; /* Child */
1063 /* NtQuerySystemInformation */
1065 /* 0x0 SystemBasicInformation */
1066 trace("Starting test_query_basic()\n");
1069 /* 0x1 SystemCpuInformation */
1070 trace("Starting test_query_cpu()\n");
1073 /* 0x2 SystemPerformanceInformation */
1074 trace("Starting test_query_performance()\n");
1075 test_query_performance();
1077 /* 0x3 SystemTimeOfDayInformation */
1078 trace("Starting test_query_timeofday()\n");
1079 test_query_timeofday();
1081 /* 0x5 SystemProcessInformation */
1082 trace("Starting test_query_process()\n");
1083 test_query_process();
1085 /* 0x8 SystemProcessorPerformanceInformation */
1086 trace("Starting test_query_procperf()\n");
1087 test_query_procperf();
1089 /* 0xb SystemModuleInformation */
1090 trace("Starting test_query_module()\n");
1091 test_query_module();
1093 /* 0x10 SystemHandleInformation */
1094 trace("Starting test_query_handle()\n");
1095 test_query_handle();
1097 /* 0x15 SystemCacheInformation */
1098 trace("Starting test_query_cache()\n");
1101 /* 0x17 SystemInterruptInformation */
1102 trace("Starting test_query_interrupt()\n");
1103 test_query_interrupt();
1105 /* 0x23 SystemKernelDebuggerInformation */
1106 trace("Starting test_query_kerndebug()\n");
1107 test_query_kerndebug();
1109 /* 0x25 SystemRegistryQuotaInformation */
1110 trace("Starting test_query_regquota()\n");
1111 test_query_regquota();
1113 /* NtQueryInformationProcess */
1115 /* 0x0 ProcessBasicInformation */
1116 trace("Starting test_query_process_basic()\n");
1117 test_query_process_basic();
1119 /* 0x2 ProcessIoCounters */
1120 trace("Starting test_query_process_io()\n");
1121 test_query_process_io();
1123 /* 0x3 ProcessVmCounters */
1124 trace("Starting test_query_process_vm()\n");
1125 test_query_process_vm();
1127 /* 0x4 ProcessTimes */
1128 trace("Starting test_query_process_times()\n");
1129 test_query_process_times();
1131 /* 0x7 ProcessDebugPort */
1132 trace("Starting test_process_debug_port()\n");
1133 test_query_process_debug_port(argc, argv);
1135 /* 0x14 ProcessHandleCount */
1136 trace("Starting test_query_process_handlecount()\n");
1137 test_query_process_handlecount();
1139 /* 27 ProcessImageFileName */
1140 trace("Starting test_query_process_image_file_name()\n");
1141 test_query_process_image_file_name();
1143 /* belongs into it's own file */
1144 trace("Starting test_readvirtualmemory()\n");
1145 test_readvirtualmemory();
1147 trace("Starting test_affinity()\n");