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"
24 static NTSTATUS (WINAPI
* pNtQuerySystemInformation
)(SYSTEM_INFORMATION_CLASS
, PVOID
, ULONG
, PULONG
);
25 static NTSTATUS (WINAPI
* pNtQueryInformationProcess
)(HANDLE
, PROCESSINFOCLASS
, PVOID
, ULONG
, PULONG
);
26 static NTSTATUS (WINAPI
* pNtReadVirtualMemory
)(HANDLE
, const void*, void*, SIZE_T
, SIZE_T
*);
28 /* one_before_last_pid is used to be able to compare values of a still running process
29 with the output of the test_query_process_times and test_query_process_handlecount tests.
31 static DWORD one_before_last_pid
= 0;
33 #define NTDLL_GET_PROC(func) do { \
34 p ## func = (void*)GetProcAddress(hntdll, #func); \
36 trace("GetProcAddress(%s) failed\n", #func); \
41 static BOOL
InitFunctionPtrs(void)
43 /* All needed functions are NT based, so using GetModuleHandle is a good check */
44 HMODULE hntdll
= GetModuleHandle("ntdll");
47 skip("Not running on NT\n");
51 NTDLL_GET_PROC(NtQuerySystemInformation
);
52 NTDLL_GET_PROC(NtQueryInformationProcess
);
53 NTDLL_GET_PROC(NtReadVirtualMemory
);
58 static void test_query_basic(void)
62 SYSTEM_BASIC_INFORMATION sbi
;
64 /* This test also covers some basic parameter testing that should be the same for
65 * every information class
68 /* Use a nonexistent info class */
69 trace("Check nonexistent info class\n");
70 status
= pNtQuerySystemInformation(-1, NULL
, 0, NULL
);
71 ok( status
== STATUS_INVALID_INFO_CLASS
|| status
== STATUS_NOT_IMPLEMENTED
/* vista */,
72 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status
);
74 /* Use an existing class but with a zero-length buffer */
75 trace("Check zero-length buffer\n");
76 status
= pNtQuerySystemInformation(SystemBasicInformation
, NULL
, 0, NULL
);
77 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
79 /* Use an existing class, correct length but no SystemInformation buffer */
80 trace("Check no SystemInformation buffer\n");
81 status
= pNtQuerySystemInformation(SystemBasicInformation
, NULL
, sizeof(sbi
), NULL
);
82 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_PARAMETER
/* vista */,
83 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER, got %08x\n", status
);
85 /* Use a existing class, correct length, a pointer to a buffer but no ReturnLength pointer */
86 trace("Check no ReturnLength pointer\n");
87 status
= pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
), NULL
);
88 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
90 /* Check a too large buffer size */
91 trace("Check a too large buffer size\n");
92 status
= pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
) * 2, &ReturnLength
);
93 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
95 /* Finally some correct calls */
96 trace("Check with correct parameters\n");
97 status
= pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
), &ReturnLength
);
98 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
99 ok( sizeof(sbi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
101 /* Check if we have some return values */
102 trace("Number of Processors : %d\n", sbi
.NumberOfProcessors
);
103 ok( sbi
.NumberOfProcessors
> 0, "Expected more than 0 processors, got %d\n", sbi
.NumberOfProcessors
);
106 static void test_query_cpu(void)
110 SYSTEM_CPU_INFORMATION sci
;
112 status
= pNtQuerySystemInformation(SystemCpuInformation
, &sci
, sizeof(sci
), &ReturnLength
);
113 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
114 ok( sizeof(sci
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
116 /* Check if we have some return values */
117 trace("Processor FeatureSet : %08x\n", sci
.FeatureSet
);
118 ok( sci
.FeatureSet
!= 0, "Expected some features for this processor, got %08x\n", sci
.FeatureSet
);
121 static void test_query_performance(void)
125 SYSTEM_PERFORMANCE_INFORMATION spi
;
127 status
= pNtQuerySystemInformation(SystemPerformanceInformation
, &spi
, 0, &ReturnLength
);
128 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
130 status
= pNtQuerySystemInformation(SystemPerformanceInformation
, &spi
, sizeof(spi
), &ReturnLength
);
131 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
132 ok( sizeof(spi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
134 status
= pNtQuerySystemInformation(SystemPerformanceInformation
, &spi
, sizeof(spi
) + 2, &ReturnLength
);
135 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
136 ok( sizeof(spi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
138 /* Not return values yet, as struct members are unknown */
141 static void test_query_timeofday(void)
146 /* Copy of our winternl.h structure turned into a private one */
147 typedef struct _SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE
{
148 LARGE_INTEGER liKeBootTime
;
149 LARGE_INTEGER liKeSystemTime
;
150 LARGE_INTEGER liExpTimeZoneBias
;
151 ULONG uCurrentTimeZoneId
;
153 } SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE
, *PSYSTEM_TIMEOFDAY_INFORMATION_PRIVATE
;
155 SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE sti
;
157 /* The struct size for NT (32 bytes) and Win2K/XP (48 bytes) differ.
159 * Windows 2000 and XP return STATUS_INFO_LENGTH_MISMATCH if the given buffer size is greater
160 * then 48 and 0 otherwise
161 * Windows NT returns STATUS_INFO_LENGTH_MISMATCH when the given buffer size is not correct
164 * Windows 2000 and XP copy the given buffer size into the provided buffer, if the return code is STATUS_SUCCESS
165 * NT only fills the buffer if the return code is STATUS_SUCCESS
169 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, sizeof(sti
), &ReturnLength
);
171 if (status
== STATUS_INFO_LENGTH_MISMATCH
)
173 trace("Windows version is NT, we have to cater for differences with W2K/WinXP\n");
175 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 0, &ReturnLength
);
176 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
177 ok( 0 == ReturnLength
, "ReturnLength should be 0, it is (%d)\n", ReturnLength
);
179 sti
.uCurrentTimeZoneId
= 0xdeadbeef;
180 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 28, &ReturnLength
);
181 ok( 0xdeadbeef == sti
.uCurrentTimeZoneId
, "This part of the buffer should not have been filled\n");
183 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 32, &ReturnLength
);
184 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
185 ok( 32 == ReturnLength
, "ReturnLength should be 0, it is (%d)\n", ReturnLength
);
189 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 0, &ReturnLength
);
190 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
191 ok( 0 == ReturnLength
, "ReturnLength should be 0, it is (%d)\n", ReturnLength
);
193 sti
.uCurrentTimeZoneId
= 0xdeadbeef;
194 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 24, &ReturnLength
);
195 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
196 ok( 24 == ReturnLength
, "ReturnLength should be 24, it is (%d)\n", ReturnLength
);
197 ok( 0xdeadbeef == sti
.uCurrentTimeZoneId
, "This part of the buffer should not have been filled\n");
199 sti
.uCurrentTimeZoneId
= 0xdeadbeef;
200 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 32, &ReturnLength
);
201 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
202 ok( 32 == ReturnLength
, "ReturnLength should be 32, it is (%d)\n", ReturnLength
);
203 ok( 0xdeadbeef != sti
.uCurrentTimeZoneId
, "Buffer should have been partially filled\n");
205 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, 49, &ReturnLength
);
206 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
207 ok( ReturnLength
== 0 || ReturnLength
== sizeof(sti
) /* vista */,
208 "ReturnLength should be 0, it is (%d)\n", ReturnLength
);
210 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &sti
, sizeof(sti
), &ReturnLength
);
211 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
212 ok( sizeof(sti
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
215 /* Check if we have some return values */
216 trace("uCurrentTimeZoneId : (%d)\n", sti
.uCurrentTimeZoneId
);
219 static void test_query_process(void)
226 SYSTEM_BASIC_INFORMATION sbi
;
228 /* Copy of our winternl.h structure turned into a private one */
229 typedef struct _SYSTEM_PROCESS_INFORMATION_PRIVATE
{
233 FILETIME ftCreationTime
;
235 FILETIME ftKernelTime
;
236 UNICODE_STRING ProcessName
;
237 DWORD dwBasePriority
;
239 DWORD dwParentProcessID
;
243 VM_COUNTERS vmCounters
;
244 IO_COUNTERS ioCounters
;
245 SYSTEM_THREAD_INFORMATION ti
[1];
246 } SYSTEM_PROCESS_INFORMATION_PRIVATE
, *PSYSTEM_PROCESS_INFORMATION_PRIVATE
;
248 ULONG SystemInformationLength
= sizeof(SYSTEM_PROCESS_INFORMATION_PRIVATE
);
249 SYSTEM_PROCESS_INFORMATION_PRIVATE
*spi
, *spi_buf
= HeapAlloc(GetProcessHeap(), 0, SystemInformationLength
);
251 /* Only W2K3 returns the needed length, the rest returns 0, so we have to loop */
255 status
= pNtQuerySystemInformation(SystemProcessInformation
, spi_buf
, SystemInformationLength
, &ReturnLength
);
257 if (status
!= STATUS_INFO_LENGTH_MISMATCH
) break;
259 spi_buf
= HeapReAlloc(GetProcessHeap(), 0, spi_buf
, SystemInformationLength
*= 2);
261 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
264 /* Get the first dwOffset, from this we can deduce the OS version we're running
267 * dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
269 * dwOffset for a process is 136 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
270 * Wine (with every windows version):
271 * dwOffset for a process is 0 if just this test is running
272 * dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION) +
273 * ProcessName.MaximumLength
274 * if more wine processes are running
276 * Note : On windows the first process is in fact the Idle 'process' with a thread for every processor
279 pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
), &ReturnLength
);
281 is_nt
= ( spi
->dwOffset
- (sbi
.NumberOfProcessors
* sizeof(SYSTEM_THREAD_INFORMATION
)) == 136);
283 if (is_nt
) skip("Windows version is NT, we will skip thread tests\n");
285 /* Check if we have some return values
287 * On windows there will be several processes running (Including the always present Idle and System)
288 * On wine we only have one (if this test is the only wine process running)
291 /* Loop through the processes */
297 last_pid
= spi
->dwProcessID
;
299 ok( spi
->dwThreadCount
> 0, "Expected some threads for this process, got 0\n");
301 /* Loop through the threads, skip NT4 for now */
306 for ( j
= 0; j
< spi
->dwThreadCount
; j
++)
309 ok ( spi
->ti
[j
].dwOwningPID
== spi
->dwProcessID
,
310 "The owning pid of the thread (%d) doesn't equal the pid (%d) of the process\n",
311 spi
->ti
[j
].dwOwningPID
, spi
->dwProcessID
);
315 if (!spi
->dwOffset
) break;
317 one_before_last_pid
= last_pid
;
319 spi
= (SYSTEM_PROCESS_INFORMATION_PRIVATE
*)((char*)spi
+ spi
->dwOffset
);
321 trace("Total number of running processes : %d\n", i
);
322 if (!is_nt
) trace("Total number of running threads : %d\n", k
);
324 if (one_before_last_pid
== 0) one_before_last_pid
= last_pid
;
326 HeapFree( GetProcessHeap(), 0, spi_buf
);
329 static void test_query_procperf(void)
334 SYSTEM_BASIC_INFORMATION sbi
;
335 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
* sppi
;
337 /* Find out the number of processors */
338 status
= pNtQuerySystemInformation(SystemBasicInformation
, &sbi
, sizeof(sbi
), &ReturnLength
);
339 NeededLength
= sbi
.NumberOfProcessors
* sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
);
341 sppi
= HeapAlloc(GetProcessHeap(), 0, NeededLength
);
343 status
= pNtQuerySystemInformation(SystemProcessorPerformanceInformation
, sppi
, 0, &ReturnLength
);
344 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
346 /* Try it for 1 processor */
347 status
= pNtQuerySystemInformation(SystemProcessorPerformanceInformation
, sppi
,
348 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
), &ReturnLength
);
349 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
350 ok( sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) == ReturnLength
,
351 "Inconsistent length %d\n", ReturnLength
);
353 /* Try it for all processors */
354 status
= pNtQuerySystemInformation(SystemProcessorPerformanceInformation
, sppi
, NeededLength
, &ReturnLength
);
355 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
356 ok( NeededLength
== ReturnLength
, "Inconsistent length (%d) <-> (%d)\n", NeededLength
, ReturnLength
);
358 /* A too large given buffer size */
359 sppi
= HeapReAlloc(GetProcessHeap(), 0, sppi
, NeededLength
+ 2);
360 status
= pNtQuerySystemInformation(SystemProcessorPerformanceInformation
, sppi
, NeededLength
+ 2, &ReturnLength
);
361 ok( status
== STATUS_SUCCESS
|| status
== STATUS_INFO_LENGTH_MISMATCH
/* vista */,
362 "Expected STATUS_SUCCESS or STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
363 ok( NeededLength
== ReturnLength
, "Inconsistent length (%d) <-> (%d)\n", NeededLength
, ReturnLength
);
365 HeapFree( GetProcessHeap(), 0, sppi
);
368 static void test_query_module(void)
372 ULONG ModuleCount
, i
;
374 ULONG SystemInformationLength
= sizeof(SYSTEM_MODULE_INFORMATION
);
375 SYSTEM_MODULE_INFORMATION
* smi
= HeapAlloc(GetProcessHeap(), 0, SystemInformationLength
);
378 /* Request the needed length */
379 status
= pNtQuerySystemInformation(SystemModuleInformation
, smi
, 0, &ReturnLength
);
380 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
381 ok( ReturnLength
> 0, "Expected a ReturnLength to show the needed length\n");
383 SystemInformationLength
= ReturnLength
;
384 smi
= HeapReAlloc(GetProcessHeap(), 0, smi
, SystemInformationLength
);
385 status
= pNtQuerySystemInformation(SystemModuleInformation
, smi
, SystemInformationLength
, &ReturnLength
);
386 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
388 ModuleCount
= smi
->ModulesCount
;
389 sm
= &smi
->Modules
[0];
390 /* our implementation is a stub for now */
391 ok( ModuleCount
> 0, "Expected some modules to be loaded\n");
393 /* Loop through all the modules/drivers, Wine doesn't get here (yet) */
394 for (i
= 0; i
< ModuleCount
; i
++)
396 ok( i
== sm
->Id
, "Id (%d) should have matched %u\n", sm
->Id
, i
);
400 HeapFree( GetProcessHeap(), 0, smi
);
403 static void test_query_handle(void)
407 ULONG SystemInformationLength
= sizeof(SYSTEM_HANDLE_INFORMATION
);
408 SYSTEM_HANDLE_INFORMATION
* shi
= HeapAlloc(GetProcessHeap(), 0, SystemInformationLength
);
410 /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
411 status
= pNtQuerySystemInformation(SystemHandleInformation
, shi
, SystemInformationLength
, &ReturnLength
);
412 todo_wine
ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
414 SystemInformationLength
= ReturnLength
;
415 shi
= HeapReAlloc(GetProcessHeap(), 0, shi
, SystemInformationLength
);
416 status
= pNtQuerySystemInformation(SystemHandleInformation
, shi
, SystemInformationLength
, &ReturnLength
);
417 if (status
!= STATUS_INFO_LENGTH_MISMATCH
) /* vista */
419 ok( status
== STATUS_SUCCESS
,
420 "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
|| status
== STATUS_NOT_IMPLEMENTED
/* vista */,
539 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status
);
541 /* Do not give a handle and buffer */
542 trace("Check NULL handle and buffer and zero-length buffersize\n");
543 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, NULL
, 0, NULL
);
544 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
546 /* Use a correct info class and buffer size, but still no handle and buffer */
547 trace("Check NULL handle and buffer\n");
548 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, NULL
, sizeof(pbi
), NULL
);
549 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
550 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status
);
552 /* Use a correct info class and buffer size, but still no handle */
553 trace("Check NULL handle\n");
554 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, &pbi
, sizeof(pbi
), NULL
);
555 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08x\n", status
);
557 /* Use a greater buffer size */
558 trace("Check NULL handle and too large buffersize\n");
559 status
= pNtQueryInformationProcess(NULL
, ProcessBasicInformation
, &pbi
, sizeof(pbi
) * 2, NULL
);
560 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
562 /* Use no ReturnLength */
563 trace("Check NULL ReturnLength\n");
564 status
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation
, &pbi
, sizeof(pbi
), NULL
);
565 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
567 /* Finally some correct calls */
568 trace("Check with correct parameters\n");
569 status
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation
, &pbi
, sizeof(pbi
), &ReturnLength
);
570 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
571 ok( sizeof(pbi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
573 /* Everything is correct except a too large buffersize */
574 trace("Too large buffersize\n");
575 status
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation
, &pbi
, sizeof(pbi
) * 2, &ReturnLength
);
576 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
577 ok( sizeof(pbi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
579 /* Check if we have some return values */
580 trace("ProcessID : %d\n", pbi
.UniqueProcessId
);
581 ok( pbi
.UniqueProcessId
> 0, "Expected a ProcessID > 0, got 0\n");
584 static void test_query_process_vm(void)
590 status
= pNtQueryInformationProcess(NULL
, ProcessVmCounters
, NULL
, sizeof(pvi
), NULL
);
591 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
592 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status
);
594 status
= pNtQueryInformationProcess(NULL
, ProcessVmCounters
, &pvi
, sizeof(pvi
), NULL
);
595 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08x\n", status
);
597 /* Windows XP and W2K3 will report success for a size of 44 AND 48 !
598 Windows W2K will only report success for 44.
599 For now we only care for 44, which is sizeof(VM_COUNTERS)
600 If an app depends on it, we have to implement this in ntdll/process.c
603 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters
, &pvi
, 24, &ReturnLength
);
604 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
606 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters
, &pvi
, sizeof(pvi
), &ReturnLength
);
607 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
608 ok( sizeof(pvi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
610 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters
, &pvi
, 46, &ReturnLength
);
611 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
612 ok( sizeof(pvi
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
614 /* Check if we have some return values */
615 trace("WorkingSetSize : %ld\n", pvi
.WorkingSetSize
);
618 ok( pvi
.WorkingSetSize
> 0, "Expected a WorkingSetSize > 0\n");
622 static void test_query_process_io(void)
628 /* NT4 doesn't support this information class, so check for it */
629 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters
, &pii
, sizeof(pii
), &ReturnLength
);
630 if (status
== STATUS_NOT_SUPPORTED
)
632 skip("ProcessIoCounters information class is not supported\n");
636 status
= pNtQueryInformationProcess(NULL
, ProcessIoCounters
, NULL
, sizeof(pii
), NULL
);
637 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
638 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status
);
640 status
= pNtQueryInformationProcess(NULL
, ProcessIoCounters
, &pii
, sizeof(pii
), NULL
);
641 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08x\n", status
);
643 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters
, &pii
, 24, &ReturnLength
);
644 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
646 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters
, &pii
, sizeof(pii
), &ReturnLength
);
647 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
648 ok( sizeof(pii
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
650 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters
, &pii
, sizeof(pii
) * 2, &ReturnLength
);
651 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
652 ok( sizeof(pii
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
654 /* Check if we have some return values */
655 trace("OtherOperationCount : 0x%x%08x\n", (DWORD
)(pii
.OtherOperationCount
>> 32), (DWORD
)pii
.OtherOperationCount
);
658 ok( pii
.OtherOperationCount
> 0, "Expected an OtherOperationCount > 0\n");
662 static void test_query_process_times(void)
667 SYSTEMTIME UTC
, Local
;
668 KERNEL_USER_TIMES spti
;
670 status
= pNtQueryInformationProcess(NULL
, ProcessTimes
, NULL
, sizeof(spti
), NULL
);
671 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
672 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status
);
674 status
= pNtQueryInformationProcess(NULL
, ProcessTimes
, &spti
, sizeof(spti
), NULL
);
675 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08x\n", status
);
677 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes
, &spti
, 24, &ReturnLength
);
678 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
680 process
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, one_before_last_pid
);
683 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid
, GetLastError());
684 process
= GetCurrentProcess();
685 trace("ProcessTimes for current process\n");
688 trace("ProcessTimes for process with ID : %d\n", one_before_last_pid
);
690 status
= pNtQueryInformationProcess( process
, ProcessTimes
, &spti
, sizeof(spti
), &ReturnLength
);
691 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
692 ok( sizeof(spti
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
693 CloseHandle(process
);
695 FileTimeToSystemTime((const FILETIME
*)&spti
.CreateTime
, &UTC
);
696 SystemTimeToTzSpecificLocalTime(NULL
, &UTC
, &Local
);
697 trace("CreateTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local
.wMonth
, Local
.wDay
, Local
.wYear
,
698 Local
.wHour
, Local
.wMinute
, Local
.wSecond
);
700 FileTimeToSystemTime((const FILETIME
*)&spti
.ExitTime
, &UTC
);
701 SystemTimeToTzSpecificLocalTime(NULL
, &UTC
, &Local
);
702 trace("ExitTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local
.wMonth
, Local
.wDay
, Local
.wYear
,
703 Local
.wHour
, Local
.wMinute
, Local
.wSecond
);
705 FileTimeToSystemTime((const FILETIME
*)&spti
.KernelTime
, &Local
);
706 trace("KernelTime : %02d:%02d:%02d.%03d\n", Local
.wHour
, Local
.wMinute
, Local
.wSecond
, Local
.wMilliseconds
);
708 FileTimeToSystemTime((const FILETIME
*)&spti
.UserTime
, &Local
);
709 trace("UserTime : %02d:%02d:%02d.%03d\n", Local
.wHour
, Local
.wMinute
, Local
.wSecond
, Local
.wMilliseconds
);
711 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes
, &spti
, sizeof(spti
) * 2, &ReturnLength
);
712 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
713 ok( sizeof(spti
) == ReturnLength
|| ReturnLength
== 0 /* vista */,
714 "Inconsistent length %d\n", ReturnLength
);
717 static void test_query_process_handlecount(void)
724 status
= pNtQueryInformationProcess(NULL
, ProcessHandleCount
, NULL
, sizeof(handlecount
), NULL
);
725 ok( status
== STATUS_ACCESS_VIOLATION
|| status
== STATUS_INVALID_HANDLE
,
726 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status
);
728 status
= pNtQueryInformationProcess(NULL
, ProcessHandleCount
, &handlecount
, sizeof(handlecount
), NULL
);
729 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08x\n", status
);
731 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount
, &handlecount
, 2, &ReturnLength
);
732 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
734 process
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, one_before_last_pid
);
737 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid
, GetLastError());
738 process
= GetCurrentProcess();
739 trace("ProcessHandleCount for current process\n");
742 trace("ProcessHandleCount for process with ID : %d\n", one_before_last_pid
);
744 status
= pNtQueryInformationProcess( process
, ProcessHandleCount
, &handlecount
, sizeof(handlecount
), &ReturnLength
);
745 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
746 ok( sizeof(handlecount
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
747 CloseHandle(process
);
749 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount
, &handlecount
, sizeof(handlecount
) * 2, &ReturnLength
);
750 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
751 ok( sizeof(handlecount
) == ReturnLength
, "Inconsistent length %d\n", ReturnLength
);
753 /* Check if we have some return values */
754 trace("HandleCount : %d\n", handlecount
);
757 ok( handlecount
> 0, "Expected some handles, got 0\n");
761 static void test_query_process_image_file_name(void)
765 UNICODE_STRING image_file_name
;
770 status
= pNtQueryInformationProcess(NULL
, ProcessImageFileName
, &image_file_name
, sizeof(image_file_name
), NULL
);
771 if (status
== STATUS_INVALID_INFO_CLASS
)
773 skip("ProcessImageFileName is not supported\n");
776 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08x\n", status
);
778 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName
, &image_file_name
, 2, &ReturnLength
);
779 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
781 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName
, &image_file_name
, sizeof(image_file_name
), &ReturnLength
);
782 ok( status
== STATUS_INFO_LENGTH_MISMATCH
, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status
);
784 buffer
= HeapAlloc(GetProcessHeap(), 0, ReturnLength
);
785 status
= pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName
, buffer
, ReturnLength
, &ReturnLength
);
786 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
787 memcpy(&image_file_name
, buffer
, sizeof(image_file_name
));
788 len
= WideCharToMultiByte(CP_ACP
, 0, image_file_name
.Buffer
, image_file_name
.Length
/sizeof(WCHAR
), NULL
, 0, NULL
, NULL
);
789 file_nameA
= HeapAlloc(GetProcessHeap(), 0, len
+ 1);
790 WideCharToMultiByte(CP_ACP
, 0, image_file_name
.Buffer
, image_file_name
.Length
/sizeof(WCHAR
), file_nameA
, len
, NULL
, NULL
);
791 file_nameA
[len
] = '\0';
792 HeapFree(GetProcessHeap(), 0, buffer
);
793 trace("process image file name: %s\n", file_nameA
);
794 HeapFree(GetProcessHeap(), 0, file_nameA
);
798 static void test_readvirtualmemory(void)
803 static const char teststring
[] = "test string";
806 process
= OpenProcess(PROCESS_VM_READ
, FALSE
, GetCurrentProcessId());
807 ok(process
!= 0, "Expected to be able to open own process for reading memory\n");
809 /* normal operation */
810 status
= pNtReadVirtualMemory(process
, teststring
, buffer
, 12, &readcount
);
811 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
812 ok( readcount
== 12, "Expected to read 12 bytes, got %ld\n",readcount
);
813 ok( strcmp(teststring
, buffer
) == 0, "Expected read memory to be the same as original memory\n");
815 /* no number of bytes */
816 memset(buffer
, 0, 12);
817 status
= pNtReadVirtualMemory(process
, teststring
, buffer
, 12, NULL
);
818 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
819 ok( strcmp(teststring
, buffer
) == 0, "Expected read memory to be the same as original memory\n");
821 /* illegal remote address */
823 status
= pNtReadVirtualMemory(process
, (void *) 0x1234, buffer
, 12, &readcount
);
824 ok( status
== STATUS_PARTIAL_COPY
|| broken(status
== STATUS_ACCESS_VIOLATION
), "Expected STATUS_PARTIAL_COPY, got %08x\n", status
);
825 if (status
== STATUS_PARTIAL_COPY
)
826 ok( readcount
== 0, "Expected to read 0 bytes, got %ld\n",readcount
);
830 status
= pNtReadVirtualMemory(0, teststring
, buffer
, 12, &readcount
);
831 ok( status
== STATUS_INVALID_HANDLE
, "Expected STATUS_INVALID_HANDLE, got %08x\n", status
);
832 ok( readcount
== 0, "Expected to read 0 bytes, got %ld\n",readcount
);
834 /* pseudo handle for current process*/
835 memset(buffer
, 0, 12);
836 status
= pNtReadVirtualMemory((HANDLE
)-1, teststring
, buffer
, 12, &readcount
);
837 ok( status
== STATUS_SUCCESS
, "Expected STATUS_SUCCESS, got %08x\n", status
);
838 ok( readcount
== 12, "Expected to read 12 bytes, got %ld\n",readcount
);
839 ok( strcmp(teststring
, buffer
) == 0, "Expected read memory to be the same as original memory\n");
841 /* this test currently crashes wine with "wine client error:<process id>: read: Bad address"
842 * because the reply from wine server is directly read into the buffer and that fails with EFAULT
844 /* illegal local address */
845 /*status = pNtReadVirtualMemory(process, teststring, (void *)0x1234, 12, &readcount);
846 ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08lx\n", status);
847 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
850 CloseHandle(process
);
855 if(!InitFunctionPtrs())
858 /* NtQuerySystemInformation */
860 /* 0x0 SystemBasicInformation */
861 trace("Starting test_query_basic()\n");
864 /* 0x1 SystemCpuInformation */
865 trace("Starting test_query_cpu()\n");
868 /* 0x2 SystemPerformanceInformation */
869 trace("Starting test_query_performance()\n");
870 test_query_performance();
872 /* 0x3 SystemTimeOfDayInformation */
873 trace("Starting test_query_timeofday()\n");
874 test_query_timeofday();
876 /* 0x5 SystemProcessInformation */
877 trace("Starting test_query_process()\n");
878 test_query_process();
880 /* 0x8 SystemProcessorPerformanceInformation */
881 trace("Starting test_query_procperf()\n");
882 test_query_procperf();
884 /* 0xb SystemModuleInformation */
885 trace("Starting test_query_module()\n");
888 /* 0x10 SystemHandleInformation */
889 trace("Starting test_query_handle()\n");
892 /* 0x15 SystemCacheInformation */
893 trace("Starting test_query_cache()\n");
896 /* 0x17 SystemInterruptInformation */
897 trace("Starting test_query_interrupt()\n");
898 test_query_interrupt();
900 /* 0x23 SystemKernelDebuggerInformation */
901 trace("Starting test_query_kerndebug()\n");
902 test_query_kerndebug();
904 /* 0x25 SystemRegistryQuotaInformation */
905 trace("Starting test_query_regquota()\n");
906 test_query_regquota();
908 /* NtQueryInformationProcess */
910 /* 0x0 ProcessBasicInformation */
911 trace("Starting test_query_process_basic()\n");
912 test_query_process_basic();
914 /* 0x2 ProcessIoCounters */
915 trace("Starting test_query_process_io()\n");
916 test_query_process_io();
918 /* 0x3 ProcessVmCounters */
919 trace("Starting test_query_process_vm()\n");
920 test_query_process_vm();
922 /* 0x4 ProcessTimes */
923 trace("Starting test_query_process_times()\n");
924 test_query_process_times();
926 /* 0x14 ProcessHandleCount */
927 trace("Starting test_query_process_handlecount()\n");
928 test_query_process_handlecount();
930 /* 27 ProcessImageFileName */
931 trace("Starting test_query_process_image_file_name()\n");
932 test_query_process_image_file_name();
934 /* belongs into it's own file */
935 trace("Starting test_readvirtualmemory()\n");
936 test_readvirtualmemory();