From c0642c44b6fdaae2b6753b0598e993aba4093358 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Wed, 27 Mar 2013 19:10:51 +0000 Subject: [PATCH] [NTDLL_APITEST] Add more tests for NtAllocateVirtualMemory and NtMapViewOfSection svn path=/trunk/; revision=58613 --- rostests/apitests/ntdll/CMakeLists.txt | 1 + .../apitests/ntdll/NtAllocateVirtualMemory.c | 273 ++++++++++++ rostests/apitests/ntdll/NtMapViewOfSection.c | 390 ++++++++++++++++++ rostests/apitests/ntdll/testlist.c | 2 + rostests/apitests/testdata/test.dll | Bin 0 -> 3072 bytes 5 files changed, 666 insertions(+) create mode 100644 rostests/apitests/ntdll/NtMapViewOfSection.c create mode 100644 rostests/apitests/testdata/test.dll diff --git a/rostests/apitests/ntdll/CMakeLists.txt b/rostests/apitests/ntdll/CMakeLists.txt index 086a90af207..dd78b59121a 100644 --- a/rostests/apitests/ntdll/CMakeLists.txt +++ b/rostests/apitests/ntdll/CMakeLists.txt @@ -3,6 +3,7 @@ list(APPEND SOURCE LdrEnumResources.c NtAllocateVirtualMemory.c NtFreeVirtualMemory.c + NtMapViewOfSection.c NtQuerySystemEnvironmentValue.c RtlBitmap.c RtlDetermineDosPathNameType.c diff --git a/rostests/apitests/ntdll/NtAllocateVirtualMemory.c b/rostests/apitests/ntdll/NtAllocateVirtualMemory.c index 03884d651a9..597f3328959 100644 --- a/rostests/apitests/ntdll/NtAllocateVirtualMemory.c +++ b/rostests/apitests/ntdll/NtAllocateVirtualMemory.c @@ -9,6 +9,7 @@ #include #include #include +#include static PVOID Allocations[4096] = { NULL }; static ULONG CurrentAllocation = 0; @@ -198,6 +199,275 @@ CheckMemory2( return TRUE; } +VOID +CheckSize(ULONG_PTR Base, SIZE_T InSize, SIZE_T ExpectedSize) +{ + NTSTATUS Status; + PVOID BaseAddress; + SIZE_T Size; + + /* Reserve memory */ + BaseAddress = UlongToPtr(Base); + Size = InSize; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &Size, + MEM_RESERVE, + PAGE_NOACCESS); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n"); + ok(BaseAddress == UlongToPtr(Base & ~0xFFFF), "Got back wrong base address: %p\n", BaseAddress); + ok(Size == ExpectedSize, "Alloc of 0x%Ix: got back wrong size: 0x%Ix, expected 0x%Ix\n", InSize, Size, ExpectedSize); + Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE); + ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n"); +} + +VOID +CheckAlignment() +{ + NTSTATUS Status; + PVOID BaseAddress; + SIZE_T Size; + + CheckSize(0x50000000, 0x0001, 0x1000); + CheckSize(0x50008000, 0x0001, 0x9000); + CheckSize(0x50000010, 0x1000, 0x2000); + CheckSize(0x50010000, 0x2000, 0x2000); + CheckSize(0x5000FFFF, 0x3000, 0x13000); + CheckSize(0x50001010, 0x7000, 0x9000); + CheckSize(0x50001010, 0xC000, 0xe000); + + /* Reserve memory not aligned to allocation granularity */ + BaseAddress = UlongToPtr(0x50001010); + Size = 0x1000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &Size, + MEM_RESERVE, + PAGE_NOACCESS); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n"); + ok(BaseAddress == UlongToPtr(0x50000000), "Got back wrong base address: %p", BaseAddress); + ok(Size == 0x3000, "Got back wrong size: 0x%Ix", Size); + + /* Try to reserve again in the same 64k region */ + BaseAddress = UlongToPtr(0x50008000); + Size = 0x1000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &Size, + MEM_RESERVE, + PAGE_NOACCESS); + ok(!NT_SUCCESS(Status), "NtAllocateVirtualMemory should fail!\n"); + + /* Commit memory */ + BaseAddress = UlongToPtr(0x50002000); + Size = 0x1000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &Size, + MEM_COMMIT, + PAGE_NOACCESS); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n"); + ok(BaseAddress == UlongToPtr(0x50002000), "Got back wrong base address: %p", BaseAddress); + ok(Size == 0x1000, "Got back wrong size: 0x%Ix", Size); + + /* Commit memory */ + BaseAddress = UlongToPtr(0x50003000); + Size = 0x1000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &Size, + MEM_COMMIT, + PAGE_NOACCESS); + ok(!NT_SUCCESS(Status), "NtAllocateVirtualMemory should fail!\n"); + + /* Try to release memory in a different 64k region */ + BaseAddress = UlongToPtr(0x50010000); + Size = 0x1000; + Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE); + ok(!NT_SUCCESS(Status), "NtFreeVirtualMemory should fail!\n"); + + /* Release the memory in the same 64k region at a different address */ + BaseAddress = UlongToPtr(0x50008000); + Size = 0x1000; + Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE); + ok(!NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n"); + + /* Release the memory at the correct address but with wrong size */ + BaseAddress = UlongToPtr(0x50000000); + Size = 0x4000; + Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE); + ok(!NT_SUCCESS(Status), "NtFreeVirtualMemory should fail!\n"); + + /* Release the memory */ + BaseAddress = UlongToPtr(0x50000000); + Size = 0x3000; + Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE); + ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n"); + + /* Reserve and commit at once */ + BaseAddress = UlongToPtr(0x50004080); + Size = 0x1000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &Size, + MEM_RESERVE | MEM_COMMIT, + PAGE_READWRITE); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n"); + ok(BaseAddress == UlongToPtr(0x50000000), "Got back wrong base address: %p", BaseAddress); + ok(Size == 0x6000, "Got back wrong size: 0x%Ix", Size); + + _SEH2_TRY + { + *(int*)UlongToPtr(BaseAddress) = 1; + *(int*)UlongToPtr(0x50004080) = 1; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + ok(0, "Got exception\n"); + } + _SEH2_END; + + /* Release the memory */ + Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE); + ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n"); + +} + +static +VOID +CheckAdjacentVADs() +{ + NTSTATUS Status; + PVOID BaseAddress; + SIZE_T Size; + + /* Reserve a full 64k region */ + BaseAddress = UlongToPtr(0x50000000); + Size = 0x10000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &Size, + MEM_RESERVE, + PAGE_NOACCESS); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n"); + if (!NT_SUCCESS(Status)) + return; + + /* Reserve another 64k region, but with 64k between */ + BaseAddress = UlongToPtr(0x50020000); + Size = 0x10000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &Size, + MEM_RESERVE, + PAGE_NOACCESS); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n"); + if (!NT_SUCCESS(Status)) + return; + + /* Try to free the whole at once */ + BaseAddress = UlongToPtr(0x50000000); + Size = 0x30000; + Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE); + ok(!NT_SUCCESS(Status), "NtFreeVirtualMemory should fail!\n"); + + /* Reserve the part in the middle */ + BaseAddress = UlongToPtr(0x50010000); + Size = 0x10000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &Size, + MEM_RESERVE, + PAGE_NOACCESS); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n"); + + /* Try to commit memory covering 2 allocations */ + BaseAddress = UlongToPtr(0x50004000); + Size = 0x10000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &Size, + MEM_COMMIT, + PAGE_NOACCESS); + ok(!NT_SUCCESS(Status), "NtAllocateVirtualMemory should fail!\n"); + + /* Allocate a page */ + BaseAddress = UlongToPtr(0x50000000); + Size = 0x1000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &Size, + MEM_COMMIT, + PAGE_READWRITE); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n"); + + /* Allocate another page */ + BaseAddress = UlongToPtr(0x50002000); + Size = 0x1000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &Size, + MEM_COMMIT, + PAGE_NOACCESS); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n"); + + _SEH2_TRY + { + *(int*)UlongToPtr(0x50000000) = 1; + //*(int*)UlongToPtr(0x50002000) = 1; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + ok(0, "Got exception\n"); + } + _SEH2_END; + + /* Allocate 3 pages, on top of the previous 2 */ + BaseAddress = UlongToPtr(0x50000000); + Size = 0x3000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &Size, + MEM_COMMIT, + PAGE_NOACCESS); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n"); + + /* Try to free the whole region at once */ + BaseAddress = UlongToPtr(0x50000000); + Size = 0x30000; + Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE); + ok(!NT_SUCCESS(Status), "NtFreeVirtualMemory should fail!\n"); + + BaseAddress = UlongToPtr(0x50000000); + Size = 0x10000; + Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE); + ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n"); + + BaseAddress = UlongToPtr(0x50010000); + Size = 0x10000; + Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE); + ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n"); + + BaseAddress = UlongToPtr(0x50020000); + Size = 0x10000; + Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE); + ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n"); + +} + #define RUNS 32 START_TEST(NtAllocateVirtualMemory) @@ -206,6 +476,9 @@ START_TEST(NtAllocateVirtualMemory) SIZE_T Size1, Size2; ULONG i; + CheckAlignment(); + CheckAdjacentVADs(); + Size1 = 32; Mem1 = Allocate(Size1); AccessMemory1(Mem1, Size1); diff --git a/rostests/apitests/ntdll/NtMapViewOfSection.c b/rostests/apitests/ntdll/NtMapViewOfSection.c new file mode 100644 index 00000000000..08b300cc4e3 --- /dev/null +++ b/rostests/apitests/ntdll/NtMapViewOfSection.c @@ -0,0 +1,390 @@ + +#define WIN32_NO_STATUS +#include +#include +#include + +NTSYSAPI +NTSTATUS +NTAPI +NtMapViewOfSection( + HANDLE SectionHandle, + HANDLE ProcessHandle, + PVOID *BaseAddress, + ULONG_PTR ZeroBits, + SIZE_T CommitSize, + PLARGE_INTEGER SectionOffset, + PSIZE_T ViewSize, + SECTION_INHERIT InheritDisposition, + ULONG AllocationType, + ULONG Protect); + +void +Test_PageFileSection(void) +{ + NTSTATUS Status; + HANDLE SectionHandle; + LARGE_INTEGER MaximumSize, SectionOffset; + PVOID BaseAddress; + SIZE_T ViewSize; + + /* Create a page file backed section */ + MaximumSize.QuadPart = 0x20000; + Status = NtCreateSection(&SectionHandle, + SECTION_ALL_ACCESS, + NULL, + &MaximumSize, + PAGE_READWRITE, + SEC_COMMIT, + NULL); + ok(NT_SUCCESS(Status), "NtCreateSection failed with Status %lx\n", Status); + if (!NT_SUCCESS(Status)) + return; + + /* Try to map a page at an address that is not 64k aligned */ + BaseAddress = (PVOID)0x30001000; + SectionOffset.QuadPart = 0; + ViewSize = 0x1000; + Status = NtMapViewOfSection(SectionHandle, + NtCurrentProcess(), + &BaseAddress, + 0, + 0, + &SectionOffset, + &ViewSize, + ViewShare, + 0, + PAGE_READWRITE); + ok(Status == STATUS_MAPPED_ALIGNMENT, + "NtMapViewOfSection returned wrong Status %lx\n", Status); + + /* Try to map a page with execute rights */ + BaseAddress = (PVOID)0x30000000; + SectionOffset.QuadPart = 0; + ViewSize = 0x1000; + Status = NtMapViewOfSection(SectionHandle, + NtCurrentProcess(), + &BaseAddress, + 0, + 0, + &SectionOffset, + &ViewSize, + ViewShare, + 0, + PAGE_EXECUTE_READWRITE); + ok(Status == STATUS_SECTION_PROTECTION, + "NtMapViewOfSection returned wrong Status %lx\n", Status); + + /* Map 2 pages, not comitting them */ + BaseAddress = (PVOID)0x30000000; + SectionOffset.QuadPart = 0; + ViewSize = 0x2000; + Status = NtMapViewOfSection(SectionHandle, + NtCurrentProcess(), + &BaseAddress, + 0, + 0, + &SectionOffset, + &ViewSize, + ViewShare, + 0, + PAGE_READWRITE); + ok(NT_SUCCESS(Status), "NtMapViewOfSection failed with Status %lx\n", Status); + if (!NT_SUCCESS(Status)) + return; + + /* Commit a page in the section */ + BaseAddress = (PVOID)0x30000000; + ViewSize = 0x1000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &ViewSize, + MEM_COMMIT, + PAGE_READWRITE); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed with Status %lx\n", Status); + + /* Try to commit a range larger than the section */ + BaseAddress = (PVOID)0x30000000; + ViewSize = 0x3000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &ViewSize, + MEM_COMMIT, + PAGE_READWRITE); + ok(Status == STATUS_CONFLICTING_ADDRESSES, + "NtAllocateVirtualMemory failed with wrong Status %lx\n", Status); + + /* Try to commit a page after the section */ + BaseAddress = (PVOID)0x30002000; + ViewSize = 0x1000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &ViewSize, + MEM_COMMIT, + PAGE_READWRITE); + ok(!NT_SUCCESS(Status), "NtAllocateVirtualMemory Should fail\n"); + + /* Try to allocate a page after the section */ + BaseAddress = (PVOID)0x30002000; + ViewSize = 0x1000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &ViewSize, + MEM_RESERVE | MEM_COMMIT, + PAGE_READWRITE); + ok(!NT_SUCCESS(Status), "NtAllocateVirtualMemory should fail\n"); + + /* Need to go to next 64k boundary */ + BaseAddress = (PVOID)0x30010000; + ViewSize = 0x1000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &ViewSize, + MEM_RESERVE | MEM_COMMIT, + PAGE_READWRITE); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed with Status %lx\n", Status); + if (!NT_SUCCESS(Status)) + return; + + /* Free the allocation */ + BaseAddress = (PVOID)0x30010000; + ViewSize = 0x1000; + Status = NtFreeVirtualMemory(NtCurrentProcess(), + &BaseAddress, + &ViewSize, + MEM_RELEASE); + ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed with Status %lx\n", Status); + + /* Free the section mapping */ + BaseAddress = (PVOID)0x30000000; + ViewSize = 0x1000; + Status = NtFreeVirtualMemory(NtCurrentProcess(), + &BaseAddress, + &ViewSize, + MEM_RELEASE); + ok(Status == STATUS_UNABLE_TO_DELETE_SECTION, + "NtFreeVirtualMemory failed with wrong Status %lx\n", Status); + + /* Commit a page in the section */ + BaseAddress = (PVOID)0x30001000; + ViewSize = 0x1000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &ViewSize, + MEM_COMMIT, + PAGE_READWRITE); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed with Status %lx\n", Status); + + /* Try to decommit the page */ + BaseAddress = (PVOID)0x30001000; + ViewSize = 0x1000; + Status = NtFreeVirtualMemory(NtCurrentProcess(), + &BaseAddress, + &ViewSize, + MEM_DECOMMIT); + ok(Status == STATUS_UNABLE_TO_DELETE_SECTION, + "NtFreeVirtualMemory failed with wrong Status %lx\n", Status); + + BaseAddress = (PVOID)0x40000000; + SectionOffset.QuadPart = 0; + ViewSize = 0x1000; + Status = NtMapViewOfSection(SectionHandle, + NtCurrentProcess(), + &BaseAddress, + 0, + 0, + &SectionOffset, + &ViewSize, + ViewShare, + 0, + PAGE_READWRITE); + ok(NT_SUCCESS(Status), "NtMapViewOfSection failed with Status %lx\n", Status); + if (!NT_SUCCESS(Status)) + return; + + ok(BaseAddress == (PVOID)0x40000000, "Invalid BaseAddress: %p", BaseAddress); + + BaseAddress = (PVOID)0x40080000; + SectionOffset.QuadPart = 0x10000; + ViewSize = 0x1000; + Status = NtMapViewOfSection(SectionHandle, + NtCurrentProcess(), + &BaseAddress, + 0, + 0, + &SectionOffset, + &ViewSize, + ViewShare, + 0, + PAGE_READWRITE); + ok(NT_SUCCESS(Status), "NtMapViewOfSection failed with Status %lx\n", Status); + if (!NT_SUCCESS(Status)) + return; + + ok(BaseAddress == (PVOID)0x40080000, "Invalid BaseAddress: %p", BaseAddress); + + /* Commit a page in the section */ + BaseAddress = (PVOID)0x40000000; + Status = NtAllocateVirtualMemory(NtCurrentProcess(), + &BaseAddress, + 0, + &ViewSize, + MEM_COMMIT, + PAGE_READWRITE); + ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed with Status %lx\n", Status); + if (!NT_SUCCESS(Status)) + return; + +} + +void +Test_ImageSection(void) +{ + UNICODE_STRING FileName; + NTSTATUS Status; + OBJECT_ATTRIBUTES FileObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + HANDLE FileHandle, DataSectionHandle, ImageSectionHandle; + PVOID DataBase, ImageBase; + SIZE_T ViewSize; + + if (!RtlDosPathNameToNtPathName_U(L"testdata\\test.dll", + &FileName, + NULL, + NULL)) + { + ok(0, "RtlDosPathNameToNtPathName_U failed\n"); + return; + } + + InitializeObjectAttributes(&FileObjectAttributes, + &FileName, + 0, + NULL, + NULL); + + Status = NtOpenFile(&FileHandle, + GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE, + &FileObjectAttributes, + &IoStatusBlock, + FILE_SHARE_READ, + FILE_SYNCHRONOUS_IO_NONALERT); + ok(Status == STATUS_SUCCESS, "NtOpenFile failed, Status 0x%lx\n", Status); + + /* Create a data section with write access */ + Status = NtCreateSection(&DataSectionHandle, + SECTION_ALL_ACCESS, // DesiredAccess + NULL, // ObjectAttributes + NULL, // MaximumSize + PAGE_READWRITE, // SectionPageProtection + SEC_COMMIT, // AllocationAttributes + FileHandle); + ok(Status == STATUS_SUCCESS, "NtCreateSection failed, Status 0x%lx\n", Status); + + /* Map the data section */ + DataBase = NULL; + ViewSize = 0; + Status = NtMapViewOfSection(DataSectionHandle, + NtCurrentProcess(), + &DataBase, + 0, + 0, + NULL, + &ViewSize, + ViewShare, + 0, + PAGE_READWRITE); + ok(Status == STATUS_SUCCESS, "NtMapViewOfSection failed, Status 0x%lx\n", Status); + + /* Check the original data */ + ok(*(ULONG*)DataBase == 0x00905a4d, "Header not ok\n"); + + /* Now modify the data in the data section */ + *(ULONG*)DataBase = 0xdeadbabe; + + /* Check the data */ + ok(*(ULONG*)DataBase == 0xdeadbabe, "Header not ok\n"); + + /* Now try to create an image section */ + Status = NtCreateSection(&ImageSectionHandle, + SECTION_ALL_ACCESS, // DesiredAccess + NULL, // ObjectAttributes + NULL, // MaximumSize + PAGE_READWRITE, // SectionPageProtection + SEC_IMAGE, // AllocationAttributes + FileHandle); + ok(Status == STATUS_INVALID_IMAGE_NOT_MZ, "NtCreateSection failed, Status 0x%lx\n", Status); + + /* Restore the original data */ + *(ULONG*)DataBase = 0x00905a4d; + + /* Try to create an image section again */ + Status = NtCreateSection(&ImageSectionHandle, + SECTION_ALL_ACCESS, // DesiredAccess + NULL, // ObjectAttributes + NULL, // MaximumSize + PAGE_READWRITE, // SectionPageProtection + SEC_IMAGE, // AllocationAttributes + FileHandle); + ok(Status == STATUS_SUCCESS, "NtCreateSection failed, Status 0x%lx\n", Status); + + /* Map the image section */ + ImageBase = NULL; + ViewSize = 0; + Status = NtMapViewOfSection(ImageSectionHandle, + NtCurrentProcess(), + &ImageBase, + 0, + 0, + NULL, + &ViewSize, + ViewShare, + 0, + PAGE_READONLY); + ok(Status == STATUS_SUCCESS, "NtMapViewOfSection failed, Status 0x%lx\n", Status); + + /* Check the data */ + ok(*(ULONG*)DataBase == 0x00905a4d, "Header not ok\n"); + ok(*(ULONG*)ImageBase == 0x00905a4d, "Header not ok\n"); + + /* Now modify the data again */ + *(ULONG*)DataBase = 0xdeadbabe; + + /* Check the data */ + ok(*(ULONG*)DataBase == 0xdeadbabe, "Header not ok\n"); + ok(*(ULONG*)ImageBase == 0x00905a4d, "Data should not be synced!\n"); + + /* Flush the view */ + ViewSize = 0x1000; + Status = NtFlushVirtualMemory(NtCurrentProcess(), + &DataBase, + &ViewSize, + &IoStatusBlock); + ok(Status == STATUS_SUCCESS, "NtFlushVirtualMemory failed, Status 0x%lx\n", Status); + + /* Check the data again */ + ok(*(ULONG*)ImageBase == 0x00905a4d, "Data should not be synced!\n"); + + /* Restore the original data */ + *(ULONG*)DataBase = 0x00905a4d; + ok(*(ULONG*)DataBase == 0x00905a4d, "Header not ok\n"); + + /* Cleanup */ + NtUnmapViewOfSection(NtCurrentProcess(), ImageBase); + NtUnmapViewOfSection(NtCurrentProcess(), DataBase); + NtClose(ImageSectionHandle); + NtClose(DataSectionHandle); + NtClose(FileHandle); +} + +START_TEST(NtMapViewOfSection) +{ + //Test_PageFileSection(); + Test_ImageSection(); +} diff --git a/rostests/apitests/ntdll/testlist.c b/rostests/apitests/ntdll/testlist.c index ac23a9b12ac..b8a6c9e8e45 100644 --- a/rostests/apitests/ntdll/testlist.c +++ b/rostests/apitests/ntdll/testlist.c @@ -6,6 +6,7 @@ extern void func_LdrEnumResources(void); extern void func_NtAllocateVirtualMemory(void); extern void func_NtFreeVirtualMemory(void); +extern void func_NtMapViewOfSection(void); extern void func_NtQuerySystemEnvironmentValue(void); extern void func_NtSystemInformation(void); extern void func_RtlBitmap(void); @@ -26,6 +27,7 @@ const struct test winetest_testlist[] = { "LdrEnumResources", func_LdrEnumResources }, { "NtAllocateVirtualMemory", func_NtAllocateVirtualMemory }, { "NtFreeVirtualMemory", func_NtFreeVirtualMemory }, + { "NtMapViewOfSection", func_NtMapViewOfSection }, { "NtQuerySystemEnvironmentValue", func_NtQuerySystemEnvironmentValue }, { "NtSystemInformation", func_NtSystemInformation }, { "RtlBitmapApi", func_RtlBitmap }, diff --git a/rostests/apitests/testdata/test.dll b/rostests/apitests/testdata/test.dll new file mode 100644 index 0000000000000000000000000000000000000000..a95851e64d1cc1920758ab7d290de5dd48239ff5 GIT binary patch literal 3072 zcmeZ`n!v!!z`(!)#Q*;@Fzf)*Am9Kd@e?350j>-TK8#EZN+$yYVX7Z6Fe!2~ax*Y6 z!9<|60FYJyvjrGHY@nrVU@n4Y5a0ldUoZn{cVJ}zDFms7(@-u{-#}4%C8-r9Aj?0n zLmUJOKoCX(3JeShdMSw|i9j((P(b{~0Hn~s0W|(7cQgd(5(35t4%5Y+QA