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 BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
40 /* one_before_last_pid is used to be able to compare values of a still running process
41 with the output of the test_query_process_times and test_query_process_handlecount tests.
43 static DWORD one_before_last_pid = 0;
45 #define NTDLL_GET_PROC(func) do { \
46 p ## func = (void*)GetProcAddress(hntdll, #func); \
48 trace("GetProcAddress(%s) failed\n", #func); \
53 static BOOL InitFunctionPtrs(void)
55 /* All needed functions are NT based, so using GetModuleHandle is a good check */
56 HMODULE hntdll = GetModuleHandle("ntdll");
59 win_skip("Not running on NT\n");
63 NTDLL_GET_PROC(NtQuerySystemInformation);
64 NTDLL_GET_PROC(NtQueryInformationProcess);
65 NTDLL_GET_PROC(NtQueryInformationThread);
66 NTDLL_GET_PROC(NtSetInformationProcess);
67 NTDLL_GET_PROC(NtSetInformationThread);
68 NTDLL_GET_PROC(NtReadVirtualMemory);
69 NTDLL_GET_PROC(NtQueryVirtualMemory);
70 NTDLL_GET_PROC(NtClose);
71 NTDLL_GET_PROC(NtCreateSection);
72 NTDLL_GET_PROC(NtMapViewOfSection);
73 NTDLL_GET_PROC(NtUnmapViewOfSection);
75 pIsWow64Process = (void *)GetProcAddress(GetModuleHandle("kernel32.dll"), "IsWow64Process");
76 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
80 static void test_query_basic(void)
84 SYSTEM_BASIC_INFORMATION sbi;
86 /* This test also covers some basic parameter testing that should be the same for
87 * every information class
90 /* Use a nonexistent info class */
91 trace("Check nonexistent info class\n");
92 status = pNtQuerySystemInformation(-1, NULL, 0, NULL);
93 ok( status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* vista */,
94 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status);
96 /* Use an existing class but with a zero-length buffer */
97 trace("Check zero-length buffer\n");
98 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, 0, NULL);
99 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
101 /* Use an existing class, correct length but no SystemInformation buffer */
102 trace("Check no SystemInformation buffer\n");
103 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, sizeof(sbi), NULL);
104 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_PARAMETER /* vista */,
105 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER, got %08x\n", status);
107 /* Use a existing class, correct length, a pointer to a buffer but no ReturnLength pointer */
108 trace("Check no ReturnLength pointer\n");
109 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), NULL);
110 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
112 /* Check a too large buffer size */
113 trace("Check a too large buffer size\n");
114 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi) * 2, &ReturnLength);
115 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
117 /* Finally some correct calls */
118 trace("Check with correct parameters\n");
119 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
120 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
121 ok( sizeof(sbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
123 /* Check if we have some return values */
124 trace("Number of Processors : %d\n", sbi.NumberOfProcessors);
125 ok( sbi.NumberOfProcessors > 0, "Expected more than 0 processors, got %d\n", sbi.NumberOfProcessors);
128 static void test_query_cpu(void)
132 SYSTEM_CPU_INFORMATION sci;
134 status = pNtQuerySystemInformation(SystemCpuInformation, &sci, sizeof(sci), &ReturnLength);
135 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
136 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
138 /* Check if we have some return values */
139 trace("Processor FeatureSet : %08x\n", sci.FeatureSet);
140 ok( sci.FeatureSet != 0, "Expected some features for this processor, got %08x\n", sci.FeatureSet);
143 static void test_query_performance(void)
147 ULONGLONG buffer[sizeof(SYSTEM_PERFORMANCE_INFORMATION)/sizeof(ULONGLONG) + 5];
148 DWORD size = sizeof(SYSTEM_PERFORMANCE_INFORMATION);
150 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, 0, &ReturnLength);
151 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
153 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, size, &ReturnLength);
154 if (status == STATUS_INFO_LENGTH_MISMATCH && is_wow64)
156 /* size is larger on wow64 under w2k8/win7 */
158 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, size, &ReturnLength);
160 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
161 ok( ReturnLength == size, "Inconsistent length %d\n", ReturnLength);
163 status = pNtQuerySystemInformation(SystemPerformanceInformation, buffer, size + 2, &ReturnLength);
164 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
165 ok( ReturnLength == size || ReturnLength == size + 2,
166 "Inconsistent length %d\n", ReturnLength);
168 /* Not return values yet, as struct members are unknown */
171 static void test_query_timeofday(void)
176 /* Copy of our winternl.h structure turned into a private one */
177 typedef struct _SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE {
178 LARGE_INTEGER liKeBootTime;
179 LARGE_INTEGER liKeSystemTime;
180 LARGE_INTEGER liExpTimeZoneBias;
181 ULONG uCurrentTimeZoneId;
183 } SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE, *PSYSTEM_TIMEOFDAY_INFORMATION_PRIVATE;
185 SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE sti;
187 /* The struct size for NT (32 bytes) and Win2K/XP (48 bytes) differ.
189 * Windows 2000 and XP return STATUS_INFO_LENGTH_MISMATCH if the given buffer size is greater
190 * then 48 and 0 otherwise
191 * Windows NT returns STATUS_INFO_LENGTH_MISMATCH when the given buffer size is not correct
194 * Windows 2000 and XP copy the given buffer size into the provided buffer, if the return code is STATUS_SUCCESS
195 * NT only fills the buffer if the return code is STATUS_SUCCESS
199 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
201 if (status == STATUS_INFO_LENGTH_MISMATCH)
203 trace("Windows version is NT, we have to cater for differences with W2K/WinXP\n");
205 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
206 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
207 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
209 sti.uCurrentTimeZoneId = 0xdeadbeef;
210 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 28, &ReturnLength);
211 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
213 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
214 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
215 ok( 32 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
219 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
220 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
221 ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%d)\n", ReturnLength);
223 sti.uCurrentTimeZoneId = 0xdeadbeef;
224 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 24, &ReturnLength);
225 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
226 ok( 24 == ReturnLength, "ReturnLength should be 24, it is (%d)\n", ReturnLength);
227 ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
229 sti.uCurrentTimeZoneId = 0xdeadbeef;
230 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
231 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
232 ok( 32 == ReturnLength, "ReturnLength should be 32, it is (%d)\n", ReturnLength);
233 ok( 0xdeadbeef != sti.uCurrentTimeZoneId, "Buffer should have been partially filled\n");
235 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 49, &ReturnLength);
236 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
237 ok( ReturnLength == 0 || ReturnLength == sizeof(sti) /* vista */,
238 "ReturnLength should be 0, it is (%d)\n", ReturnLength);
240 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
241 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
242 ok( sizeof(sti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
245 /* Check if we have some return values */
246 trace("uCurrentTimeZoneId : (%d)\n", sti.uCurrentTimeZoneId);
249 static void test_query_process(void)
256 SYSTEM_BASIC_INFORMATION sbi;
258 /* Copy of our winternl.h structure turned into a private one */
259 typedef struct _SYSTEM_PROCESS_INFORMATION_PRIVATE {
260 ULONG NextEntryOffset;
263 FILETIME ftCreationTime;
265 FILETIME ftKernelTime;
266 UNICODE_STRING ProcessName;
267 DWORD dwBasePriority;
268 HANDLE UniqueProcessId;
269 HANDLE ParentProcessId;
273 VM_COUNTERS vmCounters;
274 IO_COUNTERS ioCounters;
275 SYSTEM_THREAD_INFORMATION ti[1];
276 } SYSTEM_PROCESS_INFORMATION_PRIVATE, *PSYSTEM_PROCESS_INFORMATION_PRIVATE;
278 ULONG SystemInformationLength = sizeof(SYSTEM_PROCESS_INFORMATION_PRIVATE);
279 SYSTEM_PROCESS_INFORMATION_PRIVATE *spi, *spi_buf = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
281 /* Only W2K3 returns the needed length, the rest returns 0, so we have to loop */
285 status = pNtQuerySystemInformation(SystemProcessInformation, spi_buf, SystemInformationLength, &ReturnLength);
287 if (status != STATUS_INFO_LENGTH_MISMATCH) break;
289 spi_buf = HeapReAlloc(GetProcessHeap(), 0, spi_buf , SystemInformationLength *= 2);
291 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
294 /* Get the first NextEntryOffset, from this we can deduce the OS version we're running
297 * NextEntryOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
299 * NextEntryOffset for a process is 136 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
300 * Wine (with every windows version):
301 * NextEntryOffset for a process is 0 if just this test is running
302 * NextEntryOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION) +
303 * ProcessName.MaximumLength
304 * if more wine processes are running
306 * Note : On windows the first process is in fact the Idle 'process' with a thread for every processor
309 pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
311 is_nt = ( spi->NextEntryOffset - (sbi.NumberOfProcessors * sizeof(SYSTEM_THREAD_INFORMATION)) == 136);
313 if (is_nt) win_skip("Windows version is NT, we will skip thread tests\n");
315 /* Check if we have some return values
317 * On windows there will be several processes running (Including the always present Idle and System)
318 * On wine we only have one (if this test is the only wine process running)
321 /* Loop through the processes */
327 last_pid = (DWORD_PTR)spi->UniqueProcessId;
329 ok( spi->dwThreadCount > 0, "Expected some threads for this process, got 0\n");
331 /* Loop through the threads, skip NT4 for now */
336 for ( j = 0; j < spi->dwThreadCount; j++)
339 ok ( spi->ti[j].ClientId.UniqueProcess == spi->UniqueProcessId,
340 "The owning pid of the thread (%p) doesn't equal the pid (%p) of the process\n",
341 spi->ti[j].ClientId.UniqueProcess, spi->UniqueProcessId);
345 if (!spi->NextEntryOffset) break;
347 one_before_last_pid = last_pid;
349 spi = (SYSTEM_PROCESS_INFORMATION_PRIVATE*)((char*)spi + spi->NextEntryOffset);
351 trace("Total number of running processes : %d\n", i);
352 if (!is_nt) trace("Total number of running threads : %d\n", k);
354 if (one_before_last_pid == 0) one_before_last_pid = last_pid;
356 HeapFree( GetProcessHeap(), 0, spi_buf);
359 static void test_query_procperf(void)
364 SYSTEM_BASIC_INFORMATION sbi;
365 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi;
367 /* Find out the number of processors */
368 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
369 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
371 sppi = HeapAlloc(GetProcessHeap(), 0, NeededLength);
373 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, 0, &ReturnLength);
374 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
376 /* Try it for 1 processor */
377 sppi->KernelTime.QuadPart = 0xdeaddead;
378 sppi->UserTime.QuadPart = 0xdeaddead;
379 sppi->IdleTime.QuadPart = 0xdeaddead;
380 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi,
381 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION), &ReturnLength);
382 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
383 ok( sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) == ReturnLength,
384 "Inconsistent length %d\n", ReturnLength);
385 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
386 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
387 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
389 /* Try it for all processors */
390 sppi->KernelTime.QuadPart = 0xdeaddead;
391 sppi->UserTime.QuadPart = 0xdeaddead;
392 sppi->IdleTime.QuadPart = 0xdeaddead;
393 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength, &ReturnLength);
394 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
395 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
396 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
397 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
398 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
400 /* A too large given buffer size */
401 sppi = HeapReAlloc(GetProcessHeap(), 0, sppi , NeededLength + 2);
402 sppi->KernelTime.QuadPart = 0xdeaddead;
403 sppi->UserTime.QuadPart = 0xdeaddead;
404 sppi->IdleTime.QuadPart = 0xdeaddead;
405 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, sppi, NeededLength + 2, &ReturnLength);
406 ok( status == STATUS_SUCCESS || status == STATUS_INFO_LENGTH_MISMATCH /* vista */,
407 "Expected STATUS_SUCCESS or STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
408 ok( NeededLength == ReturnLength, "Inconsistent length (%d) <-> (%d)\n", NeededLength, ReturnLength);
409 if (status == STATUS_SUCCESS)
411 ok (sppi->KernelTime.QuadPart != 0xdeaddead, "KernelTime unchanged\n");
412 ok (sppi->UserTime.QuadPart != 0xdeaddead, "UserTime unchanged\n");
413 ok (sppi->IdleTime.QuadPart != 0xdeaddead, "IdleTime unchanged\n");
415 else /* vista and 2008 */
417 ok (sppi->KernelTime.QuadPart == 0xdeaddead, "KernelTime changed\n");
418 ok (sppi->UserTime.QuadPart == 0xdeaddead, "UserTime changed\n");
419 ok (sppi->IdleTime.QuadPart == 0xdeaddead, "IdleTime changed\n");
422 HeapFree( GetProcessHeap(), 0, sppi);
425 static void test_query_module(void)
429 ULONG ModuleCount, i;
431 ULONG SystemInformationLength = sizeof(SYSTEM_MODULE_INFORMATION);
432 SYSTEM_MODULE_INFORMATION* smi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
435 /* Request the needed length */
436 status = pNtQuerySystemInformation(SystemModuleInformation, smi, 0, &ReturnLength);
437 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
438 ok( ReturnLength > 0, "Expected a ReturnLength to show the needed length\n");
440 SystemInformationLength = ReturnLength;
441 smi = HeapReAlloc(GetProcessHeap(), 0, smi , SystemInformationLength);
442 status = pNtQuerySystemInformation(SystemModuleInformation, smi, SystemInformationLength, &ReturnLength);
443 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
445 ModuleCount = smi->ModulesCount;
446 sm = &smi->Modules[0];
447 /* our implementation is a stub for now */
448 ok( ModuleCount > 0, "Expected some modules to be loaded\n");
450 /* Loop through all the modules/drivers, Wine doesn't get here (yet) */
451 for (i = 0; i < ModuleCount ; i++)
453 ok( i == sm->Id, "Id (%d) should have matched %u\n", sm->Id, i);
457 HeapFree( GetProcessHeap(), 0, smi);
460 static void test_query_handle(void)
464 ULONG SystemInformationLength = sizeof(SYSTEM_HANDLE_INFORMATION);
465 SYSTEM_HANDLE_INFORMATION* shi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
467 /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
468 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
469 todo_wine ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
471 SystemInformationLength = ReturnLength;
472 shi = HeapReAlloc(GetProcessHeap(), 0, shi , SystemInformationLength);
473 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
474 if (status != STATUS_INFO_LENGTH_MISMATCH) /* vista */
476 ok( status == STATUS_SUCCESS,
477 "Expected STATUS_SUCCESS, got %08x\n", status);
479 /* Check if we have some return values */
480 trace("Number of Handles : %d\n", shi->Count);
483 /* our implementation is a stub for now */
484 ok( shi->Count > 1, "Expected more than 1 handles, got (%d)\n", shi->Count);
487 HeapFree( GetProcessHeap(), 0, shi);
490 static void test_query_cache(void)
494 SYSTEM_CACHE_INFORMATION sci;
496 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, 0, &ReturnLength);
497 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
499 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci), &ReturnLength);
500 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
501 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
503 status = pNtQuerySystemInformation(SystemCacheInformation, &sci, sizeof(sci) + 2, &ReturnLength);
504 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
505 ok( sizeof(sci) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
508 static void test_query_interrupt(void)
513 SYSTEM_BASIC_INFORMATION sbi;
514 SYSTEM_INTERRUPT_INFORMATION* sii;
516 /* Find out the number of processors */
517 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
518 NeededLength = sbi.NumberOfProcessors * sizeof(SYSTEM_INTERRUPT_INFORMATION);
520 sii = HeapAlloc(GetProcessHeap(), 0, NeededLength);
522 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, 0, &ReturnLength);
523 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
525 /* Try it for all processors */
526 status = pNtQuerySystemInformation(SystemInterruptInformation, sii, NeededLength, &ReturnLength);
527 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
529 /* Windows XP and W2K3 (and others?) always return 0 for the ReturnLength
530 * No test added for this as it's highly unlikely that an app depends on this
533 HeapFree( GetProcessHeap(), 0, sii);
536 static void test_query_kerndebug(void)
540 SYSTEM_KERNEL_DEBUGGER_INFORMATION skdi;
542 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, 0, &ReturnLength);
543 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
545 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi), &ReturnLength);
546 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
547 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
549 status = pNtQuerySystemInformation(SystemKernelDebuggerInformation, &skdi, sizeof(skdi) + 2, &ReturnLength);
550 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
551 ok( sizeof(skdi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
554 static void test_query_regquota(void)
558 SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
560 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, 0, &ReturnLength);
561 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
563 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi), &ReturnLength);
564 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
565 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
567 status = pNtQuerySystemInformation(SystemRegistryQuotaInformation, &srqi, sizeof(srqi) + 2, &ReturnLength);
568 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
569 ok( sizeof(srqi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
572 static void test_query_process_basic(void)
577 typedef struct _PROCESS_BASIC_INFORMATION_PRIVATE {
578 DWORD_PTR ExitStatus;
580 DWORD_PTR AffinityMask;
581 DWORD_PTR BasePriority;
582 ULONG_PTR UniqueProcessId;
583 ULONG_PTR InheritedFromUniqueProcessId;
584 } PROCESS_BASIC_INFORMATION_PRIVATE, *PPROCESS_BASIC_INFORMATION_PRIVATE;
586 PROCESS_BASIC_INFORMATION_PRIVATE pbi;
588 /* This test also covers some basic parameter testing that should be the same for
589 * every information class
592 /* Use a nonexistent info class */
593 trace("Check nonexistent info class\n");
594 status = pNtQueryInformationProcess(NULL, -1, NULL, 0, NULL);
595 ok( status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED /* vista */,
596 "Expected STATUS_INVALID_INFO_CLASS or STATUS_NOT_IMPLEMENTED, got %08x\n", status);
598 /* Do not give a handle and buffer */
599 trace("Check NULL handle and buffer and zero-length buffersize\n");
600 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, 0, NULL);
601 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
603 /* Use a correct info class and buffer size, but still no handle and buffer */
604 trace("Check NULL handle and buffer\n");
605 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, sizeof(pbi), NULL);
606 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
607 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
609 /* Use a correct info class and buffer size, but still no handle */
610 trace("Check NULL handle\n");
611 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
612 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
614 /* Use a greater buffer size */
615 trace("Check NULL handle and too large buffersize\n");
616 status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi) * 2, NULL);
617 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
619 /* Use no ReturnLength */
620 trace("Check NULL ReturnLength\n");
621 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
622 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
624 /* Finally some correct calls */
625 trace("Check with correct parameters\n");
626 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), &ReturnLength);
627 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
628 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
630 /* Everything is correct except a too large buffersize */
631 trace("Too large buffersize\n");
632 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi) * 2, &ReturnLength);
633 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
634 ok( sizeof(pbi) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
636 /* Check if we have some return values */
637 trace("ProcessID : %lx\n", pbi.UniqueProcessId);
638 ok( pbi.UniqueProcessId > 0, "Expected a ProcessID > 0, got 0\n");
641 static void test_query_process_vm(void)
646 ULONG old_size = FIELD_OFFSET(VM_COUNTERS,PrivatePageCount);
648 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, NULL, sizeof(pvi), NULL);
649 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
650 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
652 status = pNtQueryInformationProcess(NULL, ProcessVmCounters, &pvi, old_size, NULL);
653 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
655 /* Windows XP and W2K3 will report success for a size of 44 AND 48 !
656 Windows W2K will only report success for 44.
657 For now we only care for 44, which is FIELD_OFFSET(VM_COUNTERS,PrivatePageCount))
660 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 24, &ReturnLength);
661 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
663 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, old_size, &ReturnLength);
664 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
665 ok( old_size == ReturnLength, "Inconsistent length %d\n", ReturnLength);
667 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 46, &ReturnLength);
668 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
669 ok( ReturnLength == old_size || ReturnLength == sizeof(pvi), "Inconsistent length %d\n", ReturnLength);
671 /* Check if we have some return values */
672 trace("WorkingSetSize : %ld\n", pvi.WorkingSetSize);
675 ok( pvi.WorkingSetSize > 0, "Expected a WorkingSetSize > 0\n");
679 static void test_query_process_io(void)
685 /* NT4 doesn't support this information class, so check for it */
686 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
687 if (status == STATUS_NOT_SUPPORTED)
689 win_skip("ProcessIoCounters information class is not supported\n");
693 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, NULL, sizeof(pii), NULL);
694 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
695 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
697 status = pNtQueryInformationProcess(NULL, ProcessIoCounters, &pii, sizeof(pii), NULL);
698 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
700 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, 24, &ReturnLength);
701 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
703 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
704 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
705 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
707 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii) * 2, &ReturnLength);
708 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
709 ok( sizeof(pii) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
711 /* Check if we have some return values */
712 trace("OtherOperationCount : 0x%x%08x\n", (DWORD)(pii.OtherOperationCount >> 32), (DWORD)pii.OtherOperationCount);
715 ok( pii.OtherOperationCount > 0, "Expected an OtherOperationCount > 0\n");
719 static void test_query_process_times(void)
724 SYSTEMTIME UTC, Local;
725 KERNEL_USER_TIMES spti;
727 status = pNtQueryInformationProcess(NULL, ProcessTimes, NULL, sizeof(spti), NULL);
728 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
729 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
731 status = pNtQueryInformationProcess(NULL, ProcessTimes, &spti, sizeof(spti), NULL);
732 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
734 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, 24, &ReturnLength);
735 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
737 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
740 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
741 process = GetCurrentProcess();
742 trace("ProcessTimes for current process\n");
745 trace("ProcessTimes for process with ID : %d\n", one_before_last_pid);
747 status = pNtQueryInformationProcess( process, ProcessTimes, &spti, sizeof(spti), &ReturnLength);
748 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
749 ok( sizeof(spti) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
750 CloseHandle(process);
752 FileTimeToSystemTime((const FILETIME *)&spti.CreateTime, &UTC);
753 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
754 trace("CreateTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
755 Local.wHour, Local.wMinute, Local.wSecond);
757 FileTimeToSystemTime((const FILETIME *)&spti.ExitTime, &UTC);
758 SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
759 trace("ExitTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
760 Local.wHour, Local.wMinute, Local.wSecond);
762 FileTimeToSystemTime((const FILETIME *)&spti.KernelTime, &Local);
763 trace("KernelTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
765 FileTimeToSystemTime((const FILETIME *)&spti.UserTime, &Local);
766 trace("UserTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
768 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, sizeof(spti) * 2, &ReturnLength);
769 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
770 ok( sizeof(spti) == ReturnLength ||
771 ReturnLength == 0 /* vista */ ||
772 broken(is_wow64), /* returns garbage on wow64 */
773 "Inconsistent length %d\n", ReturnLength);
776 static void test_query_process_debug_port(int argc, char **argv)
778 DWORD_PTR debug_port = 0xdeadbeef;
779 char cmdline[MAX_PATH];
780 PROCESS_INFORMATION pi;
781 STARTUPINFO si = { 0 };
785 sprintf(cmdline, "%s %s %s", argv[0], argv[1], "debuggee");
788 ret = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &si, &pi);
789 ok(ret, "CreateProcess failed, last error %#x.\n", GetLastError());
792 status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
794 ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
796 status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
797 NULL, sizeof(debug_port), NULL);
798 ok(status == STATUS_INVALID_HANDLE || status == STATUS_ACCESS_VIOLATION,
799 "Expected STATUS_INVALID_HANDLE, got %#x.\n", status);
801 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
802 NULL, sizeof(debug_port), NULL);
803 ok(status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
805 status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
806 &debug_port, sizeof(debug_port), NULL);
807 ok(status == STATUS_INVALID_HANDLE, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
809 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
810 &debug_port, sizeof(debug_port) - 1, NULL);
811 ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
813 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
814 &debug_port, sizeof(debug_port) + 1, NULL);
815 ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
817 status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
818 &debug_port, sizeof(debug_port), NULL);
819 ok(!status, "NtQueryInformationProcess failed, status %#x.\n", status);
820 ok(debug_port == 0, "Expected port 0, got %#lx.\n", debug_port);
822 status = pNtQueryInformationProcess(pi.hProcess, ProcessDebugPort,
823 &debug_port, sizeof(debug_port), NULL);
824 ok(!status, "NtQueryInformationProcess failed, status %#x.\n", status);
825 ok(debug_port == ~(DWORD_PTR)0, "Expected port %#lx, got %#lx.\n", ~(DWORD_PTR)0, debug_port);
831 ret = WaitForDebugEvent(&ev, INFINITE);
832 ok(ret, "WaitForDebugEvent failed, last error %#x.\n", GetLastError());
835 if (ev.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break;
837 ret = ContinueDebugEvent(ev.dwProcessId, ev.dwThreadId, DBG_CONTINUE);
838 ok(ret, "ContinueDebugEvent failed, last error %#x.\n", GetLastError());
842 ret = CloseHandle(pi.hThread);
843 ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
844 ret = CloseHandle(pi.hProcess);
845 ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
848 static void test_query_process_handlecount(void)
853 BYTE buffer[2 * sizeof(DWORD)];
856 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, NULL, sizeof(handlecount), NULL);
857 ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
858 "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08x\n", status);
860 status = pNtQueryInformationProcess(NULL, ProcessHandleCount, &handlecount, sizeof(handlecount), NULL);
861 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
863 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, &handlecount, 2, &ReturnLength);
864 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
866 process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, one_before_last_pid);
869 trace("Could not open process with ID : %d, error : %u. Going to use current one.\n", one_before_last_pid, GetLastError());
870 process = GetCurrentProcess();
871 trace("ProcessHandleCount for current process\n");
874 trace("ProcessHandleCount for process with ID : %d\n", one_before_last_pid);
876 status = pNtQueryInformationProcess( process, ProcessHandleCount, &handlecount, sizeof(handlecount), &ReturnLength);
877 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
878 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
879 CloseHandle(process);
881 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, buffer, sizeof(buffer), &ReturnLength);
882 ok( status == STATUS_INFO_LENGTH_MISMATCH || status == STATUS_SUCCESS,
883 "Expected STATUS_INFO_LENGTH_MISMATCH or STATUS_SUCCESS, got %08x\n", status);
884 ok( sizeof(handlecount) == ReturnLength, "Inconsistent length %d\n", ReturnLength);
886 /* Check if we have some return values */
887 trace("HandleCount : %d\n", handlecount);
890 ok( handlecount > 0, "Expected some handles, got 0\n");
894 static void test_query_process_image_file_name(void)
898 UNICODE_STRING image_file_name;
903 status = pNtQueryInformationProcess(NULL, ProcessImageFileName, &image_file_name, sizeof(image_file_name), NULL);
904 if (status == STATUS_INVALID_INFO_CLASS)
906 win_skip("ProcessImageFileName is not supported\n");
909 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
911 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, &image_file_name, 2, &ReturnLength);
912 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
914 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, &image_file_name, sizeof(image_file_name), &ReturnLength);
915 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
917 buffer = HeapAlloc(GetProcessHeap(), 0, ReturnLength);
918 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessImageFileName, buffer, ReturnLength, &ReturnLength);
919 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
920 memcpy(&image_file_name, buffer, sizeof(image_file_name));
921 len = WideCharToMultiByte(CP_ACP, 0, image_file_name.Buffer, image_file_name.Length/sizeof(WCHAR), NULL, 0, NULL, NULL);
922 file_nameA = HeapAlloc(GetProcessHeap(), 0, len + 1);
923 WideCharToMultiByte(CP_ACP, 0, image_file_name.Buffer, image_file_name.Length/sizeof(WCHAR), file_nameA, len, NULL, NULL);
924 file_nameA[len] = '\0';
925 HeapFree(GetProcessHeap(), 0, buffer);
926 trace("process image file name: %s\n", file_nameA);
927 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);
928 HeapFree(GetProcessHeap(), 0, file_nameA);
931 static void test_query_process_debug_object_handle(int argc, char **argv)
933 char cmdline[MAX_PATH];
934 STARTUPINFO si = {0};
935 PROCESS_INFORMATION pi;
940 sprintf(cmdline, "%s %s %s", argv[0], argv[1], "debuggee");
943 ret = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, DEBUG_PROCESS, NULL,
945 ok(ret, "CreateProcess failed with last error %u\n", GetLastError());
948 status = pNtQueryInformationProcess(NULL, ProcessDebugObjectHandle, NULL,
950 if (status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED)
952 win_skip("ProcessDebugObjectHandle is not supported\n");
955 ok(status == STATUS_INFO_LENGTH_MISMATCH,
956 "Expected NtQueryInformationProcess to return STATUS_INFO_LENGTH_MISMATCH, got 0x%08x\n",
959 status = pNtQueryInformationProcess(NULL, ProcessDebugObjectHandle, NULL,
960 sizeof(debug_object), NULL);
961 ok(status == STATUS_INVALID_HANDLE ||
962 status == STATUS_ACCESS_VIOLATION, /* XP */
963 "Expected NtQueryInformationProcess to return STATUS_INVALID_HANDLE, got 0x%08x\n", status);
965 status = pNtQueryInformationProcess(GetCurrentProcess(),
966 ProcessDebugObjectHandle, NULL, sizeof(debug_object), NULL);
967 ok(status == STATUS_ACCESS_VIOLATION,
968 "Expected NtQueryInformationProcess to return STATUS_ACCESS_VIOLATION, got 0x%08x\n", status);
970 status = pNtQueryInformationProcess(NULL, ProcessDebugObjectHandle,
971 &debug_object, sizeof(debug_object), NULL);
972 ok(status == STATUS_INVALID_HANDLE,
973 "Expected NtQueryInformationProcess to return STATUS_ACCESS_VIOLATION, got 0x%08x\n", status);
975 status = pNtQueryInformationProcess(GetCurrentProcess(),
976 ProcessDebugObjectHandle, &debug_object,
977 sizeof(debug_object) - 1, NULL);
978 ok(status == STATUS_INFO_LENGTH_MISMATCH,
979 "Expected NtQueryInformationProcess to return STATUS_INFO_LENGTH_MISMATCH, got 0x%08x\n", status);
981 status = pNtQueryInformationProcess(GetCurrentProcess(),
982 ProcessDebugObjectHandle, &debug_object,
983 sizeof(debug_object) + 1, NULL);
984 ok(status == STATUS_INFO_LENGTH_MISMATCH,
985 "Expected NtQueryInformationProcess to return STATUS_INFO_LENGTH_MISMATCH, got 0x%08x\n", status);
987 debug_object = (HANDLE)0xdeadbeef;
988 status = pNtQueryInformationProcess(GetCurrentProcess(),
989 ProcessDebugObjectHandle, &debug_object,
990 sizeof(debug_object), NULL);
991 ok(status == STATUS_PORT_NOT_SET,
992 "Expected NtQueryInformationProcess to return STATUS_PORT_NOT_SET, got 0x%08x\n", status);
993 ok(debug_object == NULL ||
994 broken(debug_object == (HANDLE)0xdeadbeef), /* Wow64 */
995 "Expected debug object handle to be NULL, got %p\n", debug_object);
997 debug_object = (HANDLE)0xdeadbeef;
998 status = pNtQueryInformationProcess(pi.hProcess, ProcessDebugObjectHandle,
999 &debug_object, sizeof(debug_object), NULL);
1001 ok(status == STATUS_SUCCESS,
1002 "Expected NtQueryInformationProcess to return STATUS_SUCCESS, got 0x%08x\n", status);
1004 ok(debug_object != NULL,
1005 "Expected debug object handle to be non-NULL, got %p\n", debug_object);
1011 ret = WaitForDebugEvent(&ev, INFINITE);
1012 ok(ret, "WaitForDebugEvent failed with last error %u\n", GetLastError());
1015 if (ev.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break;
1017 ret = ContinueDebugEvent(ev.dwProcessId, ev.dwThreadId, DBG_CONTINUE);
1018 ok(ret, "ContinueDebugEvent failed with last error %u\n", GetLastError());
1022 ret = CloseHandle(pi.hThread);
1023 ok(ret, "CloseHandle failed with last error %u\n", GetLastError());
1024 ret = CloseHandle(pi.hProcess);
1025 ok(ret, "CloseHandle failed with last error %u\n", GetLastError());
1028 static void test_readvirtualmemory(void)
1033 static const char teststring[] = "test string";
1036 process = OpenProcess(PROCESS_VM_READ, FALSE, GetCurrentProcessId());
1037 ok(process != 0, "Expected to be able to open own process for reading memory\n");
1039 /* normal operation */
1040 status = pNtReadVirtualMemory(process, teststring, buffer, 12, &readcount);
1041 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1042 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
1043 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
1045 /* no number of bytes */
1046 memset(buffer, 0, 12);
1047 status = pNtReadVirtualMemory(process, teststring, buffer, 12, NULL);
1048 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1049 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
1051 /* illegal remote address */
1053 status = pNtReadVirtualMemory(process, (void *) 0x1234, buffer, 12, &readcount);
1054 ok( status == STATUS_PARTIAL_COPY || broken(status == STATUS_ACCESS_VIOLATION), "Expected STATUS_PARTIAL_COPY, got %08x\n", status);
1055 if (status == STATUS_PARTIAL_COPY)
1056 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
1060 status = pNtReadVirtualMemory(0, teststring, buffer, 12, &readcount);
1061 ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08x\n", status);
1062 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
1064 /* pseudo handle for current process*/
1065 memset(buffer, 0, 12);
1066 status = pNtReadVirtualMemory((HANDLE)-1, teststring, buffer, 12, &readcount);
1067 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1068 ok( readcount == 12, "Expected to read 12 bytes, got %ld\n",readcount);
1069 ok( strcmp(teststring, buffer) == 0, "Expected read memory to be the same as original memory\n");
1071 /* illegal local address */
1072 status = pNtReadVirtualMemory(process, teststring, (void *)0x1234, 12, &readcount);
1073 ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
1074 ok( readcount == 0, "Expected to read 0 bytes, got %ld\n",readcount);
1076 CloseHandle(process);
1079 static void test_mapprotection(void)
1083 MEMORY_BASIC_INFORMATION info;
1084 ULONG oldflags, flagsize, flags = MEM_EXECUTE_OPTION_ENABLE;
1085 LARGE_INTEGER size, offset;
1087 SIZE_T retlen, count;
1091 skip("No NtClose ... Win98\n");
1094 /* Switch to being a noexec unaware process */
1095 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &oldflags, sizeof (oldflags), &flagsize);
1096 if (status == STATUS_INVALID_PARAMETER) {
1097 skip("Invalid Parameter on ProcessExecuteFlags query?\n");
1100 ok( (status == STATUS_SUCCESS) || (status == STATUS_INVALID_INFO_CLASS), "Expected STATUS_SUCCESS, got %08x\n", status);
1101 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &flags, sizeof(flags) );
1102 ok( (status == STATUS_SUCCESS) || (status == STATUS_INVALID_INFO_CLASS), "Expected STATUS_SUCCESS, got %08x\n", status);
1104 size.u.LowPart = 0x1000;
1105 size.u.HighPart = 0;
1106 status = pNtCreateSection ( &h,
1107 STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE | SECTION_MAP_EXECUTE,
1111 SEC_COMMIT | SEC_NOCACHE,
1114 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1116 offset.u.LowPart = 0;
1117 offset.u.HighPart = 0;
1120 status = pNtMapViewOfSection ( h, GetCurrentProcess(), &addr, 0, 0, &offset, &count, ViewShare, 0, PAGE_READWRITE);
1121 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1122 memset (addr, 0xc3, 1); /* lret ... in both i386 and x86_64 */
1123 trace("trying to execute code in the readwrite only mapped anon file...\n");
1125 trace("...done.\n");
1127 status = pNtQueryVirtualMemory( GetCurrentProcess(), addr, MemoryBasicInformation, &info, sizeof(info), &retlen );
1128 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1129 ok( retlen == sizeof(info), "Expected STATUS_SUCCESS, got %08x\n", status);
1130 ok(info.Protect == PAGE_READWRITE, "addr.Protect is not PAGE_READWRITE, but 0x%x\n", info.Protect);
1132 status = pNtUnmapViewOfSection (GetCurrentProcess(), addr);
1133 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1137 pNtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags, &oldflags, sizeof(oldflags) );
1140 static void test_queryvirtualmemory(void)
1144 static const char teststring[] = "test string";
1145 static char datatestbuf[42] = "abc";
1146 static char rwtestbuf[42];
1147 MEMORY_BASIC_INFORMATION mbi;
1151 module = GetModuleHandle( "ntdll.dll" );
1152 trace("Check flags of the PE header of NTDLL.DLL at %p\n", module);
1153 status = pNtQueryVirtualMemory(NtCurrentProcess(), module, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1154 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1155 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1156 ok (mbi.AllocationBase == module, "mbi.AllocationBase is 0x%p, expected 0x%p\n", mbi.AllocationBase, module);
1157 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1158 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%x\n", mbi.State, MEM_COMMIT);
1159 ok (mbi.Protect == PAGE_READONLY, "mbi.Protect is 0x%x, expected 0x%x\n", mbi.Protect, PAGE_READONLY);
1160 ok (mbi.Type == MEM_IMAGE, "mbi.Type is 0x%x, expected 0x%x\n", mbi.Type, MEM_IMAGE);
1162 trace("Check flags of a function entry in NTDLL.DLL at %p\n", pNtQueryVirtualMemory);
1163 module = GetModuleHandle( "ntdll.dll" );
1164 status = pNtQueryVirtualMemory(NtCurrentProcess(), pNtQueryVirtualMemory, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1165 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1166 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1167 ok (mbi.AllocationBase == module, "mbi.AllocationBase is 0x%p, expected 0x%p\n", mbi.AllocationBase, module);
1168 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1169 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%x\n", mbi.State, MEM_COMMIT);
1170 ok (mbi.Protect == PAGE_EXECUTE_READ, "mbi.Protect is 0x%x, expected 0x%x\n", mbi.Protect, PAGE_EXECUTE_READ);
1172 trace("Check flags of heap at %p\n", GetProcessHeap());
1173 status = pNtQueryVirtualMemory(NtCurrentProcess(), GetProcessHeap(), MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1174 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1175 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1176 ok (mbi.AllocationProtect == PAGE_READWRITE || mbi.AllocationProtect == PAGE_EXECUTE_READWRITE,
1177 "mbi.AllocationProtect is 0x%x\n", mbi.AllocationProtect);
1178 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%x\n", mbi.State, MEM_COMMIT);
1179 ok (mbi.Protect == PAGE_READWRITE || mbi.Protect == PAGE_EXECUTE_READWRITE,
1180 "mbi.Protect is 0x%x\n", mbi.Protect);
1182 trace("Check flags of stack at %p\n", stackbuf);
1183 status = pNtQueryVirtualMemory(NtCurrentProcess(), stackbuf, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1184 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1185 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1186 ok (mbi.AllocationProtect == PAGE_READWRITE, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_READWRITE);
1187 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%x\n", mbi.State, MEM_COMMIT);
1188 ok (mbi.Protect == PAGE_READWRITE, "mbi.Protect is 0x%x, expected 0x%x\n", mbi.Protect, PAGE_READWRITE);
1190 trace("Check flags of read-only data at %p\n", teststring);
1191 module = GetModuleHandle( NULL );
1192 status = pNtQueryVirtualMemory(NtCurrentProcess(), teststring, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1193 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1194 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1195 ok (mbi.AllocationBase == module, "mbi.AllocationBase is 0x%p, expected 0x%p\n", mbi.AllocationBase, module);
1196 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1197 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%X\n", mbi.State, MEM_COMMIT);
1198 if (mbi.Protect != PAGE_READONLY)
1199 todo_wine ok( mbi.Protect == PAGE_READONLY, "mbi.Protect is 0x%x, expected 0x%X\n", mbi.Protect, PAGE_READONLY);
1201 trace("Check flags of read-write data at %p\n", datatestbuf);
1202 status = pNtQueryVirtualMemory(NtCurrentProcess(), datatestbuf, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1203 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1204 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1205 ok (mbi.AllocationBase == module, "mbi.AllocationBase is 0x%p, expected 0x%p\n", mbi.AllocationBase, module);
1206 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1207 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%X\n", mbi.State, MEM_COMMIT);
1208 ok (mbi.Protect == PAGE_READWRITE || mbi.Protect == PAGE_WRITECOPY,
1209 "mbi.Protect is 0x%x\n", mbi.Protect);
1211 trace("Check flags of read-write uninitialized data (.bss) at %p\n", rwtestbuf);
1212 status = pNtQueryVirtualMemory(NtCurrentProcess(), rwtestbuf, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount);
1213 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1214 ok( readcount == sizeof(MEMORY_BASIC_INFORMATION), "Expected to read %d bytes, got %ld\n",(int)sizeof(MEMORY_BASIC_INFORMATION),readcount);
1215 if (mbi.AllocationBase == module)
1217 ok (mbi.AllocationProtect == PAGE_EXECUTE_WRITECOPY, "mbi.AllocationProtect is 0x%x, expected 0x%x\n", mbi.AllocationProtect, PAGE_EXECUTE_WRITECOPY);
1218 ok (mbi.State == MEM_COMMIT, "mbi.State is 0x%x, expected 0x%X\n", mbi.State, MEM_COMMIT);
1219 ok (mbi.Protect == PAGE_READWRITE, "mbi.Protect is 0x%x, expected 0x%X\n", mbi.Protect, PAGE_READWRITE);
1221 else skip( "bss is outside of module\n" ); /* this can happen on Mac OS */
1224 static void test_affinity(void)
1227 PROCESS_BASIC_INFORMATION pbi;
1228 DWORD_PTR proc_affinity, thread_affinity;
1229 THREAD_BASIC_INFORMATION tbi;
1233 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL );
1234 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1235 proc_affinity = (DWORD_PTR)pbi.Reserved2[0];
1236 ok( proc_affinity == (1 << si.dwNumberOfProcessors) - 1, "Unexpected process affinity\n" );
1237 proc_affinity = 1 << si.dwNumberOfProcessors;
1238 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1239 ok( status == STATUS_INVALID_PARAMETER,
1240 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1243 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1244 ok( status == STATUS_INVALID_PARAMETER,
1245 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1247 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1248 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1249 ok( tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1, "Unexpected thread affinity\n" );
1250 thread_affinity = 1 << si.dwNumberOfProcessors;
1251 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1252 ok( status == STATUS_INVALID_PARAMETER,
1253 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1254 thread_affinity = 0;
1255 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1256 ok( status == STATUS_INVALID_PARAMETER,
1257 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1259 thread_affinity = 1;
1260 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1261 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1262 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1263 ok( tbi.AffinityMask == 1, "Unexpected thread affinity\n" );
1265 /* NOTE: Pre-Vista does not recognize the "all processors" flag (all bits set) */
1266 thread_affinity = ~(DWORD_PTR)0;
1267 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1268 ok( broken(status == STATUS_INVALID_PARAMETER) || status == STATUS_SUCCESS,
1269 "Expected STATUS_SUCCESS, got %08x\n", status);
1271 if (si.dwNumberOfProcessors <= 1)
1273 skip("only one processor, skipping affinity testing\n");
1277 /* Test thread affinity mask resulting from "all processors" flag */
1278 if (status == STATUS_SUCCESS)
1280 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1281 ok( broken(tbi.AffinityMask == 1) || tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1,
1282 "Unexpected thread affinity\n" );
1285 skip("Cannot test thread affinity mask for 'all processors' flag\n");
1288 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1289 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1290 status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL );
1291 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1292 proc_affinity = (DWORD_PTR)pbi.Reserved2[0];
1293 ok( proc_affinity == 2, "Unexpected process affinity\n" );
1294 /* Setting the process affinity changes the thread affinity to match */
1295 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1296 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1297 ok( tbi.AffinityMask == 2, "Unexpected thread affinity\n" );
1298 /* The thread affinity is restricted to the process affinity */
1299 thread_affinity = 1;
1300 status = pNtSetInformationThread( GetCurrentThread(), ThreadAffinityMask, &thread_affinity, sizeof(thread_affinity) );
1301 ok( status == STATUS_INVALID_PARAMETER,
1302 "Expected STATUS_INVALID_PARAMETER, got %08x\n", status);
1304 proc_affinity = (1 << si.dwNumberOfProcessors) - 1;
1305 status = pNtSetInformationProcess( GetCurrentProcess(), ProcessAffinityMask, &proc_affinity, sizeof(proc_affinity) );
1306 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1307 /* Resetting the process affinity also resets the thread affinity */
1308 status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
1309 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
1310 ok( tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1,
1311 "Unexpected thread affinity\n" );
1319 if(!InitFunctionPtrs())
1322 argc = winetest_get_mainargs(&argv);
1323 if (argc >= 3) return; /* Child */
1325 /* NtQuerySystemInformation */
1327 /* 0x0 SystemBasicInformation */
1328 trace("Starting test_query_basic()\n");
1331 /* 0x1 SystemCpuInformation */
1332 trace("Starting test_query_cpu()\n");
1335 /* 0x2 SystemPerformanceInformation */
1336 trace("Starting test_query_performance()\n");
1337 test_query_performance();
1339 /* 0x3 SystemTimeOfDayInformation */
1340 trace("Starting test_query_timeofday()\n");
1341 test_query_timeofday();
1343 /* 0x5 SystemProcessInformation */
1344 trace("Starting test_query_process()\n");
1345 test_query_process();
1347 /* 0x8 SystemProcessorPerformanceInformation */
1348 trace("Starting test_query_procperf()\n");
1349 test_query_procperf();
1351 /* 0xb SystemModuleInformation */
1352 trace("Starting test_query_module()\n");
1353 test_query_module();
1355 /* 0x10 SystemHandleInformation */
1356 trace("Starting test_query_handle()\n");
1357 test_query_handle();
1359 /* 0x15 SystemCacheInformation */
1360 trace("Starting test_query_cache()\n");
1363 /* 0x17 SystemInterruptInformation */
1364 trace("Starting test_query_interrupt()\n");
1365 test_query_interrupt();
1367 /* 0x23 SystemKernelDebuggerInformation */
1368 trace("Starting test_query_kerndebug()\n");
1369 test_query_kerndebug();
1371 /* 0x25 SystemRegistryQuotaInformation */
1372 trace("Starting test_query_regquota()\n");
1373 test_query_regquota();
1375 /* NtQueryInformationProcess */
1377 /* 0x0 ProcessBasicInformation */
1378 trace("Starting test_query_process_basic()\n");
1379 test_query_process_basic();
1381 /* 0x2 ProcessIoCounters */
1382 trace("Starting test_query_process_io()\n");
1383 test_query_process_io();
1385 /* 0x3 ProcessVmCounters */
1386 trace("Starting test_query_process_vm()\n");
1387 test_query_process_vm();
1389 /* 0x4 ProcessTimes */
1390 trace("Starting test_query_process_times()\n");
1391 test_query_process_times();
1393 /* 0x7 ProcessDebugPort */
1394 trace("Starting test_process_debug_port()\n");
1395 test_query_process_debug_port(argc, argv);
1397 /* 0x14 ProcessHandleCount */
1398 trace("Starting test_query_process_handlecount()\n");
1399 test_query_process_handlecount();
1401 /* 0x1B ProcessImageFileName */
1402 trace("Starting test_query_process_image_file_name()\n");
1403 test_query_process_image_file_name();
1405 /* 0x1E ProcessDebugObjectHandle */
1406 trace("Starting test_query_process_debug_object_handle()\n");
1407 test_query_process_debug_object_handle(argc, argv);
1409 /* belongs into it's own file */
1410 trace("Starting test_readvirtualmemory()\n");
1411 test_readvirtualmemory();
1413 trace("Starting test_queryvirtualmemory()\n");
1414 test_queryvirtualmemory();
1416 trace("Starting test_mapprotection()\n");
1417 test_mapprotection();
1419 trace("Starting test_affinity()\n");