summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.c
blob: 1ff137d8d3aa3fadbdf390e4bc090e260e2f0208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*=============================================================
**
** Source:  createfilemappingw.c (test 8)
**
** Purpose: Positive test the CreateFileMappingW API.
**          Test the un-verifiable parameter combinations.
**
**
**============================================================*/
#define UNICODE
#include <palsuite.h>

const   int MAPPINGSIZE = 2048;
HANDLE  SWAP_HANDLE     = ((VOID *)(-1));

int __cdecl main(int argc, char *argv[])
{
    WCHAR   lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'};
    
    HANDLE  hFileMap;

    /* Initialize the PAL environment.
     */
    if(0 != PAL_Initialize(argc, argv))
    {
        return FAIL;
    }

    /* Create a READONLY, "swap", un-named file mapping.
     * This test is unverifiable since there is no hook back to the file map
     * because it is un-named. As well, since it resides in "swap", and is
     * initialized to zero, there is nothing to read.
     */
    hFileMap = CreateFileMapping(
                            SWAP_HANDLE,
                            NULL,               /*not inherited*/
                            PAGE_READONLY,      /*read only*/
                            0,                  /*high-order size*/
                            MAPPINGSIZE,        /*low-order size*/
                            NULL);              /*un-named object*/

    if(NULL == hFileMap)
    {
        Fail("ERROR:%u: Failed to create File Mapping.\n", 
              GetLastError());
    }

    
    /* Create a COPYWRITE, "swap", un-named file mapping.
     * This test is unverifiable, here is a quote from MSDN:
     * 
     * Copy on write access. If you create the map with PAGE_WRITECOPY and 
     * the view with FILE_MAP_COPY, you will receive a view to file. If you 
     * write to it, the pages are automatically swappable and the modifications
     * you make will not go to the original data file. 
     *
     */
    hFileMap = CreateFileMapping(
                            SWAP_HANDLE,
                            NULL,               /*not inherited*/
                            PAGE_WRITECOPY,     /*write copy*/
                            0,                  /*high-order size*/
                            MAPPINGSIZE,        /*low-order size*/
                            NULL);              /*unnamed object*/

    if(NULL == hFileMap)
    {
        Fail("ERROR:%u: Failed to create File Mapping.\n", 
              GetLastError());
    }


    /* Terminate the PAL.
     */ 
    PAL_Terminate();
    return PASS;
}