1 /* Unit test suite for *Information* Registry API functions
3 * Copyright 2005 Paul Vriens
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "ntdll_test.h"
25 static NTSTATUS (WINAPI * pNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG);
26 static NTSTATUS (WINAPI * pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
27 static NTSTATUS (WINAPI * pNtQueryInformationThread)(HANDLE, THREADINFOCLASS, PVOID, ULONG, PULONG);
28 static NTSTATUS (WINAPI * pNtSetInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG);
29 static NTSTATUS (WINAPI * pNtSetInformationThread)(HANDLE, THREADINFOCLASS, PVOID, ULONG);
30 static NTSTATUS (WINAPI * pNtReadVirtualMemory)(HANDLE, const void*, void*, SIZE_T, SIZE_T*);
31 static NTSTATUS (WINAPI * pNtQueryVirtualMemory)(HANDLE, LPCVOID, MEMORY_INFORMATION_CLASS , PVOID , SIZE_T , SIZE_T *);
32 static NTSTATUS (WINAPI * pNtCreateSection)(HANDLE*,ACCESS_MASK,const OBJECT_ATTRIBUTES*,const LARGE_INTEGER*,ULONG,ULONG,HANDLE);
33 static NTSTATUS (WINAPI * pNtMapViewOfSection)(HANDLE,HANDLE,PVOID*,ULONG,SIZE_T,const LARGE_INTEGER*,SIZE_T*,SECTION_INHERIT,ULONG,ULONG);
34 static NTSTATUS (WINAPI * pNtUnmapViewOfSection)(HANDLE,PVOID);
35 static NTSTATUS (WINAPI * pNtClose)(HANDLE);
36 static ULONG (WINAPI * pNtGetCurrentProcessorNumber)(void);
37 static BOOL (WINAPI * pIsWow64Process)(HANDLE, PBOOL);
41 /* one_before_last_pid is used to be able to compare values of a still running process
42 with the output of the test_query_process_times and test_query_process_handlecount tests.
44 static DWORD one_before_last_pid = 0;
46 #define NTDLL_GET_PROC(func) do { \
47 p ## func = (void*)GetProcAddress(hntdll, #func); \
49 trace("GetProcAddress(%s) failed\n", #func); \
54 static BOOL InitFunctionPtrs(void)
56 /* All needed functions are NT based, so using GetModuleHandle is a good check */
57 HMODULE hntdll = GetModuleHandle("ntdll");
60 win_skip("Not running on NT\n");
64 NTDLL_GET_PROC(NtQuerySystemInformation);
65 NTDLL_GET_PROC(NtQueryInformationProcess);
66 NTDLL_GET_PROC(NtQueryInformationThread);
67 NTDLL_GET_PROC(NtSetInformationProcess);
68 NTDLL_GET_PROC(NtSetInformationThread);
69 NTDLL_GET_PROC(NtReadVirtualMemory);
70 NTDLL_GET_PROC(NtQueryVirtualMemory);
71 NTDLL_GET_PROC(NtClose);
72 NTDLL_GET_PROC(NtCreateSection);
73 NTDLL_GET_PROC(NtMapViewOfSection);
74 NTDLL_GET_PROC(NtUnmapViewOfSection);
76 /* not present before XP */
77 pNtGetCurrentProcessorNumber = (void *) GetProcAddress(hntdll, "NtGetCurrentProcessorNumber");
79 pIsWow64Process = (void *)GetProcAddress(GetModuleHandle("kernel32.dll"), "IsWow64Process");
80 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
84 static void test_query_basic(void)
88 SYSTEM_BASIC_INFORMATION sbi;
90 /* This test also covers some basic parameter testing that should be the same for
91 * every information class
94 /* Use a nonexistent info class */
95 trace("Check nonexistent info class\n");
96 status = pNtQuerySystemInformation(-1, NULL, 0, NULL);
97 ok( status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* vista */,
98 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status);
100 /* Use an existing class but with a zero-length buffer */
101 trace("Check zero-length buffer\n");
102 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, 0, NULL);
103 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
105 /* Use an existing class, correct length but no SystemInformation buffer */
106 trace("Check no SystemInformation buffer\n");
107 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, sizeof(sbi), NULL);
108 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_PARAMETER /* vista */,
109 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER, got %08x\n", status);
111 /* Use a existing class, correct length, a pointer to a buffer but no ReturnLength pointer */
112 trace("Check no ReturnLength pointer\n");
113 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), NULL);
114 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
116 /* Check a too large buffer size */
117 trace("Check a too large buffer size\n");
118 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi) * 2, &ReturnLength);
119 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
121 /* Finally some correct calls */
122 trace("Check with correct parameters\n");
123 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
124 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
125 ok( sizeof(sbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
127 /* Check if we have some return values */
128 trace("Number of Processors : %d\n", sbi.NumberOfProcessors);
129 ok( sbi.NumberOfProcessors > 0, "Expected more than 0 processors, got %d\n", sbi.NumberOfProcessors);
132 static void test_query_cpu(void)
136 SYSTEM_CPU_INFORMATION sci;
138 status = pNtQuerySystemInformation(SystemCpuInformation, &sci, sizeof(sci), &ReturnLength);
139 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
140 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
142 /* Check if we have some return values */
143 trace("Processor FeatureSet : %08x\n", sci.FeatureSet);
144 ok( sci.FeatureSet != 0, "Expected some features for this processor, got %08x\n", sci.FeatureSet);
147 static void test_query_performance(void)
151 ULONGLONG buffer[sizeof(SYSTEM_PERFORMANCE_INFORMATION)/sizeof(ULONGLONG) + 5];
152 DWORD size = sizeof(SYSTEM_PERFORMANCE_INFORMATION);
154 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, 0, &ReturnLength);
155 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
157 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, size, &ReturnLength);
158 if (status == STATUS_INFO_LENGTH_MISMATCH && is_wow64)
160 /* size is larger on wow64 under w2k8/win7 */
162 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, size, &ReturnLength);
164 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
165 ok( ReturnLength == size, "Inconsistent length %d\n", ReturnLength);
167 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, size + 2, &ReturnLength);
168 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
169 ok( ReturnLength == size || ReturnLength == size + 2,
170 "Inconsistent length %d\n", ReturnLength);
172 /* Not return values yet, as struct members are unknown */
175 static void test_query_timeofday(void)
180 /* Copy of our winternl.h structure turned into a private one */
181 typedef struct _SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE {
182 LARGE_INTEGER liKeBootTime;
183 LARGE_INTEGER liKeSystemTime;
184 LARGE_INTEGER liExpTimeZoneBias;
185 ULONG uCurrentTimeZoneId;
187 } SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE;
189 SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE sti;
191 /* The struct size for NT (32 bytes) and Win2K/XP (48 bytes) differ.
193 * Windows 2000 and XP return STATUS_INFO_LENGTH_MISMATCH if the given buffer size is greater
194 * then 48 and 0 otherwise
195 * Windows NT returns STATUS_INFO_LENGTH_MISMATCH when the given buffer size is not correct
198 * Windows 2000 and XP copy the given buffer size into the provided buffer, if the return code is STATUS_SUCCESS
199 * NT only fills the buffer if the return code is STATUS_SUCCESS
203 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
205 if (status == STATUS_INFO_LENGTH_MISMATCH)
207 trace("Windows version is NT, we have to cater for differences with W2K/WinXP\n");
209 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
210 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
211 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
213 sti.uCurrentTimeZoneId = 0xdeadbeef;
214 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 28, &ReturnLength);
215 ok(status == STATUS_SUCCESS || broken(status == STATUS_INFO_LENGTH_MISMATCH /* NT4 */), "Expected STATUS_SUCCESS, got %08x\n", status);
216 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
218 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
219 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
220 ok( 32 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
224 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
225 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
226 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
228 sti.uCurrentTimeZoneId = 0xdeadbeef;
229 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 24, &ReturnLength);
230 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
231 ok( 24 == ReturnLength, "ReturnLength should be 24, it is (%d)\n", ReturnLength);
232 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
234 sti.uCurrentTimeZoneId = 0xdeadbeef;
235 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
236 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
237 ok( 32 == ReturnLength, "ReturnLength should be 32, it is (%d)\n", ReturnLength);
238 ok( 0xdeadbeef != sti.uCurrentTimeZoneId, "Buffer should have been partially filled\n");
240 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 49, &ReturnLength);
241 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
242 ok( ReturnLength == 0 || ReturnLength == sizeof(sti) /* vista */,
243 "ReturnLength should be 0, it is (%d)\n", ReturnLength);
245 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
246 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
247 ok( sizeof(sti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
250 /* Check if we have some return values */
251 trace("uCurrentTimeZoneId : (%d)\n", sti.uCurrentTimeZoneId);
254 static void test_query_process(void)
261 SYSTEM_BASIC_INFORMATION sbi;
263 /* Copy of our winternl.h structure turned into a private one */
264 typedef struct _SYSTEM_PROCESS_INFORMATION_PRIVATE {
265 ULONG NextEntryOffset;
268 FILETIME ftCreationTime;
270 FILETIME ftKernelTime;
271 UNICODE_STRING ProcessName;
272 DWORD dwBasePriority;
273 HANDLE UniqueProcessId;
274 HANDLE ParentProcessId;
278 VM_COUNTERS vmCounters;
279 IO_COUNTERS ioCounters;
280 SYSTEM_THREAD_INFORMATION ti[1];
281 } SYSTEM_PROCESS_INFORMATION_PRIVATE;
283 ULONG SystemInformationLength = sizeof(SYSTEM_PROCESS_INFORMATION_PRIVATE);
284 SYSTEM_PROCESS_INFORMATION_PRIVATE *spi, *spi_buf = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
286 /* Only W2K3 returns the needed length, the rest returns 0, so we have to loop */
290 status = pNtQuerySystemInformation(SystemProcessInformation, spi_buf, SystemInformationLength, &ReturnLength);
292 if (status != STATUS_INFO_LENGTH_MISMATCH) break;
294 spi_buf = HeapReAlloc(GetProcessHeap(), 0, spi_buf , SystemInformationLength *= 2);
296 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
299 /* Get the first NextEntryOffset, from this we can deduce the OS version we're running
302 * NextEntryOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
304 * NextEntryOffset for a process is 136 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
305 * Wine (with every windows version):
306 * NextEntryOffset for a process is 0 if just this test is running
307 * NextEntryOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION) +
308 * ProcessName.MaximumLength
309 * if more wine processes are running
311 * Note : On windows the first process is in fact the Idle 'process' with a thread for every processor
314 pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
316 is_nt = ( spi->NextEntryOffset - (sbi.NumberOfProcessors * sizeof(SYSTEM_THREAD_INFORMATION)) == 136);
318 if (is_nt) win_skip("Windows version is NT, we will skip thread tests\n");
320 /* Check if we have some return values
322 * On windows there will be several processes running (Including the always present Idle and System)
323 * On wine we only have one (if this test is the only wine process running)
326 /* Loop through the processes */
332 last_pid = (DWORD_PTR)spi->UniqueProcessId;
334 ok( spi->dwThreadCount > 0, "Expected some threads for this process, got 0\n");
336 /* Loop through the threads, skip NT4 for now */
341 for ( j = 0; j < spi->dwThreadCount; j++)
344 ok ( spi->ti[j].ClientId.UniqueProcess == spi->UniqueProcessId,
345 "The owning pid of the thread (%p) doesn't equal the pid (%p) of the process\n",
346 spi->ti[j].ClientId.UniqueProcess, spi->UniqueProcessId);
350 if (!spi->NextEntryOffset) break;
352 one_before_last_pid = last_pid;
354 spi = (SYSTEM_PROCESS_INFORMATION_PRIVATE*)((char*)spi + spi->NextEntryOffset);
356 trace("Total number of running processes : %d\n", i);
357 if (!is_nt) trace("Total number of running threads : %d\n", k);
359 if (one_before_last_pid == 0) one_before_last_pid = last_pid;
361 HeapFree( GetProcessHeap(), 0, spi_buf);
364 static void test_query_procperf(void)
369 SYSTEM_BASIC_INFORMATION sbi;
370 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi;
372 /* Find out the number of processors */
373 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
374 ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
375 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
377 sppi = HeapAlloc(GetProcessHeap(), 0, NeededLength);
379 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, 0, &ReturnLength);
380 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
382 /* Try it for 1 processor */
383 sppi->KernelTime.QuadPart = 0xdeaddead;
384 sppi->UserTime.QuadPart = 0xdeaddead;
385 sppi->IdleTime.QuadPart = 0xdeaddead;
386 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi,
387 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION), &ReturnLength);
388 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
389 ok( sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) == ReturnLength,
390 "Inconsistent length %d\n", ReturnLength);
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 /* Try it for all processors */
396 sppi->KernelTime.QuadPart = 0xdeaddead;
397 sppi->UserTime.QuadPart = 0xdeaddead;
398 sppi->IdleTime.QuadPart = 0xdeaddead;
399 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength, &ReturnLength);
400 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
401 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
402 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
403 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
404 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
406 /* A too large given buffer size */
407 sppi = HeapReAlloc(GetProcessHeap(), 0, sppi , NeededLength + 2);
408 sppi->KernelTime.QuadPart = 0xdeaddead;
409 sppi->UserTime.QuadPart = 0xdeaddead;
410 sppi->IdleTime.QuadPart = 0xdeaddead;
411 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength + 2, &ReturnLength);
412 ok( status == STATUS_SUCCESS || status == STATUS_INFO_LENGTH_MISMATCH /* vista */,
413 "Expected STATUS_SUCCESS or STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
414 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
415 if (status == STATUS_SUCCESS)
417 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
418 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
419 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
421 else /* vista and 2008 */
423 ok (sppi->KernelTime.QuadPart == 0xdeaddead, "KernelTime changed\n");
424 ok (sppi->UserTime.QuadPart == 0xdeaddead, "UserTime changed\n");
425 ok (sppi->IdleTime.QuadPart == 0xdeaddead, "IdleTime changed\n");
428 HeapFree( GetProcessHeap(), 0, sppi);
431 static void test_query_module(void)
435 ULONG ModuleCount, i;
437 ULONG SystemInformationLength = sizeof(SYSTEM_MODULE_INFORMATION);
438 SYSTEM_MODULE_INFORMATION* smi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
441 /* Request the needed length */
442 status = pNtQuerySystemInformation(SystemModuleInformation, smi, 0, &ReturnLength);
443 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
444 ok( ReturnLength > 0, "Expected a ReturnLength to show the needed length\n");
446 SystemInformationLength = ReturnLength;
447 smi = HeapReAlloc(GetProcessHeap(), 0, smi , SystemInformationLength);
448 status = pNtQuerySystemInformation(SystemModuleInformation, smi, SystemInformationLength, &ReturnLength);
449 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
451 ModuleCount = smi->ModulesCount;
452 sm = &smi->Modules[0];
453 /* our implementation is a stub for now */
454 ok( ModuleCount > 0, "Expected some modules to be loaded\n");
456 /* Loop through all the modules/drivers, Wine doesn't get here (yet) */
457 for (i = 0; i < ModuleCount ; i++)
459 ok( i == sm->Id, "Id (%d) should have matched %u\n", sm->Id, i);
463 HeapFree( GetProcessHeap(), 0, smi);
466 static void test_query_handle(void)
470 ULONG SystemInformationLength = sizeof(SYSTEM_HANDLE_INFORMATION);
471 SYSTEM_HANDLE_INFORMATION* shi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
473 /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
474 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
475 todo_wine ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
477 SystemInformationLength = ReturnLength;
478 shi = HeapReAlloc(GetProcessHeap(), 0, shi , SystemInformationLength);
479 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
480 if (status != STATUS_INFO_LENGTH_MISMATCH) /* vista */
482 ok( status == STATUS_SUCCESS,
483 "Expected STATUS_SUCCESS, got %08x\n", status);
485 /* Check if we have some return values */
486 trace("Number of Handles : %d\n", shi->Count);
489 /* our implementation is a stub for now */
490 ok( shi->Count > 1, "Expected more than 1 handles, got (%d)\n", shi->Count);
493 HeapFree( GetProcessHeap(), 0, shi);
496 static void test_query_cache(void)
500 SYSTEM_CACHE_INFORMATION sci;
502 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, 0, &ReturnLength);
503 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
505 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci), &ReturnLength);
506 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
507 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
509 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci) + 2, &ReturnLength);
510 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
511 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
514 static void test_query_interrupt(void)
519 SYSTEM_BASIC_INFORMATION sbi;
520 SYSTEM_INTERRUPT_INFORMATION* sii;
522 /* Find out the number of processors */
523 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
524 ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
525 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_INTERRUPT_INFORMATION);
527 sii = HeapAlloc(GetProcessHeap(), 0, NeededLength);
529 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, 0, &ReturnLength);
530 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
532 /* Try it for all processors */
533 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, NeededLength, &ReturnLength);
534 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
536 /* Windows XP and W2K3 (and others?) always return 0 for the ReturnLength
537 * No test added for this as it's highly unlikely that an app depends on this
540 HeapFree( GetProcessHeap(), 0, sii);
543 static void test_query_kerndebug(void)
547 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
549 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, 0, &ReturnLength);
550 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
552 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi), &ReturnLength);
553 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
554 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
556 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi) + 2, &ReturnLength);
557 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
558 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
561 static void test_query_regquota(void)
565 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
567 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, 0, &ReturnLength);
568 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
570 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi), &ReturnLength);
571 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
572 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
574 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi) + 2, &ReturnLength);
575 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
576 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
579 static void test_query_process_basic(void)
584 typedef struct _PROCESS_BASIC_INFORMATION_PRIVATE {
585 DWORD_PTR ExitStatus;
587 DWORD_PTR AffinityMask;
588 DWORD_PTR BasePriority;
589 ULONG_PTR UniqueProcessId;
590 ULONG_PTR InheritedFromUniqueProcessId;
591 } PROCESS_BASIC_INFORMATION_PRIVATE, *PPROCESS_BASIC_INFORMATION_PRIVATE;
593 PROCESS_BASIC_INFORMATION_PRIVATE pbi;
595 /* This test also covers some basic parameter testing that should be the same for
596 * every information class
599 /* Use a nonexistent info class */
600 trace("Check nonexistent info class\n");
601 status = pNtQueryInformationProcess(NULL, -1, NULL, 0, NULL);
602 ok( status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* vista */,
603 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status);
605 /* Do not give a handle and buffer */
606 trace("Check NULL handle and buffer and zero-length buffersize\n");
607 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, 0, NULL);
608 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
610 /* Use a correct info class and buffer size, but still no handle and buffer */
611 trace("Check NULL handle and buffer\n");
612 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, sizeof(pbi), NULL);
613 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
614 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
616 /* Use a correct info class and buffer size, but still no handle */
617 trace("Check NULL handle\n");
618 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
619 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
621 /* Use a greater buffer size */
622 trace("Check NULL handle and too large buffersize\n");
623 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi) * 2, NULL);
624 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
626 /* Use no ReturnLength */
627 trace("Check NULL ReturnLength\n");
628 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
629 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
631 /* Finally some correct calls */
632 trace("Check with correct parameters\n");
633 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), &ReturnLength);
634 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
635 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
637 /* Everything is correct except a too large buffersize */
638 trace("Too large buffersize\n");
639 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi) * 2, &ReturnLength);
640 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
641 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
643 /* Check if we have some return values */
644 trace("ProcessID : %lx\n", pbi.UniqueProcessId);
645 ok( pbi.UniqueProcessId > 0, "Expected a ProcessID > 0, got 0\n");
648 static void test_query_process_vm(void)
653 ULONG old_size = FIELD_OFFSET(VM_COUNTERS,PrivatePageCount);
655 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, NULL, sizeof(pvi), NULL);
656 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
657 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
659 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, &pvi, old_size, NULL);
660 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
662 /* Windows XP and W2K3 will report success for a size of 44 AND 48 !
663 Windows W2K will only report success for 44.
664 For now we only care for 44, which is FIELD_OFFSET(VM_COUNTERS,PrivatePageCount))
667 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 24, &ReturnLength);
668 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
670 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, old_size, &ReturnLength);
671 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
672 ok( old_size == ReturnLength, "Inconsistent length %d\n", ReturnLength);
674 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 46, &ReturnLength);
675 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
676 ok( ReturnLength == old_size || ReturnLength == sizeof(pvi), "Inconsistent length %d\n", ReturnLength);
678 /* Check if we have some return values */
679 trace("WorkingSetSize : %ld\n", pvi.WorkingSetSize);
682 ok( pvi.WorkingSetSize > 0, "Expected a WorkingSetSize > 0\n");
686 static void test_query_process_io(void)
692 /* NT4 doesn't support this information class, so check for it */
693 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
694 if (status == STATUS_NOT_SUPPORTED)
696 win_skip("ProcessIoCounters information class is not supported\n");
700 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, NULL, sizeof(pii), NULL);
701 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
702 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
704 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, &pii, sizeof(pii), NULL);
705 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
707 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, 24, &ReturnLength);
708 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
710 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
711 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
712 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
714 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii) * 2, &ReturnLength);
715 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
716 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
718 /* Check if we have some return values */
719 trace("OtherOperationCount : 0x%x%08x\n", (DWORD)(pii.OtherOperationCount >> 32), (DWORD)pii.OtherOperationCount);
722 ok( pii.OtherOperationCount > 0, "Expected an OtherOperationCount > 0\n");
726 static void test_query_process_times(void)
731 SYSTEMTIME UTC, Local;
732 KERNEL_USER_TIMES spti;
734 status = pNtQueryInformationProcess(NULL, ProcessTimes, NULL, sizeof(spti), NULL);
735 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
736 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
738 status = pNtQueryInformationProcess(NULL, ProcessTimes, &spti, sizeof(spti), NULL);
739 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
741 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, 24, &ReturnLength);
742 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
744 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
747 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
748 process = GetCurrentProcess();
749 trace("ProcessTimes for current process\n");
752 trace("ProcessTimes for process with ID : %d\n", one_before_last_pid);
754 status = pNtQueryInformationProcess( process, ProcessTimes, &spti, sizeof(spti), &ReturnLength);
755 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
756 ok( sizeof(spti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
757 CloseHandle(process);
759 FileTimeToSystemTime((const FILETIME *)&spti.CreateTime, &UTC);
760 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
761 trace("CreateTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
762 Local.wHour, Local.wMinute, Local.wSecond);
764 FileTimeToSystemTime((const FILETIME *)&spti.ExitTime, &UTC);
765 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
766 trace("ExitTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
767 Local.wHour, Local.wMinute, Local.wSecond);
769 FileTimeToSystemTime((const FILETIME *)&spti.KernelTime, &Local);
770 trace("KernelTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
772 FileTimeToSystemTime((const FILETIME *)&spti.UserTime, &Local);
773 trace("UserTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
775 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, sizeof(spti) * 2, &ReturnLength);
776 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
777 ok( sizeof(spti) == ReturnLength ||
778 ReturnLength == 0 /* vista */ ||
779 broken(is_wow64), /* returns garbage on wow64 */
780 "Inconsistent length %d\n", ReturnLength);
783 static void test_query_process_debug_port(int argc, char **argv)
785 DWORD_PTR debug_port = 0xdeadbeef;
786 char cmdline[MAX_PATH];
787 PROCESS_INFORMATION pi;
788 STARTUPINFO si = { 0 };
792 sprintf(cmdline, "%s %s %s", argv[0], argv[1], "debuggee");
795 ret = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &si, &pi);
796 ok(ret, "CreateProcess failed, last error %#x.\n", GetLastError());
799 status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
801 ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
803 status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
804 NULL, sizeof(debug_port), NULL);
805 ok(status == STATUS_INVALID_HANDLE || status == STATUS_ACCESS_VIOLATION,
806 "Expected STATUS_INVALID_HANDLE, got %#x.\n", status);
808 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
809 NULL, sizeof(debug_port), NULL);
810 ok(status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
812 status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
813 &debug_port, sizeof(debug_port), NULL);
814 ok(status == STATUS_INVALID_HANDLE, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
816 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
817 &debug_port, sizeof(debug_port) - 1, NULL);
818 ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
820 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
821 &debug_port, sizeof(debug_port) + 1, NULL);
822 ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
824 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
825 &debug_port, sizeof(debug_port), NULL);
826 ok(!status, "NtQueryInformationProcess failed, status %#x.\n", status);
827 ok(debug_port == 0, "Expected port 0, got %#lx.\n", debug_port);
829 status = pNtQueryInformationProcess(pi.hProcess, ProcessDebugPort,
830 &debug_port, sizeof(debug_port), NULL);
831 ok(!status, "NtQueryInformationProcess failed, status %#x.\n", status);
832 ok(debug_port == ~(DWORD_PTR)0, "Expected port %#lx, got %#lx.\n", ~(DWORD_PTR)0, debug_port);
838 ret = WaitForDebugEvent(&ev, INFINITE);
839 ok(ret, "WaitForDebugEvent failed, last error %#x.\n", GetLastError());
842 if (ev.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break;
844 ret = ContinueDebugEvent(ev.dwProcessId, ev.dwThreadId, DBG_CONTINUE);
845 ok(ret, "ContinueDebugEvent failed, last error %#x.\n", GetLastError());
849 ret = CloseHandle(pi.hThread);
850 ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
851 ret = CloseHandle(pi.hProcess);
852 ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
855 static void test_query_process_handlecount(void)
860 BYTE buffer[2 * sizeof(DWORD)];
863 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, NULL, sizeof(handlecount), NULL);
864 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
865 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
867 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, &handlecount, sizeof(handlecount), NULL);
868 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
870 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, &handlecount, 2, &ReturnLength);
871 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
873 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
876 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
877 process = GetCurrentProcess();
878 trace("ProcessHandleCount for current process\n");
881 trace("ProcessHandleCount for process with ID : %d\n", one_before_last_pid);
883 status = pNtQueryInformationProcess( process, ProcessHandleCount, &handlecount, sizeof(handlecount), &ReturnLength);
884 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
885 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
886 CloseHandle(process);
888 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, buffer, sizeof(buffer), &ReturnLength);
889 ok( status == STATUS_INFO_LENGTH_MISMATCH || status == STATUS_SUCCESS,
890 "Expected STATUS_INFO_LENGTH_MISMATCH or STATUS_SUCCESS, got %08x\n", status);
891 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
893 /* Check if we have some return values */
894 trace("HandleCount : %d\n", handlecount);
897 ok( handlecount > 0, "Expected some handles, got 0\n");
901 static void test_query_process_image_file_name(void)
905 UNICODE_STRING image_file_name;
910 status = pNtQueryInformationProcess(NULL, ProcessImageFileName, &image_file_name, sizeof(image_file_name), NULL);
911 if (status == STATUS_INVALID_INFO_CLASS)
913 win_skip("ProcessImageFileName is not supported\n");
916 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
918 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, &image_file_name, 2, &ReturnLength);
919 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
921 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, &image_file_name, sizeof(image_file_name), &ReturnLength);
922 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
924 buffer = HeapAlloc(GetProcessHeap(), 0, ReturnLength);
925 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, buffer, ReturnLength, &ReturnLength);
926 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
927 memcpy(&image_file_name, buffer, sizeof(image_file_name));
928 len = WideCharToMultiByte(CP_ACP, 0, image_file_name.Buffer, image_file_name.Length/sizeof(WCHAR), NULL, 0, NULL, NULL);
929 file_nameA = HeapAlloc(GetProcessHeap(), 0, len + 1);
930 WideCharToMultiByte(CP_ACP, 0, image_file_name.Buffer, image_file_name.Length/sizeof(WCHAR), file_nameA, len, NULL, NULL);
931 file_nameA[len] = '\0';
932 HeapFree(GetProcessHeap(), 0, buffer);
933 trace("process image file name: %s\n", file_nameA);
934 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);
935 HeapFree(GetProcessHeap(), 0, file_nameA);
938 static void test_query_process_debug_object_handle(int argc, char **argv)
940 char cmdline[MAX_PATH];
941 STARTUPINFO si = {0};
942 PROCESS_INFORMATION pi;
947 sprintf(cmdline, "%s %s %s", argv[0], argv[1], "debuggee");
950 ret = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, DEBUG_PROCESS, NULL,
952 ok(ret, "CreateProcess failed with last error %u\n", GetLastError());
955 status = pNtQueryInformationProcess(NULL, ProcessDebugObjectHandle, NULL,
957 if (status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED)
959 win_skip("ProcessDebugObjectHandle is not supported\n");
962 ok(status == STATUS_INFO_LENGTH_MISMATCH,
963 "Expected NtQueryInformationProcess to return STATUS_INFO_LENGTH_MISMATCH, got 0x%08x\n",
966 status = pNtQueryInformationProcess(NULL, ProcessDebugObjectHandle, NULL,
967 sizeof(debug_object), NULL);
968 ok(status == STATUS_INVALID_HANDLE ||
969 status == STATUS_ACCESS_VIOLATION, /* XP */
970 "Expected NtQueryInformationProcess to return STATUS_INVALID_HANDLE, got 0x%08x\n", status);
972 status = pNtQueryInformationProcess(GetCurrentProcess(),
973 ProcessDebugObjectHandle, NULL, sizeof(debug_object), NULL);
974 ok(status == STATUS_ACCESS_VIOLATION,
975 "Expected NtQueryInformationProcess to return STATUS_ACCESS_VIOLATION, got 0x%08x\n", status);
977 status = pNtQueryInformationProcess(NULL, ProcessDebugObjectHandle,
978 &debug_object, sizeof(debug_object), NULL);
979 ok(status == STATUS_INVALID_HANDLE,
980 "Expected NtQueryInformationProcess to return STATUS_ACCESS_VIOLATION, got 0x%08x\n", status);
982 status = pNtQueryInformationProcess(GetCurrentProcess(),
983 ProcessDebugObjectHandle, &debug_object,
984 sizeof(debug_object) - 1, NULL);
985 ok(status == STATUS_INFO_LENGTH_MISMATCH,
986 "Expected NtQueryInformationProcess to return STATUS_INFO_LENGTH_MISMATCH, got 0x%08x\n", status);
988 status = pNtQueryInformationProcess(GetCurrentProcess(),
989 ProcessDebugObjectHandle, &debug_object,
990 sizeof(debug_object) + 1, NULL);
991 ok(status == STATUS_INFO_LENGTH_MISMATCH,
992 "Expected NtQueryInformationProcess to return STATUS_INFO_LENGTH_MISMATCH, got 0x%08x\n", status);
994 debug_object = (HANDLE)0xdeadbeef;
995 status = pNtQueryInformationProcess(GetCurrentProcess(),
996 ProcessDebugObjectHandle, &debug_object,
997 sizeof(debug_object), NULL);
998 ok(status == STATUS_PORT_NOT_SET,
999 "Expected NtQueryInformationProcess to return STATUS_PORT_NOT_SET, got 0x%08x\n", status);
1000 ok(debug_object == NULL ||
1001 broken(debug_object == (HANDLE)0xdeadbeef), /* Wow64 */
1002 "Expected debug object handle to be NULL, got %p\n", debug_object);
1004 debug_object = (HANDLE)0xdeadbeef;
1005 status = pNtQueryInformationProcess(pi.hProcess, ProcessDebugObjectHandle,
1006 &debug_object, sizeof(debug_object), NULL);
1008 ok(status == STATUS_SUCCESS,
1009 "Expected NtQueryInformationProcess to return STATUS_SUCCESS, got 0x%08x\n", status);
1011 ok(debug_object != NULL,
1012 "Expected debug object handle to be non-NULL, got %p\n", debug_object);
1018 ret = WaitForDebugEvent(&ev, INFINITE);
1019 ok(ret, "WaitForDebugEvent failed with last error %u\n", GetLastError());
1022 if (ev.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break;
1024 ret = ContinueDebugEvent(ev.dwProcessId, ev.dwThreadId, DBG_CONTINUE);
1025 ok(ret, "ContinueDebugEvent failed with last error %u\n", GetLastError());
1029 ret = CloseHandle(pi.hThread);
1030 ok(ret, "CloseHandle failed with last error %u\n", GetLastError());
1031 ret = CloseHandle(pi.hProcess);
1032 ok(ret, "CloseHandle failed with last error %u\n", GetLastError());
1035 static void test_query_process_debug_flags(int argc, char **argv)
1037 DWORD debug_flags = 0xdeadbeef;
1038 char cmdline[MAX_PATH];
1039 PROCESS_INFORMATION pi;
1040 STARTUPINFO si = { 0 };
1044 sprintf(cmdline, "%s %s %s", argv[0], argv[1], "debuggee");
1047 ret = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS, NULL, NULL, &si, &pi);
1048 ok(ret, "CreateProcess failed, last error %#x.\n", GetLastError());
1051 status = pNtQueryInformationProcess(NULL, ProcessDebugFlags,
1053 ok(status == STATUS_INFO_LENGTH_MISMATCH || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
1055 status = pNtQueryInformationProcess(NULL, ProcessDebugFlags,
1056 NULL, sizeof(debug_flags), NULL);
1057 ok(status == STATUS_INVALID_HANDLE || status == STATUS_ACCESS_VIOLATION || broken(status == STATUS_INVALID_INFO_CLASS) /* W7PROX64 (32-bit) */,
1058 "Expected STATUS_INVALID_HANDLE, got %#x.\n", status);
1060 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugFlags,
1061 NULL, sizeof(debug_flags), NULL);
1062 ok(status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
1064 status = pNtQueryInformationProcess(NULL, ProcessDebugFlags,
1065 &debug_flags, sizeof(debug_flags), NULL);
1066 ok(status == STATUS_INVALID_HANDLE || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
1068 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugFlags,
1069 &debug_flags, sizeof(debug_flags) - 1, NULL);
1070 ok(status == STATUS_INFO_LENGTH_MISMATCH || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
1072 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugFlags,
1073 &debug_flags, sizeof(debug_flags) + 1, NULL);
1074 ok(status == STATUS_INFO_LENGTH_MISMATCH || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
1076 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugFlags,
1077 &debug_flags, sizeof(debug_flags), NULL);
1078 ok(!status || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "NtQueryInformationProcess failed, status %#x.\n", status);
1079 ok(debug_flags == TRUE|| broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "Expected flag TRUE, got %x.\n", debug_flags);
1081 status = pNtQueryInformationProcess(pi.hProcess, ProcessDebugFlags,
1082 &debug_flags, sizeof(debug_flags), NULL);
1083 ok(!status || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "NtQueryInformationProcess failed, status %#x.\n", status);
1084 ok(debug_flags == FALSE || broken(status == STATUS_INVALID_INFO_CLASS) /* NT4 */, "Expected flag FALSE, got %x.\n", debug_flags);
1090 ret = WaitForDebugEvent(&ev, INFINITE);
1091 ok(ret, "WaitForDebugEvent failed, last error %#x.\n", GetLastError());
1094 if (ev.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break;
1096 ret = ContinueDebugEvent(ev.dwProcessId, ev.dwThreadId, DBG_CONTINUE);
1097 ok(ret, "ContinueDebugEvent failed, last error %#x.\n", GetLastError());
1101 ret = CloseHandle(pi.hThread);
1102 ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
1103 ret = CloseHandle(pi.hProcess);
1104 ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
1107 static void test_readvirtualmemory(void)
1112 static const char teststring[] = "test string";
1115 process = OpenProcess(PROCESS_VM_READ, FALSE, GetCurrentProcessId());
1116 ok(process != 0, "Expected to be able to open own process for reading memory\n");
1118 /* normal operation */
1119 status = pNtReadVirtualMemory(process, teststring, buffer, 12, &readcount);
1120 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1121 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
1122 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
1124 /* no number of bytes */
1125 memset(buffer, 0, 12);
1126 status = pNtReadVirtualMemory(process, teststring, buffer, 12, NULL);
1127 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1128 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
1130 /* illegal remote address */
1132 status = pNtReadVirtualMemory(process, (void *) 0x1234, buffer, 12, &readcount);
1133 ok( status == STATUS_PARTIAL_COPY || broken(status == STATUS_ACCESS_VIOLATION), "Expected STATUS_PARTIAL_COPY, got %08x\n", status);
1134 if (status == STATUS_PARTIAL_COPY)
1135 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
1139 status = pNtReadVirtualMemory(0, teststring, buffer, 12, &readcount);
1140 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
1141 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
1143 /* pseudo handle for current process*/
1144 memset(buffer, 0, 12);
1145 status = pNtReadVirtualMemory((HANDLE)-1, teststring, buffer, 12, &readcount);
1146 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1147 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
1148 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
1150 /* illegal local address */
1151 status = pNtReadVirtualMemory(process, teststring, (void *)0x1234, 12, &readcount);
1152 ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
1153 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
1155 CloseHandle(process);
1158 static void test_mapprotection(void)
1162 MEMORY_BASIC_INFORMATION info;
1163 ULONG oldflags, flagsize, flags = MEM_EXECUTE_OPTION_ENABLE;
1164 LARGE_INTEGER size, offset;
1166 SIZE_T retlen, count;
1170 skip("No NtClose ... Win98\n");
1173 /* Switch to being a noexec unaware process */
1174 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &oldflags, sizeof (oldflags), &flagsize);
1175 if (status == STATUS_INVALID_PARAMETER) {
1176 skip("Invalid Parameter on ProcessExecuteFlags query?\n");
1179 ok( (status == STATUS_SUCCESS) || (status == STATUS_INVALID_INFO_CLASS), "Expected STATUS_SUCCESS, got %08x\n", status);
1180 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &flags, sizeof(flags) );
1181 ok( (status == STATUS_SUCCESS) || (status == STATUS_INVALID_INFO_CLASS), "Expected STATUS_SUCCESS, got %08x\n", status);
1183 size.u.LowPart = 0x1000;
1184 size.u.HighPart = 0;
1185 status = pNtCreateSection ( &h,
1186 STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE | SECTION_MAP_EXECUTE,
1190 SEC_COMMIT | SEC_NOCACHE,
1193 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1195 offset.u.LowPart = 0;
1196 offset.u.HighPart = 0;
1199 status = pNtMapViewOfSection ( h, GetCurrentProcess(), &addr, 0, 0, &offset, &count, ViewShare, 0, PAGE_READWRITE);
1200 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1201 #if defined(__x86_64__) || defined(__i386__)
1202 memset (addr, 0xc3, 1); /* lret ... in both i386 and x86_64 */
1203 trace("trying to execute code in the readwrite only mapped anon file...\n");
1205 trace("...done.\n");
1208 status = pNtQueryVirtualMemory( GetCurrentProcess(), addr, MemoryBasicInformation, &info, sizeof(info), &retlen );
1209 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1210 ok( retlen == sizeof(info), "Expected STATUS_SUCCESS, got %08x\n", status);
1211 ok(info.Protect == PAGE_READWRITE, "addr.Protect is not PAGE_READWRITE, but 0x%x\n", info.Protect);
1213 status = pNtUnmapViewOfSection (GetCurrentProcess(), addr);
1214 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1218 pNtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &oldflags, sizeof(oldflags) );
1221 static void test_queryvirtualmemory(void)
1225 static const char teststring[] = "test string";
1226 static char datatestbuf[42] = "abc";
1227 static char rwtestbuf[42];
1228 MEMORY_BASIC_INFORMATION mbi;
1232 module = GetModuleHandle( "ntdll.dll" );
1233 trace("Check flags of the PE header of NTDLL.DLL at %p\n", module);
1234 status = pNtQueryVirtualMemory(NtCurrentProcess(), module, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1235 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1236 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1237 ok (mbi.AllocationBase == module, "mbi.AllocationBase is 0x%p, expected 0x%p\n", mbi.AllocationBase, module);
1238 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1239 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%x\n", mbi.State, MEM_COMMIT);
1240 ok (mbi.Protect == PAGE_READONLY, "mbi.Protect is 0x%x, expected 0x%x\n", mbi.Protect, PAGE_READONLY);
1241 ok (mbi.Type == MEM_IMAGE, "mbi.Type is 0x%x, expected 0x%x\n", mbi.Type, MEM_IMAGE);
1243 trace("Check flags of a function entry in NTDLL.DLL at %p\n", pNtQueryVirtualMemory);
1244 module = GetModuleHandle( "ntdll.dll" );
1245 status = pNtQueryVirtualMemory(NtCurrentProcess(), pNtQueryVirtualMemory, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1246 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1247 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1248 ok (mbi.AllocationBase == module, "mbi.AllocationBase is 0x%p, expected 0x%p\n", mbi.AllocationBase, module);
1249 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1250 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%x\n", mbi.State, MEM_COMMIT);
1251 ok (mbi.Protect == PAGE_EXECUTE_READ, "mbi.Protect is 0x%x, expected 0x%x\n", mbi.Protect, PAGE_EXECUTE_READ);
1253 trace("Check flags of heap at %p\n", GetProcessHeap());
1254 status = pNtQueryVirtualMemory(NtCurrentProcess(), GetProcessHeap(), MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1255 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1256 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1257 ok (mbi.AllocationProtect == PAGE_READWRITE || mbi.AllocationProtect == PAGE_EXECUTE_READWRITE,
1258 "mbi.AllocationProtect is 0x%x\n", mbi.AllocationProtect);
1259 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%x\n", mbi.State, MEM_COMMIT);
1260 ok (mbi.Protect == PAGE_READWRITE || mbi.Protect == PAGE_EXECUTE_READWRITE,
1261 "mbi.Protect is 0x%x\n", mbi.Protect);
1263 trace("Check flags of stack at %p\n", stackbuf);
1264 status = pNtQueryVirtualMemory(NtCurrentProcess(), stackbuf, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1265 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1266 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1267 ok (mbi.AllocationProtect == PAGE_READWRITE, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_READWRITE);
1268 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%x\n", mbi.State, MEM_COMMIT);
1269 ok (mbi.Protect == PAGE_READWRITE, "mbi.Protect is 0x%x, expected 0x%x\n", mbi.Protect, PAGE_READWRITE);
1271 trace("Check flags of read-only data at %p\n", teststring);
1272 module = GetModuleHandle( NULL );
1273 status = pNtQueryVirtualMemory(NtCurrentProcess(), teststring, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1274 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1275 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1276 ok (mbi.AllocationBase == module, "mbi.AllocationBase is 0x%p, expected 0x%p\n", mbi.AllocationBase, module);
1277 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1278 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%X\n", mbi.State, MEM_COMMIT);
1279 if (mbi.Protect != PAGE_READONLY)
1280 todo_wine ok( mbi.Protect == PAGE_READONLY, "mbi.Protect is 0x%x, expected 0x%X\n", mbi.Protect, PAGE_READONLY);
1282 trace("Check flags of read-write data at %p\n", datatestbuf);
1283 status = pNtQueryVirtualMemory(NtCurrentProcess(), datatestbuf, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1284 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1285 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1286 ok (mbi.AllocationBase == module, "mbi.AllocationBase is 0x%p, expected 0x%p\n", mbi.AllocationBase, module);
1287 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1288 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%X\n", mbi.State, MEM_COMMIT);
1289 ok (mbi.Protect == PAGE_READWRITE || mbi.Protect == PAGE_WRITECOPY,
1290 "mbi.Protect is 0x%x\n", mbi.Protect);
1292 trace("Check flags of read-write uninitialized data (.bss) at %p\n", rwtestbuf);
1293 status = pNtQueryVirtualMemory(NtCurrentProcess(), rwtestbuf, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1294 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1295 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1296 if (mbi.AllocationBase == module)
1298 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1299 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%X\n", mbi.State, MEM_COMMIT);
1300 ok (mbi.Protect == PAGE_READWRITE || mbi.Protect == PAGE_WRITECOPY,
1301 "mbi.Protect is 0x%x\n", mbi.Protect);
1303 else skip( "bss is outside of module\n" ); /* this can happen on Mac OS */
1306 static void test_affinity(void)
1309 PROCESS_BASIC_INFORMATION pbi;
1310 DWORD_PTR proc_affinity, thread_affinity;
1311 THREAD_BASIC_INFORMATION tbi;
1315 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL );
1316 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1317 proc_affinity = (DWORD_PTR)pbi.Reserved2[0];
1318 ok( proc_affinity == (1 << si.dwNumberOfProcessors) - 1, "Unexpected process affinity\n" );
1319 proc_affinity = 1 << si.dwNumberOfProcessors;
1320 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1321 ok( status == STATUS_INVALID_PARAMETER,
1322 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1325 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1326 ok( status == STATUS_INVALID_PARAMETER,
1327 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1329 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1330 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1331 ok( tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1, "Unexpected thread affinity\n" );
1332 thread_affinity = 1 << si.dwNumberOfProcessors;
1333 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1334 ok( status == STATUS_INVALID_PARAMETER,
1335 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1336 thread_affinity = 0;
1337 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1338 ok( status == STATUS_INVALID_PARAMETER,
1339 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1341 thread_affinity = 1;
1342 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1343 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1344 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1345 ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1346 ok( tbi.AffinityMask == 1, "Unexpected thread affinity\n" );
1348 /* NOTE: Pre-Vista does not recognize the "all processors" flag (all bits set) */
1349 thread_affinity = ~(DWORD_PTR)0;
1350 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1351 ok( broken(status == STATUS_INVALID_PARAMETER) || status == STATUS_SUCCESS,
1352 "Expected STATUS_SUCCESS, got %08x\n", status);
1354 if (si.dwNumberOfProcessors <= 1)
1356 skip("only one processor, skipping affinity testing\n");
1360 /* Test thread affinity mask resulting from "all processors" flag */
1361 if (status == STATUS_SUCCESS)
1363 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1364 ok(status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1365 ok( broken(tbi.AffinityMask == 1) || tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1,
1366 "Unexpected thread affinity\n" );
1369 skip("Cannot test thread affinity mask for 'all processors' flag\n");
1372 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1373 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1374 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL );
1375 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1376 proc_affinity = (DWORD_PTR)pbi.Reserved2[0];
1377 ok( proc_affinity == 2, "Unexpected process affinity\n" );
1378 /* Setting the process affinity changes the thread affinity to match */
1379 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1380 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1381 ok( tbi.AffinityMask == 2, "Unexpected thread affinity\n" );
1382 /* The thread affinity is restricted to the process affinity */
1383 thread_affinity = 1;
1384 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1385 ok( status == STATUS_INVALID_PARAMETER,
1386 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1388 proc_affinity = (1 << si.dwNumberOfProcessors) - 1;
1389 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1390 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1391 /* Resetting the process affinity also resets the thread affinity */
1392 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1393 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1394 ok( tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1,
1395 "Unexpected thread affinity\n" );
1398 static void test_NtGetCurrentProcessorNumber(void)
1402 PROCESS_BASIC_INFORMATION pbi;
1403 THREAD_BASIC_INFORMATION tbi;
1404 DWORD_PTR old_process_mask;
1405 DWORD_PTR old_thread_mask;
1410 if (!pNtGetCurrentProcessorNumber) {
1411 win_skip("NtGetCurrentProcessorNumber not available\n");
1416 current_cpu = pNtGetCurrentProcessorNumber();
1417 trace("dwNumberOfProcessors: %d, current processor: %d\n", si.dwNumberOfProcessors, current_cpu);
1419 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
1420 old_process_mask = (DWORD_PTR)pbi.Reserved2[0];
1421 ok(status == STATUS_SUCCESS, "got 0x%x (expected STATUS_SUCCESS)\n", status);
1423 status = pNtQueryInformationThread(GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL);
1424 old_thread_mask = tbi.AffinityMask;
1425 ok(status == STATUS_SUCCESS, "got 0x%x (expected STATUS_SUCCESS)\n", status);
1427 /* allow the test to run on all processors */
1428 new_mask = (1 << si.dwNumberOfProcessors) - 1;
1429 status = pNtSetInformationProcess(GetCurrentProcess(), ProcessAffinityMask, &new_mask, sizeof(new_mask));
1430 ok(status == STATUS_SUCCESS, "got 0x%x (expected STATUS_SUCCESS)\n", status);
1432 for (i = 0; i < si.dwNumberOfProcessors; i++)
1435 status = pNtSetInformationThread(GetCurrentThread(), ThreadAffinityMask, &new_mask, sizeof(new_mask));
1436 ok(status == STATUS_SUCCESS, "%d: got 0x%x (expected STATUS_SUCCESS)\n", i, status);
1438 status = pNtQueryInformationThread(GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL);
1439 ok(status == STATUS_SUCCESS, "%d: got 0x%x (expected STATUS_SUCCESS)\n", i, status);
1441 current_cpu = pNtGetCurrentProcessorNumber();
1442 ok((current_cpu == i), "%d (new_mask 0x%lx): running on processor %d (AffinityMask: 0x%lx)\n",
1443 i, new_mask, current_cpu, tbi.AffinityMask);
1446 /* restore old values */
1447 status = pNtSetInformationProcess(GetCurrentProcess(), ProcessAffinityMask, &old_process_mask, sizeof(old_process_mask));
1448 ok(status == STATUS_SUCCESS, "got 0x%x (expected STATUS_SUCCESS)\n", status);
1450 status = pNtSetInformationThread(GetCurrentThread(), ThreadAffinityMask, &old_thread_mask, sizeof(old_thread_mask));
1451 ok(status == STATUS_SUCCESS, "got 0x%x (expected STATUS_SUCCESS)\n", status);
1460 if(!InitFunctionPtrs())
1463 argc = winetest_get_mainargs(&argv);
1464 if (argc >= 3) return; /* Child */
1466 /* NtQuerySystemInformation */
1468 /* 0x0 SystemBasicInformation */
1469 trace("Starting test_query_basic()\n");
1472 /* 0x1 SystemCpuInformation */
1473 trace("Starting test_query_cpu()\n");
1476 /* 0x2 SystemPerformanceInformation */
1477 trace("Starting test_query_performance()\n");
1478 test_query_performance();
1480 /* 0x3 SystemTimeOfDayInformation */
1481 trace("Starting test_query_timeofday()\n");
1482 test_query_timeofday();
1484 /* 0x5 SystemProcessInformation */
1485 trace("Starting test_query_process()\n");
1486 test_query_process();
1488 /* 0x8 SystemProcessorPerformanceInformation */
1489 trace("Starting test_query_procperf()\n");
1490 test_query_procperf();
1492 /* 0xb SystemModuleInformation */
1493 trace("Starting test_query_module()\n");
1494 test_query_module();
1496 /* 0x10 SystemHandleInformation */
1497 trace("Starting test_query_handle()\n");
1498 test_query_handle();
1500 /* 0x15 SystemCacheInformation */
1501 trace("Starting test_query_cache()\n");
1504 /* 0x17 SystemInterruptInformation */
1505 trace("Starting test_query_interrupt()\n");
1506 test_query_interrupt();
1508 /* 0x23 SystemKernelDebuggerInformation */
1509 trace("Starting test_query_kerndebug()\n");
1510 test_query_kerndebug();
1512 /* 0x25 SystemRegistryQuotaInformation */
1513 trace("Starting test_query_regquota()\n");
1514 test_query_regquota();
1516 /* NtQueryInformationProcess */
1518 /* 0x0 ProcessBasicInformation */
1519 trace("Starting test_query_process_basic()\n");
1520 test_query_process_basic();
1522 /* 0x2 ProcessIoCounters */
1523 trace("Starting test_query_process_io()\n");
1524 test_query_process_io();
1526 /* 0x3 ProcessVmCounters */
1527 trace("Starting test_query_process_vm()\n");
1528 test_query_process_vm();
1530 /* 0x4 ProcessTimes */
1531 trace("Starting test_query_process_times()\n");
1532 test_query_process_times();
1534 /* 0x7 ProcessDebugPort */
1535 trace("Starting test_process_debug_port()\n");
1536 test_query_process_debug_port(argc, argv);
1538 /* 0x14 ProcessHandleCount */
1539 trace("Starting test_query_process_handlecount()\n");
1540 test_query_process_handlecount();
1542 /* 0x1B ProcessImageFileName */
1543 trace("Starting test_query_process_image_file_name()\n");
1544 test_query_process_image_file_name();
1546 /* 0x1E ProcessDebugObjectHandle */
1547 trace("Starting test_query_process_debug_object_handle()\n");
1548 test_query_process_debug_object_handle(argc, argv);
1550 /* 0x1F ProcessDebugFlags */
1551 trace("Starting test_process_debug_flags()\n");
1552 test_query_process_debug_flags(argc, argv);
1554 /* belongs into it's own file */
1555 trace("Starting test_readvirtualmemory()\n");
1556 test_readvirtualmemory();
1558 trace("Starting test_queryvirtualmemory()\n");
1559 test_queryvirtualmemory();
1561 trace("Starting test_mapprotection()\n");
1562 test_mapprotection();
1564 trace("Starting test_affinity()\n");
1566 test_NtGetCurrentProcessorNumber();