| 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:  virtualfree.c | 
| 8 | ** | 
| 9 | ** Purpose: Positive test the VirtualFree API. | 
| 10 | **          Call VirtualFree with MEM_RELEASE | 
| 11 | **          and MEM_DECOMMIT free operation type | 
| 12 | ** | 
| 13 | ** | 
| 14 | **============================================================*/ | 
| 15 | #include <palsuite.h> | 
| 16 |  | 
| 17 | #define VIRTUALSIZE 1024 | 
| 18 |  | 
| 19 |  | 
| 20 | int __cdecl main(int argc, char *argv[]) | 
| 21 | { | 
| 22 |     int err; | 
| 23 |     LPVOID lpVirtualAddress; | 
| 24 |  | 
| 25 |     //Initialize the PAL environment | 
| 26 |     err = PAL_Initialize(argc, argv); | 
| 27 |     if(0 != err) | 
| 28 |     { | 
| 29 |         ExitProcess(FAIL); | 
| 30 |     } | 
| 31 |      | 
| 32 |     //Allocate the physical storage in memory or in the paging file on disk  | 
| 33 |     lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region | 
| 34 |             VIRTUALSIZE,         //specify the size  | 
| 35 |             MEM_RESERVE,         //allocation type | 
| 36 |             PAGE_NOACCESS);      //access protection | 
| 37 |     if(NULL == lpVirtualAddress) | 
| 38 |     { | 
| 39 |         Fail("\nFailed to call VirtualAlloc API!\n" ); | 
| 40 |     } | 
| 41 |  | 
| 42 |     //decommit and release the specified region | 
| 43 |     err = VirtualFree(lpVirtualAddress,     //base address | 
| 44 |                     VIRTUALSIZE,            //decommited size | 
| 45 |                     MEM_DECOMMIT|MEM_RELEASE);//free operation | 
| 46 |     if(0 != err) | 
| 47 |     { | 
| 48 |         Fail("\nFailed to call VirtualFree API!\n" ); | 
| 49 |     } | 
| 50 |  | 
| 51 |     PAL_Terminate(); | 
| 52 |     return PASS; | 
| 53 | } | 
| 54 |  |