26#define MAPPING_SIZE 0x100000
50#define ROUND_SIZE(addr,size) \
51 (((SIZE_T)(size) + ((UINT_PTR)(addr) & page_mask) + page_mask) & ~page_mask)
86 const unsigned int alloc_size = 1<<15;
88 SIZE_T bytes_written = 0, bytes_read = 0,
i;
96 if ((!pVirtualAllocEx) || (!pVirtualFreeEx)) {
97 win_skip(
"Virtual{Alloc,Free}Ex not available\n");
111 for (
i = 0;
i < alloc_size;
i++)
115 ok(
b && (bytes_written == alloc_size),
"%lu bytes written\n",
118 ok(
b && (bytes_read == alloc_size),
"%lu bytes read\n", bytes_read);
119 ok(!
memcmp(
src,
dst, alloc_size),
"Data from remote process differs\n");
126 ok( !
b,
"WriteProcessMemory succeeded\n" );
130 ok( bytes_written == 0,
"%lu bytes written\n", bytes_written );
132 ok( !
b,
"ReadProcessMemory succeeded\n" );
134 ok( bytes_read == 0,
"%lu bytes written\n", bytes_read );
139 ok( !
b,
"WriteProcessMemory succeeded\n" );
143 ok( bytes_written == 0,
"%lu bytes written\n", bytes_written );
145 ok( !
b,
"ReadProcessMemory succeeded\n" );
147 ok( bytes_read == 0,
"%lu bytes written\n", bytes_read );
161 ok(addr1 ==
NULL,
"VirtualAllocEx should fail on zero-sized allocation\n");
163 "got %u, expected ERROR_INVALID_PARAMETER\n",
GetLastError());
166 ok(addr1 !=
NULL,
"VirtualAllocEx failed\n");
171 ok(
info.BaseAddress == addr1,
"%p != %p\n",
info.BaseAddress, addr1);
172 ok(
info.AllocationBase == addr1,
"%p != %p\n",
info.AllocationBase, addr1);
174 ok(
info.RegionSize == 0x10000,
"%lx != 0x10000\n",
info.RegionSize);
176 ok(
info.Protect == 0,
"%x != PAGE_NOACCESS\n",
info.Protect);
181 "VirtualProtectEx should fail on a not committed memory\n");
183 "got %u, expected ERROR_INVALID_ADDRESS\n",
GetLastError());
186 ok(addr1 == addr2,
"VirtualAllocEx failed\n");
190 "VirtualQueryEx failed\n");
191 ok(
info.BaseAddress == addr1,
"%p != %p\n",
info.BaseAddress, addr1);
192 ok(
info.AllocationBase == addr1,
"%p != %p\n",
info.AllocationBase, addr1);
194 ok(
info.RegionSize == 0x1000,
"%lx != 0x1000\n",
info.RegionSize);
203 "VirtualProtectEx should fail on a not committed memory\n");
205 "got %u, expected ERROR_INVALID_ADDRESS\n",
GetLastError());
209 ok(old_prot ==
PAGE_NOACCESS,
"wrong old protection: got %04x instead of PAGE_NOACCESS\n", old_prot);
213 ok(old_prot ==
PAGE_READONLY,
"wrong old protection: got %04x instead of PAGE_READONLY\n", old_prot);
215 ok(!pVirtualFreeEx(
hProcess, addr1, 0x10000, 0),
216 "VirtualFreeEx should fail with type 0\n");
218 "got %u, expected ERROR_INVALID_PARAMETER\n",
GetLastError());
224 "VirtualFreeEx should fail\n");
226 "got %u, expected ERROR_INVALID_PARAMETER\n",
GetLastError());
244 ok(addr1 ==
NULL,
"VirtualAlloc should fail on zero-sized allocation\n");
246 "got %d, expected ERROR_INVALID_PARAMETER\n",
GetLastError());
249 ok(addr1 !=
NULL,
"VirtualAlloc failed\n");
253 "VirtualQuery failed\n");
254 ok(
info.BaseAddress == addr1,
"%p != %p\n",
info.BaseAddress, addr1);
255 ok(
info.AllocationBase == addr1,
"%p != %p\n",
info.AllocationBase, addr1);
257 ok(
info.RegionSize == 0x10000,
"%lx != 0x10000\n",
info.RegionSize);
259 ok(
info.Protect == 0,
"%x != PAGE_NOACCESS\n",
info.Protect);
264 "VirtualProtect should fail on a not committed memory\n");
266 "got %d, expected ERROR_INVALID_ADDRESS\n",
GetLastError());
269 ok(addr1 == addr2,
"VirtualAlloc failed\n");
273 "VirtualQuery failed\n");
274 ok(
info.BaseAddress == addr1,
"%p != %p\n",
info.BaseAddress, addr1);
275 ok(
info.AllocationBase == addr1,
"%p != %p\n",
info.AllocationBase, addr1);
277 ok(
info.RegionSize == 0x1000,
"%lx != 0x1000\n",
info.RegionSize);
286 "VirtualProtect should fail on a not committed memory\n");
288 "got %d, expected ERROR_INVALID_ADDRESS\n",
GetLastError());
292 "wrong old protection: got %04x instead of PAGE_NOACCESS\n", old_prot);
296 "wrong old protection: got %04x instead of PAGE_READONLY\n", old_prot);
299 "VirtualQuery failed\n");
300 ok(
info.RegionSize == 0x1000,
"%lx != 0x1000\n",
info.RegionSize);
303 memset( addr1, 0x55, 20 );
304 ok( *(
DWORD *)addr1 == 0x55555555,
"wrong data %x\n", *(
DWORD *)addr1 );
307 ok( addr2 == addr1,
"VirtualAlloc failed err %u\n",
GetLastError() );
308 ok( *(
DWORD *)addr1 == 0x55555555 || *(
DWORD *)addr1 == 0,
"wrong data %x\n", *(
DWORD *)addr1 );
310 "VirtualQuery failed\n");
311 ok(
info.RegionSize == 0x1000,
"%lx != 0x1000\n",
info.RegionSize);
316 ok( (
char *)addr2 == (
char *)addr1 + 0x1000,
"VirtualAlloc failed\n" );
319 "VirtualQuery failed\n");
320 ok(
info.RegionSize == 0xf000,
"%lx != 0xf000\n",
info.RegionSize);
322 ok(
info.Protect == 0,
"%x != 0\n",
info.Protect);
325 ok( !addr2,
"VirtualAlloc failed\n" );
331 ok(!addr2,
"VirtualAlloc succeeded\n");
336 ok(!addr2,
"VirtualAlloc succeeded\n");
341 ok(!addr2,
"VirtualAlloc succeeded\n");
346 "VirtualProtect succeeded\n");
350 ok(!
VirtualProtect(addr1, 0x1000, 0, &old_prot),
"VirtualProtect succeeded\n");
354 ok(!
VirtualFree(addr1, 0x10000, 0),
"VirtualFree should fail with type 0\n");
356 "got %d, expected ERROR_INVALID_PARAMETER\n",
GetLastError());
361 "got %d, expected ERROR_INVALID_PARAMETER\n",
GetLastError());
368 "got %d, expected ERROR_INVALID_PARAMETER\n",
GetLastError());
374 ok(addr1 !=
NULL,
"VirtualAlloc failed\n");
375 ok(!((
ULONG_PTR)addr1 & 0xffff),
"returned memory %p is not aligned to 64k\n", addr1);
378 ok(addr2 == addr1,
"VirtualAlloc returned %p, expected %p\n", addr2, addr1);
382 addr2 = (
char *)addr1 + 0x1000;
389 addr2 = (
char *)addr1 + 0x1000;
402 "NtAllocateVirtualMemory returned %08x\n",
status);
416 ok(!addr2,
"VirtualAlloc unexpectedly succeeded\n");
421 addr2 = (
char *)addr1 + 0x1000;
432 static const char testfile[] =
"testfile.xxx";
490 ok( !
ptr,
"MapViewOfFile succeeded\n" );
497 ok( !
ptr,
"MapViewOfFile succeeded\n" );
533 ok( !
ptr,
"MapViewOfFile FILE_MAP_WRITE succeeded\n" );
561 ok( !
ptr,
"MapViewOfFile FILE_MAP_WRITE succeeded\n" );
570 ok( !
mapping,
"CreateFileMappingA succeeded\n" );
582 ok( !
mapping,
"CreateFileMapping PAGE_READWRITE succeeded\n" );
605 ok( !
mapping,
"CreateFileMapping PAGE_READWRITE succeeded\n" );
611 ok( !
mapping,
"CreateFileMapping PAGE_WRITECOPY succeeded\n" );
617 ok( !
mapping,
"CreateFileMapping PAGE_READONLY succeeded\n" );
640 ok( !
ptr,
"MapViewOfFile FILE_MAP_WRITE succeeded\n" );
652 ok(
info.RegionSize == 4096,
"%lx != 4096\n",
info.RegionSize );
665 ok( info_size ==
sizeof(
section_info),
"NtQuerySection wrong size %u\n", info_size );
669 ok(
section_info.Size.QuadPart ==
info.RegionSize,
"NtQuerySection wrong size %x%08x / %08lx\n",
678 ok( !
ptr,
"MapViewOfFile succeeded\n" );
690 ok(
info.RegionSize == 4096,
"%lx != 4096\n",
info.RegionSize );
704 ok( info_size ==
sizeof(
section_info),
"NtQuerySection wrong size %u\n", info_size );
708 ok(
section_info.Size.QuadPart ==
info.RegionSize,
"NtQuerySection wrong size %x%08x / %08lx\n",
731 ok(
ptr != ptr2,
"MapViewOfFile returned same pointer\n" );
735 ok(
info.BaseAddress ==
ptr,
"BaseAddress should have been %p but was %p instead\n",
ptr,
info.BaseAddress);
736 ok(
info.AllocationBase ==
ptr,
"AllocationBase should have been %p but was %p instead\n",
ptr,
info.AllocationBase);
740 "AllocationProtect should have been PAGE_READWRITE but was 0x%x\n",
info.AllocationProtect);
741 ok(
info.Protect == 0,
"Protect should have been 0 instead of 0x%x\n",
info.Protect);
746 ok(
info.BaseAddress == ptr2,
747 "BaseAddress should have been %p but was %p instead\n", ptr2,
info.BaseAddress);
748 ok(
info.AllocationBase == ptr2,
749 "AllocationBase should have been %p but was %p instead\n", ptr2,
info.AllocationBase);
751 "AllocationProtect should have been PAGE_READWRITE but was 0x%x\n",
info.AllocationProtect);
753 "RegionSize should have been 0x%x but was 0x%lx\n",
MAPPING_SIZE,
info.RegionSize);
755 ok(
info.Protect == 0,
"Protect should have been 0 instead of 0x%x\n",
info.Protect);
763 ok(
info.BaseAddress ==
ptr,
"BaseAddress should have been %p but was %p instead\n",
ptr,
info.BaseAddress);
764 ok(
info.AllocationBase ==
ptr,
"AllocationBase should have been %p but was %p instead\n",
ptr,
info.AllocationBase);
765 ok(
info.RegionSize == 0x10000,
"RegionSize should have been 0x10000 but was 0x%lx\n",
info.RegionSize);
766 ok(
info.State ==
MEM_COMMIT,
"State should have been MEM_COMMIT instead of 0x%x\n",
info.State);
769 "AllocationProtect should have been PAGE_READWRITE but was 0x%x\n",
info.AllocationProtect);
777 ok(
info.BaseAddress == ptr2,
778 "BaseAddress should have been %p but was %p instead\n", ptr2,
info.BaseAddress);
779 ok(
info.AllocationBase == ptr2,
780 "AllocationBase should have been %p but was %p instead\n", ptr2,
info.AllocationBase);
782 "AllocationProtect should have been PAGE_READWRITE but was 0x%x\n",
info.AllocationProtect);
783 ok(
info.RegionSize == 0x10000,
784 "RegionSize should have been 0x10000 but was 0x%lx\n",
info.RegionSize);
786 "State should have been MEM_COMMIT instead of 0x%x\n",
info.State);
788 "Protect should have been PAGE_READWRITE instead of 0x%x\n",
info.Protect);
795 ok( !
ret,
"VirtualFree succeeded\n" );
810 "got %u, expected ERROR_INVALID_ADDRESS\n",
GetLastError());
814 "got %u, expected ERROR_INVALID_ADDRESS\n",
GetLastError());
816 ok( !
UnmapViewOfFile((
void *)0xdeadbeef),
"UnmapViewOfFile should fail on VirtualAlloc mem\n" );
818 "got %u, expected ERROR_INVALID_ADDRESS\n",
GetLastError());
832 ok( map2 != 0,
"OpenFileMappingA failed with error %d\n",
GetLastError() );
841 ok( !
ret,
"memory is not accessible\n" );
845 ok(
info.BaseAddress ==
ptr,
"got %p != expected %p\n",
info.BaseAddress,
ptr);
856 ok( map2 == 0,
"OpenFileMappingA succeeded\n" );
862 ok(
mapping != 0,
"CreateFileMappingA failed\n" );
870 ok( !
ret,
"memory is not accessible\n" );
874 ok(
info.BaseAddress ==
ptr,
"got %p != expected %p\n",
info.BaseAddress,
ptr);
887 ok(
ret,
"memory is accessible\n" );
891 ok(
info.BaseAddress ==
ptr,
"got %p != expected %p\n",
info.BaseAddress,
ptr);
893 ok(
info.AllocationBase ==
NULL,
"%p != NULL\n",
info.AllocationBase);
894 ok(
info.AllocationProtect == 0,
"%#x != 0\n",
info.AllocationProtect);
912 ok( map2 != 0,
"OpenFileMappingA failed with error %d\n",
GetLastError() );
919 ok( info_size ==
sizeof(
section_info),
"NtQuerySection wrong size %u\n", info_size );
930 ok( !
ret,
"memory is not accessible\n" );
934 ok(
info.BaseAddress ==
ptr,
"got %p != expected %p\n",
info.BaseAddress,
ptr);
945 ok( map2 == 0,
"OpenFileMappingA succeeded\n" );
951 ok(
mapping != 0,
"CreateFileMappingA failed\n" );
959 ok( !
ret,
"memory is not accessible\n" );
963 ok(
info.BaseAddress ==
ptr,
"got %p != expected %p\n",
info.BaseAddress,
ptr);
976 ok(
ret,
"memory is accessible\n" );
980 ok(
info.BaseAddress ==
ptr,
"got %p != expected %p\n",
info.BaseAddress,
ptr);
982 ok(
info.AllocationBase ==
NULL,
"%p != NULL\n",
info.AllocationBase);
983 ok(
info.AllocationProtect == 0,
"%#x != 0\n",
info.AllocationProtect);
1015 ok( info_size ==
sizeof(
section_info),
"NtQuerySection wrong size %u\n", info_size );
1019 ok(
section_info.Size.QuadPart == 36,
"NtQuerySection wrong size %x%08x\n",
1030 ok( info_size ==
sizeof(
section_info),
"NtQuerySection wrong size %u\n", info_size );
1034 ok(
section_info.Size.QuadPart == 0x3456,
"NtQuerySection wrong size %x%08x\n",
1055 ok(
section_info.Size.QuadPart == 0x3452,
"NtQuerySection wrong size %x%08x\n",
1076 ok(
section_info.Size.QuadPart == 0x4000,
"NtQuerySection wrong size %x%08x\n",
1107 static const char testfile[] =
"testfile.xxx";
1108 static const char data[] =
"test data for NtMapViewOfSection";
1117 if (!pNtMapViewOfSection || !pNtUnmapViewOfSection)
1119 win_skip(
"NtMapViewOfSection not available\n" );
1132 ok(
mapping != 0,
"CreateFileMapping failed\n" );
1142 ok( !((
ULONG_PTR)
ptr & 0xffff),
"returned memory %p is not aligned to 64k\n",
ptr );
1145 ok(
ret,
"ReadProcessMemory failed\n" );
1159 ok( !
status,
"NtUnmapViewOfSection failed status %x\n",
status );
1170 ok( !
status,
"NtUnmapViewOfSection failed status %x\n",
status );
1181 ok( !
status,
"NtUnmapViewOfSection failed status %x\n",
status );
1199 ptr2 = (
char *)
ptr + 42;
1206 ptr2 = (
char *)
ptr + 0x1000;
1213 ptr2 = (
char *)
ptr + 0x1000;
1219 ptr2 = (
char *)
ptr + 0x1000;
1225 ptr2 = (
char *)
ptr + 0x1001;
1231 ptr2 = (
char *)
ptr + 0x1000;
1237 if (
sizeof(
void *) ==
sizeof(
int) && (!pIsWow64Process ||
1248 ptr2 = (
char *)
ptr + 42;
1256 ptr2 = (
char *)
ptr + 0x1000;
1262 ok( (
char *)ptr2 == (
char *)
ptr + 0x1000,
1263 "expected address %p, got %p\n", (
char *)
ptr + 0x1000, ptr2 );
1265 ok( !
status,
"NtUnmapViewOfSection failed status %x\n",
status );
1268 ptr2 = (
char *)
ptr + 0x1001;
1274 ok( (
char *)ptr2 == (
char *)
ptr + 0x1000,
1275 "expected address %p, got %p\n", (
char *)
ptr + 0x1000, ptr2 );
1277 ok( !
status,
"NtUnmapViewOfSection failed status %x\n",
status );
1279 ptr2 = (
char *)
ptr + 0x2000;
1285 ok( (
char *)ptr2 == (
char *)
ptr + 0x2000,
1286 "expected address %p, got %p\n", (
char *)
ptr + 0x2000, ptr2 );
1288 ok( !
status,
"NtUnmapViewOfSection failed status %x\n",
status );
1292 ptr2 = (
char *)
ptr + 0x1000;
1302 ok( !
status,
"NtUnmapViewOfSection failed status %x\n",
status );
1314 static const char testfile[] =
"testfile.xxx";
1320 if (!pNtAreMappedFilesTheSame)
1322 win_skip(
"NtAreMappedFilesTheSame not available\n" );
1346 status = pNtAreMappedFilesTheSame(
ptr, ptr2 );
1352 status = pNtAreMappedFilesTheSame(
ptr, ptr2 );
1361 status = pNtAreMappedFilesTheSame(
ptr, ptr2 );
1369 "NtAreMappedFilesTheSame returned %x\n",
status );
1371 status = pNtAreMappedFilesTheSame(
ptr, (
char *)
ptr + 30 );
1373 "NtAreMappedFilesTheSame returned %x\n",
status );
1378 status = pNtAreMappedFilesTheSame(
ptr, (
void *)0xdeadbeef );
1380 "NtAreMappedFilesTheSame returned %x\n",
status );
1393 status = pNtAreMappedFilesTheSame(
ptr, ptr2 );
1439 status = pNtAreMappedFilesTheSame(
ptr, ptr2 );
1460 "Wine Test Mapping");
1466 "Wine Test Mapping");
1473 "WINE TEST MAPPING");
1485 ok( !handle2,
"OpenFileMapping succeeded\n");
1494 void *
ptr = (
void *)0xdeadbeef;
1498 ok(
ret ==
FALSE,
"Expected IsBadReadPtr to return FALSE, got %d\n",
ret);
1501 ok(
ret ==
TRUE,
"Expected IsBadReadPtr to return TRUE, got %d\n",
ret);
1504 ok(
ret ==
FALSE,
"Expected IsBadReadPtr to return FALSE, got %d\n",
ret);
1507 ok(
ret ==
TRUE,
"Expected IsBadReadPtr to return TRUE, got %d\n",
ret);
1510 ok(
ret ==
FALSE,
"Expected IsBadReadPtr to return FALSE, got %d\n",
ret);
1513 ok(
ret ==
FALSE,
"Expected IsBadReadPtr to return FALSE, got %d\n",
ret);
1519 void *
ptr = (
void *)0xdeadbeef;
1523 ok(
ret ==
FALSE,
"Expected IsBadWritePtr to return FALSE, got %d\n",
ret);
1526 ok(
ret ==
TRUE,
"Expected IsBadWritePtr to return TRUE, got %d\n",
ret);
1529 ok(
ret ==
FALSE,
"Expected IsBadWritePtr to return FALSE, got %d\n",
ret);
1532 ok(
ret ==
TRUE,
"Expected IsBadWritePtr to return TRUE, got %d\n",
ret);
1535 ok(
ret ==
FALSE,
"Expected IsBadWritePtr to return FALSE, got %d\n",
ret);
1538 ok(
ret ==
FALSE,
"Expected IsBadWritePtr to return FALSE, got %d\n",
ret);
1544 void *
ptr = (
void *)0xdeadbeef;
1548 ok(
ret ==
TRUE,
"Expected IsBadCodePtr to return TRUE, got %d\n",
ret);
1551 ok(
ret ==
TRUE,
"Expected IsBadCodePtr to return TRUE, got %d\n",
ret);
1554 ok(
ret ==
FALSE,
"Expected IsBadCodePtr to return FALSE, got %d\n",
ret);
1559 static const char pipename[] =
"\\\\.\\pipe\\test_write_watch_pipe";
1560 static const char testdata[] =
"Hello World";
1563 HANDLE readpipe, writepipe;
1571 if (!pGetWriteWatch || !pResetWriteWatch)
1573 win_skip(
"GetWriteWatch not supported\n" );
1582 win_skip(
"MEM_WRITE_WATCH not supported\n" );
1588 ok(
info.BaseAddress ==
base,
"BaseAddress %p instead of %p\n",
info.BaseAddress,
base );
1590 ok(
info.RegionSize ==
size,
"wrong RegionSize 0x%lx\n",
info.RegionSize );
1598 ok(
ret == ~0
u,
"GetWriteWatch succeeded %u\n",
ret );
1607 ok(
ret == ~0
u,
"GetWriteWatch succeeded %u\n",
ret );
1619 base[pagesize + 1] = 0x44;
1638 base[2*pagesize + 3] = 0x11;
1639 base[4*pagesize + 8] = 0x11;
1654 ret = pResetWriteWatch(
base, 3*pagesize );
1663 *(
DWORD *)(
base + 2*pagesize - 2) = 0xdeadbeef;
1694 ok(
info.BaseAddress ==
base,
"BaseAddress %p instead of %p\n",
info.BaseAddress,
base );
1695 ok(
info.RegionSize == 3*pagesize,
"wrong RegionSize 0x%lx\n",
info.RegionSize );
1712 ok(
info.BaseAddress ==
base,
"BaseAddress %p instead of %p\n",
info.BaseAddress,
base );
1713 ok(
info.RegionSize ==
size,
"wrong RegionSize 0x%lx\n",
info.RegionSize );
1728 ok( !
success,
"ConnectNamedPipe unexpectedly succeeded\n" );
1745 ok( !
success,
"ReadFile unexpectedly succeeded\n" );
1756 ok( num_bytes ==
sizeof(
testdata),
"wrong number of bytes written\n" );
1761 ok( num_bytes ==
sizeof(
testdata),
"wrong number of bytes read\n" );
1782 ok(
ret == ~0
u,
"GetWriteWatch succeeded %u\n",
ret );
1787 ok(
ret == ~0
u,
"GetWriteWatch succeeded %u\n",
ret );
1793 ok(
ret == ~0
u,
"GetWriteWatch succeeded %u\n",
ret );
1799 ok(
ret == ~0
u,
"GetWriteWatch succeeded %u\n",
ret );
1805 ok(
ret == ~0
u,
"GetWriteWatch succeeded %u\n",
ret );
1811 ok(
ret == ~0
u,
"GetWriteWatch succeeded %u\n",
ret );
1817 ok(
ret == ~0
u,
"GetWriteWatch succeeded %u\n",
ret );
1823 ok(
ret == ~0
u,
"GetWriteWatch succeeded %u\n",
ret );
1829 ok(
ret == ~0
u,
"GetWriteWatch succeeded %u\n",
ret );
1833 ret = pResetWriteWatch(
base, 0 );
1834 ok(
ret == ~0
u,
"ResetWriteWatch succeeded %u\n",
ret );
1839 ok(
ret == ~0
u,
"ResetWriteWatch succeeded %u\n",
ret );
1852 ok( !
ret,
"GetWriteWatch failed %u\n",
ret );
1856 ok( !
ret,
"GetWriteWatch failed %u\n",
ret );
1860 ok( !
ret,
"GetWriteWatch failed %u\n",
ret );
1862 ret = pResetWriteWatch(
base, 0 );
1863 ok( !
ret,
"ResetWriteWatch failed %u\n",
ret );
1866 ok( !
ret,
"ResetWriteWatch failed %u\n",
ret );
1876 ok( !
base,
"VirtualAlloc succeeded\n" );
1895 base[5*pagesize + 200] = 3;
1914 "wrong count %lu\n",
count );
1920#if defined(__i386__) || defined(__x86_64__)
1924 volatile char *
p = (
char *)&
p;
1927 while (
p >= (
char *)
NtCurrentTeb()->DeallocationStack + 4 * 0x1000)
1933 ok(
arg == (
void *)0xdeadbeef,
"expected 0xdeadbeef, got %p\n",
arg );
1937static void test_stack_commit(
void)
1940 static const char code_call_on_stack[] = {
1944 0x8b, 0x4c, 0x24, 0x0c,
1945 0x8b, 0x54, 0x24, 0x10,
1946 0x8b, 0x44, 0x24, 0x14,
1958 static const char code_call_on_stack[] = {
1963 0x49, 0x83, 0xe0, 0xf0,
1964 0x49, 0x83, 0xe8, 0x20,
1972 void *old_stack, *old_stack_base, *old_stack_limit;
1973 void *new_stack, *new_stack_base;
1978 memcpy( call_on_stack, code_call_on_stack,
sizeof(code_call_on_stack) );
1983 new_stack_base = (
char *)new_stack + 0x400000;
1994 result = call_on_stack( stack_commit_func, (
void *)0xdeadbeef, new_stack_base );
2009static LONG num_guard_page_calls;
2014 trace(
"exception: %08x flags:%x addr:%p\n",
2027static void test_guard_page(
void)
2047 ok(
info.BaseAddress ==
base,
"BaseAddress %p instead of %p\n",
info.BaseAddress,
base );
2049 ok(
info.RegionSize ==
size,
"wrong RegionSize 0x%lx\n",
info.RegionSize );
2069 ok( !
success,
"VirtualLock unexpectedly succeeded\n" );
2078 ok( *
value == 1,
"memory block contains wrong value, expected 1, got 0x%x\n", *
value );
2086 ok(
info.BaseAddress ==
base,
"BaseAddress %p instead of %p\n",
info.BaseAddress,
base );
2088 ok(
info.RegionSize ==
size,
"wrong RegionSize 0x%lx\n",
info.RegionSize );
2100 frame.
Handler = guard_page_handler;
2107 ok(
old_value == 0x101,
"memory block contains wrong value, expected 0x101, got 0x%x\n",
old_value );
2108 ok( num_guard_page_calls == 1,
"expected one callback of guard page handler, got %d calls\n", num_guard_page_calls );
2122 frame.
Handler = guard_page_handler;
2128 ok(
old_value == 0x102,
"memory block contains wrong value, expected 0x102, got 0x%x\n",
old_value );
2129 ok( *
value == 2,
"memory block contains wrong value, expected 2, got 0x%x\n", *
value );
2130 ok( num_guard_page_calls == 1,
"expected one callback of guard page handler, got %d calls\n", num_guard_page_calls );
2138 ok( *
value == 2,
"memory block contains wrong value, expected 2, got 0x%x\n", *
value );
2146 if (!pGetWriteWatch || !pResetWriteWatch)
2148 win_skip(
"GetWriteWatch not supported, skipping combined guard page / write watch tests\n" );
2155 win_skip(
"MEM_WRITE_WATCH not supported\n" );
2163 ok(
info.BaseAddress ==
base,
"BaseAddress %p instead of %p\n",
info.BaseAddress,
base );
2165 ok(
info.RegionSize ==
size,
"wrong RegionSize 0x%lx\n",
info.RegionSize );
2176 frame.
Handler = guard_page_handler;
2183 ok( num_guard_page_calls == 1,
"expected one callback of guard page handler, got %d calls\n", num_guard_page_calls );
2197 frame.
Handler = guard_page_handler;
2203 ok(
old_value == 0x102,
"memory block contains wrong value, expected 0x102, got 0x%x\n",
old_value );
2204 ok( *
value == 1,
"memory block contains wrong value, expected 1, got 0x%x\n", *
value );
2205 ok( num_guard_page_calls == 1,
"expected one callback of guard page handler, got %d calls\n", num_guard_page_calls );
2221 ok( !
success,
"VirtualLock unexpectedly succeeded\n" );
2235 ok( *
value == 1,
"memory block contains wrong value, expected 1, got 0x%x\n", *
value );
2241 results[0] = (
void *)0xdeadbeef;
2252static LONG num_execute_fault_calls;
2260 trace(
"exception: %08x flags:%x addr:%p info[0]:%ld info[1]:%p\n",
2266 "ExceptionCode is %08x instead of STATUS_ACCESS_VIOLATION or STATUS_GUARD_PAGE_VIOLATION\n", rec->
ExceptionCode );
2304 trace(
"exception: %08x flags:%x addr:%p info[0]:%ld info[1]:%p\n",
2310 "ExceptionCode is %08x instead of STATUS_ACCESS_VIOLATION\n", rec->
ExceptionCode );
2330 frame.
Handler = execute_fault_seh_handler;
2348 frame.
Handler = execute_fault_seh_handler;
2373 ok(
arg == 0x11223344,
"arg is 0x%08x instead of 0x11223344\n",
arg );
2375 ok(
arg != 0x11223344,
"arg is unexpectedly 0x11223344\n" );
2384static void test_atl_thunk_emulation(
ULONG dep_flags )
2386 static const char code_jmp[] = {0xE9, 0x00, 0x00, 0x00, 0x00};
2387 static const char code_atl1[] = {0xC7, 0x44, 0x24, 0x04, 0x44, 0x33, 0x22, 0x11, 0xE9, 0x00, 0x00, 0x00, 0x00};
2388 static const char code_atl2[] = {0xB9, 0x44, 0x33, 0x22, 0x11, 0xE9, 0x00, 0x00, 0x00, 0x00};
2389 static const char code_atl3[] = {0xBA, 0x44, 0x33, 0x22, 0x11, 0xB9, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xE1};
2390 static const char code_atl4[] = {0xB9, 0x44, 0x33, 0x22, 0x11, 0xB8, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xE0};
2391 static const char code_atl5[] = {0x59, 0x58, 0x51, 0xFF, 0x60, 0x04};
2392 static const char cls_name[] =
"atl_thunk_class";
2403 trace(
"Running DEP tests with ProcessExecuteFlags = %d\n", dep_flags );
2406 if (old_flags != dep_flags)
2411 win_skip(
"Skipping DEP tests with ProcessExecuteFlags = %d\n", dep_flags );
2414 ok( !
ret,
"NtSetInformationProcess failed with status %08x\n",
ret );
2415 restore_flags =
TRUE;
2423 if (!pGetProcessDEPPolicy)
2424 win_skip(
"GetProcessDEPPolicy not supported\n" );
2428 BOOL policy_permanent = 0xdeadbeef;
2429 DWORD policy_flags = 0xdeadbeef;
2437 memcpy(
base, code_atl2,
sizeof(code_atl2) );
2448 ret |= PROCESS_DEP_ENABLE;
2450 ret |= PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION;
2452 ok( policy_flags ==
ret,
"expected policy flags %d, got %d\n",
ret, policy_flags );
2453 ok( !policy_permanent ||
broken(policy_permanent == 0x44),
2454 "expected policy permanent FALSE, got %d\n", policy_permanent );
2469 memset( &wc, 0,
sizeof(wc) );
2480 hWnd =
CreateWindowExA(0,
cls_name,
"Test",
WS_TILEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0);
2484 ok(
ret == 42,
"SendMessage returned unexpected result %d\n",
ret );
2494 ok(
ret == 42,
"call returned wrong result, expected 42, got %d\n",
ret );
2495 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2498 trace(
"DEP hardware support is not available\n" );
2499 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2504 trace(
"DEP hardware support is available\n" );
2505 ok( num_execute_fault_calls == 1,
"expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2508 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2517 ok(
ret == 42,
"call returned wrong result, expected 42, got %d\n",
ret );
2518 ok( num_guard_page_calls == 1,
"expected one STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2520 ok( num_execute_fault_calls == 1,
"expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2522 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2525 ok(
ret == 42,
"call returned wrong result, expected 42, got %d\n",
ret );
2526 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2527 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2531 memcpy(
base, code_atl1,
sizeof(code_atl1) );
2538 ok(
ret == 43,
"SendMessage returned unexpected result %d\n",
ret );
2546 ok(
ret == 43,
"call returned wrong result, expected 43, got %d\n",
ret );
2547 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2549 ok( num_execute_fault_calls == 1,
"expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2551 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2561 ok(
ret == 43,
"call returned wrong result, expected 43, got %d\n",
ret );
2562 ok( num_guard_page_calls == 1,
"expected one STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2564 ok( num_execute_fault_calls == 1,
"expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2566 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2569 ok(
ret == 43,
"call returned wrong result, expected 43, got %d\n",
ret );
2570 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2571 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2578 if (pRtlAddVectoredExceptionHandler && pRtlRemoveVectoredExceptionHandler)
2580 PVOID vectored_handler;
2585 vectored_handler = pRtlAddVectoredExceptionHandler(
TRUE, &execute_fault_vec_handler );
2586 ok( vectored_handler != 0,
"RtlAddVectoredExceptionHandler failed\n" );
2590 pRtlRemoveVectoredExceptionHandler( vectored_handler );
2592 ok(
ret == 43,
"call returned wrong result, expected 43, got %d\n",
ret );
2593 ok( num_execute_fault_calls == 1,
"expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2596 win_skip(
"RtlAddVectoredExceptionHandler or RtlRemoveVectoredExceptionHandler not found\n" );
2601 memcpy(
base, code_atl2,
sizeof(code_atl2) );
2609 ok(
ret == 43,
"call returned wrong result, expected 43, got %d\n",
ret );
2610 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2612 ok( num_execute_fault_calls == 1,
"expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2614 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2616 memcpy(
base, code_atl3,
sizeof(code_atl3) );
2624 ok(
ret == 43,
"call returned wrong result, expected 43, got %d\n",
ret );
2625 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2627 ok( num_execute_fault_calls == 1,
"expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2629 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2631 memcpy(
base, code_atl4,
sizeof(code_atl4) );
2639 ok(
ret == 43,
"call returned wrong result, expected 43, got %d\n",
ret );
2640 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2642 ok( num_execute_fault_calls == 1,
"expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2644 ok( num_execute_fault_calls == 0 ||
broken(num_execute_fault_calls == 1) ,
2645 "expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2647 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2649 memcpy(
base, code_atl5,
sizeof(code_atl5) );
2655 ret = call_proc_excpt( (
void *)
base, &
ret - 1 );
2657 ok(
ret == 44,
"call returned wrong result, expected 44, got %d\n",
ret );
2658 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2660 ok( num_execute_fault_calls == 1,
"expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2662 ok( num_execute_fault_calls == 0 ||
broken(num_execute_fault_calls == 1) ,
2663 "expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2665 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2687 win_skip(
"MEM_WRITE_WATCH not supported\n" );
2711 memset( &wc, 0,
sizeof(wc) );
2722 hWnd =
CreateWindowExA(0,
cls_name,
"Test",
WS_TILEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0);
2726 ok(
ret == 42,
"SendMessage returned unexpected result %d\n",
ret );
2741 ok(
ret == 42,
"call returned wrong result, expected 42, got %d\n",
ret );
2742 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2744 ok( num_execute_fault_calls == 1,
"expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2746 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2754 ok(
ret == 42,
"call returned wrong result, expected 42, got %d\n",
ret );
2755 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2756 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2765 ok(
ret == 42,
"call returned wrong result, expected 42, got %d\n",
ret );
2766 ok( num_guard_page_calls == 1,
"expected one STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2768 ok( num_execute_fault_calls == 1,
"expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2770 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2773 ok(
ret == 42,
"call returned wrong result, expected 42, got %d\n",
ret );
2774 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2775 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2784 memcpy(
base, code_atl1,
sizeof(code_atl1) );
2797 ok(
ret == 43,
"SendMessage returned unexpected result %d\n",
ret );
2805 ok(
ret == 43,
"call returned wrong result, expected 43, got %d\n",
ret );
2806 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2808 ok( num_execute_fault_calls == 1,
"expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2810 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2818 ok(
ret == 43,
"call returned wrong result, expected 43, got %d\n",
ret );
2819 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2820 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2830 ok(
ret == 43,
"call returned wrong result, expected 43, got %d\n",
ret );
2831 ok( num_guard_page_calls == 1,
"expected one STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2833 ok( num_execute_fault_calls == 1,
"expected one STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2835 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );
2838 ok(
ret == 43,
"call returned wrong result, expected 43, got %d\n",
ret );
2839 ok( num_guard_page_calls == 0,
"expected no STATUS_GUARD_PAGE_VIOLATION exception, got %d exceptions\n", num_guard_page_calls );
2840 ok( num_execute_fault_calls == 0,
"expected no STATUS_ACCESS_VIOLATION exception, got %d exceptions\n", num_execute_fault_calls );