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_NOACCESS access protection |
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 | |
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_COMMIT|MEM_TOP_DOWN, //allocation type |
34 | PAGE_NOACCESS); //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 | |