wined3d: Remove stray '\' at end of lines.
[wine] / dlls / kernel32 / tests / virtual.c
1 /*
2  * Unit test suite for Virtual* family of APIs.
3  *
4  * Copyright 2004 Dmitry Timoshkov
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "wine/test.h"
28
29 #define NUM_THREADS 4
30
31 static HANDLE create_target_process(const char *arg)
32 {
33     char **argv;
34     char cmdline[MAX_PATH];
35     PROCESS_INFORMATION pi;
36     STARTUPINFO si = { 0 };
37     si.cb = sizeof(si);
38
39     winetest_get_mainargs( &argv );
40     sprintf(cmdline, "%s %s %s", argv[0], argv[1], arg);
41     ok(CreateProcess(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL,
42                      &si, &pi) != 0, "error: %u\n", GetLastError());
43     ok(CloseHandle(pi.hThread) != 0, "error %u\n", GetLastError());
44     return pi.hProcess;
45 }
46
47 static void test_VirtualAllocEx(void)
48 {
49     const unsigned int alloc_size = 1<<15;
50     char *src, *dst;
51     unsigned long bytes_written = 0, bytes_read = 0, i;
52     void *addr1, *addr2;
53     BOOL b;
54     DWORD old_prot;
55     MEMORY_BASIC_INFORMATION info;
56     HANDLE hProcess;
57
58     hProcess = create_target_process("sleep");
59     ok(hProcess != NULL, "Can't start process\n");
60
61     SetLastError(0xdeadbeef);
62     addr1 = VirtualAllocEx(hProcess, NULL, alloc_size, MEM_COMMIT,
63                            PAGE_EXECUTE_READWRITE);
64     if (!addr1 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
65     {   /* Win9x */
66         trace("VirtualAllocEx is not implemented, skipping the test\n");
67         return;
68     }
69
70     src = (char *) HeapAlloc( GetProcessHeap(), 0, alloc_size );
71     dst = (char *) HeapAlloc( GetProcessHeap(), 0, alloc_size );
72     for (i = 0; i < alloc_size; i++)
73         src[i] = 0xcafedead + i;
74
75     todo_wine ok(addr1 != NULL, "VirtualAllocEx error %u\n", GetLastError());
76     b = WriteProcessMemory(hProcess, addr1, src, alloc_size, &bytes_written);
77     ok(b && (bytes_written == alloc_size), "%lu bytes written\n",
78        bytes_written);
79     b = ReadProcessMemory(hProcess, addr1, dst, alloc_size, &bytes_read);
80     ok(b && (bytes_read == alloc_size), "%lu bytes read\n", bytes_read);
81     ok(!memcmp(src, dst, alloc_size), "Data from remote process differs\n");
82     b = VirtualFreeEx(hProcess, addr1, 0, MEM_RELEASE);
83     todo_wine ok(b != 0, "VirtualFreeEx, error %u\n", GetLastError());
84
85     HeapFree( GetProcessHeap(), 0, src );
86     HeapFree( GetProcessHeap(), 0, dst );
87
88     /*
89      * The following tests parallel those in test_VirtualAlloc()
90      */
91
92     SetLastError(0xdeadbeef);
93     addr1 = VirtualAllocEx(hProcess, 0, 0, MEM_RESERVE, PAGE_NOACCESS);
94     ok(addr1 == NULL, "VirtualAllocEx should fail on zero-sized allocation\n");
95     ok(GetLastError() == ERROR_INVALID_PARAMETER /* NT */ ||
96        GetLastError() == ERROR_NOT_ENOUGH_MEMORY, /* Win9x */
97         "got %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
98
99     addr1 = VirtualAllocEx(hProcess, 0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
100     todo_wine ok(addr1 != NULL, "VirtualAllocEx failed\n");
101
102     /* test a not committed memory */
103     memset(&info, 'q', sizeof(info));
104     todo_wine ok(VirtualQueryEx(hProcess, addr1, &info, sizeof(info))
105                  == sizeof(info), "VirtualQueryEx failed\n");
106     todo_wine ok(info.BaseAddress == addr1, "%p != %p\n", info.BaseAddress,
107                  addr1);
108     todo_wine ok(info.AllocationBase == addr1, "%p != %p\n",
109                  info.AllocationBase, addr1);
110     todo_wine ok(info.AllocationProtect == PAGE_NOACCESS,
111                  "%x != PAGE_NOACCESS\n", info.AllocationProtect);
112     todo_wine ok(info.RegionSize == 0x10000, "%lx != 0x10000\n",
113                  info.RegionSize);
114     todo_wine ok(info.State == MEM_RESERVE, "%x != MEM_RESERVE\n", info.State);
115     /* NT reports Protect == 0 for a not committed memory block */
116     todo_wine ok(info.Protect == 0 /* NT */ ||
117        info.Protect == PAGE_NOACCESS, /* Win9x */
118         "%x != PAGE_NOACCESS\n", info.Protect);
119     todo_wine ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
120
121     SetLastError(0xdeadbeef);
122     ok(!VirtualProtectEx(hProcess, addr1, 0xFFFC, PAGE_READONLY, &old_prot),
123        "VirtualProtectEx should fail on a not committed memory\n");
124     todo_wine ok(GetLastError() == ERROR_INVALID_ADDRESS /* NT */ ||
125        GetLastError() == ERROR_INVALID_PARAMETER, /* Win9x */
126         "got %u, expected ERROR_INVALID_ADDRESS\n", GetLastError());
127
128     addr2 = VirtualAllocEx(hProcess, addr1, 0x1000, MEM_COMMIT, PAGE_NOACCESS);
129     ok(addr1 == addr2, "VirtualAllocEx failed\n");
130
131     /* test a committed memory */
132     todo_wine ok(VirtualQueryEx(hProcess, addr1, &info, sizeof(info))
133                  == sizeof(info),
134         "VirtualQueryEx failed\n");
135     todo_wine ok(info.BaseAddress == addr1, "%p != %p\n", info.BaseAddress,
136                  addr1);
137     todo_wine ok(info.AllocationBase == addr1, "%p != %p\n",
138                  info.AllocationBase, addr1);
139     todo_wine ok(info.AllocationProtect == PAGE_NOACCESS,
140                  "%x != PAGE_NOACCESS\n", info.AllocationProtect);
141     todo_wine ok(info.RegionSize == 0x1000, "%lx != 0x1000\n", info.RegionSize);
142     todo_wine ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
143     /* this time NT reports PAGE_NOACCESS as well */
144     todo_wine ok(info.Protect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.Protect);
145     todo_wine ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
146
147     /* this should fail, since not the whole range is committed yet */
148     SetLastError(0xdeadbeef);
149     ok(!VirtualProtectEx(hProcess, addr1, 0xFFFC, PAGE_READONLY, &old_prot),
150         "VirtualProtectEx should fail on a not committed memory\n");
151     todo_wine ok(GetLastError() == ERROR_INVALID_ADDRESS /* NT */ ||
152        GetLastError() == ERROR_INVALID_PARAMETER, /* Win9x */
153         "got %u, expected ERROR_INVALID_ADDRESS\n", GetLastError());
154
155     todo_wine ok(VirtualProtectEx(hProcess, addr1, 0x1000, PAGE_READONLY,
156                                   &old_prot), "VirtualProtectEx failed\n");
157     todo_wine ok(old_prot == PAGE_NOACCESS,
158         "wrong old protection: got %04x instead of PAGE_NOACCESS\n", old_prot);
159
160     todo_wine ok(VirtualProtectEx(hProcess, addr1, 0x1000, PAGE_READWRITE,
161                                   &old_prot), "VirtualProtectEx failed\n");
162     todo_wine ok(old_prot == PAGE_READONLY,
163         "wrong old protection: got %04x instead of PAGE_READONLY\n", old_prot);
164
165     ok(!VirtualFreeEx(hProcess, addr1, 0x10000, 0),
166        "VirtualFreeEx should fail with type 0\n");
167     todo_wine ok(GetLastError() == ERROR_INVALID_PARAMETER,
168         "got %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
169
170     todo_wine ok(VirtualFreeEx(hProcess, addr1, 0x10000, MEM_DECOMMIT),
171                  "VirtualFreeEx failed\n");
172
173     /* if the type is MEM_RELEASE, size must be 0 */
174     ok(!VirtualFreeEx(hProcess, addr1, 1, MEM_RELEASE),
175        "VirtualFreeEx should fail\n");
176     todo_wine ok(GetLastError() == ERROR_INVALID_PARAMETER,
177         "got %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
178
179     todo_wine ok(VirtualFreeEx(hProcess, addr1, 0, MEM_RELEASE),
180                  "VirtualFreeEx failed\n");
181
182     TerminateProcess(hProcess, 0);
183     CloseHandle(hProcess);
184 }
185
186 static void test_VirtualAlloc(void)
187 {
188     void *addr1, *addr2;
189     DWORD old_prot;
190     MEMORY_BASIC_INFORMATION info;
191
192     SetLastError(0xdeadbeef);
193     addr1 = VirtualAlloc(0, 0, MEM_RESERVE, PAGE_NOACCESS);
194     ok(addr1 == NULL, "VirtualAlloc should fail on zero-sized allocation\n");
195     ok(GetLastError() == ERROR_INVALID_PARAMETER /* NT */ ||
196        GetLastError() == ERROR_NOT_ENOUGH_MEMORY, /* Win9x */
197         "got %d, expected ERROR_INVALID_PARAMETER\n", GetLastError());
198
199     addr1 = VirtualAlloc(0, 0xFFFC, MEM_RESERVE, PAGE_NOACCESS);
200     ok(addr1 != NULL, "VirtualAlloc failed\n");
201
202     /* test a not committed memory */
203     ok(VirtualQuery(addr1, &info, sizeof(info)) == sizeof(info),
204         "VirtualQuery failed\n");
205     ok(info.BaseAddress == addr1, "%p != %p\n", info.BaseAddress, addr1);
206     ok(info.AllocationBase == addr1, "%p != %p\n", info.AllocationBase, addr1);
207     ok(info.AllocationProtect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.AllocationProtect);
208     ok(info.RegionSize == 0x10000, "%lx != 0x10000\n", info.RegionSize);
209     ok(info.State == MEM_RESERVE, "%x != MEM_RESERVE\n", info.State);
210     /* NT reports Protect == 0 for a not committed memory block */
211     ok(info.Protect == 0 /* NT */ ||
212        info.Protect == PAGE_NOACCESS, /* Win9x */
213         "%x != PAGE_NOACCESS\n", info.Protect);
214     ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
215
216     SetLastError(0xdeadbeef);
217     ok(!VirtualProtect(addr1, 0xFFFC, PAGE_READONLY, &old_prot),
218        "VirtualProtect should fail on a not committed memory\n");
219     ok(GetLastError() == ERROR_INVALID_ADDRESS /* NT */ ||
220        GetLastError() == ERROR_INVALID_PARAMETER, /* Win9x */
221         "got %d, expected ERROR_INVALID_ADDRESS\n", GetLastError());
222
223     addr2 = VirtualAlloc(addr1, 0x1000, MEM_COMMIT, PAGE_NOACCESS);
224     ok(addr1 == addr2, "VirtualAlloc failed\n");
225
226     /* test a committed memory */
227     ok(VirtualQuery(addr1, &info, sizeof(info)) == sizeof(info),
228         "VirtualQuery failed\n");
229     ok(info.BaseAddress == addr1, "%p != %p\n", info.BaseAddress, addr1);
230     ok(info.AllocationBase == addr1, "%p != %p\n", info.AllocationBase, addr1);
231     ok(info.AllocationProtect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.AllocationProtect);
232     ok(info.RegionSize == 0x1000, "%lx != 0x1000\n", info.RegionSize);
233     ok(info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State);
234     /* this time NT reports PAGE_NOACCESS as well */
235     ok(info.Protect == PAGE_NOACCESS, "%x != PAGE_NOACCESS\n", info.Protect);
236     ok(info.Type == MEM_PRIVATE, "%x != MEM_PRIVATE\n", info.Type);
237
238     /* this should fail, since not the whole range is committed yet */
239     SetLastError(0xdeadbeef);
240     ok(!VirtualProtect(addr1, 0xFFFC, PAGE_READONLY, &old_prot),
241         "VirtualProtect should fail on a not committed memory\n");
242     ok(GetLastError() == ERROR_INVALID_ADDRESS /* NT */ ||
243        GetLastError() == ERROR_INVALID_PARAMETER, /* Win9x */
244         "got %d, expected ERROR_INVALID_ADDRESS\n", GetLastError());
245
246     ok(VirtualProtect(addr1, 0x1000, PAGE_READONLY, &old_prot), "VirtualProtect failed\n");
247     ok(old_prot == PAGE_NOACCESS,
248         "wrong old protection: got %04x instead of PAGE_NOACCESS\n", old_prot);
249
250     ok(VirtualProtect(addr1, 0x1000, PAGE_READWRITE, &old_prot), "VirtualProtect failed\n");
251     ok(old_prot == PAGE_READONLY,
252         "wrong old protection: got %04x instead of PAGE_READONLY\n", old_prot);
253
254     ok(!VirtualFree(addr1, 0x10000, 0), "VirtualFree should fail with type 0\n");
255     ok(GetLastError() == ERROR_INVALID_PARAMETER,
256         "got %d, expected ERROR_INVALID_PARAMETER\n", GetLastError());
257
258     ok(VirtualFree(addr1, 0x10000, MEM_DECOMMIT), "VirtualFree failed\n");
259
260     /* if the type is MEM_RELEASE, size must be 0 */
261     ok(!VirtualFree(addr1, 1, MEM_RELEASE), "VirtualFree should fail\n");
262     ok(GetLastError() == ERROR_INVALID_PARAMETER,
263         "got %d, expected ERROR_INVALID_PARAMETER\n", GetLastError());
264
265     ok(VirtualFree(addr1, 0, MEM_RELEASE), "VirtualFree failed\n");
266 }
267
268 static void test_MapViewOfFile(void)
269 {
270     static const char testfile[] = "testfile.xxx";
271     HANDLE file, mapping;
272     void *ptr;
273
274     file = CreateFileA( testfile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
275     ok( file != INVALID_HANDLE_VALUE, "Failed to create test file\n" );
276     SetFilePointer( file, 4096, NULL, FILE_BEGIN );
277     SetEndOfFile( file );
278
279     /* read/write mapping */
280
281     mapping = CreateFileMappingA( file, NULL, PAGE_READWRITE, 0, 4096, NULL );
282     ok( mapping != 0, "CreateFileMapping failed\n" );
283
284     ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
285     ok( ptr != NULL, "MapViewOfFile FILE_MAPE_READ failed\n" );
286     UnmapViewOfFile( ptr );
287
288     /* this fails on win9x but succeeds on NT */
289     ptr = MapViewOfFile( mapping, FILE_MAP_COPY, 0, 0, 4096 );
290     if (ptr) UnmapViewOfFile( ptr );
291     else ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error %d\n", GetLastError() );
292
293     ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
294     ok( ptr != NULL, "MapViewOfFile 0 failed\n" );
295     UnmapViewOfFile( ptr );
296
297     ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 4096 );
298     ok( ptr != NULL, "MapViewOfFile FILE_MAP_WRITE failed\n" );
299     UnmapViewOfFile( ptr );
300     CloseHandle( mapping );
301
302     /* read-only mapping */
303
304     mapping = CreateFileMappingA( file, NULL, PAGE_READONLY, 0, 4096, NULL );
305     ok( mapping != 0, "CreateFileMapping failed\n" );
306
307     ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
308     ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ failed\n" );
309     UnmapViewOfFile( ptr );
310
311     /* this fails on win9x but succeeds on NT */
312     ptr = MapViewOfFile( mapping, FILE_MAP_COPY, 0, 0, 4096 );
313     if (ptr) UnmapViewOfFile( ptr );
314     else ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error %d\n", GetLastError() );
315
316     ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
317     ok( ptr != NULL, "MapViewOfFile 0 failed\n" );
318     UnmapViewOfFile( ptr );
319
320     ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 4096 );
321     ok( !ptr, "MapViewOfFile FILE_MAP_WRITE succeeded\n" );
322     ok( GetLastError() == ERROR_INVALID_PARAMETER ||
323         GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
324     CloseHandle( mapping );
325
326     /* copy-on-write mapping */
327
328     mapping = CreateFileMappingA( file, NULL, PAGE_WRITECOPY, 0, 4096, NULL );
329     ok( mapping != 0, "CreateFileMapping failed\n" );
330
331     ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
332     ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ failed\n" );
333     UnmapViewOfFile( ptr );
334
335     ptr = MapViewOfFile( mapping, FILE_MAP_COPY, 0, 0, 4096 );
336     ok( ptr != NULL, "MapViewOfFile FILE_MAP_COPY failed\n" );
337     UnmapViewOfFile( ptr );
338
339     ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
340     ok( ptr != NULL, "MapViewOfFile 0 failed\n" );
341     UnmapViewOfFile( ptr );
342
343     ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 4096 );
344     ok( !ptr, "MapViewOfFile FILE_MAP_WRITE succeeded\n" );
345     ok( GetLastError() == ERROR_INVALID_PARAMETER ||
346         GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
347     CloseHandle( mapping );
348
349     /* no access mapping */
350
351     mapping = CreateFileMappingA( file, NULL, PAGE_NOACCESS, 0, 4096, NULL );
352     /* fails on NT but succeeds on win9x */
353     if (!mapping) ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error %d\n", GetLastError() );
354     else
355     {
356         ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
357         ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ failed\n" );
358         UnmapViewOfFile( ptr );
359
360         ptr = MapViewOfFile( mapping, FILE_MAP_COPY, 0, 0, 4096 );
361         ok( !ptr, "MapViewOfFile FILE_MAP_COPY succeeded\n" );
362         ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error %d\n", GetLastError() );
363
364         ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
365         ok( ptr != NULL, "MapViewOfFile 0 failed\n" );
366         UnmapViewOfFile( ptr );
367
368         ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 4096 );
369         ok( !ptr, "MapViewOfFile FILE_MAP_WRITE succeeded\n" );
370         ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error %d\n", GetLastError() );
371
372         CloseHandle( mapping );
373     }
374
375     CloseHandle( file );
376
377     /* now try read-only file */
378
379     file = CreateFileA( testfile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0 );
380     ok( file != INVALID_HANDLE_VALUE, "Failed to create test file\n" );
381
382     mapping = CreateFileMappingA( file, NULL, PAGE_READWRITE, 0, 4096, NULL );
383     ok( !mapping, "CreateFileMapping PAGE_READWRITE succeeded\n" );
384     ok( GetLastError() == ERROR_INVALID_PARAMETER ||
385         GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
386
387     mapping = CreateFileMappingA( file, NULL, PAGE_WRITECOPY, 0, 4096, NULL );
388     ok( mapping != 0, "CreateFileMapping PAGE_WRITECOPY failed\n" );
389     CloseHandle( mapping );
390
391     mapping = CreateFileMappingA( file, NULL, PAGE_READONLY, 0, 4096, NULL );
392     ok( mapping != 0, "CreateFileMapping PAGE_READONLY failed\n" );
393     CloseHandle( mapping );
394     CloseHandle( file );
395
396     /* now try no access file */
397
398     file = CreateFileA( testfile, 0, 0, NULL, OPEN_EXISTING, 0, 0 );
399     ok( file != INVALID_HANDLE_VALUE, "Failed to create test file\n" );
400
401     mapping = CreateFileMappingA( file, NULL, PAGE_READWRITE, 0, 4096, NULL );
402     ok( !mapping, "CreateFileMapping PAGE_READWRITE succeeded\n" );
403     ok( GetLastError() == ERROR_INVALID_PARAMETER ||
404         GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
405
406     mapping = CreateFileMappingA( file, NULL, PAGE_WRITECOPY, 0, 4096, NULL );
407     ok( !mapping, "CreateFileMapping PAGE_WRITECOPY succeeded\n" );
408     ok( GetLastError() == ERROR_INVALID_PARAMETER ||
409         GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
410
411     mapping = CreateFileMappingA( file, NULL, PAGE_READONLY, 0, 4096, NULL );
412     ok( !mapping, "CreateFileMapping PAGE_READONLY succeeded\n" );
413     ok( GetLastError() == ERROR_INVALID_PARAMETER ||
414         GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
415
416     CloseHandle( file );
417
418     CloseHandle( file );
419     DeleteFileA( testfile );
420 }
421
422 START_TEST(virtual)
423 {
424     int argc;
425     char **argv;
426     argc = winetest_get_mainargs( &argv );
427
428     if (argc >= 3)
429     {
430         if (!strcmp(argv[2], "sleep"))
431         {
432             Sleep(5000); /* spawned process runs for at most 5 seconds */
433             return;
434         }
435         while (1)
436         {
437             void *mem;
438             BOOL ret;
439             mem = VirtualAlloc(NULL, 1<<20, MEM_COMMIT|MEM_RESERVE,
440                                PAGE_EXECUTE_READWRITE);
441             ok(mem != NULL, "VirtualAlloc failed %u\n", GetLastError());
442             if (mem == NULL) break;
443             ret = VirtualFree(mem, 0, MEM_RELEASE);
444             ok(ret, "VirtualFree failed %u\n", GetLastError());
445             if (!ret) break;
446         }
447         return;
448     }
449
450     test_VirtualAllocEx();
451     test_VirtualAlloc();
452     test_MapViewOfFile();
453 }