Commit 3dcb85f5 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

kernelbase/tests: Move VirtualAllocFromApp() tests.

parent e44a9d2c
......@@ -50,7 +50,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 PVOID (WINAPI *pVirtualAllocFromApp)(PVOID, SIZE_T, DWORD, DWORD);
/* ############################### */
......@@ -454,39 +453,6 @@ static void test_VirtualAlloc(void)
ok(VirtualFree(addr1, 0, MEM_RELEASE), "VirtualFree failed\n");
}
static void test_VirtualAllocFromApp(void)
{
void *p;
BOOL ret;
if (!pVirtualAllocFromApp)
{
win_skip("VirtualAllocFromApp is not available.\n");
return;
}
p = GetProcAddress(hkernel32, "VirtualAllocFromApp");
ok(!p, "Found VirtualAllocFromApp in kernel32.dll.\n");
SetLastError(0xdeadbeef);
p = pVirtualAllocFromApp(NULL, 0x1000, MEM_RESERVE, PAGE_READWRITE);
ok(p && GetLastError() == 0xdeadbeef, "Got unexpected mem %p, GetLastError() %lu.\n", p, GetLastError());
ret = VirtualFree(p, 0, MEM_RELEASE);
ok(ret, "Got unexpected ret %#x, GetLastError() %lu.\n", ret, GetLastError());
SetLastError(0xdeadbeef);
p = pVirtualAllocFromApp(NULL, 0x1000, MEM_RESERVE, PAGE_EXECUTE);
ok(!p && GetLastError() == ERROR_INVALID_PARAMETER, "Got unexpected mem %p, GetLastError() %lu.\n",
p, GetLastError());
SetLastError(0xdeadbeef);
p = pVirtualAllocFromApp(NULL, 0x1000, MEM_RESERVE, PAGE_EXECUTE_READ);
ok(!p && GetLastError() == ERROR_INVALID_PARAMETER, "Got unexpected mem %p, GetLastError() %lu.\n",
p, GetLastError());
SetLastError(0xdeadbeef);
p = pVirtualAllocFromApp(NULL, 0x1000, MEM_RESERVE, PAGE_EXECUTE_READWRITE);
ok(!p && GetLastError() == ERROR_INVALID_PARAMETER, "Got unexpected mem %p, GetLastError() %lu.\n",
p, GetLastError());
}
static void test_MapViewOfFile(void)
{
static const char testfile[] = "testfile.xxx";
......@@ -4304,7 +4270,6 @@ START_TEST(virtual)
pRtlAddVectoredExceptionHandler = (void *)GetProcAddress( hntdll, "RtlAddVectoredExceptionHandler" );
pRtlRemoveVectoredExceptionHandler = (void *)GetProcAddress( hntdll, "RtlRemoveVectoredExceptionHandler" );
pNtProtectVirtualMemory = (void *)GetProcAddress( hntdll, "NtProtectVirtualMemory" );
pVirtualAllocFromApp = (void *)GetProcAddress( hkernelbase, "VirtualAllocFromApp" );
GetSystemInfo(&si);
trace("system page size %#lx\n", si.dwPageSize);
......@@ -4319,7 +4284,6 @@ START_TEST(virtual)
test_VirtualProtect();
test_VirtualAllocEx();
test_VirtualAlloc();
test_VirtualAllocFromApp();
test_MapViewOfFile();
test_NtAreMappedFilesTheSame();
test_CreateFileMapping();
......
......@@ -34,6 +34,7 @@ static BOOL (WINAPI *pCompareObjectHandles)(HANDLE, HANDLE);
static LPVOID (WINAPI *pMapViewOfFile3)(HANDLE, HANDLE, PVOID, ULONG64 offset, SIZE_T size,
ULONG, ULONG, MEM_EXTENDED_PARAMETER *, ULONG);
static LPVOID (WINAPI *pVirtualAlloc2)(HANDLE, void *, SIZE_T, DWORD, DWORD, MEM_EXTENDED_PARAMETER *, ULONG);
static PVOID (WINAPI *pVirtualAllocFromApp)(PVOID, SIZE_T, DWORD, DWORD);
static void test_CompareObjectHandles(void)
{
......@@ -194,20 +195,55 @@ static void test_VirtualAlloc2(void)
VirtualFree(placeholder2, 0, MEM_RELEASE);
}
START_TEST(process)
static void test_VirtualAllocFromApp(void)
{
HMODULE hmod;
BOOL ret;
void *p;
hmod = GetModuleHandleA("kernel32.dll");
pCompareObjectHandles = (void *)GetProcAddress(hmod, "CompareObjectHandles");
ok(!pCompareObjectHandles, "expected CompareObjectHandles only in kernelbase.dll\n");
if (!pVirtualAllocFromApp)
{
win_skip("VirtualAllocFromApp is not available.\n");
return;
}
hmod = GetModuleHandleA("kernelbase.dll");
pCompareObjectHandles = (void *)GetProcAddress(hmod, "CompareObjectHandles");
pMapViewOfFile3 = (void *)GetProcAddress(hmod, "MapViewOfFile3");
pVirtualAlloc2 = (void *)GetProcAddress(hmod, "VirtualAlloc2");
SetLastError(0xdeadbeef);
p = pVirtualAllocFromApp(NULL, 0x1000, MEM_RESERVE, PAGE_READWRITE);
ok(p && GetLastError() == 0xdeadbeef, "Got unexpected mem %p, GetLastError() %lu.\n", p, GetLastError());
ret = VirtualFree(p, 0, MEM_RELEASE);
ok(ret, "Got unexpected ret %#x, GetLastError() %lu.\n", ret, GetLastError());
SetLastError(0xdeadbeef);
p = pVirtualAllocFromApp(NULL, 0x1000, MEM_RESERVE, PAGE_EXECUTE);
ok(!p && GetLastError() == ERROR_INVALID_PARAMETER, "Got unexpected mem %p, GetLastError() %lu.\n",
p, GetLastError());
SetLastError(0xdeadbeef);
p = pVirtualAllocFromApp(NULL, 0x1000, MEM_RESERVE, PAGE_EXECUTE_READ);
ok(!p && GetLastError() == ERROR_INVALID_PARAMETER, "Got unexpected mem %p, GetLastError() %lu.\n",
p, GetLastError());
SetLastError(0xdeadbeef);
p = pVirtualAllocFromApp(NULL, 0x1000, MEM_RESERVE, PAGE_EXECUTE_READWRITE);
ok(!p && GetLastError() == ERROR_INVALID_PARAMETER, "Got unexpected mem %p, GetLastError() %lu.\n",
p, GetLastError());
}
static void init_funcs(void)
{
HMODULE hmod = GetModuleHandleA("kernelbase.dll");
#define X(f) { p##f = (void*)GetProcAddress(hmod, #f); }
X(CompareObjectHandles);
X(MapViewOfFile3);
X(VirtualAlloc2);
X(VirtualAllocFromApp);
#undef X
}
START_TEST(process)
{
init_funcs();
test_CompareObjectHandles();
test_MapViewOfFile3();
test_VirtualAlloc2();
test_VirtualAllocFromApp();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment