[NTDLL_APITEST]
[reactos.git] / rostests / apitests / ntdll / NtAllocateVirtualMemory.c
1 /*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Stress Test for virtual memory allocation
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <ndk/rtlfuncs.h>
12 #include <ndk/mmfuncs.h>
13
14 static PVOID Allocations[4096] = { NULL };
15 static ULONG CurrentAllocation = 0;
16
17 static
18 VOID
19 ValidateAllocations(VOID)
20 {
21 ULONG i;
22
23 ASSERT(CurrentAllocation < sizeof(Allocations) / sizeof(Allocations[0]));
24 for (i = 0; i < CurrentAllocation; ++i)
25 {
26 PUCHAR UserBuffer = Allocations[i];
27 SIZE_T AllocationSize;
28 SIZE_T DataSize;
29
30 if (UserBuffer == NULL)
31 continue;
32
33 AllocationSize = ((PSIZE_T)UserBuffer)[-2];
34 DataSize = ((PSIZE_T)UserBuffer)[-1];
35 ASSERT(AllocationSize != 0);
36 ASSERT(AllocationSize % PAGE_SIZE == 0);
37 ASSERT(DataSize != 0);
38 ASSERT(((SIZE_T)UserBuffer + DataSize) % PAGE_SIZE == 0);
39 }
40 }
41
42 static
43 PVOID
44 Allocate(
45 SIZE_T DataSize)
46 {
47 NTSTATUS Status;
48 PVOID AllocationStart = NULL;
49 SIZE_T AllocationSize = PAGE_ROUND_UP(DataSize + PAGE_SIZE + 2 * sizeof(SIZE_T));
50 PVOID FirstPageStart;
51 SIZE_T NumberOfPages = AllocationSize / PAGE_SIZE;
52 SIZE_T Size;
53 PUCHAR UserBuffer;
54
55 Status = NtAllocateVirtualMemory(NtCurrentProcess(), &AllocationStart, 0, &AllocationSize, MEM_RESERVE, PAGE_NOACCESS);
56
57 if (!NT_SUCCESS(Status))
58 return NULL;
59
60 FirstPageStart = (PUCHAR)AllocationStart + AllocationSize - PAGE_SIZE * NumberOfPages;
61 Size = (NumberOfPages - 1) * PAGE_SIZE;
62 Status = NtAllocateVirtualMemory(NtCurrentProcess(), &FirstPageStart, 0, &Size, MEM_COMMIT, PAGE_READWRITE);
63 if (!NT_SUCCESS(Status))
64 {
65 AllocationSize = 0;
66 Status = NtFreeVirtualMemory(NtCurrentProcess(), &AllocationStart, &AllocationSize, MEM_RELEASE);
67 ASSERT(Status == STATUS_SUCCESS);
68 return NULL;
69 }
70 ASSERT(Size % sizeof(ULONG) == 0);
71 ASSERT(RtlCompareMemoryUlong(FirstPageStart, Size, 0) == Size);
72
73 UserBuffer = AllocationStart;
74 UserBuffer += AllocationSize - PAGE_SIZE - DataSize;
75 RtlFillMemory(FirstPageStart, UserBuffer - (PUCHAR)FirstPageStart, 0xae);
76 RtlZeroMemory(UserBuffer, DataSize);
77 ((PSIZE_T)UserBuffer)[-2] = AllocationSize;
78 ((PSIZE_T)UserBuffer)[-1] = DataSize;
79
80 Allocations[CurrentAllocation++] = UserBuffer;
81 ValidateAllocations();
82 return UserBuffer;
83 }
84
85 static
86 VOID
87 Free(
88 PVOID UserBuffer)
89 {
90 NTSTATUS Status;
91 PVOID AllocationStart;
92 SIZE_T Zero = 0;
93 SIZE_T AllocationSize;
94 SIZE_T DataSize;
95 ULONG i;
96
97 AllocationSize = ((PSIZE_T)UserBuffer)[-2];
98 DataSize = ((PSIZE_T)UserBuffer)[-1];
99 ASSERT(DataSize != 0);
100
101 AllocationStart = (PUCHAR)UserBuffer + DataSize + PAGE_SIZE - AllocationSize;
102 ASSERT((SIZE_T)AllocationStart % PAGE_SIZE == 0);
103
104 RtlFillMemory(UserBuffer, DataSize, 0xbe);
105 ((PSIZE_T)UserBuffer)[-1] = 0;
106 ((PSIZE_T)UserBuffer)[-2] = 0xFAFBFCFD;
107
108 for (i = 0; i < CurrentAllocation; ++i)
109 if (Allocations[i] == UserBuffer)
110 {
111 Allocations[i] = NULL;
112 break;
113 }
114 ValidateAllocations();
115
116 Status = NtFreeVirtualMemory(NtCurrentProcess(), &AllocationStart, &Zero, MEM_RELEASE);
117 ASSERT(Status == STATUS_SUCCESS);
118 }
119
120 static
121 PVOID
122 ReAllocate(
123 PVOID OldUserBuffer,
124 SIZE_T NewDataSize)
125 {
126 PVOID NewUserBuffer;
127 SIZE_T OldDataSize;
128
129 OldDataSize = ((PSIZE_T)OldUserBuffer)[-1];
130 ASSERT(OldDataSize != 0);
131
132 NewUserBuffer = Allocate(NewDataSize);
133 ASSERT(((PSIZE_T)OldUserBuffer)[-1] == OldDataSize);
134 RtlCopyMemory(NewUserBuffer, OldUserBuffer, min(OldDataSize, NewDataSize));
135 ASSERT(((PSIZE_T)OldUserBuffer)[-1] == OldDataSize);
136 Free(OldUserBuffer);
137 return NewUserBuffer;
138 }
139
140 static
141 VOID
142 AccessMemory1(
143 PVOID UserBuffer,
144 SIZE_T DataSize)
145 {
146 PBYTE Buffer = UserBuffer;
147 SIZE_T i;
148
149 for (i = 0; i < DataSize; ++i)
150 Buffer[i] = LOBYTE(i);
151 }
152
153 static
154 BOOLEAN
155 CheckMemory1(
156 PVOID UserBuffer,
157 SIZE_T DataSize)
158 {
159 PBYTE Buffer = UserBuffer;
160 SIZE_T i;
161
162 for (i = 0; i < DataSize; ++i)
163 if (Buffer[i] != LOBYTE(i))
164 {
165 trace("Mismatch in region %p at index %lu. Value=%02x\n", UserBuffer, (ULONG)i, Buffer[i]);
166 ASSERT(FALSE);
167 return FALSE;
168 }
169 return TRUE;
170 }
171
172 static
173 VOID
174 AccessMemory2(
175 PVOID UserBuffer,
176 SIZE_T DataSize)
177 {
178 PBYTE Buffer = UserBuffer;
179 SIZE_T i;
180
181 for (i = 0; i < DataSize; ++i)
182 Buffer[i] = UCHAR_MAX - LOBYTE(i);
183 }
184
185 static
186 BOOLEAN
187 CheckMemory2(
188 PVOID UserBuffer,
189 SIZE_T DataSize)
190 {
191 PBYTE Buffer = UserBuffer;
192 SIZE_T i;
193
194 for (i = 0; i < DataSize; ++i)
195 if (Buffer[i] != UCHAR_MAX - LOBYTE(i))
196 {
197 trace("Mismatch in region %p at index %lu. Value=%02x\n", UserBuffer, (ULONG)i, Buffer[i]);
198 ASSERT(FALSE);
199 return FALSE;
200 }
201 return TRUE;
202 }
203
204 VOID
205 CheckSize(ULONG_PTR Base, SIZE_T InSize, SIZE_T ExpectedSize)
206 {
207 NTSTATUS Status;
208 PVOID BaseAddress;
209 SIZE_T Size;
210
211 /* Reserve memory */
212 BaseAddress = (PVOID)Base;
213 Size = InSize;
214 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
215 &BaseAddress,
216 0,
217 &Size,
218 MEM_RESERVE,
219 PAGE_NOACCESS);
220 ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
221 ok(BaseAddress == (PVOID)(Base & ~((ULONG_PTR)0xFFFF)), "Got back wrong base address: %p\n", BaseAddress);
222 ok(Size == ExpectedSize, "Alloc of 0x%Ix: got back wrong size: 0x%Ix, expected 0x%Ix\n", InSize, Size, ExpectedSize);
223 Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
224 ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n");
225 }
226
227 VOID
228 CheckAlignment()
229 {
230 NTSTATUS Status;
231 PVOID BaseAddress;
232 SIZE_T Size;
233
234 CheckSize(0x50000000, 0x0001, 0x1000);
235 CheckSize(0x50008000, 0x0001, 0x9000);
236 CheckSize(0x50000010, 0x1000, 0x2000);
237 CheckSize(0x50010000, 0x2000, 0x2000);
238 CheckSize(0x5000FFFF, 0x3000, 0x13000);
239 CheckSize(0x50001010, 0x7000, 0x9000);
240 CheckSize(0x50001010, 0xC000, 0xe000);
241
242 /* Reserve memory not aligned to allocation granularity */
243 BaseAddress = UlongToPtr(0x50001010);
244 Size = 0x1000;
245 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
246 &BaseAddress,
247 0,
248 &Size,
249 MEM_RESERVE,
250 PAGE_NOACCESS);
251 ok_ntstatus(Status, STATUS_SUCCESS);
252 ok(BaseAddress == UlongToPtr(0x50000000), "Got back wrong base address: %p", BaseAddress);
253 ok(Size == 0x3000, "Got back wrong size: 0x%Ix", Size);
254
255 /* Try to reserve again in the same 64k region */
256 BaseAddress = UlongToPtr(0x50008000);
257 Size = 0x1000;
258 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
259 &BaseAddress,
260 0,
261 &Size,
262 MEM_RESERVE,
263 PAGE_NOACCESS);
264 ok_ntstatus(Status, STATUS_CONFLICTING_ADDRESSES);
265
266 /* Commit memory */
267 BaseAddress = UlongToPtr(0x50002000);
268 Size = 0x1000;
269 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
270 &BaseAddress,
271 0,
272 &Size,
273 MEM_COMMIT,
274 PAGE_NOACCESS);
275 ok_ntstatus(Status, STATUS_SUCCESS);
276 ok(BaseAddress == UlongToPtr(0x50002000), "Got back wrong base address: %p", BaseAddress);
277 ok(Size == 0x1000, "Got back wrong size: 0x%Ix", Size);
278
279 /* Commit the same address again with a different protection */
280 BaseAddress = UlongToPtr(0x50002000);
281 Size = 0x1000;
282 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
283 &BaseAddress,
284 0,
285 &Size,
286 MEM_COMMIT,
287 PAGE_READWRITE);
288 ok_ntstatus(Status, STATUS_SUCCESS);
289 ok(BaseAddress == UlongToPtr(0x50002000), "Got back wrong base address: %p", BaseAddress);
290 ok(Size == 0x1000, "Got back wrong size: 0x%Ix", Size);
291
292 /* Commit memory at a too high address */
293 BaseAddress = UlongToPtr(0x50003000);
294 Size = 0x1000;
295 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
296 &BaseAddress,
297 0,
298 &Size,
299 MEM_COMMIT,
300 PAGE_NOACCESS);
301 ok_ntstatus(Status, STATUS_CONFLICTING_ADDRESSES);
302
303 /* Decommit the memory, even those pages that were not committed */
304 BaseAddress = UlongToPtr(0x50000000);
305 Size = 0x3000;
306 Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_DECOMMIT);
307 ok_ntstatus(Status, STATUS_SUCCESS);
308
309 /* Try to release memory in a different 64k region */
310 BaseAddress = UlongToPtr(0x50010000);
311 Size = 0x1000;
312 Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
313 ok_ntstatus(Status, STATUS_MEMORY_NOT_ALLOCATED);
314
315 /* Release the memory in the same 64k region at a different address */
316 BaseAddress = UlongToPtr(0x50008000);
317 Size = 0x1000;
318 Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
319 ok_ntstatus(Status, STATUS_MEMORY_NOT_ALLOCATED);
320
321 /* Release the memory at the correct address but with wrong size */
322 BaseAddress = UlongToPtr(0x50000000);
323 Size = 0x4000;
324 Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
325 ok_ntstatus(Status, STATUS_UNABLE_TO_FREE_VM);
326
327 /* Release the memory */
328 BaseAddress = UlongToPtr(0x50000000);
329 Size = 0x3000;
330 Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
331 ok_ntstatus(Status, STATUS_SUCCESS);
332
333 /* Reserve and commit at once */
334 BaseAddress = UlongToPtr(0x50004080);
335 Size = 0x1000;
336 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
337 &BaseAddress,
338 0,
339 &Size,
340 MEM_RESERVE | MEM_COMMIT,
341 PAGE_READWRITE);
342 ok_ntstatus(Status, STATUS_SUCCESS);
343 ok(BaseAddress == UlongToPtr(0x50000000), "Got back wrong base address: %p", BaseAddress);
344 ok(Size == 0x6000, "Got back wrong size: 0x%Ix", Size);
345
346 _SEH2_TRY
347 {
348 *(int*)BaseAddress = 1;
349 *(int*)UlongToPtr(0x50004080) = 1;
350 }
351 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
352 {
353 ok(0, "Got exception\n");
354 }
355 _SEH2_END;
356
357 /* Release the memory */
358 Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
359 ok_ntstatus(Status, STATUS_SUCCESS);
360
361 }
362
363 static
364 VOID
365 CheckAdjacentVADs()
366 {
367 NTSTATUS Status;
368 PVOID BaseAddress;
369 SIZE_T Size;
370 MEMORY_BASIC_INFORMATION MemoryBasicInfo;
371
372 /* Reserve a full 64k region */
373 BaseAddress = UlongToPtr(0x50000000);
374 Size = 0x10000;
375 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
376 &BaseAddress,
377 0,
378 &Size,
379 MEM_RESERVE,
380 PAGE_NOACCESS);
381 ok_ntstatus(Status, STATUS_SUCCESS);
382 if (!NT_SUCCESS(Status))
383 return;
384
385 /* Reserve another 64k region, but with 64k between */
386 BaseAddress = UlongToPtr(0x50020000);
387 Size = 0x10000;
388 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
389 &BaseAddress,
390 0,
391 &Size,
392 MEM_RESERVE,
393 PAGE_NOACCESS);
394 ok_ntstatus(Status, STATUS_SUCCESS);
395 if (!NT_SUCCESS(Status))
396 return;
397
398 /* Try to free the whole at once */
399 BaseAddress = UlongToPtr(0x50000000);
400 Size = 0x30000;
401 Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
402 ok_ntstatus(Status, STATUS_UNABLE_TO_FREE_VM);
403
404 /* Reserve the part in the middle */
405 BaseAddress = UlongToPtr(0x50010000);
406 Size = 0x10000;
407 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
408 &BaseAddress,
409 0,
410 &Size,
411 MEM_RESERVE,
412 PAGE_NOACCESS);
413 ok_ntstatus(Status, STATUS_SUCCESS);
414
415 /* Try to commit memory covering 2 allocations */
416 BaseAddress = UlongToPtr(0x50004000);
417 Size = 0x10000;
418 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
419 &BaseAddress,
420 0,
421 &Size,
422 MEM_COMMIT,
423 PAGE_NOACCESS);
424 ok_ntstatus(Status, STATUS_CONFLICTING_ADDRESSES);
425
426 /* Commit a page */
427 BaseAddress = UlongToPtr(0x50000000);
428 Size = 0x1000;
429 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
430 &BaseAddress,
431 0,
432 &Size,
433 MEM_COMMIT,
434 PAGE_READWRITE);
435 ok_ntstatus(Status, STATUS_SUCCESS);
436
437 /* Commit another page */
438 BaseAddress = UlongToPtr(0x50002000);
439 Size = 0x1000;
440 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
441 &BaseAddress,
442 0,
443 &Size,
444 MEM_COMMIT,
445 PAGE_NOACCESS);
446 ok_ntstatus(Status, STATUS_SUCCESS);
447
448 _SEH2_TRY
449 {
450 *(int*)UlongToPtr(0x50000000) = 1;
451 }
452 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
453 {
454 ok(0, "Got exception\n");
455 }
456 _SEH2_END;
457
458 _SEH2_TRY
459 {
460 (void)*(volatile int*)UlongToPtr(0x50002000);
461 }
462 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
463 {
464 Status = _SEH2_GetExceptionCode();
465 }
466 _SEH2_END;
467 ok_ntstatus(Status, STATUS_ACCESS_VIOLATION);
468
469 /* Allocate 3 pages, on top of the previous 2 */
470 BaseAddress = UlongToPtr(0x50000000);
471 Size = 0x3000;
472 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
473 &BaseAddress,
474 0,
475 &Size,
476 MEM_COMMIT,
477 PAGE_READONLY);
478 ok_ntstatus(Status, STATUS_SUCCESS);
479
480 _SEH2_TRY
481 {
482 *(int*)UlongToPtr(0x50000000) = 1;
483 }
484 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
485 {
486 Status = _SEH2_GetExceptionCode();
487 }
488 _SEH2_END;
489 ok_ntstatus(Status, STATUS_ACCESS_VIOLATION);
490
491 /* Commit a page at the end of the first region */
492 BaseAddress = UlongToPtr(0x5000F000);
493 Size = 0x1000;
494 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
495 &BaseAddress,
496 0,
497 &Size,
498 MEM_COMMIT,
499 PAGE_READWRITE);
500 ok_ntstatus(Status, STATUS_SUCCESS);
501 ok_ptr(BaseAddress, UlongToPtr(0x5000F000));
502
503 /* See where is the base of this newly committed area
504 * (choose a base address in the middle of it) */
505 Status = NtQueryVirtualMemory(NtCurrentProcess(),
506 UlongToPtr(0x5000F700),
507 MemoryBasicInformation,
508 &MemoryBasicInfo,
509 sizeof(MemoryBasicInfo),
510 NULL);
511 ok_ntstatus(Status, STATUS_SUCCESS);
512 /* The base address is the beginning of the committed area */
513 ok_ptr(MemoryBasicInfo.BaseAddress, UlongToPtr(0x5000F000));
514 /* The allocation base address is the beginning of the whole region */
515 ok_ptr(MemoryBasicInfo.AllocationBase, UlongToPtr(0x50000000));
516 /* This is the protection of the memory when it was reserved. */
517 ok_long(MemoryBasicInfo.AllocationProtect, PAGE_NOACCESS);
518 /* This is the size of the committed region. (ie, smallest chunk size) */
519 ok_long(MemoryBasicInfo.RegionSize, 0x1000);
520 /* This is the state of the queried address */
521 ok_long(MemoryBasicInfo.State, MEM_COMMIT);
522 /* This is the protection of the queried address */
523 ok_long(MemoryBasicInfo.Protect, PAGE_READWRITE);
524 /* NtAllocateVirtualMemory makes it MEM_PRIVATE */
525 ok_long(MemoryBasicInfo.Type, MEM_PRIVATE);
526
527 /* Try to free the whole region at once */
528 BaseAddress = UlongToPtr(0x50000000);
529 Size = 0x30000;
530 Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
531 ok_ntstatus(Status, STATUS_UNABLE_TO_FREE_VM);
532
533 BaseAddress = UlongToPtr(0x50000000);
534 Size = 0x10000;
535 Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
536 ok_ntstatus(Status, STATUS_SUCCESS);
537
538 BaseAddress = UlongToPtr(0x50010000);
539 Size = 0x10000;
540 Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
541 ok_ntstatus(Status, STATUS_SUCCESS);
542
543 BaseAddress = UlongToPtr(0x50020000);
544 Size = 0x10000;
545 Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
546 ok_ntstatus(Status, STATUS_SUCCESS);
547
548 /* Reserve 3 full 64k region */
549 BaseAddress = UlongToPtr(0x50000000);
550 Size = 0x30000;
551 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
552 &BaseAddress,
553 0,
554 &Size,
555 MEM_RESERVE,
556 PAGE_NOACCESS);
557 ok_ntstatus(Status, STATUS_SUCCESS);
558 if (!NT_SUCCESS(Status))
559 return;
560
561 /* Release the 64k region in the middle */
562 BaseAddress = UlongToPtr(0x50010000);
563 Size = 0x10000;
564 Status = NtFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &Size, MEM_RELEASE);
565 ok_ntstatus(Status, STATUS_SUCCESS);
566
567 }
568
569 #define RUNS 32
570
571 START_TEST(NtAllocateVirtualMemory)
572 {
573 PVOID Mem1, Mem2;
574 SIZE_T Size1, Size2;
575 ULONG i;
576 NTSTATUS Status;
577
578 CheckAlignment();
579 CheckAdjacentVADs();
580
581 /* Reserve memory below 0x10000 */
582 Mem1 = UlongToPtr(0xf000);
583 Size1 = 0x1000;
584 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
585 &Mem1,
586 0,
587 &Size1,
588 MEM_RESERVE,
589 PAGE_READWRITE);
590 ok_ntstatus(Status, STATUS_INVALID_PARAMETER_2);
591
592 /* Reserve memory at 0x10000 */
593 Mem1 = UlongToPtr(0x10000);
594 Size1 = 0x1000;
595 Status = NtAllocateVirtualMemory(NtCurrentProcess(),
596 &Mem1,
597 0,
598 &Size1,
599 MEM_RESERVE,
600 PAGE_READWRITE);
601 ok_ntstatus(Status, STATUS_CONFLICTING_ADDRESSES);
602
603 Size1 = 32;
604 Mem1 = Allocate(Size1);
605 AccessMemory1(Mem1, Size1);
606 Size2 = 128;
607 Mem2 = Allocate(Size2);
608 AccessMemory2(Mem2, Size2);
609 for (i = 0; i < RUNS; ++i)
610 {
611 PVOID New;
612 ok(CheckMemory1(Mem1, Size1) == TRUE, "CheckMemory1 failure\n");
613 New = ReAllocate(Mem1, Size1 * 3 / 2);
614 if (New == NULL)
615 {
616 skip("Realloc failure\n");
617 break;
618 }
619 Mem1 = New;
620 ok(CheckMemory1(Mem1, Size1) == TRUE, "CheckMemory1 failure\n");
621 Size1 = Size1 * 3 / 2;
622 AccessMemory1(Mem1, Size1);
623
624 ok(CheckMemory2(Mem2, Size2) == TRUE, "CheckMemory2 failure\n");
625 New = ReAllocate(Mem2, Size2 + 128);
626 if (New == NULL)
627 {
628 skip("Realloc failure\n");
629 break;
630 }
631 Mem2 = New;
632 ok(CheckMemory2(Mem2, Size2) == TRUE, "CheckMemory2 failure\n");
633 Size2 += 128;
634 AccessMemory2(Mem2, Size2);
635 }
636 ok(CheckMemory2(Mem2, Size2) == TRUE, "CheckMemory2 failure\n");
637 Free(Mem2);
638 ok(CheckMemory1(Mem1, Size1) == TRUE, "CheckMemory1 failure\n");
639 Free(Mem1);
640 }