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