Author: tkreuzer
Date: Thu Feb 20 21:19:16 2014
New Revision: 62270
URL:
http://svn.reactos.org/svn/reactos?rev=62270&view=rev
Log:
[NTDLL_APITEST]
Add a few more tests for NtAllocateVirtualMemory
Modified:
trunk/rostests/apitests/ntdll/NtAllocateVirtualMemory.c
Modified: trunk/rostests/apitests/ntdll/NtAllocateVirtualMemory.c
URL:
http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/NtAllocate…
==============================================================================
--- trunk/rostests/apitests/ntdll/NtAllocateVirtualMemory.c [iso-8859-1] (original)
+++ trunk/rostests/apitests/ntdll/NtAllocateVirtualMemory.c [iso-8859-1] Thu Feb 20
21:19:16 2014
@@ -248,7 +248,7 @@
&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 @@
&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 @@
&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 @@
&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 @@
&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 @@
/* 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 @@
&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 @@
&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 @@
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 @@
&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 @@
&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 @@
&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 @@
&Size,
MEM_COMMIT,
PAGE_NOACCESS);
- ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
+ ok_ntstatus(Status, STATUS_SUCCESS);
_SEH2_TRY
{
@@ -444,7 +463,7 @@
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 @@
&Size,
MEM_COMMIT,
PAGE_READONLY);
- ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
+ ok_ntstatus(Status, STATUS_SUCCESS);
_SEH2_TRY
{
@@ -466,28 +485,28 @@
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");
-
- BaseAddress = UlongToPtr(0x50000000);
- Size = 0x10000;
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size,
MEM_RELEASE);
- ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n");
+ ok_ntstatus(Status, STATUS_UNABLE_TO_FREE_VM);
+
+ BaseAddress = UlongToPtr(0x50000000);
+ Size = 0x10000;
+ Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size,
MEM_RELEASE);
+ 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 @@
&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 @@
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,9 +536,32 @@
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);