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** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type
11** and PAGE_EXECUTE_READ access protection
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|MEM_TOP_DOWN, //allocation type
33 PAGE_EXECUTE_READ); //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