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];
386 /* our implementation is a stub for now */
387 ok( ModuleCount
> 0, "Expected some modules to be loaded\n");
390 /* Loop through all the modules/drivers, Wine doesn't get here (yet) */
391 for (i
= 0; i
< ModuleCount
; i
++)
393 ok( i
== sm
->Id
, "Id (%d) should have matched %u\n", sm
->Id
, i
);
397 HeapFree( GetProcessHeap(), 0, smi
);
400 static void test_query_handle(void)
404 ULONG SystemInformationLength
= sizeof(SYSTEM_HANDLE_INFORMATION
);
405 SYSTEM_HANDLE_INFORMATION
* shi
= HeapAlloc(GetProcessHeap(), 0, SystemInformationLength
);
407 /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
408 status
= pNtQuerySystemInformation(SystemHandleInformation
, shi
, SystemInformationLength
, &ReturnLength
);
410 /* The following check assumes more than one handle on any given system */
413 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
415 ok( ReturnLength
> 0, "Expected ReturnLength to be > 0, it was %d\n", ReturnLength
);
417 SystemInformationLength
= ReturnLength
;
418 shi
= HeapReAlloc(GetProcessHeap(), 0, shi
, SystemInformationLength
);
419 status
= pNtQuerySystemInformation(SystemHandleInformation
, shi
, SystemInformationLength
, &ReturnLength
);
420 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
422 /* Check if we have some return values */
423 trace("Number of Handles : %d\n", shi
->Count
);
426 /* our implementation is a stub for now */
427 ok( shi
->Count
> 1, "Expected more than 1 handles, got (%d)\n", shi
->Count
);
430 HeapFree( GetProcessHeap(), 0, shi
);
433 static void test_query_cache(void)
437 SYSTEM_CACHE_INFORMATION sci
;
439 status
= pNtQuerySystemInformation(SystemCacheInformation
, &sci
, 0, &ReturnLength
);
440 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
442 status
= pNtQuerySystemInformation(SystemCacheInformation
, &sci
, sizeof(sci
), &ReturnLength
);
443 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
444 ok( sizeof(sci
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
446 status
= pNtQuerySystemInformation(SystemCacheInformation
, &sci
, sizeof(sci
) + 2, &ReturnLength
);
447 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
448 ok( sizeof(sci
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
451 static void test_query_interrupt(void)
456 SYSTEM_BASIC_INFORMATION sbi
;
457 SYSTEM_INTERRUPT_INFORMATION
* sii
;
459 /* Find out the number of processors */
460 status
= pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
), &ReturnLength
);
461 NeededLength
= sbi
.NumberOfProcessors
* sizeof(SYSTEM_INTERRUPT_INFORMATION
);
463 sii
= HeapAlloc(GetProcessHeap(), 0, NeededLength
);
465 status
= pNtQuerySystemInformation(SystemInterruptInformation
, sii
, 0, &ReturnLength
);
466 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
468 /* Try it for all processors */
469 status
= pNtQuerySystemInformation(SystemInterruptInformation
, sii
, NeededLength
, &ReturnLength
);
470 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
472 /* Windows XP and W2K3 (and others?) always return 0 for the ReturnLength
473 * No test added for this as it's highly unlikely that an app depends on this
476 HeapFree( GetProcessHeap(), 0, sii
);
479 static void test_query_kerndebug(void)
483 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi
;
485 status
= pNtQuerySystemInformation(SystemKernelDebuggerInformation
, &skdi
, 0, &ReturnLength
);
486 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
488 status
= pNtQuerySystemInformation(SystemKernelDebuggerInformation
, &skdi
, sizeof(skdi
), &ReturnLength
);
489 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
490 ok( sizeof(skdi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
492 status
= pNtQuerySystemInformation(SystemKernelDebuggerInformation
, &skdi
, sizeof(skdi
) + 2, &ReturnLength
);
493 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
494 ok( sizeof(skdi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
497 static void test_query_regquota(void)
501 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi
;
503 status
= pNtQuerySystemInformation(SystemRegistryQuotaInformation
, &srqi
, 0, &ReturnLength
);
504 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
506 status
= pNtQuerySystemInformation(SystemRegistryQuotaInformation
, &srqi
, sizeof(srqi
), &ReturnLength
);
507 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
508 ok( sizeof(srqi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
510 status
= pNtQuerySystemInformation(SystemRegistryQuotaInformation
, &srqi
, sizeof(srqi
) + 2, &ReturnLength
);
511 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
512 ok( sizeof(srqi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
515 static void test_query_process_basic(void)
520 typedef struct _PROCESS_BASIC_INFORMATION_PRIVATE
{
522 DWORD PebBaseAddress
;
525 ULONG UniqueProcessId
;
526 ULONG InheritedFromUniqueProcessId
;
527 } PROCESS_BASIC_INFORMATION_PRIVATE
, *PPROCESS_BASIC_INFORMATION_PRIVATE
;
529 PROCESS_BASIC_INFORMATION_PRIVATE pbi
;
531 /* This test also covers some basic parameter testing that should be the same for
532 * every information class
535 /* Use a nonexistent info class */
536 trace("Check nonexistent info class\n");
537 status
= pNtQueryInformationProcess(NULL
, -1, NULL
, 0, NULL
);
538 ok( status
== STATUS_INVALID_INFO_CLASS
, "Expected STATUS_INVALID_INFO_CLASS, got %08x\n", status
);
540 /* Do not give a handle and buffer */
541 trace("Check NULL handle and buffer and zero-length buffersize\n");
542 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, NULL
, 0, NULL
);
543 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
545 /* Use a correct info class and buffer size, but still no handle and buffer */
546 trace("Check NULL handle and buffer\n");
547 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, NULL
, sizeof(pbi
), NULL
);
548 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
549 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status
);
551 /* Use a correct info class and buffer size, but still no handle */
552 trace("Check NULL handle\n");
553 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, &pbi
, sizeof(pbi
), NULL
);
554 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08x\n", status
);
556 /* Use a greater buffer size */
557 trace("Check NULL handle and too large buffersize\n");
558 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, &pbi
, sizeof(pbi
) * 2, NULL
);
559 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
561 /* Use no ReturnLength */
562 trace("Check NULL ReturnLength\n");
563 status
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation
, &pbi
, sizeof(pbi
), NULL
);
564 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
566 /* Finally some correct calls */
567 trace("Check with correct parameters\n");
568 status
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation
, &pbi
, sizeof(pbi
), &ReturnLength
);
569 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
570 ok( sizeof(pbi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
572 /* Everything is correct except a too large buffersize */
573 trace("Too large buffersize\n");
574 status
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation
, &pbi
, sizeof(pbi
) * 2, &ReturnLength
);
575 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
576 ok( sizeof(pbi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
578 /* Check if we have some return values */
579 trace("ProcessID : %d\n", pbi
.UniqueProcessId
);
580 ok( pbi
.UniqueProcessId
> 0, "Expected a ProcessID > 0, got 0\n");
583 static void test_query_process_vm(void)
589 status
= pNtQueryInformationProcess(NULL
, ProcessVmCounters
, NULL
, sizeof(pvi
), NULL
);
590 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
591 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status
);
593 status
= pNtQueryInformationProcess(NULL
, ProcessVmCounters
, &pvi
, sizeof(pvi
), NULL
);
594 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08x\n", status
);
596 /* Windows XP and W2K3 will report success for a size of 44 AND 48 !
597 Windows W2K will only report success for 44.
598 For now we only care for 44, which is sizeof(VM_COUNTERS)
599 If an app depends on it, we have to implement this in ntdll/process.c
602 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters
, &pvi
, 24, &ReturnLength
);
603 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
605 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters
, &pvi
, sizeof(pvi
), &ReturnLength
);
606 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
607 ok( sizeof(pvi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
609 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters
, &pvi
, 46, &ReturnLength
);
610 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
611 ok( sizeof(pvi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
613 /* Check if we have some return values */
614 trace("WorkingSetSize : %ld\n", pvi
.WorkingSetSize
);
617 ok( pvi
.WorkingSetSize
> 0, "Expected a WorkingSetSize > 0\n");
621 static void test_query_process_io(void)
627 /* NT4 doesn't support this information class, so check for it */
628 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters
, &pii
, sizeof(pii
), &ReturnLength
);
629 if (status
== STATUS_NOT_SUPPORTED
)
631 skip("ProcessIoCounters information class is not supported\n");
635 status
= pNtQueryInformationProcess(NULL
, ProcessIoCounters
, NULL
, sizeof(pii
), NULL
);
636 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
637 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status
);
639 status
= pNtQueryInformationProcess(NULL
, ProcessIoCounters
, &pii
, sizeof(pii
), NULL
);
640 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08x\n", status
);
642 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters
, &pii
, 24, &ReturnLength
);
643 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
645 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters
, &pii
, sizeof(pii
), &ReturnLength
);
646 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
647 ok( sizeof(pii
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
649 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters
, &pii
, sizeof(pii
) * 2, &ReturnLength
);
650 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
651 ok( sizeof(pii
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
653 /* Check if we have some return values */
654 trace("OtherOperationCount : 0x%x%08x\n", (DWORD
)(pii
.OtherOperationCount
>> 32), (DWORD
)pii
.OtherOperationCount
);
657 ok( pii
.OtherOperationCount
> 0, "Expected an OtherOperationCount > 0\n");
661 static void test_query_process_times(void)
666 SYSTEMTIME UTC
, Local
;
667 KERNEL_USER_TIMES spti
;
669 status
= pNtQueryInformationProcess(NULL
, ProcessTimes
, NULL
, sizeof(spti
), NULL
);
670 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
671 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status
);
673 status
= pNtQueryInformationProcess(NULL
, ProcessTimes
, &spti
, sizeof(spti
), NULL
);
674 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08x\n", status
);
676 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes
, &spti
, 24, &ReturnLength
);
677 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
679 process
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, one_before_last_pid
);
682 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid
, GetLastError());
683 process
= GetCurrentProcess();
684 trace("ProcessTimes for current process\n");
687 trace("ProcessTimes for process with ID : %d\n", one_before_last_pid
);
689 status
= pNtQueryInformationProcess( process
, ProcessTimes
, &spti
, sizeof(spti
), &ReturnLength
);
690 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
691 ok( sizeof(spti
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
692 CloseHandle(process
);
694 FileTimeToSystemTime((const FILETIME
*)&spti
.CreateTime
, &UTC
);
695 SystemTimeToTzSpecificLocalTime(NULL
, &UTC
, &Local
);
696 trace("CreateTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local
.wMonth
, Local
.wDay
, Local
.wYear
,
697 Local
.wHour
, Local
.wMinute
, Local
.wSecond
);
699 FileTimeToSystemTime((const FILETIME
*)&spti
.ExitTime
, &UTC
);
700 SystemTimeToTzSpecificLocalTime(NULL
, &UTC
, &Local
);
701 trace("ExitTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local
.wMonth
, Local
.wDay
, Local
.wYear
,
702 Local
.wHour
, Local
.wMinute
, Local
.wSecond
);
704 FileTimeToSystemTime((const FILETIME
*)&spti
.KernelTime
, &Local
);
705 trace("KernelTime : %02d:%02d:%02d.%03d\n", Local
.wHour
, Local
.wMinute
, Local
.wSecond
, Local
.wMilliseconds
);
707 FileTimeToSystemTime((const FILETIME
*)&spti
.UserTime
, &Local
);
708 trace("UserTime : %02d:%02d:%02d.%03d\n", Local
.wHour
, Local
.wMinute
, Local
.wSecond
, Local
.wMilliseconds
);
710 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes
, &spti
, sizeof(spti
) * 2, &ReturnLength
);
711 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
712 ok( sizeof(spti
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
715 static void test_query_process_handlecount(void)
722 status
= pNtQueryInformationProcess(NULL
, ProcessHandleCount
, NULL
, sizeof(handlecount
), NULL
);
723 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
724 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status
);
726 status
= pNtQueryInformationProcess(NULL
, ProcessHandleCount
, &handlecount
, sizeof(handlecount
), NULL
);
727 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08x\n", status
);
729 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount
, &handlecount
, 2, &ReturnLength
);
730 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
732 process
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, one_before_last_pid
);
735 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid
, GetLastError());
736 process
= GetCurrentProcess();
737 trace("ProcessHandleCount for current process\n");
740 trace("ProcessHandleCount for process with ID : %d\n", one_before_last_pid
);
742 status
= pNtQueryInformationProcess( process
, ProcessHandleCount
, &handlecount
, sizeof(handlecount
), &ReturnLength
);
743 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
744 ok( sizeof(handlecount
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
745 CloseHandle(process
);
747 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount
, &handlecount
, sizeof(handlecount
) * 2, &ReturnLength
);
748 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
749 ok( sizeof(handlecount
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
751 /* Check if we have some return values */
752 trace("HandleCount : %d\n", handlecount
);
755 ok( handlecount
> 0, "Expected some handles, got 0\n");
760 static void test_readvirtualmemory(void)
765 static const char teststring
[] = "test string";
768 process
= OpenProcess(PROCESS_VM_READ
, FALSE
, GetCurrentProcessId());
769 ok(process
!= 0, "Expected to be able to open own process for reading memory\n");
771 /* normal operation */
772 status
= pNtReadVirtualMemory(process
, teststring
, buffer
, 12, &readcount
);
773 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
774 ok( readcount
== 12, "Expected to read 12 bytes, got %ld\n",readcount
);
775 ok( strcmp(teststring
, buffer
) == 0, "Expected read memory to be the same as original memory\n");
777 /* no number of bytes */
778 memset(buffer
, 0, 12);
779 status
= pNtReadVirtualMemory(process
, teststring
, buffer
, 12, NULL
);
780 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
781 ok( strcmp(teststring
, buffer
) == 0, "Expected read memory to be the same as original memory\n");
783 /* illegal remote address */
785 status
= pNtReadVirtualMemory(process
, (void *) 0x1234, buffer
, 12, &readcount
);
786 ok( status
== STATUS_PARTIAL_COPY
, "Expected STATUS_PARTIAL_COPY, got %08x\n", status
);
787 ok( readcount
== 0, "Expected to read 0 bytes, got %ld\n",readcount
);
791 status
= pNtReadVirtualMemory(0, teststring
, buffer
, 12, &readcount
);
792 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08x\n", status
);
793 ok( readcount
== 0, "Expected to read 0 bytes, got %ld\n",readcount
);
795 /* pseudo handle for current process*/
796 memset(buffer
, 0, 12);
797 status
= pNtReadVirtualMemory((HANDLE
)-1, teststring
, buffer
, 12, &readcount
);
798 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
799 ok( readcount
== 12, "Expected to read 12 bytes, got %ld\n",readcount
);
800 ok( strcmp(teststring
, buffer
) == 0, "Expected read memory to be the same as original memory\n");
802 /* this test currently crashes wine with "wine client error:<process id>: read: Bad address"
803 * because the reply from wine server is directly read into the buffer and that fails with EFAULT
805 /* illegal local address */
806 /*status = pNtReadVirtualMemory(process, teststring, (void *)0x1234, 12, &readcount);
807 ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08lx\n", status);
808 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
811 CloseHandle(process
);
816 if(!InitFunctionPtrs())
819 /* NtQuerySystemInformation */
821 /* 0x0 SystemBasicInformation */
822 trace("Starting test_query_basic()\n");
825 /* 0x1 SystemCpuInformation */
826 trace("Starting test_query_cpu()\n");
829 /* 0x2 SystemPerformanceInformation */
830 trace("Starting test_query_performance()\n");
831 test_query_performance();
833 /* 0x3 SystemTimeOfDayInformation */
834 trace("Starting test_query_timeofday()\n");
835 test_query_timeofday();
837 /* 0x5 SystemProcessInformation */
838 trace("Starting test_query_process()\n");
839 test_query_process();
841 /* 0x8 SystemProcessorPerformanceInformation */
842 trace("Starting test_query_procperf()\n");
843 test_query_procperf();
845 /* 0xb SystemModuleInformation */
846 trace("Starting test_query_module()\n");
849 /* 0x10 SystemHandleInformation */
850 trace("Starting test_query_handle()\n");
853 /* 0x15 SystemCacheInformation */
854 trace("Starting test_query_cache()\n");
857 /* 0x17 SystemInterruptInformation */
858 trace("Starting test_query_interrupt()\n");
859 test_query_interrupt();
861 /* 0x23 SystemKernelDebuggerInformation */
862 trace("Starting test_query_kerndebug()\n");
863 test_query_kerndebug();
865 /* 0x25 SystemRegistryQuotaInformation */
866 trace("Starting test_query_regquota()\n");
867 test_query_regquota();
869 /* NtQueryInformationProcess */
871 /* 0x0 ProcessBasicInformation */
872 trace("Starting test_query_process_basic()\n");
873 test_query_process_basic();
875 /* 0x2 ProcessIoCounters */
876 trace("Starting test_query_process_io()\n");
877 test_query_process_io();
879 /* 0x3 ProcessVmCounters */
880 trace("Starting test_query_process_vm()\n");
881 test_query_process_vm();
883 /* 0x4 ProcessTimes */
884 trace("Starting test_query_process_times()\n");
885 test_query_process_times();
887 /* 0x14 ProcessHandleCount */
888 trace("Starting test_query_process_handlecount()\n");
889 test_query_process_handlecount();
891 /* belongs into it's own file */
892 trace("Starting test_readvirtualmemory()\n");
893 test_readvirtualmemory();