mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 08:25:03 +00:00
[NTDLL_APITEST]
Add a few more tests for NtAllocateVirtualMemory svn path=/trunk/; revision=62270
This commit is contained in:
parent
86d2e8f543
commit
6b2e326be9
1 changed files with 69 additions and 27 deletions
|
@ -248,7 +248,7 @@ CheckAlignment()
|
|||
&Size,
|
||||
MEM_RESERVE,
|
||||
PAGE_NOACCESS);
|
||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
ok(BaseAddress == UlongToPtr(0x50000000), "Got back wrong base address: %p", BaseAddress);
|
||||
ok(Size == 0x3000, "Got back wrong size: 0x%Ix", Size);
|
||||
|
||||
|
@ -261,7 +261,7 @@ CheckAlignment()
|
|||
&Size,
|
||||
MEM_RESERVE,
|
||||
PAGE_NOACCESS);
|
||||
ok(!NT_SUCCESS(Status), "NtAllocateVirtualMemory should fail!\n");
|
||||
ok_ntstatus(Status, STATUS_CONFLICTING_ADDRESSES);
|
||||
|
||||
/* Commit memory */
|
||||
BaseAddress = UlongToPtr(0x50002000);
|
||||
|
@ -272,11 +272,24 @@ CheckAlignment()
|
|||
&Size,
|
||||
MEM_COMMIT,
|
||||
PAGE_NOACCESS);
|
||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
ok(BaseAddress == UlongToPtr(0x50002000), "Got back wrong base address: %p", BaseAddress);
|
||||
ok(Size == 0x1000, "Got back wrong size: 0x%Ix", Size);
|
||||
|
||||
/* Commit memory */
|
||||
/* Commit the same address again with a different protection */
|
||||
BaseAddress = UlongToPtr(0x50002000);
|
||||
Size = 0x1000;
|
||||
Status = NtAllocateVirtualMemory(NtCurrentProcess(),
|
||||
&BaseAddress,
|
||||
0,
|
||||
&Size,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
ok(BaseAddress == UlongToPtr(0x50002000), "Got back wrong base address: %p", BaseAddress);
|
||||
ok(Size == 0x1000, "Got back wrong size: 0x%Ix", Size);
|
||||
|
||||
/* Commit memory at a too high address */
|
||||
BaseAddress = UlongToPtr(0x50003000);
|
||||
Size = 0x1000;
|
||||
Status = NtAllocateVirtualMemory(NtCurrentProcess(),
|
||||
|
@ -285,31 +298,37 @@ CheckAlignment()
|
|||
&Size,
|
||||
MEM_COMMIT,
|
||||
PAGE_NOACCESS);
|
||||
ok(!NT_SUCCESS(Status), "NtAllocateVirtualMemory should fail!\n");
|
||||
ok_ntstatus(Status, STATUS_CONFLICTING_ADDRESSES);
|
||||
|
||||
/* Decommit the memory, even those pages that were not committed */
|
||||
BaseAddress = UlongToPtr(0x50000000);
|
||||
Size = 0x3000;
|
||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_DECOMMIT);
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
|
||||
/* 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");
|
||||
ok_ntstatus(Status, STATUS_MEMORY_NOT_ALLOCATED);
|
||||
|
||||
/* 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");
|
||||
ok_ntstatus(Status, STATUS_MEMORY_NOT_ALLOCATED);
|
||||
|
||||
/* 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");
|
||||
ok_ntstatus(Status, STATUS_UNABLE_TO_FREE_VM);
|
||||
|
||||
/* Release the memory */
|
||||
BaseAddress = UlongToPtr(0x50000000);
|
||||
Size = 0x3000;
|
||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
||||
ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
|
||||
/* Reserve and commit at once */
|
||||
BaseAddress = UlongToPtr(0x50004080);
|
||||
|
@ -320,7 +339,7 @@ CheckAlignment()
|
|||
&Size,
|
||||
MEM_RESERVE | MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
ok(BaseAddress == UlongToPtr(0x50000000), "Got back wrong base address: %p", BaseAddress);
|
||||
ok(Size == 0x6000, "Got back wrong size: 0x%Ix", Size);
|
||||
|
||||
|
@ -337,7 +356,7 @@ CheckAlignment()
|
|||
|
||||
/* Release the memory */
|
||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
||||
ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
|
||||
}
|
||||
|
||||
|
@ -358,7 +377,7 @@ CheckAdjacentVADs()
|
|||
&Size,
|
||||
MEM_RESERVE,
|
||||
PAGE_NOACCESS);
|
||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
if (!NT_SUCCESS(Status))
|
||||
return;
|
||||
|
||||
|
@ -371,7 +390,7 @@ CheckAdjacentVADs()
|
|||
&Size,
|
||||
MEM_RESERVE,
|
||||
PAGE_NOACCESS);
|
||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
if (!NT_SUCCESS(Status))
|
||||
return;
|
||||
|
||||
|
@ -379,7 +398,7 @@ CheckAdjacentVADs()
|
|||
BaseAddress = UlongToPtr(0x50000000);
|
||||
Size = 0x30000;
|
||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
||||
ok(!NT_SUCCESS(Status), "NtFreeVirtualMemory should fail!\n");
|
||||
ok_ntstatus(Status, STATUS_UNABLE_TO_FREE_VM);
|
||||
|
||||
/* Reserve the part in the middle */
|
||||
BaseAddress = UlongToPtr(0x50010000);
|
||||
|
@ -390,7 +409,7 @@ CheckAdjacentVADs()
|
|||
&Size,
|
||||
MEM_RESERVE,
|
||||
PAGE_NOACCESS);
|
||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
|
||||
/* Try to commit memory covering 2 allocations */
|
||||
BaseAddress = UlongToPtr(0x50004000);
|
||||
|
@ -401,7 +420,7 @@ CheckAdjacentVADs()
|
|||
&Size,
|
||||
MEM_COMMIT,
|
||||
PAGE_NOACCESS);
|
||||
ok(!NT_SUCCESS(Status), "NtAllocateVirtualMemory should fail!\n");
|
||||
ok_ntstatus(Status, STATUS_CONFLICTING_ADDRESSES);
|
||||
|
||||
/* Commit a page */
|
||||
BaseAddress = UlongToPtr(0x50000000);
|
||||
|
@ -412,7 +431,7 @@ CheckAdjacentVADs()
|
|||
&Size,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
|
||||
/* Commit another page */
|
||||
BaseAddress = UlongToPtr(0x50002000);
|
||||
|
@ -423,7 +442,7 @@ CheckAdjacentVADs()
|
|||
&Size,
|
||||
MEM_COMMIT,
|
||||
PAGE_NOACCESS);
|
||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
|
||||
_SEH2_TRY
|
||||
{
|
||||
|
@ -444,7 +463,7 @@ CheckAdjacentVADs()
|
|||
Status = _SEH2_GetExceptionCode();
|
||||
}
|
||||
_SEH2_END;
|
||||
ok(Status = STATUS_ACCESS_VIOLATION, "Should get an exception!\n");
|
||||
ok_ntstatus(Status, STATUS_ACCESS_VIOLATION);
|
||||
|
||||
/* Allocate 3 pages, on top of the previous 2 */
|
||||
BaseAddress = UlongToPtr(0x50000000);
|
||||
|
@ -455,7 +474,7 @@ CheckAdjacentVADs()
|
|||
&Size,
|
||||
MEM_COMMIT,
|
||||
PAGE_READONLY);
|
||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
|
||||
_SEH2_TRY
|
||||
{
|
||||
|
@ -466,28 +485,28 @@ CheckAdjacentVADs()
|
|||
Status = _SEH2_GetExceptionCode();
|
||||
}
|
||||
_SEH2_END;
|
||||
ok(Status = STATUS_ACCESS_VIOLATION, "Should get an exception!\n");
|
||||
ok_ntstatus(Status, STATUS_ACCESS_VIOLATION);
|
||||
|
||||
/* 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");
|
||||
ok_ntstatus(Status, STATUS_UNABLE_TO_FREE_VM);
|
||||
|
||||
BaseAddress = UlongToPtr(0x50000000);
|
||||
Size = 0x10000;
|
||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
||||
ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
|
||||
BaseAddress = UlongToPtr(0x50010000);
|
||||
Size = 0x10000;
|
||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
||||
ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
|
||||
BaseAddress = UlongToPtr(0x50020000);
|
||||
Size = 0x10000;
|
||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
||||
ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
|
||||
/* Reserve 3 full 64k region */
|
||||
BaseAddress = UlongToPtr(0x50000000);
|
||||
|
@ -498,7 +517,7 @@ CheckAdjacentVADs()
|
|||
&Size,
|
||||
MEM_RESERVE,
|
||||
PAGE_NOACCESS);
|
||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
if (!NT_SUCCESS(Status))
|
||||
return;
|
||||
|
||||
|
@ -506,7 +525,7 @@ CheckAdjacentVADs()
|
|||
BaseAddress = UlongToPtr(0x50010000);
|
||||
Size = 0x10000;
|
||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
||||
ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n");
|
||||
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||
|
||||
}
|
||||
|
||||
|
@ -517,10 +536,33 @@ START_TEST(NtAllocateVirtualMemory)
|
|||
PVOID Mem1, Mem2;
|
||||
SIZE_T Size1, Size2;
|
||||
ULONG i;
|
||||
NTSTATUS Status;
|
||||
|
||||
CheckAlignment();
|
||||
CheckAdjacentVADs();
|
||||
|
||||
/* Reserve memory below 0x10000 */
|
||||
Mem1 = UlongToPtr(0xf000);
|
||||
Size1 = 0x1000;
|
||||
Status = NtAllocateVirtualMemory(NtCurrentProcess(),
|
||||
&Mem1,
|
||||
0,
|
||||
&Size1,
|
||||
MEM_RESERVE,
|
||||
PAGE_READWRITE);
|
||||
ok_ntstatus(Status, STATUS_INVALID_PARAMETER_2);
|
||||
|
||||
/* Reserve memory at 0x10000 */
|
||||
Mem1 = UlongToPtr(0x10000);
|
||||
Size1 = 0x1000;
|
||||
Status = NtAllocateVirtualMemory(NtCurrentProcess(),
|
||||
&Mem1,
|
||||
0,
|
||||
&Size1,
|
||||
MEM_RESERVE,
|
||||
PAGE_READWRITE);
|
||||
ok_ntstatus(Status, STATUS_CONFLICTING_ADDRESSES);
|
||||
|
||||
Size1 = 32;
|
||||
Mem1 = Allocate(Size1);
|
||||
AccessMemory1(Mem1, Size1);
|
||||
|
|
Loading…
Reference in a new issue