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"
23 static NTSTATUS (WINAPI * pNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG);
24 static NTSTATUS (WINAPI * pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
25 static NTSTATUS (WINAPI * pNtReadVirtualMemory)(HANDLE, const void*, void*, SIZE_T, SIZE_T*);
27 /* one_before_last_pid is used to be able to compare values of a still running process
28 with the output of the test_query_process_times and test_query_process_handlecount tests.
30 static DWORD one_before_last_pid = 0;
32 #define NTDLL_GET_PROC(func) do { \
33 p ## func = (void*)GetProcAddress(hntdll, #func); \
35 trace("GetProcAddress(%s) failed\n", #func); \
40 static BOOL InitFunctionPtrs(void)
42 /* All needed functions are NT based, so using GetModuleHandle is a good check */
43 HMODULE hntdll = GetModuleHandle("ntdll");
46 skip("Not running on NT\n");
50 NTDLL_GET_PROC(NtQuerySystemInformation);
51 NTDLL_GET_PROC(NtQueryInformationProcess);
52 NTDLL_GET_PROC(NtReadVirtualMemory);
57 static void test_query_basic(void)
61 SYSTEM_BASIC_INFORMATION sbi;
63 /* This test also covers some basic parameter testing that should be the same for
64 * every information class
67 /* Use a nonexistent info class */
68 trace("Check nonexistent info class\n");
69 status = pNtQuerySystemInformation(-1, NULL, 0, NULL);
70 ok( status == STATUS_INVALID_INFO_CLASS, "Expected STATUS_INVALID_INFO_CLASS, got %08x\n", status);
72 /* Use an existing class but with a zero-length buffer */
73 trace("Check zero-length buffer\n");
74 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, 0, NULL);
75 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
77 /* Use an existing class, correct length but no SystemInformation buffer */
78 trace("Check no SystemInformation buffer\n");
79 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, sizeof(sbi), NULL);
80 ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
82 /* Use a existing class, correct length, a pointer to a buffer but no ReturnLength pointer */
83 trace("Check no ReturnLength pointer\n");
84 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), NULL);
85 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
87 /* Check a too large buffer size */
88 trace("Check a too large buffer size\n");
89 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi) * 2, &ReturnLength);
90 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
92 /* Finally some correct calls */
93 trace("Check with correct parameters\n");
94 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
95 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
96 ok( sizeof(sbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
98 /* Check if we have some return values */
99 trace("Number of Processors : %d\n", sbi.NumberOfProcessors);
100 ok( sbi.NumberOfProcessors > 0, "Expected more than 0 processors, got %d\n", sbi.NumberOfProcessors);
103 static void test_query_cpu(void)
107 SYSTEM_CPU_INFORMATION sci;
109 status = pNtQuerySystemInformation(SystemCpuInformation, &sci, sizeof(sci), &ReturnLength);
110 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
111 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
113 /* Check if we have some return values */
114 trace("Processor FeatureSet : %08x\n", sci.FeatureSet);
115 ok( sci.FeatureSet != 0, "Expected some features for this processor, got %08x\n", sci.FeatureSet);
118 static void test_query_performance(void)
122 SYSTEM_PERFORMANCE_INFORMATION spi;
124 status = pNtQuerySystemInformation(SystemPerformanceInformation, &spi, 0, &ReturnLength);
125 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
127 status = pNtQuerySystemInformation(SystemPerformanceInformation, &spi, sizeof(spi), &ReturnLength);
128 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
129 ok( sizeof(spi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
131 status = pNtQuerySystemInformation(SystemPerformanceInformation, &spi, sizeof(spi) + 2, &ReturnLength);
132 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
133 ok( sizeof(spi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
135 /* Not return values yet, as struct members are unknown */
138 static void test_query_timeofday(void)
143 /* Copy of our winternl.h structure turned into a private one */
144 typedef struct _SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE {
145 LARGE_INTEGER liKeBootTime;
146 LARGE_INTEGER liKeSystemTime;
147 LARGE_INTEGER liExpTimeZoneBias;
148 ULONG uCurrentTimeZoneId;
150 } SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE, *PSYSTEM_TIMEOFDAY_INFORMATION_PRIVATE;
152 SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE sti;
154 /* The struct size for NT (32 bytes) and Win2K/XP (48 bytes) differ.
156 * Windows 2000 and XP return STATUS_INFO_LENGTH_MISMATCH if the given buffer size is greater
157 * then 48 and 0 otherwise
158 * Windows NT returns STATUS_INFO_LENGTH_MISMATCH when the given buffer size is not correct
161 * Windows 2000 and XP copy the given buffer size into the provided buffer, if the return code is STATUS_SUCCESS
162 * NT only fills the buffer if the return code is STATUS_SUCCESS
166 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
168 if (status == STATUS_INFO_LENGTH_MISMATCH)
170 trace("Windows version is NT, we have to cater for differences with W2K/WinXP\n");
172 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
173 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
174 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
176 sti.uCurrentTimeZoneId = 0xdeadbeef;
177 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 28, &ReturnLength);
178 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
180 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
181 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
182 ok( 32 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
186 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
187 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, 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, 24, &ReturnLength);
192 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
193 ok( 24 == ReturnLength, "ReturnLength should be 24, it is (%d)\n", ReturnLength);
194 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
196 sti.uCurrentTimeZoneId = 0xdeadbeef;
197 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
198 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
199 ok( 32 == ReturnLength, "ReturnLength should be 32, it is (%d)\n", ReturnLength);
200 ok( 0xdeadbeef != sti.uCurrentTimeZoneId, "Buffer should have been partially filled\n");
202 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 49, &ReturnLength);
203 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
204 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
206 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
207 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
208 ok( sizeof(sti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
211 /* Check if we have some return values */
212 trace("uCurrentTimeZoneId : (%d)\n", sti.uCurrentTimeZoneId);
215 static void test_query_process(void)
222 SYSTEM_BASIC_INFORMATION sbi;
224 /* Copy of our winternl.h structure turned into a private one */
225 typedef struct _SYSTEM_PROCESS_INFORMATION_PRIVATE {
229 FILETIME ftCreationTime;
231 FILETIME ftKernelTime;
232 UNICODE_STRING ProcessName;
233 DWORD dwBasePriority;
235 DWORD dwParentProcessID;
239 VM_COUNTERS vmCounters;
240 IO_COUNTERS ioCounters;
241 SYSTEM_THREAD_INFORMATION ti[1];
242 } SYSTEM_PROCESS_INFORMATION_PRIVATE, *PSYSTEM_PROCESS_INFORMATION_PRIVATE;
244 ULONG SystemInformationLength = sizeof(SYSTEM_PROCESS_INFORMATION_PRIVATE);
245 SYSTEM_PROCESS_INFORMATION_PRIVATE* spi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
247 /* Only W2K3 returns the needed length, the rest returns 0, so we have to loop */
251 status = pNtQuerySystemInformation(SystemProcessInformation, spi, SystemInformationLength, &ReturnLength);
253 if (status != STATUS_INFO_LENGTH_MISMATCH) break;
255 spi = HeapReAlloc(GetProcessHeap(), 0, spi , SystemInformationLength *= 2);
258 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
260 /* Get the first dwOffset, from this we can deduce the OS version we're running
263 * dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
265 * dwOffset for a process is 136 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
266 * Wine (with every windows version):
267 * dwOffset for a process is 0 if just this test is running
268 * dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION) +
269 * ProcessName.MaximumLength
270 * if more wine processes are running
272 * Note : On windows the first process is in fact the Idle 'process' with a thread for every processor
275 pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
277 is_nt = ( spi->dwOffset - (sbi.NumberOfProcessors * sizeof(SYSTEM_THREAD_INFORMATION)) == 136);
279 if (is_nt) skip("Windows version is NT, we will skip thread tests\n");
281 /* Check if we have some return values
283 * On windows there will be several processes running (Including the always present Idle and System)
284 * On wine we only have one (if this test is the only wine process running)
287 /* Loop through the processes */
293 last_pid = spi->dwProcessID;
295 ok( spi->dwThreadCount > 0, "Expected some threads for this process, got 0\n");
297 /* Loop through the threads, skip NT4 for now */
302 for ( j = 0; j < spi->dwThreadCount; j++)
305 ok ( spi->ti[j].dwOwningPID == spi->dwProcessID,
306 "The owning pid of the thread (%d) doesn't equal the pid (%d) of the process\n",
307 spi->ti[j].dwOwningPID, spi->dwProcessID);
311 if (!spi->dwOffset) break;
313 one_before_last_pid = last_pid;
315 spi = (SYSTEM_PROCESS_INFORMATION_PRIVATE*)((char*)spi + spi->dwOffset);
317 trace("Total number of running processes : %d\n", i);
318 if (!is_nt) trace("Total number of running threads : %d\n", k);
320 if (one_before_last_pid == 0) one_before_last_pid = last_pid;
322 HeapFree( GetProcessHeap(), 0, spi);
325 static void test_query_procperf(void)
330 SYSTEM_BASIC_INFORMATION sbi;
331 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi;
333 /* Find out the number of processors */
334 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
335 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
337 sppi = HeapAlloc(GetProcessHeap(), 0, NeededLength);
339 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, 0, &ReturnLength);
340 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
342 /* Try it for 1 processor */
343 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi,
344 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION), &ReturnLength);
345 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
346 ok( sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) == ReturnLength,
347 "Inconsistent length %d\n", ReturnLength);
349 /* Try it for all processors */
350 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength, &ReturnLength);
351 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
352 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
354 /* A too large given buffer size */
355 sppi = HeapReAlloc(GetProcessHeap(), 0, sppi , NeededLength + 2);
356 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength + 2, &ReturnLength);
357 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
358 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
360 HeapFree( GetProcessHeap(), 0, sppi);
363 static void test_query_module(void)
367 ULONG ModuleCount, i;
369 ULONG SystemInformationLength = sizeof(SYSTEM_MODULE_INFORMATION);
370 SYSTEM_MODULE_INFORMATION* smi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
373 /* Request the needed length */
374 status = pNtQuerySystemInformation(SystemModuleInformation, smi, 0, &ReturnLength);
375 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
376 ok( ReturnLength > 0, "Expected a ReturnLength to show the needed length\n");
378 SystemInformationLength = ReturnLength;
379 smi = HeapReAlloc(GetProcessHeap(), 0, smi , SystemInformationLength);
380 status = pNtQuerySystemInformation(SystemModuleInformation, smi, SystemInformationLength, &ReturnLength);
381 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
383 ModuleCount = smi->ModulesCount;
384 sm = &smi->Modules[0];
385 /* our implementation is a stub for now */
386 ok( ModuleCount > 0, "Expected some modules to be loaded\n");
388 /* Loop through all the modules/drivers, Wine doesn't get here (yet) */
389 for (i = 0; i < ModuleCount ; i++)
391 ok( i == sm->Id, "Id (%d) should have matched %u\n", sm->Id, i);
395 HeapFree( GetProcessHeap(), 0, smi);
398 static void test_query_handle(void)
402 ULONG SystemInformationLength = sizeof(SYSTEM_HANDLE_INFORMATION);
403 SYSTEM_HANDLE_INFORMATION* shi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
405 /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
406 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
408 /* The following check assumes more than one handle on any given system */
411 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
413 ok( ReturnLength > 0, "Expected ReturnLength to be > 0, it was %d\n", ReturnLength);
415 SystemInformationLength = ReturnLength;
416 shi = HeapReAlloc(GetProcessHeap(), 0, shi , SystemInformationLength);
417 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
418 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
420 /* Check if we have some return values */
421 trace("Number of Handles : %d\n", shi->Count);
424 /* our implementation is a stub for now */
425 ok( shi->Count > 1, "Expected more than 1 handles, got (%d)\n", shi->Count);
428 HeapFree( GetProcessHeap(), 0, shi);
431 static void test_query_cache(void)
435 SYSTEM_CACHE_INFORMATION sci;
437 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, 0, &ReturnLength);
438 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
440 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci), &ReturnLength);
441 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
442 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
444 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci) + 2, &ReturnLength);
445 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
446 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
449 static void test_query_interrupt(void)
454 SYSTEM_BASIC_INFORMATION sbi;
455 SYSTEM_INTERRUPT_INFORMATION* sii;
457 /* Find out the number of processors */
458 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
459 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_INTERRUPT_INFORMATION);
461 sii = HeapAlloc(GetProcessHeap(), 0, NeededLength);
463 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, 0, &ReturnLength);
464 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
466 /* Try it for all processors */
467 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, NeededLength, &ReturnLength);
468 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
470 /* Windows XP and W2K3 (and others?) always return 0 for the ReturnLength
471 * No test added for this as it's highly unlikely that an app depends on this
474 HeapFree( GetProcessHeap(), 0, sii);
477 static void test_query_kerndebug(void)
481 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
483 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, 0, &ReturnLength);
484 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
486 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi), &ReturnLength);
487 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
488 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
490 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi) + 2, &ReturnLength);
491 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
492 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
495 static void test_query_regquota(void)
499 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
501 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, 0, &ReturnLength);
502 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
504 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi), &ReturnLength);
505 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
506 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
508 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi) + 2, &ReturnLength);
509 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
510 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
513 static void test_query_process_basic(void)
518 typedef struct _PROCESS_BASIC_INFORMATION_PRIVATE {
520 DWORD PebBaseAddress;
523 ULONG UniqueProcessId;
524 ULONG InheritedFromUniqueProcessId;
525 } PROCESS_BASIC_INFORMATION_PRIVATE, *PPROCESS_BASIC_INFORMATION_PRIVATE;
527 PROCESS_BASIC_INFORMATION_PRIVATE pbi;
529 /* This test also covers some basic parameter testing that should be the same for
530 * every information class
533 /* Use a nonexistent info class */
534 trace("Check nonexistent info class\n");
535 status = pNtQueryInformationProcess(NULL, -1, NULL, 0, NULL);
536 ok( status == STATUS_INVALID_INFO_CLASS, "Expected STATUS_INVALID_INFO_CLASS, got %08x\n", status);
538 /* Do not give a handle and buffer */
539 trace("Check NULL handle and buffer and zero-length buffersize\n");
540 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, 0, NULL);
541 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
543 /* Use a correct info class and buffer size, but still no handle and buffer */
544 trace("Check NULL handle and buffer\n");
545 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, sizeof(pbi), NULL);
546 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
547 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
549 /* Use a correct info class and buffer size, but still no handle */
550 trace("Check NULL handle\n");
551 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
552 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
554 /* Use a greater buffer size */
555 trace("Check NULL handle and too large buffersize\n");
556 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi) * 2, NULL);
557 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
559 /* Use no ReturnLength */
560 trace("Check NULL ReturnLength\n");
561 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
562 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
564 /* Finally some correct calls */
565 trace("Check with correct parameters\n");
566 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), &ReturnLength);
567 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
568 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
570 /* Everything is correct except a too large buffersize */
571 trace("Too large buffersize\n");
572 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi) * 2, &ReturnLength);
573 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
574 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
576 /* Check if we have some return values */
577 trace("ProcessID : %d\n", pbi.UniqueProcessId);
578 ok( pbi.UniqueProcessId > 0, "Expected a ProcessID > 0, got 0\n");
581 static void test_query_process_vm(void)
587 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, NULL, sizeof(pvi), NULL);
588 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
589 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
591 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, &pvi, sizeof(pvi), NULL);
592 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
594 /* Windows XP and W2K3 will report success for a size of 44 AND 48 !
595 Windows W2K will only report success for 44.
596 For now we only care for 44, which is sizeof(VM_COUNTERS)
597 If an app depends on it, we have to implement this in ntdll/process.c
600 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 24, &ReturnLength);
601 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
603 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, sizeof(pvi), &ReturnLength);
604 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
605 ok( sizeof(pvi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
607 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 46, &ReturnLength);
608 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
609 ok( sizeof(pvi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
611 /* Check if we have some return values */
612 trace("WorkingSetSize : %ld\n", pvi.WorkingSetSize);
615 ok( pvi.WorkingSetSize > 0, "Expected a WorkingSetSize > 0\n");
619 static void test_query_process_io(void)
625 /* NT4 doesn't support this information class, so check for it */
626 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
627 if (status == STATUS_NOT_SUPPORTED)
629 skip("ProcessIoCounters information class is not supported\n");
633 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, NULL, sizeof(pii), NULL);
634 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
635 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
637 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, &pii, sizeof(pii), NULL);
638 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
640 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, 24, &ReturnLength);
641 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
643 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
644 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
645 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
647 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii) * 2, &ReturnLength);
648 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
649 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
651 /* Check if we have some return values */
652 trace("OtherOperationCount : 0x%x%08x\n", (DWORD)(pii.OtherOperationCount >> 32), (DWORD)pii.OtherOperationCount);
655 ok( pii.OtherOperationCount > 0, "Expected an OtherOperationCount > 0\n");
659 static void test_query_process_times(void)
664 SYSTEMTIME UTC, Local;
665 KERNEL_USER_TIMES spti;
667 status = pNtQueryInformationProcess(NULL, ProcessTimes, NULL, sizeof(spti), NULL);
668 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
669 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
671 status = pNtQueryInformationProcess(NULL, ProcessTimes, &spti, sizeof(spti), NULL);
672 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
674 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, 24, &ReturnLength);
675 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
677 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
680 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
681 process = GetCurrentProcess();
682 trace("ProcessTimes for current process\n");
685 trace("ProcessTimes for process with ID : %d\n", one_before_last_pid);
687 status = pNtQueryInformationProcess( process, ProcessTimes, &spti, sizeof(spti), &ReturnLength);
688 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
689 ok( sizeof(spti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
690 CloseHandle(process);
692 FileTimeToSystemTime((const FILETIME *)&spti.CreateTime, &UTC);
693 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
694 trace("CreateTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
695 Local.wHour, Local.wMinute, Local.wSecond);
697 FileTimeToSystemTime((const FILETIME *)&spti.ExitTime, &UTC);
698 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
699 trace("ExitTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
700 Local.wHour, Local.wMinute, Local.wSecond);
702 FileTimeToSystemTime((const FILETIME *)&spti.KernelTime, &Local);
703 trace("KernelTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
705 FileTimeToSystemTime((const FILETIME *)&spti.UserTime, &Local);
706 trace("UserTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
708 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, sizeof(spti) * 2, &ReturnLength);
709 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
710 ok( sizeof(spti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
713 static void test_query_process_handlecount(void)
720 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, NULL, sizeof(handlecount), NULL);
721 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
722 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
724 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, &handlecount, sizeof(handlecount), NULL);
725 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
727 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, &handlecount, 2, &ReturnLength);
728 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
730 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
733 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
734 process = GetCurrentProcess();
735 trace("ProcessHandleCount for current process\n");
738 trace("ProcessHandleCount for process with ID : %d\n", one_before_last_pid);
740 status = pNtQueryInformationProcess( process, ProcessHandleCount, &handlecount, sizeof(handlecount), &ReturnLength);
741 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
742 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
743 CloseHandle(process);
745 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, &handlecount, sizeof(handlecount) * 2, &ReturnLength);
746 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
747 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
749 /* Check if we have some return values */
750 trace("HandleCount : %d\n", handlecount);
753 ok( handlecount > 0, "Expected some handles, got 0\n");
758 static void test_readvirtualmemory(void)
763 static const char teststring[] = "test string";
766 process = OpenProcess(PROCESS_VM_READ, FALSE, GetCurrentProcessId());
767 ok(process != 0, "Expected to be able to open own process for reading memory\n");
769 /* normal operation */
770 status = pNtReadVirtualMemory(process, teststring, buffer, 12, &readcount);
771 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
772 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
773 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
775 /* no number of bytes */
776 memset(buffer, 0, 12);
777 status = pNtReadVirtualMemory(process, teststring, buffer, 12, NULL);
778 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
779 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
781 /* illegal remote address */
783 status = pNtReadVirtualMemory(process, (void *) 0x1234, buffer, 12, &readcount);
784 ok( status == STATUS_PARTIAL_COPY, "Expected STATUS_PARTIAL_COPY, got %08x\n", status);
785 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
789 status = pNtReadVirtualMemory(0, teststring, buffer, 12, &readcount);
790 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
791 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
793 /* pseudo handle for current process*/
794 memset(buffer, 0, 12);
795 status = pNtReadVirtualMemory((HANDLE)-1, teststring, buffer, 12, &readcount);
796 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
797 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
798 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
800 /* this test currently crashes wine with "wine client error:<process id>: read: Bad address"
801 * because the reply from wine server is directly read into the buffer and that fails with EFAULT
803 /* illegal local address */
804 /*status = pNtReadVirtualMemory(process, teststring, (void *)0x1234, 12, &readcount);
805 ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08lx\n", status);
806 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
809 CloseHandle(process);
814 if(!InitFunctionPtrs())
817 /* NtQuerySystemInformation */
819 /* 0x0 SystemBasicInformation */
820 trace("Starting test_query_basic()\n");
823 /* 0x1 SystemCpuInformation */
824 trace("Starting test_query_cpu()\n");
827 /* 0x2 SystemPerformanceInformation */
828 trace("Starting test_query_performance()\n");
829 test_query_performance();
831 /* 0x3 SystemTimeOfDayInformation */
832 trace("Starting test_query_timeofday()\n");
833 test_query_timeofday();
835 /* 0x5 SystemProcessInformation */
836 trace("Starting test_query_process()\n");
837 test_query_process();
839 /* 0x8 SystemProcessorPerformanceInformation */
840 trace("Starting test_query_procperf()\n");
841 test_query_procperf();
843 /* 0xb SystemModuleInformation */
844 trace("Starting test_query_module()\n");
847 /* 0x10 SystemHandleInformation */
848 trace("Starting test_query_handle()\n");
851 /* 0x15 SystemCacheInformation */
852 trace("Starting test_query_cache()\n");
855 /* 0x17 SystemInterruptInformation */
856 trace("Starting test_query_interrupt()\n");
857 test_query_interrupt();
859 /* 0x23 SystemKernelDebuggerInformation */
860 trace("Starting test_query_kerndebug()\n");
861 test_query_kerndebug();
863 /* 0x25 SystemRegistryQuotaInformation */
864 trace("Starting test_query_regquota()\n");
865 test_query_regquota();
867 /* NtQueryInformationProcess */
869 /* 0x0 ProcessBasicInformation */
870 trace("Starting test_query_process_basic()\n");
871 test_query_process_basic();
873 /* 0x2 ProcessIoCounters */
874 trace("Starting test_query_process_io()\n");
875 test_query_process_io();
877 /* 0x3 ProcessVmCounters */
878 trace("Starting test_query_process_vm()\n");
879 test_query_process_vm();
881 /* 0x4 ProcessTimes */
882 trace("Starting test_query_process_times()\n");
883 test_query_process_times();
885 /* 0x14 ProcessHandleCount */
886 trace("Starting test_query_process_handlecount()\n");
887 test_query_process_handlecount();
889 /* belongs into it's own file */
890 trace("Starting test_readvirtualmemory()\n");
891 test_readvirtualmemory();