Signed-off-by: Jinoh Kang jinoh.kang.kr@gmail.com ---
Notes: v2 -> v3: Guard wow64 status code tests with todo_wine v4 -> v5: fix one wow64 test item v5 -> v6: use ULongToPtr/PtrToUlong macro; edit subject
dlls/ntdll/tests/virtual.c | 164 +++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+)
diff --git a/dlls/ntdll/tests/virtual.c b/dlls/ntdll/tests/virtual.c index adc9b1ae6dc..ed8ff3f5c11 100644 --- a/dlls/ntdll/tests/virtual.c +++ b/dlls/ntdll/tests/virtual.c @@ -39,6 +39,9 @@ static void * (WINAPI *pRtlFindExportedRoutineByName)(HMODULE,const char*); static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL); static NTSTATUS (WINAPI *pNtAllocateVirtualMemoryEx)(HANDLE, PVOID *, SIZE_T *, ULONG, ULONG, MEM_EXTENDED_PARAMETER *, ULONG); +static NTSTATUS (WINAPI *pNtSetInformationVirtualMemory)(HANDLE, VIRTUAL_MEMORY_INFORMATION_CLASS, + ULONG_PTR, PMEMORY_RANGE_ENTRY, + PVOID, ULONG); static const BOOL is_win64 = sizeof(void*) != sizeof(int); static BOOL is_wow64;
@@ -1132,6 +1135,165 @@ static void test_syscalls(void) UnmapViewOfFile( ptr ); }
+static void test_prefetch(void) +{ + NTSTATUS status; + MEMORY_RANGE_ENTRY entries[2] = {{ 0 }}; + ULONG reservedarg = 0; + char stackmem[] = "Test stack mem"; + static char testmem[] = "Test memory range data"; + + if (!pNtSetInformationVirtualMemory) + { + skip("no NtSetInformationVirtualMemory in ntdll\n"); + return; + } + + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), -1UL, 1, entries, NULL, 32); + ok( status == STATUS_INVALID_PARAMETER_2, + "NtSetInformationVirtualMemory unexpected status on invalid info class (1): %08x\n", status); + + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), -1UL, 0, NULL, NULL, 0); + ok( status == STATUS_INVALID_PARAMETER_2 || (is_wow64 && status == STATUS_INVALID_PARAMETER_3), + "NtSetInformationVirtualMemory unexpected status on invalid info class (2): %08x\n", status); + if (is_wow64) + { + todo_wine + ok( status == STATUS_INVALID_PARAMETER_3, + "wow64 NtSetInformationVirtualMemory unexpected status on invalid info class (2): %08x\n", status); + } + + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), -1UL, 1, NULL, NULL, 32); + ok( status == STATUS_INVALID_PARAMETER_2 || (is_wow64 && status == STATUS_ACCESS_VIOLATION), + "NtSetInformationVirtualMemory unexpected status on invalid info class (3): %08x\n", status); + if (is_wow64) + { + todo_wine + ok( status == STATUS_ACCESS_VIOLATION, + "wow64 NtSetInformationVirtualMemory unexpected status on invalid info class (3): %08x\n", status); + } + + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 1, entries, NULL, 0 ); + ok( status == STATUS_INVALID_PARAMETER_5 || + broken( is_wow64 && status == STATUS_INVALID_PARAMETER_6 ) /* win10 1507 */, + "NtSetInformationVirtualMemory unexpected status on NULL info data (1): %08x\n", status); + + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 1, NULL, NULL, 0 ); + ok( status == STATUS_INVALID_PARAMETER_5 || (is_wow64 && status == STATUS_ACCESS_VIOLATION), + "NtSetInformationVirtualMemory unexpected status on NULL info data (2): %08x\n", status); + if (is_wow64) + { + todo_wine + ok( status == STATUS_ACCESS_VIOLATION, + "wow64 NtSetInformationVirtualMemory unexpected status on NULL info data (2): %08x\n", status); + } + + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 0, NULL, NULL, 0 ); + ok( status == STATUS_INVALID_PARAMETER_5 || (is_wow64 && status == STATUS_INVALID_PARAMETER_3), + "NtSetInformationVirtualMemory unexpected status on NULL info data (3): %08x\n", status); + if (is_wow64) + { + todo_wine + ok( status == STATUS_INVALID_PARAMETER_3, + "wow64 NtSetInformationVirtualMemory unexpected status on NULL info data (3): %08x\n", status); + } + + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 1, entries, &reservedarg, sizeof(reservedarg) * 2 ); + ok( status == STATUS_INVALID_PARAMETER_6, + "NtSetInformationVirtualMemory unexpected status on extended info data (1): %08x\n", status); + + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 0, NULL, &reservedarg, sizeof(reservedarg) * 2 ); + ok( status == STATUS_INVALID_PARAMETER_6 || (is_wow64 && status == STATUS_INVALID_PARAMETER_3), + "NtSetInformationVirtualMemory unexpected status on extended info data (2): %08x\n", status); + if (is_wow64) + { + todo_wine + ok( status == STATUS_INVALID_PARAMETER_3, + "wow64 NtSetInformationVirtualMemory unexpected status on extended info data (2): %08x\n", status); + } + + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 1, entries, &reservedarg, sizeof(reservedarg) / 2 ); + ok( status == STATUS_INVALID_PARAMETER_6, + "NtSetInformationVirtualMemory unexpected status on shrunk info data (1): %08x\n", status); + + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 0, NULL, &reservedarg, sizeof(reservedarg) / 2 ); + ok( status == STATUS_INVALID_PARAMETER_6 || (is_wow64 && status == STATUS_INVALID_PARAMETER_3), + "NtSetInformationVirtualMemory unexpected status on shrunk info data (2): %08x\n", status); + if (is_wow64) + { + todo_wine + ok( status == STATUS_INVALID_PARAMETER_3, + "wow64 NtSetInformationVirtualMemory unexpected status on shrunk info data (2): %08x\n", status); + } + + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 0, NULL, &reservedarg, sizeof(reservedarg) ); + ok( status == STATUS_INVALID_PARAMETER_3, + "NtSetInformationVirtualMemory unexpected status on 0 entries: %08x\n", status); + + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 1, NULL, &reservedarg, sizeof(reservedarg) ); + ok( status == STATUS_ACCESS_VIOLATION, + "NtSetInformationVirtualMemory unexpected status on NULL entries: %08x\n", status); + + entries[0].VirtualAddress = NULL; + entries[0].NumberOfBytes = 0; + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 1, entries, &reservedarg, sizeof(reservedarg) ); + ok( status == STATUS_INVALID_PARAMETER_4 || + broken( is_wow64 && status == STATUS_INVALID_PARAMETER_6 ) /* win10 1507 */, + "NtSetInformationVirtualMemory unexpected status on 1 empty entry: %08x\n", status); + + entries[0].VirtualAddress = NULL; + entries[0].NumberOfBytes = page_size; + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 1, entries, &reservedarg, sizeof(reservedarg) ); + ok( status == STATUS_SUCCESS || + broken( is_wow64 && status == STATUS_INVALID_PARAMETER_6 ) /* win10 1507 */, + "NtSetInformationVirtualMemory unexpected status on 1 NULL address entry: %08x\n", status); + + entries[0].VirtualAddress = ULongToPtr(PtrToUlong(testmem) & -(ULONG_PTR)page_size); + entries[0].NumberOfBytes = page_size; + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 1, entries, &reservedarg, sizeof(reservedarg) ); + ok( status == STATUS_SUCCESS || + broken( is_wow64 && status == STATUS_INVALID_PARAMETER_6 ) /* win10 1507 */, + "NtSetInformationVirtualMemory unexpected status on 1 page-aligned entry: %08x\n", status); + + entries[0].VirtualAddress = testmem; + entries[0].NumberOfBytes = sizeof(testmem); + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 1, entries, &reservedarg, sizeof(reservedarg) ); + ok( status == STATUS_SUCCESS || + broken( is_wow64 && status == STATUS_INVALID_PARAMETER_6 ) /* win10 1507 */, + "NtSetInformationVirtualMemory unexpected status on 1 entry: %08x\n", status); + + entries[0].VirtualAddress = NULL; + entries[0].NumberOfBytes = page_size; + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 1, entries, &reservedarg, sizeof(reservedarg) ); + ok( status == STATUS_SUCCESS || + broken( is_wow64 && status == STATUS_INVALID_PARAMETER_6 ) /* win10 1507 */, + "NtSetInformationVirtualMemory unexpected status on 1 unmapped entry: %08x\n", status); + + entries[0].VirtualAddress = ULongToPtr(PtrToUlong(testmem) & -(ULONG_PTR)page_size); + entries[0].NumberOfBytes = page_size; + entries[1].VirtualAddress = ULongToPtr(PtrToUlong(stackmem) & -(ULONG_PTR)page_size); + entries[1].NumberOfBytes = page_size; + status = pNtSetInformationVirtualMemory( NtCurrentProcess(), VmPrefetchInformation, + 2, entries, &reservedarg, sizeof(reservedarg) ); + ok( status == STATUS_SUCCESS || + broken( is_wow64 && status == STATUS_INVALID_PARAMETER_6 ) /* win10 1507 */, + "NtSetInformationVirtualMemory unexpected status on 2 page-aligned entries: %08x\n", status); +} + START_TEST(virtual) { HMODULE mod; @@ -1160,6 +1322,7 @@ START_TEST(virtual) pRtlFindExportedRoutineByName = (void *)GetProcAddress(mod, "RtlFindExportedRoutineByName"); pRtlGetEnabledExtendedFeatures = (void *)GetProcAddress(mod, "RtlGetEnabledExtendedFeatures"); pNtAllocateVirtualMemoryEx = (void *)GetProcAddress(mod, "NtAllocateVirtualMemoryEx"); + pNtSetInformationVirtualMemory = (void *)GetProcAddress(mod, "NtSetInformationVirtualMemory");
NtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), NULL); trace("system page size %#x\n", sbi.PageSize); @@ -1171,4 +1334,5 @@ START_TEST(virtual) test_NtMapViewOfSection(); test_user_shared_data(); test_syscalls(); + test_prefetch(); }