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** free operation type
12**
13**
14**============================================================*/
15#include <palsuite.h>
16
17int __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 PAL_Terminate();
38 return 1;
39 }
40
41 //decommit the specified region
42 err = VirtualFree(lpVirtualAddress,//base address
43 0, //must be zero with MEM_RELEASE
44 MEM_RELEASE);//free operation
45 if(0 == err)
46 {
47 Fail("\nFailed to call VirtualFree API!\n");
48 PAL_Terminate();
49 return 1;
50 }
51
52 PAL_Terminate();
53 return PASS;
54}
55