| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | /*============================================================= |
| 6 | ** |
| 7 | ** Source: virtualalloc.c |
| 8 | ** |
| 9 | ** Purpose: Positive test the VirtualAlloc API. |
| 10 | ** Ensure that memory re-committed through VirtualAlloc |
| 11 | ** is not changed. |
| 12 | ** |
| 13 | ** |
| 14 | **============================================================*/ |
| 15 | #include <palsuite.h> |
| 16 | |
| 17 | int __cdecl main(int argc, char *argv[]) |
| 18 | { |
| 19 | int err; |
| 20 | int *ptr; |
| 21 | |
| 22 | //Initialize the PAL environment |
| 23 | err = PAL_Initialize(argc, argv); |
| 24 | if(0 != err) |
| 25 | { |
| 26 | ExitProcess(FAIL); |
| 27 | } |
| 28 | |
| 29 | ptr = (int *) VirtualAlloc(NULL, 4096, MEM_COMMIT | MEM_RESERVE, |
| 30 | PAGE_READWRITE); |
| 31 | if (ptr == NULL) |
| 32 | { |
| 33 | Fail("First VirtualAlloc failed!\n" ); |
| 34 | } |
| 35 | |
| 36 | *ptr = 123; |
| 37 | |
| 38 | ptr = (int *) VirtualAlloc(ptr, 4096, MEM_COMMIT, PAGE_READWRITE); |
| 39 | if (ptr == NULL) |
| 40 | { |
| 41 | Fail("Second VirtualAlloc failed!\n" ); |
| 42 | } |
| 43 | if (*ptr != 123) |
| 44 | { |
| 45 | Fail("VirtualAlloc modified (probably zeroed) re-committed memory!\n" ); |
| 46 | } |
| 47 | |
| 48 | PAL_Terminate(); |
| 49 | return PASS; |
| 50 | } |
| 51 | |