Commit c69cc550 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

kernel32/tests: Add more VirtualAlloc and VirtualProtect tests.

parent a58e9f03
......@@ -1581,7 +1581,7 @@ static void test_VirtualProtect(void)
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ, 0 }, /* 0xe0 */
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ | PAGE_EXECUTE, 0 } /* 0xf0 */
};
char *base;
char *base, *ptr;
DWORD ret, old_prot, rw_prot, exec_prot, i, j;
MEMORY_BASIC_INFORMATION info;
SYSTEM_INFO si;
......@@ -1652,6 +1652,27 @@ static void test_VirtualProtect(void)
DWORD prot = exec_prot | rw_prot;
SetLastError(0xdeadbeef);
ptr = VirtualAlloc(base, si.dwPageSize, MEM_COMMIT, prot);
if ((rw_prot && exec_prot) || (!rw_prot && !exec_prot))
{
ok(!ptr, "VirtualAlloc(%02x) should fail\n", prot);
ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
}
else
{
if (prot & (PAGE_WRITECOPY | PAGE_EXECUTE_WRITECOPY))
{
ok(!ptr, "VirtualAlloc(%02x) should fail\n", prot);
ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
}
else
{
ok(ptr != NULL, "VirtualAlloc(%02x) error %d\n", prot, GetLastError());
ok(ptr == base, "expected %p, got %p\n", base, ptr);
}
}
SetLastError(0xdeadbeef);
ret = VirtualProtect(base, si.dwPageSize, prot, &old_prot);
if ((rw_prot && exec_prot) || (!rw_prot && !exec_prot))
{
......@@ -1734,7 +1755,7 @@ static void test_VirtualAlloc_protection(void)
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ, FALSE }, /* 0xe0 */
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ | PAGE_EXECUTE, FALSE } /* 0xf0 */
};
char *base;
char *base, *ptr;
DWORD ret, i;
MEMORY_BASIC_INFORMATION info;
SYSTEM_INFO si;
......@@ -1772,6 +1793,10 @@ static void test_VirtualAlloc_protection(void)
ok(info.Protect == td[i].prot, "%d: got %#x != expected %#x\n", i, info.Protect, td[i].prot);
}
SetLastError(0xdeadbeef);
ptr = VirtualAlloc(base, si.dwPageSize, MEM_COMMIT, td[i].prot);
ok(ptr == base, "%d: VirtualAlloc failed %d\n", i, GetLastError());
VirtualFree(base, 0, MEM_FREE);
}
else
......@@ -1824,7 +1849,7 @@ static void test_CreateFileMapping_protection(void)
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ, FALSE, PAGE_NOACCESS }, /* 0xe0 */
{ PAGE_EXECUTE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_READ | PAGE_EXECUTE, FALSE, PAGE_NOACCESS } /* 0xf0 */
};
char *base;
char *base, *ptr;
DWORD ret, i, alloc_prot, prot, old_prot;
MEMORY_BASIC_INFORMATION info;
SYSTEM_INFO si;
......@@ -1896,6 +1921,27 @@ static void test_CreateFileMapping_protection(void)
ok(info.Protect == td[i].prot, "%d: got %#x != expected %#x\n", i, info.Protect, td[i].prot);
}
SetLastError(0xdeadbeef);
ptr = VirtualAlloc(base, si.dwPageSize, MEM_COMMIT, td[i].prot);
/* FIXME: remove once Wine is fixed */
if (td[i].prot == PAGE_WRITECOPY || td[i].prot == PAGE_EXECUTE_WRITECOPY)
ok(!ptr, "%d: VirtualAlloc(%02x) should fail\n", i, td[i].prot);
else
todo_wine
ok(!ptr, "%d: VirtualAlloc(%02x) should fail\n", i, td[i].prot);
todo_wine
ok(GetLastError() == ERROR_ACCESS_DENIED, "%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
SetLastError(0xdeadbeef);
ret = VirtualProtect(base, si.dwPageSize, td[i].prot, &old_prot);
if (td[i].prot == PAGE_READONLY || td[i].prot == PAGE_WRITECOPY)
ok(ret, "%d: VirtualProtect(%02x) error %d\n", i, td[i].prot, GetLastError());
else
{
ok(!ret, "%d: VirtualProtect(%02x) should fail\n", i, td[i].prot);
ok(GetLastError() == ERROR_INVALID_PARAMETER, "%d: expected ERROR_INVALID_PARAMETER, got %d\n", i, GetLastError());
}
UnmapViewOfFile(base);
CloseHandle(hmap);
}
......@@ -2196,7 +2242,7 @@ static void test_mapping(void)
{ FILE_MAP_EXECUTE | SECTION_MAP_EXECUTE | FILE_MAP_READ | FILE_MAP_WRITE, PAGE_EXECUTE_READWRITE }, /* 0x2e */
{ FILE_MAP_EXECUTE | SECTION_MAP_EXECUTE | FILE_MAP_READ | FILE_MAP_WRITE | FILE_MAP_COPY, PAGE_EXECUTE_READWRITE } /* 0x2f */
};
void *base, *nt_base;
void *base, *nt_base, *ptr;
DWORD i, j, k, ret, old_prot, prev_prot;
SYSTEM_INFO si;
char temp_path[MAX_PATH];
......@@ -2376,6 +2422,21 @@ static void test_mapping(void)
}
}
for (k = 0; k < sizeof(page_prot)/sizeof(page_prot[0]); k++)
{
/*trace("map %#x, view %#x, requested prot %#x\n", page_prot[i], view[j].prot, page_prot[k]);*/
SetLastError(0xdeadbeef);
ptr = VirtualAlloc(base, si.dwPageSize, MEM_COMMIT, page_prot[k]);
/* FIXME: remove once Wine is fixed */
if (page_prot[k] == PAGE_WRITECOPY || page_prot[k] == PAGE_EXECUTE_WRITECOPY)
ok(!ptr, "VirtualAlloc(%02x) should fail\n", page_prot[k]);
else
todo_wine
ok(!ptr, "VirtualAlloc(%02x) should fail\n", page_prot[k]);
todo_wine
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
}
UnmapViewOfFile(base);
}
......
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