| 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: createfilemapping.c (test 8) |
| 8 | ** |
| 9 | ** Purpose: Positive test the CreateFileMapping API. |
| 10 | ** Test the un-verifiable parameter combinations. |
| 11 | ** |
| 12 | ** |
| 13 | **============================================================*/ |
| 14 | #include <palsuite.h> |
| 15 | |
| 16 | const int MAPPINGSIZE = 2048; |
| 17 | HANDLE SWAP_HANDLE = ((VOID *)(-1)); |
| 18 | |
| 19 | int __cdecl main(int argc, char *argv[]) |
| 20 | { |
| 21 | HANDLE hFileMap; |
| 22 | |
| 23 | /* Initialize the PAL environment. |
| 24 | */ |
| 25 | if(0 != PAL_Initialize(argc, argv)) |
| 26 | { |
| 27 | return FAIL; |
| 28 | } |
| 29 | |
| 30 | /* Create a READONLY, "swap", un-named file mapping. |
| 31 | * This test is unverifiable since there is no hook back to the file map |
| 32 | * because it is un-named. As well, since it resides in "swap", and is |
| 33 | * initialized to zero, there is nothing to read. |
| 34 | */ |
| 35 | hFileMap = CreateFileMapping( |
| 36 | SWAP_HANDLE, |
| 37 | NULL, /*not inherited*/ |
| 38 | PAGE_READONLY, /*read only*/ |
| 39 | 0, /*high-order size*/ |
| 40 | MAPPINGSIZE, /*low-order size*/ |
| 41 | NULL); /*un-named object*/ |
| 42 | |
| 43 | if(NULL == hFileMap) |
| 44 | { |
| 45 | Fail("ERROR:%u: Failed to create File Mapping.\n" , |
| 46 | GetLastError()); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | /* Create a COPYWRITE, "swap", un-named file mapping. |
| 51 | * This test is unverifiable, here is a quote from MSDN: |
| 52 | * |
| 53 | * Copy on write access. If you create the map with PAGE_WRITECOPY and |
| 54 | * the view with FILE_MAP_COPY, you will receive a view to file. If you |
| 55 | * write to it, the pages are automatically swappable and the modifications |
| 56 | * you make will not go to the original data file. |
| 57 | * |
| 58 | */ |
| 59 | hFileMap = CreateFileMapping( |
| 60 | SWAP_HANDLE, |
| 61 | NULL, /*not inherited*/ |
| 62 | PAGE_WRITECOPY, /*read only*/ |
| 63 | 0, /*high-order size*/ |
| 64 | MAPPINGSIZE, /*low-order size*/ |
| 65 | NULL); /*unnamed object*/ |
| 66 | |
| 67 | if(NULL == hFileMap) |
| 68 | { |
| 69 | Fail("ERROR:%u: Failed to create File Mapping.\n" , |
| 70 | GetLastError()); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | /* Terminate the PAL. |
| 75 | */ |
| 76 | PAL_Terminate(); |
| 77 | return PASS; |
| 78 | } |
| 79 | |
| 80 | |