mirror of
https://github.com/reactos/reactos.git
synced 2025-05-29 05:58:13 +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,
|
&Size,
|
||||||
MEM_RESERVE,
|
MEM_RESERVE,
|
||||||
PAGE_NOACCESS);
|
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(BaseAddress == UlongToPtr(0x50000000), "Got back wrong base address: %p", BaseAddress);
|
||||||
ok(Size == 0x3000, "Got back wrong size: 0x%Ix", Size);
|
ok(Size == 0x3000, "Got back wrong size: 0x%Ix", Size);
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ CheckAlignment()
|
||||||
&Size,
|
&Size,
|
||||||
MEM_RESERVE,
|
MEM_RESERVE,
|
||||||
PAGE_NOACCESS);
|
PAGE_NOACCESS);
|
||||||
ok(!NT_SUCCESS(Status), "NtAllocateVirtualMemory should fail!\n");
|
ok_ntstatus(Status, STATUS_CONFLICTING_ADDRESSES);
|
||||||
|
|
||||||
/* Commit memory */
|
/* Commit memory */
|
||||||
BaseAddress = UlongToPtr(0x50002000);
|
BaseAddress = UlongToPtr(0x50002000);
|
||||||
|
@ -272,11 +272,24 @@ CheckAlignment()
|
||||||
&Size,
|
&Size,
|
||||||
MEM_COMMIT,
|
MEM_COMMIT,
|
||||||
PAGE_NOACCESS);
|
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(BaseAddress == UlongToPtr(0x50002000), "Got back wrong base address: %p", BaseAddress);
|
||||||
ok(Size == 0x1000, "Got back wrong size: 0x%Ix", Size);
|
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);
|
BaseAddress = UlongToPtr(0x50003000);
|
||||||
Size = 0x1000;
|
Size = 0x1000;
|
||||||
Status = NtAllocateVirtualMemory(NtCurrentProcess(),
|
Status = NtAllocateVirtualMemory(NtCurrentProcess(),
|
||||||
|
@ -285,31 +298,37 @@ CheckAlignment()
|
||||||
&Size,
|
&Size,
|
||||||
MEM_COMMIT,
|
MEM_COMMIT,
|
||||||
PAGE_NOACCESS);
|
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 */
|
/* Try to release memory in a different 64k region */
|
||||||
BaseAddress = UlongToPtr(0x50010000);
|
BaseAddress = UlongToPtr(0x50010000);
|
||||||
Size = 0x1000;
|
Size = 0x1000;
|
||||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
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 */
|
/* Release the memory in the same 64k region at a different address */
|
||||||
BaseAddress = UlongToPtr(0x50008000);
|
BaseAddress = UlongToPtr(0x50008000);
|
||||||
Size = 0x1000;
|
Size = 0x1000;
|
||||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
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 */
|
/* Release the memory at the correct address but with wrong size */
|
||||||
BaseAddress = UlongToPtr(0x50000000);
|
BaseAddress = UlongToPtr(0x50000000);
|
||||||
Size = 0x4000;
|
Size = 0x4000;
|
||||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
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 */
|
/* Release the memory */
|
||||||
BaseAddress = UlongToPtr(0x50000000);
|
BaseAddress = UlongToPtr(0x50000000);
|
||||||
Size = 0x3000;
|
Size = 0x3000;
|
||||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
||||||
ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n");
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||||
|
|
||||||
/* Reserve and commit at once */
|
/* Reserve and commit at once */
|
||||||
BaseAddress = UlongToPtr(0x50004080);
|
BaseAddress = UlongToPtr(0x50004080);
|
||||||
|
@ -320,7 +339,7 @@ CheckAlignment()
|
||||||
&Size,
|
&Size,
|
||||||
MEM_RESERVE | MEM_COMMIT,
|
MEM_RESERVE | MEM_COMMIT,
|
||||||
PAGE_READWRITE);
|
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(BaseAddress == UlongToPtr(0x50000000), "Got back wrong base address: %p", BaseAddress);
|
||||||
ok(Size == 0x6000, "Got back wrong size: 0x%Ix", Size);
|
ok(Size == 0x6000, "Got back wrong size: 0x%Ix", Size);
|
||||||
|
|
||||||
|
@ -337,7 +356,7 @@ CheckAlignment()
|
||||||
|
|
||||||
/* Release the memory */
|
/* Release the memory */
|
||||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
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,
|
&Size,
|
||||||
MEM_RESERVE,
|
MEM_RESERVE,
|
||||||
PAGE_NOACCESS);
|
PAGE_NOACCESS);
|
||||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -371,7 +390,7 @@ CheckAdjacentVADs()
|
||||||
&Size,
|
&Size,
|
||||||
MEM_RESERVE,
|
MEM_RESERVE,
|
||||||
PAGE_NOACCESS);
|
PAGE_NOACCESS);
|
||||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -379,7 +398,7 @@ CheckAdjacentVADs()
|
||||||
BaseAddress = UlongToPtr(0x50000000);
|
BaseAddress = UlongToPtr(0x50000000);
|
||||||
Size = 0x30000;
|
Size = 0x30000;
|
||||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
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 */
|
/* Reserve the part in the middle */
|
||||||
BaseAddress = UlongToPtr(0x50010000);
|
BaseAddress = UlongToPtr(0x50010000);
|
||||||
|
@ -390,7 +409,7 @@ CheckAdjacentVADs()
|
||||||
&Size,
|
&Size,
|
||||||
MEM_RESERVE,
|
MEM_RESERVE,
|
||||||
PAGE_NOACCESS);
|
PAGE_NOACCESS);
|
||||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||||
|
|
||||||
/* Try to commit memory covering 2 allocations */
|
/* Try to commit memory covering 2 allocations */
|
||||||
BaseAddress = UlongToPtr(0x50004000);
|
BaseAddress = UlongToPtr(0x50004000);
|
||||||
|
@ -401,7 +420,7 @@ CheckAdjacentVADs()
|
||||||
&Size,
|
&Size,
|
||||||
MEM_COMMIT,
|
MEM_COMMIT,
|
||||||
PAGE_NOACCESS);
|
PAGE_NOACCESS);
|
||||||
ok(!NT_SUCCESS(Status), "NtAllocateVirtualMemory should fail!\n");
|
ok_ntstatus(Status, STATUS_CONFLICTING_ADDRESSES);
|
||||||
|
|
||||||
/* Commit a page */
|
/* Commit a page */
|
||||||
BaseAddress = UlongToPtr(0x50000000);
|
BaseAddress = UlongToPtr(0x50000000);
|
||||||
|
@ -412,7 +431,7 @@ CheckAdjacentVADs()
|
||||||
&Size,
|
&Size,
|
||||||
MEM_COMMIT,
|
MEM_COMMIT,
|
||||||
PAGE_READWRITE);
|
PAGE_READWRITE);
|
||||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||||
|
|
||||||
/* Commit another page */
|
/* Commit another page */
|
||||||
BaseAddress = UlongToPtr(0x50002000);
|
BaseAddress = UlongToPtr(0x50002000);
|
||||||
|
@ -423,7 +442,7 @@ CheckAdjacentVADs()
|
||||||
&Size,
|
&Size,
|
||||||
MEM_COMMIT,
|
MEM_COMMIT,
|
||||||
PAGE_NOACCESS);
|
PAGE_NOACCESS);
|
||||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||||
|
|
||||||
_SEH2_TRY
|
_SEH2_TRY
|
||||||
{
|
{
|
||||||
|
@ -444,7 +463,7 @@ CheckAdjacentVADs()
|
||||||
Status = _SEH2_GetExceptionCode();
|
Status = _SEH2_GetExceptionCode();
|
||||||
}
|
}
|
||||||
_SEH2_END;
|
_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 */
|
/* Allocate 3 pages, on top of the previous 2 */
|
||||||
BaseAddress = UlongToPtr(0x50000000);
|
BaseAddress = UlongToPtr(0x50000000);
|
||||||
|
@ -455,7 +474,7 @@ CheckAdjacentVADs()
|
||||||
&Size,
|
&Size,
|
||||||
MEM_COMMIT,
|
MEM_COMMIT,
|
||||||
PAGE_READONLY);
|
PAGE_READONLY);
|
||||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||||
|
|
||||||
_SEH2_TRY
|
_SEH2_TRY
|
||||||
{
|
{
|
||||||
|
@ -466,28 +485,28 @@ CheckAdjacentVADs()
|
||||||
Status = _SEH2_GetExceptionCode();
|
Status = _SEH2_GetExceptionCode();
|
||||||
}
|
}
|
||||||
_SEH2_END;
|
_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 */
|
/* Try to free the whole region at once */
|
||||||
BaseAddress = UlongToPtr(0x50000000);
|
BaseAddress = UlongToPtr(0x50000000);
|
||||||
Size = 0x30000;
|
Size = 0x30000;
|
||||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
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);
|
BaseAddress = UlongToPtr(0x50000000);
|
||||||
Size = 0x10000;
|
Size = 0x10000;
|
||||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
||||||
ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n");
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||||
|
|
||||||
BaseAddress = UlongToPtr(0x50010000);
|
BaseAddress = UlongToPtr(0x50010000);
|
||||||
Size = 0x10000;
|
Size = 0x10000;
|
||||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
||||||
ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n");
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||||
|
|
||||||
BaseAddress = UlongToPtr(0x50020000);
|
BaseAddress = UlongToPtr(0x50020000);
|
||||||
Size = 0x10000;
|
Size = 0x10000;
|
||||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
||||||
ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n");
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||||
|
|
||||||
/* Reserve 3 full 64k region */
|
/* Reserve 3 full 64k region */
|
||||||
BaseAddress = UlongToPtr(0x50000000);
|
BaseAddress = UlongToPtr(0x50000000);
|
||||||
|
@ -498,7 +517,7 @@ CheckAdjacentVADs()
|
||||||
&Size,
|
&Size,
|
||||||
MEM_RESERVE,
|
MEM_RESERVE,
|
||||||
PAGE_NOACCESS);
|
PAGE_NOACCESS);
|
||||||
ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -506,7 +525,7 @@ CheckAdjacentVADs()
|
||||||
BaseAddress = UlongToPtr(0x50010000);
|
BaseAddress = UlongToPtr(0x50010000);
|
||||||
Size = 0x10000;
|
Size = 0x10000;
|
||||||
Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
|
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;
|
PVOID Mem1, Mem2;
|
||||||
SIZE_T Size1, Size2;
|
SIZE_T Size1, Size2;
|
||||||
ULONG i;
|
ULONG i;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
CheckAlignment();
|
CheckAlignment();
|
||||||
CheckAdjacentVADs();
|
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;
|
Size1 = 32;
|
||||||
Mem1 = Allocate(Size1);
|
Mem1 = Allocate(Size1);
|
||||||
AccessMemory1(Mem1, Size1);
|
AccessMemory1(Mem1, Size1);
|
||||||
|
|
Loading…
Reference in a new issue