[PATCH v8 1/4] ntdll/tests: Move NtAllocateVirtualMemory tests that were in kernel32
Rémi Bernon
rbernon at codeweavers.com
Thu Jun 6 10:17:43 CDT 2019
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
dlls/kernel32/tests/virtual.c | 49 ---------------
dlls/ntdll/tests/Makefile.in | 3 +-
dlls/ntdll/tests/virtual.c | 113 ++++++++++++++++++++++++++++++++++
3 files changed, 115 insertions(+), 50 deletions(-)
create mode 100644 dlls/ntdll/tests/virtual.c
diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
index d797df26f6c..0b718606d0e 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -52,8 +52,6 @@ static ULONG (WINAPI *pRtlRemoveVectoredExceptionHandler)(PVOID);
static BOOL (WINAPI *pGetProcessDEPPolicy)(HANDLE, LPDWORD, PBOOL);
static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
static NTSTATUS (WINAPI *pNtProtectVirtualMemory)(HANDLE, PVOID *, SIZE_T *, ULONG, ULONG *);
-static NTSTATUS (WINAPI *pNtAllocateVirtualMemory)(HANDLE, PVOID *, ULONG, SIZE_T *, ULONG, ULONG);
-static NTSTATUS (WINAPI *pNtFreeVirtualMemory)(HANDLE, PVOID *, SIZE_T *, ULONG);
/* ############################### */
@@ -230,8 +228,6 @@ static void test_VirtualAlloc(void)
void *addr1, *addr2;
DWORD old_prot;
MEMORY_BASIC_INFORMATION info;
- NTSTATUS status;
- SIZE_T size;
SetLastError(0xdeadbeef);
addr1 = VirtualAlloc(0, 0, MEM_RESERVE, PAGE_NOACCESS);
@@ -440,55 +436,12 @@ static void test_VirtualAlloc(void)
addr2 = VirtualAlloc(addr1, 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
ok(addr2 == addr1, "VirtualAlloc returned %p, expected %p\n", addr2, addr1);
- /* allocation conflicts because of 64k align */
- size = 0x1000;
- addr2 = (char *)addr1 + 0x1000;
- status = pNtAllocateVirtualMemory(GetCurrentProcess(), &addr2, 0, &size,
- MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
- ok(status == STATUS_CONFLICTING_ADDRESSES, "NtAllocateVirtualMemory returned %08x\n", status);
-
- /* it should conflict, even when zero_bits is explicitly set */
- size = 0x1000;
- addr2 = (char *)addr1 + 0x1000;
- status = pNtAllocateVirtualMemory(GetCurrentProcess(), &addr2, 12, &size,
- MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
- todo_wine
- ok(status == STATUS_CONFLICTING_ADDRESSES, "NtAllocateVirtualMemory returned %08x\n", status);
- if (status == STATUS_SUCCESS) ok(VirtualFree(addr2, 0, MEM_RELEASE), "VirtualFree failed\n");
-
- /* 21 zero bits never succeeds */
- size = 0x1000;
- addr2 = NULL;
- status = pNtAllocateVirtualMemory(GetCurrentProcess(), &addr2, 21, &size,
- MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
- todo_wine
- ok(status == STATUS_NO_MEMORY || status == STATUS_INVALID_PARAMETER,
- "NtAllocateVirtualMemory returned %08x\n", status);
- if (status == STATUS_SUCCESS) ok(VirtualFree(addr2, 0, MEM_RELEASE), "VirtualFree failed\n");
-
- /* 22 zero bits is invalid */
- size = 0x1000;
- addr2 = NULL;
- status = pNtAllocateVirtualMemory(GetCurrentProcess(), &addr2, 22, &size,
- MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
- ok(status == STATUS_INVALID_PARAMETER_3 || status == STATUS_INVALID_PARAMETER,
- "NtAllocateVirtualMemory returned %08x\n", status);
- if (status == STATUS_SUCCESS) ok(VirtualFree(addr2, 0, MEM_RELEASE), "VirtualFree failed\n");
-
/* AT_ROUND_TO_PAGE flag is not supported for VirtualAlloc */
SetLastError(0xdeadbeef);
addr2 = VirtualAlloc(addr1, 0x1000, MEM_RESERVE | MEM_COMMIT | AT_ROUND_TO_PAGE, PAGE_EXECUTE_READWRITE);
ok(!addr2, "VirtualAlloc unexpectedly succeeded\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got %d, expected ERROR_INVALID_PARAMETER\n", GetLastError());
- /* AT_ROUND_TO_PAGE flag is not supported for NtAllocateVirtualMemory */
- size = 0x1000;
- addr2 = (char *)addr1 + 0x1000;
- status = pNtAllocateVirtualMemory(GetCurrentProcess(), &addr2, 0, &size, MEM_RESERVE |
- MEM_COMMIT | AT_ROUND_TO_PAGE, PAGE_EXECUTE_READWRITE);
- ok(status == STATUS_INVALID_PARAMETER_5 || status == STATUS_INVALID_PARAMETER,
- "NtAllocateVirtualMemory returned %08x\n", status);
-
ok(VirtualFree(addr1, 0, MEM_RELEASE), "VirtualFree failed\n");
}
@@ -4438,8 +4391,6 @@ START_TEST(virtual)
pRtlAddVectoredExceptionHandler = (void *)GetProcAddress( hntdll, "RtlAddVectoredExceptionHandler" );
pRtlRemoveVectoredExceptionHandler = (void *)GetProcAddress( hntdll, "RtlRemoveVectoredExceptionHandler" );
pNtProtectVirtualMemory = (void *)GetProcAddress( hntdll, "NtProtectVirtualMemory" );
- pNtAllocateVirtualMemory = (void *)GetProcAddress( hntdll, "NtAllocateVirtualMemory" );
- pNtFreeVirtualMemory = (void *)GetProcAddress( hntdll, "NtFreeVirtualMemory" );
GetSystemInfo(&si);
trace("system page size %#x\n", si.dwPageSize);
diff --git a/dlls/ntdll/tests/Makefile.in b/dlls/ntdll/tests/Makefile.in
index 5c70f3f01a0..ed15c51339f 100644
--- a/dlls/ntdll/tests/Makefile.in
+++ b/dlls/ntdll/tests/Makefile.in
@@ -22,4 +22,5 @@ C_SRCS = \
rtlstr.c \
string.c \
threadpool.c \
- time.c
+ time.c \
+ virtual.c
diff --git a/dlls/ntdll/tests/virtual.c b/dlls/ntdll/tests/virtual.c
new file mode 100644
index 00000000000..21dd57e8de5
--- /dev/null
+++ b/dlls/ntdll/tests/virtual.c
@@ -0,0 +1,113 @@
+/*
+ * Unit test suite for Virtual* family of APIs.
+ *
+ * Copyright 2019 Remi Bernon for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdio.h>
+
+#include "ntstatus.h"
+#define WIN32_NO_STATUS
+#include "windef.h"
+#include "winternl.h"
+#include "wine/test.h"
+
+static void test_AllocateVirtualMemory(void)
+{
+ void *addr1, *addr2;
+ NTSTATUS status;
+ SIZE_T size;
+
+ /* simple allocation should success */
+ size = 0x1000;
+ addr1 = NULL;
+ status = NtAllocateVirtualMemory(NtCurrentProcess(), &addr1, 0, &size,
+ MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+ ok(status == STATUS_SUCCESS, "NtAllocateVirtualMemory returned %08x\n", status);
+
+ /* allocation conflicts because of 64k align */
+ size = 0x1000;
+ addr2 = (char *)addr1 + 0x1000;
+ status = NtAllocateVirtualMemory(NtCurrentProcess(), &addr2, 0, &size,
+ MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+ ok(status == STATUS_CONFLICTING_ADDRESSES, "NtAllocateVirtualMemory returned %08x\n", status);
+
+ /* it should conflict, even when zero_bits is explicitly set */
+ size = 0x1000;
+ addr2 = (char *)addr1 + 0x1000;
+ status = NtAllocateVirtualMemory(NtCurrentProcess(), &addr2, 12, &size,
+ MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+ todo_wine
+ ok(status == STATUS_CONFLICTING_ADDRESSES, "NtAllocateVirtualMemory returned %08x\n", status);
+ if (status == STATUS_SUCCESS)
+ {
+ size = 0;
+ status = NtFreeVirtualMemory(NtCurrentProcess(), &addr2, &size, MEM_RELEASE);
+ ok(status == STATUS_SUCCESS, "NtFreeVirtualMemory return %08x, addr2: %p\n", status, addr2);
+ }
+
+ /* 21 zero bits never succeeds */
+ size = 0x1000;
+ addr2 = NULL;
+ status = NtAllocateVirtualMemory(NtCurrentProcess(), &addr2, 21, &size,
+ MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+ todo_wine
+ ok(status == STATUS_NO_MEMORY || status == STATUS_INVALID_PARAMETER,
+ "NtAllocateVirtualMemory returned %08x\n", status);
+ if (status == STATUS_SUCCESS)
+ {
+ size = 0;
+ status = NtFreeVirtualMemory(NtCurrentProcess(), &addr2, &size, MEM_RELEASE);
+ ok(status == STATUS_SUCCESS, "NtFreeVirtualMemory return %08x, addr2: %p\n", status, addr2);
+ }
+
+ /* 22 zero bits is invalid */
+ size = 0x1000;
+ addr2 = NULL;
+ status = NtAllocateVirtualMemory(NtCurrentProcess(), &addr2, 22, &size,
+ MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+ ok(status == STATUS_INVALID_PARAMETER_3 || status == STATUS_INVALID_PARAMETER,
+ "NtAllocateVirtualMemory returned %08x\n", status);
+ if (status == STATUS_SUCCESS)
+ {
+ size = 0;
+ status = NtFreeVirtualMemory(NtCurrentProcess(), &addr2, &size, MEM_RELEASE);
+ ok(status == STATUS_SUCCESS, "NtFreeVirtualMemory return %08x, addr2: %p\n", status, addr2);
+ }
+
+ /* AT_ROUND_TO_PAGE flag is not supported for NtAllocateVirtualMemory */
+ size = 0x1000;
+ addr2 = (char *)addr1 + 0x1000;
+ status = NtAllocateVirtualMemory(NtCurrentProcess(), &addr2, 0, &size, MEM_RESERVE |
+ MEM_COMMIT | AT_ROUND_TO_PAGE, PAGE_EXECUTE_READWRITE);
+ ok(status == STATUS_INVALID_PARAMETER_5 || status == STATUS_INVALID_PARAMETER,
+ "NtAllocateVirtualMemory returned %08x\n", status);
+
+ size = 0;
+ status = NtFreeVirtualMemory(NtCurrentProcess(), &addr1, &size, MEM_RELEASE);
+ ok(status == STATUS_SUCCESS, "NtFreeVirtualMemory failed\n");
+}
+
+START_TEST(virtual)
+{
+ SYSTEM_BASIC_INFORMATION sbi;
+
+ NtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), NULL);
+ trace("system page size %#x\n", sbi.PageSize);
+
+ test_AllocateVirtualMemory();
+}
--
2.20.1
More information about the wine-devel
mailing list