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