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