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