summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/filemapping_memmgt
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/filemapping_memmgt')
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CMakeLists.txt28
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/CMakeLists.txt11
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CreateFileMapping.c173
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CreateFileMapping.c155
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CreateFileMapping.c181
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CreateFileMapping.c193
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CreateFileMapping.c164
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/createfilemapping.c164
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/createfilemapping.c79
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/createfilemapping.c150
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CMakeLists.txt16
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.c93
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.c174
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.c124
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.c156
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.c182
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.c194
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.c165
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.c165
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.c82
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.c151
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/CMakeLists.txt5
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/CMakeLists.txt20
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/FreeLibrary.c128
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/dlltest.c32
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/test2.c52
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/CMakeLists.txt4
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/CMakeLists.txt20
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/dlltest.c32
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/test1.c183
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/testinfo.dat17
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/CMakeLists.txt5
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.c92
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.c49
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/CMakeLists.txt5
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/GetModuleFileNameW.c112
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/GetModuleFileNameW.c57
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/CMakeLists.txt5
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/CMakeLists.txt20
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/test1.c111
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testinfo.dat19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testlib.c33
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/CMakeLists.txt20
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/test2.c152
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testinfo.dat18
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testlib.c33
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/CMakeLists.txt4
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/GetProcessHeap.c39
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/CMakeLists.txt6
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.c100
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.c59
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.c62
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapFree/CMakeLists.txt4
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/HeapFree.c62
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/CMakeLists.txt8
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/test1.c72
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/test2.c79
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/test3.c78
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/testinfo.dat16
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/test4.c80
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/test5.c69
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/CMakeLists.txt4
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/LocalAlloc.c49
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LocalFree/CMakeLists.txt5
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/LocalFree.c49
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/LocalFree.c39
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/CMakeLists.txt10
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/LockFile.h152
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/CMakeLists.txt36
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/helper.c86
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/test1.c140
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/test2.c94
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/CMakeLists.txt36
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/helper.c102
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/test3.c71
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/testinfo.dat16
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/test4.c231
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/CMakeLists.txt36
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/helper.c122
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/test5.c161
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/testinfo.dat17
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/CMakeLists.txt36
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/helper.c71
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/test6.c146
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/test7.c135
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/CMakeLists.txt9
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/MapViewOfFile.c226
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/MapViewOfFile.c203
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/MapViewOfFile.c209
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/mapviewoffile.c166
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.c131
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/mapviewoffile.c85
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/CMakeLists.txt6
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/OpenFileMappingA.c157
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/OpenFileMappingA.c214
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/OpenFileMappingA.c217
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/CMakeLists.txt6
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/OpenFileMappingW.c155
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/OpenFileMappingW.c217
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/OpenFileMappingW.c210
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/CMakeLists.txt6
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/ReadProcessMemory_neg.c127
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/ReadProcessMemory.c126
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/CMakeLists.txt36
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/commonconsts.h48
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/helper.c249
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/test2.c258
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/testinfo.dat18
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/CMakeLists.txt7
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/test1.c56
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/test3.c72
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/testinfo.dat17
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/test4.c76
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/testinfo.dat18
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/test5.c63
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/testinfo.dat18
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/CMakeLists.txt7
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/UnlockFile.h112
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/CMakeLists.txt36
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/helper.c92
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/test1.c154
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/testinfo.dat17
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/test2.c154
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/testinfo.dat16
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/CMakeLists.txt36
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/helper.c103
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/test3.c142
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/testinfo.dat17
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/test4.c187
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/testinfo.dat16
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/CMakeLists.txt5
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/UnmapViewOfFile.c184
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/unmapviewoffile.c42
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/CMakeLists.txt24
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/VirtualAlloc.c50
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/VirtualAlloc.c48
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/VirtualAlloc.c49
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/VirtualAlloc.c48
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/VirtualAlloc.c48
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/VirtualAlloc.c48
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/VirtualAlloc.c48
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/VirtualAlloc.c48
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/VirtualAlloc.c49
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/VirtualAlloc.c49
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/VirtualAlloc.c51
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/VirtualAlloc.c49
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/virtualalloc.c50
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/testinfo.dat12
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/virtualalloc.c54
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/VirtualAlloc.c48
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/VirtualAlloc.c49
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/VirtualAlloc.c50
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/VirtualAlloc.c48
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/VirtualAlloc.c53
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/VirtualAlloc.c48
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/VirtualAlloc.c48
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/CMakeLists.txt6
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/VirtualFree.c48
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/VirtualFree.c54
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/VirtualFree.c53
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/CMakeLists.txt9
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/VirtualProtect.c69
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/VirtualProtect.c69
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/VirtualProtect.c69
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/VirtualProtect.c68
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/VirtualProtect.c68
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/VirtualProtect.c69
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/CMakeLists.txt4
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/VirtualQuery.c68
-rw-r--r--src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/testinfo.dat12
348 files changed, 15934 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CMakeLists.txt
new file mode 100644
index 0000000000..3fc399fe59
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CMakeLists.txt
@@ -0,0 +1,28 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(CreateFileMappingA)
+add_subdirectory(CreateFileMappingW)
+add_subdirectory(FreeLibrary)
+add_subdirectory(FreeLibraryAndExitThread)
+add_subdirectory(GetModuleFileNameA)
+add_subdirectory(GetModuleFileNameW)
+add_subdirectory(GetProcAddress)
+add_subdirectory(GetProcessHeap)
+add_subdirectory(HeapAlloc)
+add_subdirectory(HeapFree)
+add_subdirectory(HeapReAlloc)
+add_subdirectory(LocalAlloc)
+add_subdirectory(LocalFree)
+add_subdirectory(LockFile)
+add_subdirectory(MapViewOfFile)
+add_subdirectory(OpenFileMappingA)
+add_subdirectory(OpenFileMappingW)
+add_subdirectory(ReadProcessMemory)
+add_subdirectory(RtlMoveMemory)
+add_subdirectory(UnlockFile)
+add_subdirectory(UnmapViewOfFile)
+add_subdirectory(VirtualAlloc)
+add_subdirectory(VirtualFree)
+add_subdirectory(VirtualProtect)
+add_subdirectory(VirtualQuery)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/CMakeLists.txt
new file mode 100644
index 0000000000..0223c4d9b5
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test3)
+add_subdirectory(test4)
+add_subdirectory(test5)
+add_subdirectory(test6)
+add_subdirectory(test7)
+add_subdirectory(test8)
+add_subdirectory(test9)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CMakeLists.txt
new file mode 100644
index 0000000000..36084bf446
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ CreateFileMapping.c
+)
+
+add_executable(paltest_createfilemappinga_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappinga_test1 coreclrpal)
+
+target_link_libraries(paltest_createfilemappinga_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CreateFileMapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CreateFileMapping.c
new file mode 100644
index 0000000000..91640bfd04
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/CreateFileMapping.c
@@ -0,0 +1,173 @@
+// 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: createfilemapping.c (test 1)
+**
+** Purpose: Positive test the CreateFileMapping API.
+** Call CreateFileMapping with access PAGE_READONLY.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE hFile;
+ char buf[] = "this is a test string";
+ char ch[2048];
+ char lpFileName[] = "test.tmp";
+ DWORD dwBytesWritten;
+ BOOL err;
+ int RetVal = PASS;
+
+ HANDLE hFileMapping;
+ LPVOID lpMapViewAddress;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file handle with CreateFile.
+ */
+ hFile = CreateFile( lpFileName,
+ GENERIC_WRITE|GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: %u :unable to create file \"%s\".\n",
+ GetLastError(),
+ lpFileName);
+ }
+
+ /* Initialize the buffers.
+ */
+ memset(ch, 0, MAPPINGSIZE);
+
+ /* Write to the File handle.
+ */
+ err = WriteFile(hFile,
+ buf,
+ strlen(buf),
+ &dwBytesWritten,
+ NULL);
+
+ if (err == FALSE)
+ {
+ Trace("ERROR: %u :unable to write to file handle "
+ "hFile=0x%lx\n",
+ GetLastError(),
+ hFile);
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Flush to the hard-drive.
+ */
+ FlushFileBuffers(hFile);
+
+ /* Create a unnamed file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READONLY, /*read and wite*/
+ 0, /*high-order size*/
+ 0, /*low-order size*/
+ NULL); /*unnamed object*/
+
+ if(NULL == hFileMapping)
+ {
+ Trace("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_READ, /* access code */
+ 0, /*high order offset*/
+ 0, /*low order offset*/
+ 0); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Copy the MapViewOfFile to buffer, so we can
+ * compare with value read from file directly.
+ */
+ memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE);
+ if (memcmp(ch, buf, strlen(buf))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ ch, buf);
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+CleanUpThree:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Close Handle to opend file mapping.
+ */
+ if ( CloseHandle(hFileMapping) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapping);
+ RetVal = FAIL;
+ }
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(hFile) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFile);
+ RetVal = FAIL;
+ }
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/testinfo.dat
new file mode 100644
index 0000000000..36ff3238c7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test1/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMapping
+Name = CreateFileMappingA with PAGE_READONLY
+TYPE = DEFAULT
+EXE1 = createfilemapping
+Description
+=Test the CreateFileMapping to create a named file-mapping object
+=and with PAGE_READONLY protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CMakeLists.txt
new file mode 100644
index 0000000000..374f8f0946
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ CreateFileMapping.c
+)
+
+add_executable(paltest_createfilemappinga_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappinga_test3 coreclrpal)
+
+target_link_libraries(paltest_createfilemappinga_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CreateFileMapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CreateFileMapping.c
new file mode 100644
index 0000000000..2a849d86b8
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/CreateFileMapping.c
@@ -0,0 +1,155 @@
+// 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: createfilemapping.c (test 3)
+**
+** Purpose: Positive test the CreateFileMapping API.
+** Call CreateFileMapping with access PAGE_READWRITE.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE hFile;
+ char buf[] = "this is a test string";
+ char ch[2048];
+ char lpFileName[] = "test.tmp";
+ HANDLE hFileMapping;
+ LPVOID lpMapViewAddress;
+ int RetVal = PASS;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file handle with CreateFile.
+ */
+ hFile = CreateFile( lpFileName,
+ GENERIC_WRITE|GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: %u :unable to create file \"%s\".\n",
+ GetLastError(),
+ lpFileName);
+ }
+
+ /* Initialize the buffers.
+ */
+ memset(ch, 0, MAPPINGSIZE);
+
+ /* Create a unnamed file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read and wite*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ NULL); /*unnamed object*/
+
+ if(NULL == hFileMapping)
+ {
+ Trace("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /*high order offset*/
+ 0, /*low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Write to the Map view.
+ */
+ memcpy(lpMapViewAddress, buf, strlen(buf));
+
+ /* Read from the Map view.
+ */
+ memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE);
+
+ /* Copy the MapViewOfFile to buffer, so we can
+ * compare with value read from file directly.
+ */
+ if (memcmp(ch, buf, strlen(buf))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ ch, buf);
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+CleanUpThree:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Close Handle to opend file mapping.
+ */
+ if ( CloseHandle(hFileMapping) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapping);
+ RetVal = FAIL;
+ }
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(hFile) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFile);
+ RetVal = FAIL;
+ }
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/testinfo.dat
new file mode 100644
index 0000000000..4689ee6a08
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test3/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMapping
+Name = CreateFileMappingA with PAGE_READWRITE
+TYPE = DEFAULT
+EXE1 = createfilemapping
+Description
+=Test the CreateFileMapping to create a unnamed file-mapping object
+=and with PAGE_READWRITE protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CMakeLists.txt
new file mode 100644
index 0000000000..665b10a3f0
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ CreateFileMapping.c
+)
+
+add_executable(paltest_createfilemappinga_test4
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappinga_test4 coreclrpal)
+
+target_link_libraries(paltest_createfilemappinga_test4
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CreateFileMapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CreateFileMapping.c
new file mode 100644
index 0000000000..64caa88ca0
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/CreateFileMapping.c
@@ -0,0 +1,181 @@
+// 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: createfilemapping.c (test 4)
+**
+** Purpose: Positive test the CreateFileMapping API.
+** Call CreateFileMapping with access PAGE_WRITECOPY.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE hFile;
+ char buf[] = "this is a test string";
+ char ch[2048];
+ char lpFileName[] = "test.tmp";
+ HANDLE hFileMapping;
+ LPVOID lpMapViewAddress;
+ int RetVal = PASS;
+ int err;
+ DWORD dwBytesWritten;
+
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file handle with CreateFile.
+ */
+ hFile = CreateFile( lpFileName,
+ GENERIC_WRITE|GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: %u :unable to create file \"%s\".\n",
+ GetLastError(),
+ lpFileName);
+ }
+
+ /* Write to the File handle.
+ */
+ err = WriteFile(hFile,
+ buf,
+ strlen(buf),
+ &dwBytesWritten,
+ NULL);
+
+ if (err == FALSE)
+ {
+ Trace("ERROR: %u :unable to write to file handle "
+ "hFile=0x%lx\n",
+ GetLastError(),
+ hFile);
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Flush to the hard-drive.
+ */
+ FlushFileBuffers(hFile);
+
+ /* Initialize the buffers.
+ */
+ memset(ch, 0, MAPPINGSIZE);
+
+ /* Create a unnamed file-mapping object with file handle FileHandle
+ * and with PAGE_WRITECOPY protection.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_WRITECOPY, /*write copy*/
+ 0, /*high-order size*/
+ 0, /*low-order size*/
+ NULL); /*unnamed object*/
+
+ if(NULL == hFileMapping)
+ {
+ Trace("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_COPY, /* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ 0); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Write to the Map view.3
+ */
+ memcpy(lpMapViewAddress, buf, strlen(buf));
+
+ /* Read from the Map view.
+ */
+ memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE);
+
+ /* Copy the MapViewOfFile to buffer, so we can
+ * compare with value read from file directly.
+ */
+ if (memcmp(ch, buf, strlen(buf))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ ch, buf);
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+CleanUpThree:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Close Handle to opend file mapping.
+ */
+ if ( CloseHandle(hFileMapping) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapping);
+ RetVal = FAIL;
+ }
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(hFile) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFile);
+ RetVal = FAIL;
+ }
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/testinfo.dat
new file mode 100644
index 0000000000..7d9dda1a96
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test4/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMapping
+Name = CreateFileMappingA with PAGE_WRITECOPY.
+TYPE = DEFAULT
+EXE1 = createfilemapping
+Description
+= Positive test the CreateFileMapping API.
+= Call CreateFileMapping with access PAGE_WRITECOPY.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CMakeLists.txt
new file mode 100644
index 0000000000..6f7f3c3635
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ CreateFileMapping.c
+)
+
+add_executable(paltest_createfilemappinga_test5
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappinga_test5 coreclrpal)
+
+target_link_libraries(paltest_createfilemappinga_test5
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CreateFileMapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CreateFileMapping.c
new file mode 100644
index 0000000000..c7f9918b08
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/CreateFileMapping.c
@@ -0,0 +1,193 @@
+// 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: createfilemapping.c (test 5)
+**
+** Purpose: Positive test the CreateFileMapping API.
+** Test CreateFileMapping to a "swap" handle with
+** access PAGE_READONLY.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+HANDLE SWAP_HANDLE = ((VOID *)(-1));
+
+int __cdecl main(int argc, char *argv[])
+{
+ char testString[] = "this is a test string";
+ char lpObjectName[] = "myMappingObject";
+ int RetVal = FAIL;
+ char results[2048];
+
+ HANDLE hFileMapRO;
+ HANDLE hFileMapRW;
+ LPVOID lpMapViewRO;
+ LPVOID lpMapViewRW;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Initialize the buffers.
+ */
+ memset(results, 0, MAPPINGSIZE);
+
+ /* Create a named file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapRW = CreateFileMapping(
+ SWAP_HANDLE,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read only*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ lpObjectName); /*named object*/
+
+ if(NULL == hFileMapRW)
+ {
+ Fail("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewRW = MapViewOfFile(
+ hFileMapRW,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewRW)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+
+ hFileMapRO = CreateFileMapping(
+ SWAP_HANDLE,
+ NULL, /*not inherited*/
+ PAGE_READONLY, /*read and write*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ lpObjectName); /*named object*/
+
+ if(NULL == hFileMapRO)
+ {
+ Trace("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewRO = MapViewOfFile(
+ hFileMapRO,
+ FILE_MAP_READ, /* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewRO)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+ /* Write the test string to the Map view.
+ */
+ memcpy(lpMapViewRW, testString, strlen(testString));
+
+ /* Read from the second Map view.
+ */
+ memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE);
+
+ /* Verify the contents of the file mapping,
+ * by comparing what was written to what was read.
+ */
+ if (memcmp(results, testString, strlen(testString))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ results,
+ testString);
+ RetVal = FAIL;
+ goto CleanUpFour;
+ }
+
+ /* Test was successful.
+ */
+ RetVal = PASS;
+
+CleanUpFour:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewRO) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewRO);
+ RetVal = FAIL;
+ }
+
+CleanUpThree:
+
+ /* Close Handle to opend file mapping.
+ */
+ if ( CloseHandle(hFileMapRO) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapRO);
+ RetVal = FAIL;
+ }
+
+
+CleanUpTwo:
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewRW) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewRW);
+ RetVal = FAIL;
+ }
+
+
+CleanUpOne:
+
+ /* Close Handle to opend file mapping.
+ */
+ if ( CloseHandle(hFileMapRW) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapRW);
+ RetVal = FAIL;
+ }
+
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/testinfo.dat
new file mode 100644
index 0000000000..137db9d82b
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test5/testinfo.dat
@@ -0,0 +1,14 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMapping
+Name = CreateFileMappingA - with PAGE_READWRITE and INVALID_HANDLE_VALUE file handle
+TYPE = DEFAULT
+EXE1 = createfilemapping
+Description
+=Test the CreateFileMapping to create a unnamed file-mapping object
+=and with PAGE_READWRITE protection by passing INVALID_HANDLE_VALUE
+=file handle
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CMakeLists.txt
new file mode 100644
index 0000000000..2f5d98b5e6
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ CreateFileMapping.c
+)
+
+add_executable(paltest_createfilemappinga_test6
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappinga_test6 coreclrpal)
+
+target_link_libraries(paltest_createfilemappinga_test6
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CreateFileMapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CreateFileMapping.c
new file mode 100644
index 0000000000..6445295de8
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/CreateFileMapping.c
@@ -0,0 +1,164 @@
+// 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: createfilemapping.c (test 6)
+**
+** Purpose: Positive test the CreateFileMapping API.
+** Test CreateFileMapping to a "swap" handle with
+** access PAGE_READWRITE.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+HANDLE SWAP_HANDLE = ((VOID *)(-1));
+
+int __cdecl main(int argc, char *argv[])
+{
+ char testString[] = "this is a test string";
+ char lpObjectName[] = "myMappingObject";
+ char results[2048];
+ int RetVal = PASS;
+
+ HANDLE hFileMapRW;
+ LPVOID lpMapViewRW;
+ LPVOID lpMapViewRW2;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Initialize the buffers.
+ */
+ memset(results, 0, MAPPINGSIZE);
+
+ /* Create a named file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapRW = CreateFileMapping(
+ SWAP_HANDLE,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read write*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ lpObjectName); /*unnamed object*/
+
+ if(NULL == hFileMapRW)
+ {
+ Fail("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ }
+
+ /* Create a map view of the READWRITE file mapping.
+ */
+ lpMapViewRW = MapViewOfFile(
+ hFileMapRW,
+ FILE_MAP_ALL_ACCESS,/* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewRW)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewRW2 = MapViewOfFile(
+ hFileMapRW,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewRW2)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Write the test string to the Map view.
+ */
+ memcpy(lpMapViewRW, testString, strlen(testString));
+
+ /* Read from the second Map view.
+ */
+ memcpy(results, (LPCSTR)lpMapViewRW2, MAPPINGSIZE);
+
+ /* Verify the contents of the file mapping,
+ * by comparing what was written to what was read.
+ */
+ if (memcmp(results, testString, strlen(testString))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ results,
+ testString);
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+ /* Test successful.
+ */
+ RetVal = PASS;
+
+CleanUpThree:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewRW2) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewRW2);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewRW) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewRW);
+ RetVal = FAIL;
+ }
+
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(hFileMapRW) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapRW);
+ RetVal = FAIL;
+ }
+
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/testinfo.dat
new file mode 100644
index 0000000000..d088c5d562
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test6/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMapping
+Name = CreateFileMappingA - with PAGE_READONLY
+TYPE = DEFAULT
+EXE1 = createfilemapping
+Description
+=Test the CreateFileMapping to create a named file-mapping object
+=and with PAGE_READONLY protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/CMakeLists.txt
new file mode 100644
index 0000000000..4fd24a63a1
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ createfilemapping.c
+)
+
+add_executable(paltest_createfilemappinga_test7
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappinga_test7 coreclrpal)
+
+target_link_libraries(paltest_createfilemappinga_test7
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/createfilemapping.c
new file mode 100644
index 0000000000..7cef9ddcdc
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/createfilemapping.c
@@ -0,0 +1,164 @@
+// 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: createfilemapping.c (test 7)
+**
+** Purpose: Positive test the CreateFileMapping API.
+** Test CreateFileMapping to a "swap" handle with
+** access PAGE_READWRITE.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+HANDLE SWAP_HANDLE = ((VOID *)(-1));
+
+int __cdecl main(int argc, char *argv[])
+{
+ char testString[] = "this is a test string";
+ char lpObjectName[] = "myMappingObject";
+ char results[2048];
+ int RetVal = PASS;
+
+ HANDLE hFileMapRW;
+ LPVOID lpMapViewRW;
+ LPVOID lpMapViewRO;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Initialize the buffers.
+ */
+ memset(results, 0, MAPPINGSIZE);
+
+ /* Create a named file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapRW = CreateFileMapping(
+ SWAP_HANDLE,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read write*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ lpObjectName); /*unnamed object*/
+
+ if(NULL == hFileMapRW)
+ {
+ Fail("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ }
+
+ /* Create a map view to the READWRITE file mapping.
+ */
+ lpMapViewRW = MapViewOfFile(
+ hFileMapRW,
+ FILE_MAP_ALL_ACCESS,/* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewRW)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+
+ /* Create a map view to the READWRITE file mapping.
+ */
+ lpMapViewRO = MapViewOfFile(
+ hFileMapRW,
+ FILE_MAP_READ, /* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewRO)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Write the test string to the Map view.
+ */
+ memcpy(lpMapViewRW, testString, strlen(testString));
+
+ /* Read from the second Map view.
+ */
+ memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE);
+
+ /* Verify the contents of the file mapping,
+ * by comparing what was written to what was read.
+ */
+ if (memcmp(results, testString, strlen(testString))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ results,
+ testString);
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+ /* Test successful.
+ */
+ RetVal = PASS;
+
+CleanUpThree:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewRO) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewRO);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewRW) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewRW);
+ RetVal = FAIL;
+ }
+
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(hFileMapRW) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapRW);
+ RetVal = FAIL;
+ }
+
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/testinfo.dat
new file mode 100644
index 0000000000..c03d98a91c
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test7/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMapping
+Name = CreateFileMappingA - with PAGE_COPYWRITE
+TYPE = DEFAULT
+EXE1 = createfilemapping
+Description
+=Test the CreateFileMapping to create a named file-mapping object
+=and with PAGE_READONLY protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/CMakeLists.txt
new file mode 100644
index 0000000000..ae3ee8ddf6
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ createfilemapping.c
+)
+
+add_executable(paltest_createfilemappinga_test8
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappinga_test8 coreclrpal)
+
+target_link_libraries(paltest_createfilemappinga_test8
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/createfilemapping.c
new file mode 100644
index 0000000000..02b2fb5e61
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/createfilemapping.c
@@ -0,0 +1,79 @@
+// 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: createfilemapping.c (test 8)
+**
+** Purpose: Positive test the CreateFileMapping API.
+** Test the un-verifiable parameter combinations.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+HANDLE SWAP_HANDLE = ((VOID *)(-1));
+
+int __cdecl main(int argc, char *argv[])
+{
+ 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, /*read only*/
+ 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;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/testinfo.dat
new file mode 100644
index 0000000000..ebe138f659
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test8/testinfo.dat
@@ -0,0 +1,14 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMapping
+Name = CreateFileMappingA - unnamed swap, READWRITE.
+TYPE = DEFAULT
+EXE1 = createfilemapping
+Description
+= Positive test the CreateFileMapping API.
+= Test an unnamed File Mapping to a "swap"
+= handle with access PAGE_READWRITE.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/CMakeLists.txt
new file mode 100644
index 0000000000..a377632bed
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ createfilemapping.c
+)
+
+add_executable(paltest_createfilemappinga_test9
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappinga_test9 coreclrpal)
+
+target_link_libraries(paltest_createfilemappinga_test9
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/createfilemapping.c
new file mode 100644
index 0000000000..9224c22b4b
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/createfilemapping.c
@@ -0,0 +1,150 @@
+// 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: createfilemapping.c (test 9)
+**
+** Purpose: Negative test the CreateFileMapping API.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE hFile;
+ char lpFileName[] = "test.tmp";
+
+ HANDLE hFileMapping;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file handle with CreateFile, as READONLY
+ */
+ hFile = CreateFile( lpFileName,
+ GENERIC_READ,
+ FILE_SHARE_READ,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: %u :unable to create file \"%s\".\n",
+ GetLastError(),
+ lpFileName);
+ }
+
+ /* Attempt to create a unnamed file-mapping object to a READONLY file
+ * as READWRITE access.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read and write*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ NULL); /*unnamed object*/
+
+ if(NULL != hFileMapping)
+ {
+ Trace("ERROR: Able to create READWRITE mapping to a "
+ "READONLY file.\n" );
+ if( 0 == CloseHandle(hFile) )
+ {
+ Trace("Unexpected Error: Unable to close file handle\n");
+ }
+ Fail("");
+ }
+
+ /* Attempt to create a unnamed file-mapping object to a zero lenght
+ * file.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read and write*/
+ 0, /*high-order size*/
+ 0, /*low-order size*/
+ NULL); /*unnamed object*/
+
+ if( NULL != hFileMapping )
+ {
+ Trace("ERROR: Able to create READWRITE mapping to a "
+ "READONLY file.\n" );
+ if( 0 == CloseHandle(hFile) )
+ {
+ Trace("Unexpected Error: Unable to close file handle\n");
+ }
+ Fail("");
+ }
+ if(GetLastError() != ERROR_ACCESS_DENIED)
+ {
+ Trace("ERROR: Expected GetLastError() to return "
+ "ERROR_FILE_INVALID (%d), it returned %u.\n",
+ ERROR_FILE_INVALID,
+ GetLastError());
+ if( 0 == CloseHandle(hFile) )
+ {
+ Trace("Unexpected Error: Unable to close file handle\n");
+ }
+ Fail("");
+ }
+
+ /* Attempt to create a file mapping that is larger than
+ * the file.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READONLY, /*read only*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ NULL); /*unnamed object*/
+ if(NULL != hFileMapping)
+ {
+ Trace("ERROR: Able to create file mapping of size %d to "
+ "file of size 0.\n",
+ MAPPINGSIZE);
+ if( 0 == CloseHandle(hFile) )
+ {
+ Trace("Unexpected Error: Unable to close file handle\n");
+ }
+ Fail("");
+ }
+
+ if(GetLastError() != ERROR_NOT_ENOUGH_MEMORY )
+ {
+ Trace("ERROR: Expected GetLastError() to return "
+ "ERROR_NOT_ENOUGH_MEMORY (%d), it returned %u.\n",
+ ERROR_NOT_ENOUGH_MEMORY,
+ GetLastError());
+ if( 0 == CloseHandle(hFile) )
+ {
+ Trace("Unexpected Error: Unable to close file handle\n");
+ }
+ Fail("");
+ }
+
+ if( 0 == CloseHandle(hFile) )
+ {
+ Fail("Unexpected Error: Unable to close file handle\n");
+ }
+
+ /* Terminate the PAL.
+ */
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/testinfo.dat
new file mode 100644
index 0000000000..11cbedc8c5
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingA/test9/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMapping
+Name = CreateFileMappingA negative testing
+TYPE = DEFAULT
+EXE1 = createfilemapping
+Description
+= Negative test the CreateFileMapping API.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CMakeLists.txt
new file mode 100644
index 0000000000..85f5c90e2c
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CMakeLists.txt
@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(CreateFileMapping_neg1)
+add_subdirectory(test1)
+
+# TODO: make this test compile
+# add_subdirectory(test2)
+
+add_subdirectory(test3)
+add_subdirectory(test4)
+add_subdirectory(test5)
+add_subdirectory(test6)
+add_subdirectory(test7)
+add_subdirectory(test8)
+add_subdirectory(test9)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CMakeLists.txt
new file mode 100644
index 0000000000..a4ad343ea0
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ CreateFileMapping_neg.c
+)
+
+add_executable(paltest_createfilemappingw_createfilemapping_neg1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappingw_createfilemapping_neg1 coreclrpal)
+
+target_link_libraries(paltest_createfilemappingw_createfilemapping_neg1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.c
new file mode 100644
index 0000000000..8cf79b3c57
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/CreateFileMapping_neg.c
@@ -0,0 +1,93 @@
+// 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: createfilemapping_neg.c
+**
+** Purpose: Negative test the CreateFileMapping API.
+** Call CreateFileMapping to create a unnamed
+** file-mapping object with PAGE_READONLY
+** protection and try to map a zero length file
+** in UNICODE
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE FileHandle;
+ HANDLE FileMappingHandle;
+ int err;
+ WCHAR *lpFileName = NULL;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //conver string to a unicode one
+ lpFileName = convert("temp.txt");
+
+
+ //create a file and return the file handle
+ FileHandle = CreateFile(lpFileName,
+ GENERIC_READ,
+ FILE_SHARE_READ,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_ARCHIVE,
+ NULL);
+
+ //free this memory
+ free(lpFileName);
+
+ if(INVALID_HANDLE_VALUE == FileHandle)
+ {
+ Fail("Failed to call CreateFile to create a file\n");
+ }
+
+ //create a unnamed file-mapping object with file handle FileHandle
+ //and with PAGE_READONLY protection
+ //try to map a file which is zero length.
+ FileMappingHandle = CreateFileMapping(
+ FileHandle, //File Handle
+ NULL, //not inherited
+ PAGE_READONLY, //access protection
+ 0, //high-order of object size
+ 0, //low-orger of object size
+ NULL); //unnamed object
+
+
+ if(NULL != FileMappingHandle || ERROR_FILE_INVALID != GetLastError())
+ {//no error occurred
+ Trace("\nFailed to call CreateFileMapping API for a negative test!\n");
+ err = CloseHandle(FileHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to call CloseHandle API\n");
+ }
+ err = CloseHandle(FileMappingHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to call CloseHandle API\n");
+ }
+ Fail("");
+ }
+
+ //close the file handle
+ err = CloseHandle(FileHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to call CloseHandle API\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/testinfo.dat
new file mode 100644
index 0000000000..a09487d4b9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/CreateFileMapping_neg1/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMapping
+Name = Negative test for CreateFileMappingW - with a zero length file
+TYPE = DEFAULT
+EXE1 = createfilemapping_neg
+Description
+=Test the CreateFileMapping to try to map a zero length file
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CMakeLists.txt
new file mode 100644
index 0000000000..0c569ec9b6
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ CreateFileMappingW.c
+)
+
+add_executable(paltest_createfilemappingw_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappingw_test1 coreclrpal)
+
+target_link_libraries(paltest_createfilemappingw_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.c
new file mode 100644
index 0000000000..4263a3ad29
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/CreateFileMappingW.c
@@ -0,0 +1,174 @@
+// 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 1)
+**
+** Purpose: Positive test the CreateFileMappingW API.
+** Call CreateFileMappingW with access PAGE_READONLY.
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE hFile;
+ char buf[] = "this is a test string";
+ char ch[2048];
+ WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'};
+ DWORD dwBytesWritten;
+ BOOL err;
+ int RetVal = PASS;
+
+ HANDLE hFileMapping;
+ LPVOID lpMapViewAddress;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file handle with CreateFile.
+ */
+ hFile = CreateFile( lpFileName,
+ GENERIC_WRITE|GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: %u :unable to create file \"%s\".\n",
+ GetLastError(),
+ lpFileName);
+ }
+
+ /* Initialize the buffers.
+ */
+ memset(ch, 0, MAPPINGSIZE);
+
+ /* Write to the File handle.
+ */
+ err = WriteFile(hFile,
+ buf,
+ strlen(buf),
+ &dwBytesWritten,
+ NULL);
+
+ if (err == FALSE)
+ {
+ Trace("ERROR: %u :unable to write to file handle "
+ "hFile=0x%lx\n",
+ GetLastError(),
+ hFile);
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Flush to the hard-drive.
+ */
+ FlushFileBuffers(hFile);
+
+ /* Create a unnamed file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READONLY, /*read and wite*/
+ 0, /*high-order size*/
+ 0, /*low-order size*/
+ NULL); /*unnamed object*/
+
+ if(NULL == hFileMapping)
+ {
+ Trace("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_READ, /* access code */
+ 0, /*high order offset*/
+ 0, /*low order offset*/
+ 0); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Copy the MapViewOfFile to buffer, so we can
+ * compare with value read from file directly.
+ */
+ memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE);
+ if (memcmp(ch, buf, strlen(buf))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ ch, buf);
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+CleanUpThree:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Close Handle to opend file mapping.
+ */
+ if ( CloseHandle(hFileMapping) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapping);
+ RetVal = FAIL;
+ }
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(hFile) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFile);
+ RetVal = FAIL;
+ }
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/testinfo.dat
new file mode 100644
index 0000000000..464679a456
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test1/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMappingW
+Name = CreateFileMappingW with PAGE_READONLY
+TYPE = DEFAULT
+EXE1 = createfilemappingw
+Description
+=Test the CreateFileMappingW to create a unnamed file-mapping object
+=and with PAGE_READONLY protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CMakeLists.txt
new file mode 100644
index 0000000000..992645f48c
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ CreateFileMappingW.c
+)
+
+add_executable(paltest_createfilemappingw_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappingw_test2 coreclrpal)
+
+target_link_libraries(paltest_createfilemappingw_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.c
new file mode 100644
index 0000000000..11ff967dfd
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test2/CreateFileMappingW.c
@@ -0,0 +1,124 @@
+// 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
+**
+** Purpose: Positive test the CreateFileMapping API.
+** Call CreateFileMapping to create a unnamed
+** file-mapping object with PAGE_READONLY
+** protection and SEC_IMAGE attribute in UNICODE
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE FileHandle;
+ HANDLE FileMappingHandle;
+ int err;
+ WCHAR *wpFileName = NULL;
+ char executableFileName[256]="";
+
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+#if WIN32
+ sprintf(executableFileName,"%s","executable.exe");
+#else
+ sprintf(executableFileName,"%s","executable");
+#endif
+
+ //conver string to a unicode one
+ wpFileName = convert(executableFileName);
+
+
+ //create a file and return the file handle
+ FileHandle = CreateFile(wpFileName,
+ GENERIC_READ,
+ FILE_SHARE_READ,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_ARCHIVE,
+ NULL);
+
+ //free this memory
+ free(wpFileName);
+
+ if(INVALID_HANDLE_VALUE == FileHandle)
+ {
+ Fail("Failed to call CreateFile to create a file\n");
+ }
+
+ //create a unnamed file-mapping object with file handle FileHandle
+ //and with PAGE_READONLY protection
+ FileMappingHandle = CreateFileMapping(
+ FileHandle, //File Handle
+ NULL, //not inherited
+ PAGE_READONLY|SEC_IMAGE, //access protection and section attribute
+ 0, //high-order of object size
+ 0, //low-orger of object size
+ NULL); //unnamed object
+
+
+ if(NULL == FileMappingHandle)
+ {
+ Trace("\nFailed to call CreateFileMapping to create a mapping object!\n");
+ err = CloseHandle(FileHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to call CloseHandle API\n");
+ }
+ Fail("");
+ }
+ if(GetLastError() == ERROR_ALREADY_EXISTS)
+ {
+ Trace("\nFile mapping object already exists!\n");
+ err = CloseHandle(FileHandle);
+ if(0 == err)
+ {
+ Trace("\nFailed to call CloseHandle API to close a file handle\n");
+ err = CloseHandle(FileMappingHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to call CloseHandle API to close a mapping object handle\n");
+ }
+ Fail("");
+ }
+ err = CloseHandle(FileMappingHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to call CloseHandle API to close a mapping object handle\n");
+ }
+ Fail("");
+ }
+ err = CloseHandle(FileMappingHandle);
+ if(0 == err)
+ {
+ Trace("\nFailed to call CloseHandle API to close a mapping object handle\n");
+ err = CloseHandle(FileHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to call CloseHandle API to close a file handle\n");
+ }
+ Fail("");
+ }
+ err = CloseHandle(FileHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to call CloseHandle API to close a file handle\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CMakeLists.txt
new file mode 100644
index 0000000000..87832ffd9b
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ CreateFileMappingW.c
+)
+
+add_executable(paltest_createfilemappingw_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappingw_test3 coreclrpal)
+
+target_link_libraries(paltest_createfilemappingw_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.c
new file mode 100644
index 0000000000..1cbeff94a7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/CreateFileMappingW.c
@@ -0,0 +1,156 @@
+// 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 3)
+**
+** Purpose: Positive test the CreateFileMappingW API.
+** Call CreateFileMapping with access PAGE_READWRITE.
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE hFile;
+ char buf[] = "this is a test string";
+ char ch[2048];
+ WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'};
+ HANDLE hFileMapping;
+ LPVOID lpMapViewAddress;
+ int RetVal = PASS;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file handle with CreateFile.
+ */
+ hFile = CreateFile( lpFileName,
+ GENERIC_WRITE|GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: %u :unable to create file \"%s\".\n",
+ GetLastError(),
+ lpFileName);
+ }
+
+ /* Initialize the buffers.
+ */
+ memset(ch, 0, MAPPINGSIZE);
+
+ /* Create a unnamed file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read and wite*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ NULL); /*unnamed object*/
+
+ if(NULL == hFileMapping)
+ {
+ Trace("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /*high order offset*/
+ 0, /*low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Write to the Map view.
+ */
+ memcpy(lpMapViewAddress, buf, strlen(buf));
+
+ /* Read from the Map view.
+ */
+ memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE);
+
+ /* Copy the MapViewOfFile to buffer, so we can
+ * compare with value read from file directly.
+ */
+ if (memcmp(ch, buf, strlen(buf))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ ch, buf);
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+CleanUpThree:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Close Handle to opend file mapping.
+ */
+ if ( CloseHandle(hFileMapping) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapping);
+ RetVal = FAIL;
+ }
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(hFile) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFile);
+ RetVal = FAIL;
+ }
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/testinfo.dat
new file mode 100644
index 0000000000..1077316618
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test3/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMappingW
+Name = CreateFileMappingW with PAGE_READWRITE
+TYPE = DEFAULT
+EXE1 = createfilemappingw
+Description
+=Test the CreateFileMappingW to create a unnamed file-mapping object
+=and with PAGE_READWRITE protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CMakeLists.txt
new file mode 100644
index 0000000000..f8a5c9041f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ CreateFileMappingW.c
+)
+
+add_executable(paltest_createfilemappingw_test4
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappingw_test4 coreclrpal)
+
+target_link_libraries(paltest_createfilemappingw_test4
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.c
new file mode 100644
index 0000000000..265a317b2f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/CreateFileMappingW.c
@@ -0,0 +1,182 @@
+// 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 4)
+**
+** Purpose: Positive test the CreateFileMappingW API.
+** Call CreateFileMappingW with access PAGE_WRITECOPY.
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE hFile;
+ char buf[] = "this is a test string";
+ char ch[2048];
+ WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'};
+ HANDLE hFileMapping;
+ LPVOID lpMapViewAddress;
+ int RetVal = PASS;
+ int err;
+ DWORD dwBytesWritten;
+
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file handle with CreateFile.
+ */
+ hFile = CreateFile( lpFileName,
+ GENERIC_WRITE|GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: %u :unable to create file \"%s\".\n",
+ GetLastError(),
+ lpFileName);
+ }
+
+ /* Write to the File handle.
+ */
+ err = WriteFile(hFile,
+ buf,
+ strlen(buf),
+ &dwBytesWritten,
+ NULL);
+
+ if (err == FALSE)
+ {
+ Trace("ERROR: %u :unable to write to file handle "
+ "hFile=0x%lx\n",
+ GetLastError(),
+ hFile);
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Flush to the hard-drive.
+ */
+ FlushFileBuffers(hFile);
+
+ /* Initialize the buffers.
+ */
+ memset(ch, 0, MAPPINGSIZE);
+
+ /* Create a unnamed file-mapping object with file handle FileHandle
+ * and with PAGE_WRITECOPY protection.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_WRITECOPY, /*write copy*/
+ 0, /*high-order size*/
+ 0, /*low-order size*/
+ NULL); /*unnamed object*/
+
+ if(NULL == hFileMapping)
+ {
+ Trace("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_COPY, /* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ 0); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Write to the Map view.3
+ */
+ memcpy(lpMapViewAddress, buf, strlen(buf));
+
+ /* Read from the Map view.
+ */
+ memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE);
+
+ /* Copy the MapViewOfFile to buffer, so we can
+ * compare with value read from file directly.
+ */
+ if (memcmp(ch, buf, strlen(buf))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ ch, buf);
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+CleanUpThree:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Close Handle to opend file mapping.
+ */
+ if ( CloseHandle(hFileMapping) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapping);
+ RetVal = FAIL;
+ }
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(hFile) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFile);
+ RetVal = FAIL;
+ }
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/testinfo.dat
new file mode 100644
index 0000000000..472b857eff
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test4/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMappingW
+Name = CreateFileMappingW with PAGE_WRITECOPY.
+TYPE = DEFAULT
+EXE1 = createfilemappingw
+Description
+=Test the CreateFileMapping to create a unnamed file-mapping object
+=and with PAGE_WRITE protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CMakeLists.txt
new file mode 100644
index 0000000000..8391fbd721
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ CreateFileMappingW.c
+)
+
+add_executable(paltest_createfilemappingw_test5
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappingw_test5 coreclrpal)
+
+target_link_libraries(paltest_createfilemappingw_test5
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.c
new file mode 100644
index 0000000000..21bf7c6d76
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/CreateFileMappingW.c
@@ -0,0 +1,194 @@
+// 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 5)
+**
+** Purpose: Positive test the CreateFileMappingW API.
+** Test CreateFileMappingW to a "swap" handle with
+** access PAGE_READONLY.
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+HANDLE SWAP_HANDLE = ((VOID *)(-1));
+
+int __cdecl main(int argc, char *argv[])
+{
+ char testString[] = "this is a test string";
+ WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'};
+ int RetVal = FAIL;
+ char results[2048];
+
+ HANDLE hFileMapRO;
+ HANDLE hFileMapRW;
+ LPVOID lpMapViewRO;
+ LPVOID lpMapViewRW;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Initialize the buffers.
+ */
+ memset(results, 0, MAPPINGSIZE);
+
+ /* Create a named file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapRW = CreateFileMapping(
+ SWAP_HANDLE,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read only*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ lpObjectName); /*named object*/
+
+ if(NULL == hFileMapRW)
+ {
+ Fail("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewRW = MapViewOfFile(
+ hFileMapRW,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewRW)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+
+ hFileMapRO = CreateFileMapping(
+ SWAP_HANDLE,
+ NULL, /*not inherited*/
+ PAGE_READONLY, /*read and write*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ lpObjectName); /*named object*/
+
+ if(NULL == hFileMapRO)
+ {
+ Trace("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewRO = MapViewOfFile(
+ hFileMapRO,
+ FILE_MAP_READ, /* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewRO)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+ /* Write the test string to the Map view.
+ */
+ memcpy(lpMapViewRW, testString, strlen(testString));
+
+ /* Read from the second Map view.
+ */
+ memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE);
+
+ /* Verify the contents of the file mapping,
+ * by comparing what was written to what was read.
+ */
+ if (memcmp(results, testString, strlen(testString))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ results,
+ testString);
+ RetVal = FAIL;
+ goto CleanUpFour;
+ }
+
+ /* Test was successful.
+ */
+ RetVal = PASS;
+
+CleanUpFour:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewRO) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewRO);
+ RetVal = FAIL;
+ }
+
+CleanUpThree:
+
+ /* Close Handle to opend file mapping.
+ */
+ if ( CloseHandle(hFileMapRO) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapRO);
+ RetVal = FAIL;
+ }
+
+
+CleanUpTwo:
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewRW) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewRW);
+ RetVal = FAIL;
+ }
+
+
+CleanUpOne:
+
+ /* Close Handle to opend file mapping.
+ */
+ if ( CloseHandle(hFileMapRW) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapRW);
+ RetVal = FAIL;
+ }
+
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/testinfo.dat
new file mode 100644
index 0000000000..87e16d3d79
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test5/testinfo.dat
@@ -0,0 +1,14 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMappingW
+Name = CreateFileMappingW - PAGE_READWRITE
+TYPE = DEFAULT
+EXE1 = createfilemappingw
+Description
+= Positive test the CreateFileMappingW API.
+= Test CreateFileMappingW to create a named
+= "swap" handle with access PAGE_READONLY.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CMakeLists.txt
new file mode 100644
index 0000000000..abb62ad950
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ CreateFileMappingW.c
+)
+
+add_executable(paltest_createfilemappingw_test6
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappingw_test6 coreclrpal)
+
+target_link_libraries(paltest_createfilemappingw_test6
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.c
new file mode 100644
index 0000000000..acf3ac6dff
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/CreateFileMappingW.c
@@ -0,0 +1,165 @@
+// 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 6)
+**
+** Purpose: Positive test the CreateFileMappingW API.
+** Test CreateFileMappingW to a "swap" handle with
+** access PAGE_READWRITE.
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+HANDLE SWAP_HANDLE = ((VOID *)(-1));
+
+int __cdecl main(int argc, char *argv[])
+{
+ char testString[] = "this is a test string";
+ WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'};
+ char results[2048];
+ int RetVal = PASS;
+
+ HANDLE hFileMapRW;
+ LPVOID lpMapViewRW;
+ LPVOID lpMapViewRW2;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Initialize the buffers.
+ */
+ memset(results, 0, MAPPINGSIZE);
+
+ /* Create a named file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapRW = CreateFileMapping(
+ SWAP_HANDLE,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read write*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ lpObjectName); /*named object*/
+
+ if(NULL == hFileMapRW)
+ {
+ Fail("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ }
+
+ /* Create a map view of the READWRITE file mapping.
+ */
+ lpMapViewRW = MapViewOfFile(
+ hFileMapRW,
+ FILE_MAP_ALL_ACCESS,/* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewRW)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewRW2 = MapViewOfFile(
+ hFileMapRW,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewRW2)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Write the test string to the Map view.
+ */
+ memcpy(lpMapViewRW, testString, strlen(testString));
+
+ /* Read from the second Map view.
+ */
+ memcpy(results, (LPCSTR)lpMapViewRW2, MAPPINGSIZE);
+
+ /* Verify the contents of the file mapping,
+ * by comparing what was written to what was read.
+ */
+ if (memcmp(results, testString, strlen(testString))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ results,
+ testString);
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+ /* Test successful.
+ */
+ RetVal = PASS;
+
+CleanUpThree:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewRW2) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewRW2);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewRW) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewRW);
+ RetVal = FAIL;
+ }
+
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(hFileMapRW) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapRW);
+ RetVal = FAIL;
+ }
+
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/testinfo.dat
new file mode 100644
index 0000000000..7afae68f16
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test6/testinfo.dat
@@ -0,0 +1,14 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMapping
+Name = CreateFileMappingA - with PAGE_READONLY
+TYPE = DEFAULT
+EXE1 = createfilemappingw
+Description
+= Positive test the CreateFileMappingW API.
+= Test CreateFileMappingW to create a named
+= "swap" handle with access PAGE_READWRITE.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/CMakeLists.txt
new file mode 100644
index 0000000000..b40cfeae96
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ createfilemapping.c
+)
+
+add_executable(paltest_createfilemappingw_test7
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappingw_test7 coreclrpal)
+
+target_link_libraries(paltest_createfilemappingw_test7
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.c
new file mode 100644
index 0000000000..e49b9f688d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/createfilemapping.c
@@ -0,0 +1,165 @@
+// 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 7)
+**
+** Purpose: Positive test the CreateFileMappingW API.
+** Test CreateFileMappingW to a "swap" handle with
+** access PAGE_READWRITE.
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+HANDLE SWAP_HANDLE = ((VOID *)(-1));
+
+int __cdecl main(int argc, char *argv[])
+{
+ char testString[] = "this is a test string";
+ WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'};
+ char results[2048];
+ int RetVal = PASS;
+
+ HANDLE hFileMapRW;
+ LPVOID lpMapViewRW;
+ LPVOID lpMapViewRO;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Initialize the buffers.
+ */
+ memset(results, 0, MAPPINGSIZE);
+
+ /* Create a named file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapRW = CreateFileMapping(
+ SWAP_HANDLE,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read write*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ lpObjectName); /*unnamed object*/
+
+ if(NULL == hFileMapRW)
+ {
+ Fail("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ }
+
+ /* Create a map view to the READWRITE file mapping.
+ */
+ lpMapViewRW = MapViewOfFile(
+ hFileMapRW,
+ FILE_MAP_ALL_ACCESS,/* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewRW)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+
+ /* Create a map view to the READWRITE file mapping.
+ */
+ lpMapViewRO = MapViewOfFile(
+ hFileMapRW,
+ FILE_MAP_READ, /* access code */
+ 0, /* high order offset*/
+ 0, /* low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewRO)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Write the test string to the Map view.
+ */
+ memcpy(lpMapViewRW, testString, strlen(testString));
+
+ /* Read from the second Map view.
+ */
+ memcpy(results, (LPCSTR)lpMapViewRO, MAPPINGSIZE);
+
+ /* Verify the contents of the file mapping,
+ * by comparing what was written to what was read.
+ */
+ if (memcmp(results, testString, strlen(testString))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ results,
+ testString);
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+ /* Test successful.
+ */
+ RetVal = PASS;
+
+CleanUpThree:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewRO) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewRO);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewRW) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewRW);
+ RetVal = FAIL;
+ }
+
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(hFileMapRW) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ hFileMapRW);
+ RetVal = FAIL;
+ }
+
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/testinfo.dat
new file mode 100644
index 0000000000..a68a665d74
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test7/testinfo.dat
@@ -0,0 +1,14 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMappingW
+Name = CreateFileMappingW - PAGE_COPYWRITE
+TYPE = DEFAULT
+EXE1 = createfilemapping
+Description
+= Positive test the CreateFileMappingW API.
+= Test CreateFileMappingW to create a named
+= "swap" handle with access PAGE_READWRITE
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/CMakeLists.txt
new file mode 100644
index 0000000000..96658c163a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ createfilemapping.c
+)
+
+add_executable(paltest_createfilemappingw_test8
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappingw_test8 coreclrpal)
+
+target_link_libraries(paltest_createfilemappingw_test8
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.c
new file mode 100644
index 0000000000..1ff137d8d3
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/createfilemapping.c
@@ -0,0 +1,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;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/testinfo.dat
new file mode 100644
index 0000000000..475d827af4
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test8/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMappingW - Special cases
+Name = CreateFileMappingW
+TYPE = DEFAULT
+EXE1 = createfilemapping
+Description
+= Positive test the CreateFileMappingW API.
+= Test the un-verifiable parameter combinations.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/CMakeLists.txt
new file mode 100644
index 0000000000..5a55e27b33
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ createfilemapping.c
+)
+
+add_executable(paltest_createfilemappingw_test9
+ ${SOURCES}
+)
+
+add_dependencies(paltest_createfilemappingw_test9 coreclrpal)
+
+target_link_libraries(paltest_createfilemappingw_test9
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.c b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.c
new file mode 100644
index 0000000000..16ae74c126
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/createfilemapping.c
@@ -0,0 +1,151 @@
+// 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: createfilemapping.c (test 9)
+**
+** Purpose: Negative test the CreateFileMappingW API.
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+const int MAPPINGSIZE = 2048;
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE hFile;
+ WCHAR lpFileName[] = {'t','e','s','t','.','t','m','p','\0'};
+
+ HANDLE hFileMapping;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file handle with CreateFile, as READONLY
+ */
+ hFile = CreateFile( lpFileName,
+ GENERIC_READ,
+ FILE_SHARE_READ,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: %u :unable to create file \"%s\".\n",
+ GetLastError(),
+ lpFileName);
+ }
+
+ /* Attempt to create a unnamed file-mapping object to a READONLY file
+ * as READWRITE access.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read and write*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ NULL); /*unnamed object*/
+
+ if(NULL != hFileMapping)
+ {
+ Trace("ERROR: Able to create READWRITE mapping to a "
+ "READONLY file.\n" );
+ if( 0 == CloseHandle(hFile) )
+ {
+ Trace("Unexpected Error: Unable to close file handle\n");
+ }
+ Fail("");
+ }
+
+ /* Attempt to create a unnamed file-mapping object to a zero lenght
+ * file.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read and write*/
+ 0, /*high-order size*/
+ 0, /*low-order size*/
+ NULL); /*unnamed object*/
+
+ if( NULL != hFileMapping )
+ {
+ Trace("ERROR: Able to create READWRITE mapping to a "
+ "READONLY file.\n" );
+ if( 0 == CloseHandle(hFile) )
+ {
+ Trace("Unexpected Error: Unable to close file handle\n");
+ }
+ Fail("");
+ }
+ if(GetLastError() != ERROR_ACCESS_DENIED)
+ {
+ Trace("ERROR: Expected GetLastError() to return "
+ "ERROR_FILE_INVALID (%d), it returned %u.\n",
+ ERROR_FILE_INVALID,
+ GetLastError());
+ if( 0 == CloseHandle(hFile) )
+ {
+ Trace("Unexpected Error: Unable to close file handle\n");
+ }
+ Fail("");
+ }
+
+ /* Attempt to create a file mapping that is larger than
+ * the file.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READONLY, /*read only*/
+ 0, /*high-order size*/
+ MAPPINGSIZE, /*low-order size*/
+ NULL); /*unnamed object*/
+ if(NULL != hFileMapping)
+ {
+ Trace("ERROR: Able to create file mapping of size %d to "
+ "file of size 0.\n",
+ MAPPINGSIZE);
+ if( 0 == CloseHandle(hFile) )
+ {
+ Trace("Unexpected Error: Unable to close file handle\n");
+ }
+ Fail("");
+ }
+
+ if(GetLastError() != ERROR_NOT_ENOUGH_MEMORY )
+ {
+ Trace("ERROR: Expected GetLastError() to return "
+ "ERROR_NOT_ENOUGH_MEMORY (%d), it returned %u.\n",
+ ERROR_NOT_ENOUGH_MEMORY,
+ GetLastError());
+ if( 0 == CloseHandle(hFile) )
+ {
+ Trace("Unexpected Error: Unable to close file handle\n");
+ }
+ Fail("");
+ }
+
+ if( 0 == CloseHandle(hFile) )
+ {
+ Fail("Unexpected Error: Unable to close file handle\n");
+ }
+
+ /* Terminate the PAL.
+ */
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/testinfo.dat
new file mode 100644
index 0000000000..2a7ecdbab7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/CreateFileMappingW/test9/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = CreateFileMappingW
+Name = CreateFileMappingW negative testing
+TYPE = DEFAULT
+EXE1 = createfilemapping
+Description
+= Negative test the CreateFileMapping API.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/CMakeLists.txt
new file mode 100644
index 0000000000..ef14ea5352
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/CMakeLists.txt
new file mode 100644
index 0000000000..3807621e3f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/CMakeLists.txt
@@ -0,0 +1,20 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ dlltest.c
+ FreeLibrary.c
+)
+
+add_executable(paltest_freelibrary_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_freelibrary_test1 coreclrpal)
+
+target_link_libraries(paltest_freelibrary_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/FreeLibrary.c b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/FreeLibrary.c
new file mode 100644
index 0000000000..a06a231586
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/FreeLibrary.c
@@ -0,0 +1,128 @@
+// 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:
+**
+** Purpose: Positive test the FreeLibrary API.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+/*char LibraryName[] = "dlltest";*/
+/* SHLEXT is defined only for Unix variants */
+
+#if defined(SHLEXT)
+#define LibraryName "dlltest"SHLEXT
+#else
+#define LibraryName "dlltest"
+#endif
+
+
+
+
+BOOL PALAPI TestDll(HMODULE, int);
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE hLib;
+
+ /* Initialize the PAL. */
+ if ((PAL_Initialize(argc, argv)) != 0)
+ {
+ return (FAIL);
+ }
+
+ /*Load library (DLL). */
+ hLib = LoadLibrary(LibraryName);
+
+ if(hLib == NULL)
+ {
+ Fail("ERROR:%u:Unable to load library %s\n",
+ GetLastError(),
+ LibraryName);
+ }
+
+ /* Test access to DLL. */
+ if(!TestDll(hLib, PASS))
+ {
+ Trace("ERROR: TestDll function returned FALSE "
+ "expected TRUE\n.");
+ FreeLibrary(hLib);
+ Fail("");
+ }
+
+ /* Call the FreeLibrary API. */
+ if (!FreeLibrary(hLib))
+ {
+ Fail("ERROR:%u: Unable to free library \"%s\"\n",
+ GetLastError(),
+ LibraryName);
+ }
+
+ /* Test access to the free'd DLL. */
+ if(!TestDll(hLib, FAIL))
+ {
+ Fail("ERROR: TestDll function returned FALSE "
+ "expected TRUE\n.");
+ }
+
+ PAL_Terminate();
+ return PASS;
+
+}
+
+
+BOOL PALAPI TestDll(HMODULE hLib, int testResult)
+{
+ int RetVal;
+#if WIN32
+ char FunctName[] = "_DllTest@0";
+#else
+ char FunctName[] = "DllTest";
+#endif
+ FARPROC DllAddr;
+
+ /* Attempt to grab the proc address of the dll function.
+ * This one should succeed.*/
+ if(testResult == PASS)
+ {
+ DllAddr = GetProcAddress(hLib, FunctName);
+ if(DllAddr == NULL)
+ {
+ Trace("ERROR: Unable to load function \"%s\" library \"%s\"\n",
+ FunctName,
+ LibraryName);
+ return (FALSE);
+ }
+ /* Run the function in the DLL,
+ * to ensure that the DLL was loaded properly.*/
+ RetVal = DllAddr();
+ if (RetVal != 1)
+ {
+ Trace("ERROR: Unable to receive correct information from DLL! "
+ ":expected \"1\", returned \"%d\"\n",
+ RetVal);
+ return (FALSE);
+ }
+ }
+
+ /* Attempt to grab the proc address of the dll function.
+ * This one should fail.*/
+ if(testResult == FAIL)
+ {
+ DllAddr = GetProcAddress(hLib, FunctName);
+ if(DllAddr != NULL)
+ {
+ Trace("ERROR: Able to load function \"%s\" from free'd"
+ " library \"%s\"\n",
+ FunctName,
+ LibraryName);
+ return (FALSE);
+ }
+ }
+ return (TRUE);
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/dlltest.c b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/dlltest.c
new file mode 100644
index 0000000000..44f1b5a903
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/dlltest.c
@@ -0,0 +1,32 @@
+// 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: dlltest.c (FreeLibrary test dll)
+**
+** Purpose: This file will be used to create the shared library
+** that will be used in the FreeLibraryAndExitThread
+** test. A very simple shared library, with one function
+** "DllTest" which merely returns 1.
+**
+**
+**===================================================================*/
+#include "pal.h"
+
+#if WIN32
+__declspec(dllexport)
+#endif
+
+int __stdcall DllTest()
+{
+ return 1;
+}
+
+#ifdef WIN32
+int __stdcall _DllMainCRTStartup(void *hinstDLL, int reason, void * lpvReserved)
+{
+ return 1;
+}
+#endif
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/testinfo.dat
new file mode 100644
index 0000000000..a09d21428f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test1/testinfo.dat
@@ -0,0 +1,14 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = FreeLibrary
+Name = Positive test for FreeLibrary API
+TYPE = DEFAULT
+EXE1 = freelibrary
+LIB1 = dlltest
+Description
+=Test the FreeLibrary to decrement the reference
+=count of the loaded DLL
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/CMakeLists.txt
new file mode 100644
index 0000000000..00b1eca8e3
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test2.c
+)
+
+add_executable(paltest_freelibrary_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_freelibrary_test2 coreclrpal)
+
+target_link_libraries(paltest_freelibrary_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/test2.c b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/test2.c
new file mode 100644
index 0000000000..b43f74d6bc
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/test2.c
@@ -0,0 +1,52 @@
+// 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: test2.c (FreeLibrary)
+**
+** Purpose: Tests the PAL implementation of the FreeLibrary function.
+** This is a negative test that will pass an invalid and a
+** null handle to FreeLibrary.
+**
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char* argv[])
+{
+ HANDLE hLib;
+
+ /* Initialize the PAL.
+ */
+ if ((PAL_Initialize(argc, argv)) != 0)
+ {
+ return (FAIL);
+ }
+
+ /* Attempt to pass FreeLibrary an invalid handle.
+ */
+ hLib = INVALID_HANDLE_VALUE;
+ if (FreeLibrary(hLib))
+ {
+ Fail("ERROR: Able to free library handle = \"0x%lx\".\n",
+ hLib);
+ }
+
+ /* Attempt to pass FreeLibrary a NULL handle.
+ */
+ hLib = NULL;
+ if (FreeLibrary(hLib))
+ {
+ Fail("ERROR: Able to free library handle = \"NULL\".\n");
+ }
+
+
+ /* Terminate the PAL.
+ */
+ PAL_Terminate();
+ return PASS;
+
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/testinfo.dat
new file mode 100644
index 0000000000..521fa6eaea
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibrary/test2/testinfo.dat
@@ -0,0 +1,14 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = FreeLibrary
+Name = Negative test for FreeLibrary
+TYPE = DEFAULT
+EXE1 = test2
+Description
+= Tests the PAL implementation of the FreeLibrary function.
+= This is a negative test that will pass an invalid and a
+= null handle to FreeLibrary.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/CMakeLists.txt
new file mode 100644
index 0000000000..f6aa0cb2d9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/CMakeLists.txt
new file mode 100644
index 0000000000..cec083583a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/CMakeLists.txt
@@ -0,0 +1,20 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ dlltest.c
+ test1.c
+)
+
+add_executable(paltest_freelibraryandexitthread_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_freelibraryandexitthread_test1 coreclrpal)
+
+target_link_libraries(paltest_freelibraryandexitthread_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/dlltest.c b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/dlltest.c
new file mode 100644
index 0000000000..954c624d19
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/dlltest.c
@@ -0,0 +1,32 @@
+// 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: dlltest.c (FreeLibraryAndExitThread test dll)
+**
+** Purpose: This file will be used to create the shared library
+** that will be used in the FreeLibraryAndExitThread
+** test. A very simple shared library, with one function
+** "DllTest" which merely returns 1.
+**
+**
+**===================================================================*/
+#include "pal.h"
+
+#if WIN32
+__declspec(dllexport)
+#endif
+
+int _stdcall DllTest()
+{
+ return 1;
+}
+
+#if WIN32
+int __stdcall _DllMainCRTStartup(void *hinstDLL, int reason, void * lpvReserved)
+{
+ return 1;
+}
+#endif
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/test1.c b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/test1.c
new file mode 100644
index 0000000000..6aacfc83b4
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/test1.c
@@ -0,0 +1,183 @@
+// 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: test1.c (FreeLibraryAndExitThread)
+**
+** Purpose: Tests the PAL implementation of the FreeLibraryAndExitThread
+** function. FreeLibraryAndExitThread when run will exit the
+** process that it is called within, therefore we create a
+** thread to run the API. Then test for the existance of the
+** thread and access to the library.
+**
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+/*Define platform specific information*/
+
+/* SHLEXT is defined only for Unix variants */
+#if defined(SHLEXT)
+#define LibraryName "dlltest"SHLEXT
+#else
+#define LibraryName "dlltest"
+#endif
+
+#define TIMEOUT 60000
+
+BOOL PALAPI StartThreadTest();
+DWORD PALAPI CreateTestThread(LPVOID);
+BOOL PALAPI TestDll(HMODULE, int);
+
+int __cdecl main(int argc, char* argv[])
+{
+ /*Initialize the PAL*/
+ if ((PAL_Initialize(argc, argv)) != 0)
+ {
+ return (FAIL);
+ }
+
+ if (!StartThreadTest())
+ {
+ Fail("ERROR: FreeLibraryAndExitThread test failed.\n");
+ }
+
+ /*Terminate the PAL*/
+ PAL_Terminate();
+ return PASS;
+
+}
+
+
+BOOL PALAPI StartThreadTest()
+{
+ HMODULE hLib;
+ HANDLE hThread;
+ DWORD dwThreadId;
+ LPTHREAD_START_ROUTINE lpStartAddress = &CreateTestThread;
+ LPVOID lpParameter = lpStartAddress;
+ DWORD rc = -1;
+ /*Load library (DLL).*/
+ hLib = LoadLibrary(LibraryName);
+ if(hLib == NULL)
+ {
+ Trace("ERROR: Unable to load library %s\n", LibraryName);
+
+ return (FALSE);
+ }
+
+ /*Start the test thread*/
+ hThread = CreateThread(NULL,
+ (DWORD)0,
+ lpParameter,
+ hLib,
+ (DWORD)NULL,
+ &dwThreadId);
+ if(hThread == NULL)
+ {
+ Trace("ERROR:%u: Unable to create thread.\n",
+ GetLastError());
+
+ FreeLibrary(hLib);
+ return (FALSE);
+ }
+
+ /*Wait on thread.*/
+ rc = WaitForSingleObject(hThread, TIMEOUT);
+ if( rc != WAIT_OBJECT_0 )
+ {
+ Trace("ERROR:%u: hThread=0x%4.4lx not exited by "
+ "FreeLibraryAndExitThread, RC[%d]\n",
+ GetLastError(),
+ hThread, rc);
+
+// There is a possibility that the other thread might
+// still be using the library VSW:337893
+// FreeLibrary(hLib);
+ CloseHandle(hThread);
+ return (FALSE);
+ }
+
+ /*Test access to DLL.*/
+ if(!TestDll(hLib, 0))
+ {
+ Trace("ERROR: TestDll function returned FALSE "
+ "expected TRUE\n.");
+
+ CloseHandle(hThread);
+ return (FALSE);
+ }
+
+ FreeLibrary(hLib);
+ /*Clean-up thread.*/
+ CloseHandle(hThread);
+
+ return (TRUE);
+}
+
+BOOL PALAPI TestDll(HMODULE hLib, int testResult)
+{
+ int RetVal;
+ char FunctName[] = "DllTest";
+ FARPROC DllAddr;
+
+ /* Attempt to grab the proc address of the dll function.
+ * This one should succeed.*/
+ if(testResult == 1)
+ {
+ DllAddr = GetProcAddress(hLib, FunctName);
+ if(DllAddr == NULL)
+ {
+ Trace("ERROR: Unable to load function \"%s\" library \"%s\"\n",
+ FunctName,
+ LibraryName);
+ return (FALSE);
+ }
+ /* Run the function in the DLL,
+ * to ensure that the DLL was loaded properly.*/
+ RetVal = DllAddr();
+ if (RetVal != 1)
+ {
+ Trace("ERROR: Unable to receive correct information from DLL! "
+ ":expected \"1\", returned \"%d\"\n",
+ RetVal);
+ return (FALSE);
+ }
+ }
+
+ /* Attempt to grab the proc address of the dll function.
+ * This one should fail.*/
+ if(testResult == 0)
+ {
+ DllAddr = GetProcAddress(hLib, FunctName);
+ if(DllAddr != NULL)
+ {
+ Trace("ERROR: Able to load function \"%s\" from free'd"
+ " library \"%s\"\n",
+ FunctName,
+ LibraryName);
+ return (FALSE);
+ }
+ }
+ return (TRUE);
+}
+
+DWORD PALAPI CreateTestThread(LPVOID lpParam)
+{
+ /* Test access to DLL.*/
+ TestDll(lpParam, 1);
+
+ /*Free library and exit thread.*/
+ FreeLibraryAndExitThread(lpParam, (DWORD)0);
+
+ /* NOT REACHED */
+
+ /*Infinite loop, we should not get here.*/
+ while(1);
+
+ return (DWORD)0;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/testinfo.dat
new file mode 100644
index 0000000000..455829c0d5
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/FreeLibraryAndExitThread/test1/testinfo.dat
@@ -0,0 +1,17 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = FreeLibraryAndExitThread
+Name = Positive test for FreeLibraryAndExitThread
+TYPE = DEFAULT
+EXE1 = test1
+LIB1 = dlltest
+Description
+= Tests the PAL implementation of the FreeLibraryAndExitThread
+= function. When run, FreeLibraryAndExitThread will exit the
+= process that it is called within, therefore we create a
+= thread to run the API. Then we test for the existance of the
+= thread and access to the library.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/CMakeLists.txt
new file mode 100644
index 0000000000..ef14ea5352
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/CMakeLists.txt
new file mode 100644
index 0000000000..a1128c62b8
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ GetModuleFileNameA.c
+)
+
+add_executable(paltest_getmodulefilenamea_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_getmodulefilenamea_test1 coreclrpal)
+
+target_link_libraries(paltest_getmodulefilenamea_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.c b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.c
new file mode 100644
index 0000000000..d05f0ac6a9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/GetModuleFileNameA.c
@@ -0,0 +1,92 @@
+// 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: getmodulefilenamea.c
+**
+** Purpose: Positive test the GetModuleFileName API.
+** Call GetModuleFileName to retrieve the specified
+** module full path and file name
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+#define MODULENAMEBUFFERSIZE 1024
+
+/* SHLEXT is defined only for Unix variants */
+
+#if defined(SHLEXT)
+#define ModuleName "librotor_pal"SHLEXT
+#define Delimiter "/"
+#else
+#define ModuleName "rotor_pal.dll"
+#define Delimiter "\\"
+#endif
+
+int __cdecl main(int argc, char *argv[])
+{
+ HMODULE ModuleHandle;
+ int err;
+ DWORD ModuleNameLength;
+ char ModuleFileNameBuf[MODULENAMEBUFFERSIZE]="";
+ char* TempBuf = NULL;
+ char* LastBuf = NULL;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+
+ //load a module
+ ModuleHandle = LoadLibrary(ModuleName);
+ if(!ModuleHandle)
+ {
+ Fail("Failed to call LoadLibrary API!\n");
+ }
+
+
+ //retrieve the specified module full path and file name
+ ModuleNameLength = GetModuleFileName(
+ ModuleHandle,//specified module handle
+ ModuleFileNameBuf,//buffer for module file name
+ MODULENAMEBUFFERSIZE);
+
+ //strip out all full path
+ TempBuf = strtok(ModuleFileNameBuf,Delimiter);
+ LastBuf = TempBuf;
+ while(NULL != TempBuf)
+ {
+ LastBuf = TempBuf;
+ TempBuf = strtok(NULL,Delimiter);
+ }
+
+
+ if(0 == ModuleNameLength || strcmp(ModuleName,LastBuf))
+ {
+ Trace("\nFailed to all GetModuleFileName API!\n");
+ err = FreeLibrary(ModuleHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to all FreeLibrary API!\n");
+ }
+ Fail("");
+ }
+
+ //decrement the reference count of the loaded dll
+ err = FreeLibrary(ModuleHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to all FreeLibrary API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/testinfo.dat
new file mode 100644
index 0000000000..8075e840ce
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test1/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = GetModuleFileNameA
+Name = Positive test for GetModuleFileNameA API
+TYPE = DEFAULT
+EXE1 = getmodulefilenamea
+Description
+=Test the GetModuleFileNameA to retrieve the specified module
+=full path and file name
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/CMakeLists.txt
new file mode 100644
index 0000000000..c35e9acc5e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ GetModuleFileNameA.c
+)
+
+add_executable(paltest_getmodulefilenamea_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_getmodulefilenamea_test2 coreclrpal)
+
+target_link_libraries(paltest_getmodulefilenamea_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.c b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.c
new file mode 100644
index 0000000000..e8aed6d30e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/GetModuleFileNameA.c
@@ -0,0 +1,49 @@
+// 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: getmodulefilenamea.c
+**
+** Purpose: Positive test the GetModuleFileNameA API.
+** Call GetModuleFileName to retrieve current process
+** full path and file name by passing a NULL module handle
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+
+#define MODULENAMEBUFFERSIZE 1024
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ DWORD ModuleNameLength;
+ char ModuleFileNameBuf[MODULENAMEBUFFERSIZE]="";
+ int err;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+
+ //retrieve the current process full path and file name
+ //by passing a NULL module handle
+ ModuleNameLength = GetModuleFileName(
+ NULL, //a NULL handle
+ ModuleFileNameBuf,//buffer for module file name
+ MODULENAMEBUFFERSIZE);
+
+ if(0 == ModuleNameLength)
+ {
+ Fail("\nFailed to all GetModuleFileName API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/testinfo.dat
new file mode 100644
index 0000000000..45fdca6ae7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameA/test2/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = GetModuleFileNameA
+Name = Positive test for GetModuleFileNameA API
+TYPE = DEFAULT
+EXE1 = getmodulefilenamea
+Description
+=Test the GetModuleFileNameA to retrieve current process full
+=full path and file name by passing a NULL module handle
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/CMakeLists.txt
new file mode 100644
index 0000000000..ef14ea5352
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/CMakeLists.txt
new file mode 100644
index 0000000000..c702d07908
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ GetModuleFileNameW.c
+)
+
+add_executable(paltest_getmodulefilenamew_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_getmodulefilenamew_test1 coreclrpal)
+
+target_link_libraries(paltest_getmodulefilenamew_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/GetModuleFileNameW.c b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/GetModuleFileNameW.c
new file mode 100644
index 0000000000..4c1c3b00ab
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/GetModuleFileNameW.c
@@ -0,0 +1,112 @@
+// 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: getmodulefilenamew.c
+**
+** Purpose: Test the GetModuleFileNameW to retrieve the specified module
+** full path and file name in UNICODE.
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+#define MODULENAMEBUFFERSIZE 1024
+
+/* SHLEXT is defined only for Unix variants */
+
+#if defined(SHLEXT)
+#define ModuleName "librotor_pal"SHLEXT
+#define Delimiter "/"
+#else
+#define ModuleName "rotor_pal.dll"
+#define Delimiter "\\"
+#endif
+
+int __cdecl main(int argc, char *argv[])
+{
+ HMODULE ModuleHandle;
+ int err;
+ WCHAR *lpModuleName;
+ DWORD ModuleNameLength;
+ WCHAR *ModuleFileNameBuf;
+ char* TempBuf = NULL;
+ char* LastBuf = NULL;
+ char NewModuleFileNameBuf[MODULENAMEBUFFERSIZE+200] = "";
+
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ ModuleFileNameBuf = malloc(MODULENAMEBUFFERSIZE*sizeof(WCHAR));
+
+ //convert a normal string to a wide one
+ lpModuleName = convert(ModuleName);
+
+ //load a module
+ ModuleHandle = LoadLibrary(lpModuleName);
+
+ //free the memory
+ free(lpModuleName);
+
+ if(!ModuleHandle)
+ {
+ Fail("Failed to call LoadLibrary API!\n");
+ }
+
+
+ //retrieve the specified module full path and file name
+ ModuleNameLength = GetModuleFileName(
+ ModuleHandle,//specified module handle
+ ModuleFileNameBuf,//buffer for module file name
+ MODULENAMEBUFFERSIZE);
+
+
+
+ //convert a wide full path name to a normal one
+ strcpy(NewModuleFileNameBuf,convertC(ModuleFileNameBuf));
+
+ //strip out all full path
+ TempBuf = strtok(NewModuleFileNameBuf,Delimiter);
+ LastBuf = TempBuf;
+ while(NULL != TempBuf)
+ {
+ LastBuf = TempBuf;
+ TempBuf = strtok(NULL,Delimiter);
+ }
+
+
+ //free the memory
+ free(ModuleFileNameBuf);
+
+ if(0 == ModuleNameLength || strcmp(ModuleName,LastBuf))
+ {
+ Trace("\nFailed to all GetModuleFileName API!\n");
+ err = FreeLibrary(ModuleHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to all FreeLibrary API!\n");
+ }
+ Fail("");
+ }
+
+
+
+ //decrement the reference count of the loaded dll
+ err = FreeLibrary(ModuleHandle);
+ if(0 == err)
+ {
+ Fail("\nFailed to all FreeLibrary API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/testinfo.dat
new file mode 100644
index 0000000000..c8d94b73b4
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test1/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = GetModuleFileNameW
+Name = Positive test for GetModuleFileNameW API
+TYPE = DEFAULT
+EXE1 = getmodulefilenamew
+Description
+=Test the GetModuleFileNameW to retrieve the specified module
+=full path and file name in UNICODE
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/CMakeLists.txt
new file mode 100644
index 0000000000..857feb330d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ GetModuleFileNameW.c
+)
+
+add_executable(paltest_getmodulefilenamew_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_getmodulefilenamew_test2 coreclrpal)
+
+target_link_libraries(paltest_getmodulefilenamew_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/GetModuleFileNameW.c b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/GetModuleFileNameW.c
new file mode 100644
index 0000000000..6009a9d298
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/GetModuleFileNameW.c
@@ -0,0 +1,57 @@
+// 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: getmodulefilenamew.c
+**
+** Purpose: Positive test the GetModuleFileName API.
+** Call GetModuleFileName to retrieve current process
+** full path and file name by passing a NULL module handle
+** in UNICODE
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+#define MODULENAMEBUFFERSIZE 1024
+
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ DWORD ModuleNameLength;
+ WCHAR *ModuleFileNameBuf;
+ int err;
+
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ ModuleFileNameBuf = malloc(MODULENAMEBUFFERSIZE*sizeof(WCHAR));
+
+ //retrieve the current process full path and file name
+ //by passing a NULL module handle
+ ModuleNameLength = GetModuleFileName(
+ NULL, //a NULL handle
+ ModuleFileNameBuf,//buffer for module file name
+ MODULENAMEBUFFERSIZE);
+
+ //free the memory
+ free(ModuleFileNameBuf);
+
+ if(0 == ModuleNameLength)
+ {
+ Fail("\nFailed to all GetModuleFileName API!\n");
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/testinfo.dat
new file mode 100644
index 0000000000..8b8740149c
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetModuleFileNameW/test2/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = GetModuleFileNameW
+Name = Positive test for GetModuleFileNameW API
+TYPE = DEFAULT
+EXE1 = getmodulefilenamew
+Description
+=Test the GetModuleFileNameW to retrieve current process full
+=full path and file name by passing a NULL module handle in UNICODE
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/CMakeLists.txt
new file mode 100644
index 0000000000..ef14ea5352
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/CMakeLists.txt
new file mode 100644
index 0000000000..541ef8b98e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/CMakeLists.txt
@@ -0,0 +1,20 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test1.c
+ testlib.c
+)
+
+add_executable(paltest_getprocaddress_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_getprocaddress_test1 coreclrpal)
+
+target_link_libraries(paltest_getprocaddress_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/test1.c b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/test1.c
new file mode 100644
index 0000000000..f0b76c615f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/test1.c
@@ -0,0 +1,111 @@
+// 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: test1.c (filemapping_memmgt\getprocaddress\test1)
+**
+** Purpose: Positive test the GetProcAddress API.
+** The first test calls GetProcAddress to retrieve the
+** address of SimpleFunction inside testlib by its name,
+** then calls the function and checks that it worked.
+**
+**
+**===========================================================================*/
+#include <palsuite.h>
+
+typedef int (__stdcall *SIMPLEFUNCTION)(int);
+
+/* SHLEXT is defined only for Unix variants */
+#if defined(SHLEXT)
+#define lpModuleName "testlib"SHLEXT
+#else
+#define lpModuleName "testlib.dll"
+#endif
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ HMODULE hModule;
+ SIMPLEFUNCTION procAddressByName;
+
+#if WIN32
+ const char *FunctionName = "_SimpleFunction@4";
+#else
+ const char *FunctionName = "SimpleFunction";
+#endif
+
+ /* Initialize the PAL environment. */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+
+ /* load a module */
+ hModule = LoadLibrary(lpModuleName);
+ if(!hModule)
+ {
+ Fail("Unexpected error: "
+ "LoadLibrary(%s) failed.\n",
+ lpModuleName);
+ }
+
+ /*
+ * Test 1
+ *
+ * Get the address of a function
+ */
+ procAddressByName = (SIMPLEFUNCTION) GetProcAddress(hModule,FunctionName);
+ if(!procAddressByName)
+ {
+ Trace("ERROR: Unable to get address of SimpleFunction by its name. "
+ "GetProcAddress returned NULL with error %d\n",
+ GetLastError());
+
+ /* Cleanup */
+ err = FreeLibrary(hModule);
+ if(0 == err)
+ {
+ Fail("Unexpected error: Failed to FreeLibrary %s\n",
+ lpModuleName);
+ }
+ Fail("");
+ }
+
+ /* Call the function to see that it really worked */
+ /* Simple function adds 1 to the argument passed */
+ if( 2 != ((procAddressByName)(1)))
+ {
+ Trace("ERROR: Problem calling the function by its address.\n");
+
+ /* Cleanup */
+ err = FreeLibrary(hModule);
+ if(0 == err)
+ {
+ Fail("Unexpected error: Failed to FreeLibrary %s\n",
+ lpModuleName);
+ }
+ Fail("");
+ }
+
+ /* Cleanup */
+ err = FreeLibrary(hModule);
+ if(0 == err)
+ {
+ Fail("Unexpected error: Failed to FreeLibrary %s\n",
+ lpModuleName);
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
+
+
+
+
+
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testinfo.dat
new file mode 100644
index 0000000000..31b262e31e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testinfo.dat
@@ -0,0 +1,19 @@
+# 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.
+
+Version = 1.0
+Section = filemapping_memmgt
+Function = getprocaddress
+Name = Positive test for GetProcAddress API
+TYPE = DEFAULT
+EXE1 = test1
+LIB1 = testlib
+Description
+=Positive test the GetProcAddress API.
+=The first test calls GetProcAddress to retrieve the
+=address of strcpy by its name, then calls the function and
+=checks that it worked. The second part of the test
+=calls GetProcAddress to retrieve the address of
+=strcpy by its ordinal, then calls the function and
+=checks that it worked.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testlib.c b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testlib.c
new file mode 100644
index 0000000000..e8fe48e05d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test1/testlib.c
@@ -0,0 +1,33 @@
+// 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: testlib.c (filemapping_memmgt\getprocaddress\test1)
+**
+** Purpose: Create a simple library containing one function
+** to test GetProcAddress
+**
+**
+**===========================================================================*/
+#include "pal.h"
+
+#if WIN32
+__declspec(dllexport)
+#endif
+
+/**
+ * Simple function that returns i+1
+ */
+int __stdcall SimpleFunction(int i)
+{
+ return i+1;
+}
+
+#if WIN32
+int __stdcall _DllMainCRTStartup(void *hinstDLL, int reason, void *lpvReserved)
+{
+ return 1;
+}
+#endif
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/CMakeLists.txt
new file mode 100644
index 0000000000..60a5ba1a6e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/CMakeLists.txt
@@ -0,0 +1,20 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test2.c
+ testlib.c
+)
+
+add_executable(paltest_getprocaddress_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_getprocaddress_test2 coreclrpal)
+
+target_link_libraries(paltest_getprocaddress_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/test2.c b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/test2.c
new file mode 100644
index 0000000000..9107728423
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/test2.c
@@ -0,0 +1,152 @@
+// 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: test2.c (filemapping_memmgt\getprocaddress\test2)
+**
+** Purpose: This test tries to call GetProcAddress with
+** a NULL handle, with a NULL function name, with an empty
+** function name, with an invalid name and with an
+** invalid ordinal value.
+**
+**
+**===========================================================================*/
+#include <palsuite.h>
+
+
+/* SHLEXT is defined only for Unix variants */
+#if defined(SHLEXT)
+#define lpModuleName "testlib"SHLEXT
+#else
+#define lpModuleName "testlib.dll"
+#endif
+
+
+/**
+ * main
+ */
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ HMODULE hModule;
+ FARPROC procAddress;
+
+ /* Initialize the PAL environment. */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* load a module */
+ hModule = LoadLibrary(lpModuleName);
+ if(!hModule)
+ {
+ Fail("Unexpected error: "
+ "LoadLibrary(%s) failed.\n",
+ lpModuleName);
+ }
+
+ /*
+ * Test 1
+ *
+ * Call GetProcAddress with a NULL handle
+ */
+ procAddress = GetProcAddress(NULL,"SimpleFunction");
+ if(procAddress != NULL)
+ {
+ Trace("ERROR: GetProcAddress with a NULL handle "
+ "returned a non-NULL value when it should have "
+ "returned a NULL value with an error\n");
+
+ /* Cleanup */
+ err = FreeLibrary(hModule);
+ if(0 == err)
+ {
+ Fail("Unexpected error: Failed to FreeLibrary %s\n",
+ lpModuleName);
+ }
+ Fail("");
+ }
+
+ /**
+ * Test 2
+ *
+ * Call GetProcAddress with a NULL function name
+ */
+
+ procAddress = GetProcAddress(hModule,NULL);
+ if(procAddress != NULL)
+ {
+ Trace("ERROR: GetProcAddress with a NULL function name "
+ "returned a non-NULL value when it should have "
+ "returned a NULL value with an error\n");
+
+ /* Cleanup */
+ err = FreeLibrary(hModule);
+ if(0 == err)
+ {
+ Fail("Unexpected error: Failed to FreeLibrary %s\n",
+ lpModuleName);
+ }
+ Fail("");
+ }
+
+ /**
+ * Test 3
+ *
+ * Call GetProcAddress with an empty function name string
+ */
+
+ procAddress = GetProcAddress(hModule,"");
+ if(procAddress != NULL)
+ {
+ Trace("ERROR: GetProcAddress with an empty function name "
+ "returned a non-NULL value when it should have "
+ "returned a NULL value with an error\n");
+
+ /* Cleanup */
+ err = FreeLibrary(hModule);
+ if(0 == err)
+ {
+ Fail("Unexpected error: Failed to FreeLibrary %s\n",
+ lpModuleName);
+ }
+ Fail("");
+ }
+
+ /**
+ * Test 4
+ *
+ * Call GetProcAddress with an invalid name
+ */
+
+ procAddress = GetProcAddress(hModule,"Simple Function");
+ if(procAddress != NULL)
+ {
+ Trace("ERROR: GetProcAddress with an invalid function name "
+ "returned a non-NULL value when it should have "
+ "returned a NULL value with an error\n");
+
+ /* Cleanup */
+ err = FreeLibrary(hModule);
+ if(0 == err)
+ {
+ Fail("Unexpected error: Failed to FreeLibrary %s\n",
+ lpModuleName);
+ }
+ Fail("");
+ }
+
+ /* cleanup */
+ err = FreeLibrary(hModule);
+ if(0 == err)
+ {
+ Fail("Unexpected error: Failed to FreeLibrary %s\n",
+ lpModuleName);
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testinfo.dat
new file mode 100644
index 0000000000..8bf50ad812
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testinfo.dat
@@ -0,0 +1,18 @@
+# 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.
+
+Version = 1.0
+Section = filemapping_memmgt
+Function = getprocaddress
+Name = Negative test for GetProcAddress API
+TYPE = DEFAULT
+EXE1 = test2
+LIB1 = testlib
+Description
+=This test tries to call GetProcAddress with
+=a NULL handle, with a NULL function name, with an empty
+=function name, with an invalid name and with an
+=nvalid ordinal value.
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testlib.c b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testlib.c
new file mode 100644
index 0000000000..23e58e871e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcAddress/test2/testlib.c
@@ -0,0 +1,33 @@
+// 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: testlib.c (filemapping_memmgt\getprocaddress\test2)
+**
+** Purpose: Create a simple library containing one function
+** to test GetProcAddress
+**
+**
+**===========================================================================*/
+#include "pal.h"
+
+#if WIN32
+__declspec(dllexport)
+#endif
+
+/**
+ * Simple function that returns i+1
+ */
+int __stdcall SimpleFunction(int i)
+{
+ return i+1;
+}
+
+#if WIN32
+int __stdcall _DllMainCRTStartup(void *hinstDLL, int reason, void *lpvReserved)
+{
+ return 1;
+}
+#endif
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/CMakeLists.txt
new file mode 100644
index 0000000000..f6aa0cb2d9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/CMakeLists.txt
new file mode 100644
index 0000000000..18871abf00
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ GetProcessHeap.c
+)
+
+add_executable(paltest_getprocessheap_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_getprocessheap_test1 coreclrpal)
+
+target_link_libraries(paltest_getprocessheap_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/GetProcessHeap.c b/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/GetProcessHeap.c
new file mode 100644
index 0000000000..bec6b5c616
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/GetProcessHeap.c
@@ -0,0 +1,39 @@
+// 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: getprocheap.c
+**
+** Purpose: Positive test the GetProcessHeap API.
+** Call GetProcessHeap to retrieve the handle of
+** calling process heap
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ HANDLE ProcessHeapHandle;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Retrieve the calling process heap handle
+ ProcessHeapHandle = GetProcessHeap();
+
+ if(!ProcessHeapHandle)
+ {
+ Fail("\nFailed to call GetProcessHeap API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/testinfo.dat
new file mode 100644
index 0000000000..cec3dd12d7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/GetProcessHeap/test1/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = GetProcessHeap
+Name = Positive test for GetProcessHeap API retrieve the handle of calling process heap
+TYPE = DEFAULT
+EXE1 = getprocessheap
+Description
+=Test the GetProcessHeap to retrieve the handle of the calling process heap
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/CMakeLists.txt
new file mode 100644
index 0000000000..1962ade358
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/CMakeLists.txt
new file mode 100644
index 0000000000..3a64a0c58a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ HeapAlloc.c
+)
+
+add_executable(paltest_heapalloc_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_heapalloc_test1 coreclrpal)
+
+target_link_libraries(paltest_heapalloc_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.c
new file mode 100644
index 0000000000..04de274e80
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/HeapAlloc.c
@@ -0,0 +1,100 @@
+// 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: heapalloc.c
+**
+** Purpose: Positive test the HeapAlloc API.
+** Call HeapAlloc by pssing zero as control flag
+** Call HeapAlloc by passing HEAP_ZERO_MEMORY as control flag
+** Call HeapAlloc to allocate one byte heap memory
+** Call HeapAlloc to allocate maximum available heap memory
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define HEAPSIZE 64
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ HANDLE ProcessHeapHandle;
+ LPVOID lpHeap;
+
+ /* Initialize the PAL environment */
+ err = PAL_Initialize(argc, argv);
+ if(0 != 0)
+ {
+ ExitProcess(FAIL);
+ }
+
+ /* Retrieve the calling process heap handle */
+ ProcessHeapHandle = GetProcessHeap();
+
+ if(!ProcessHeapHandle)
+ {
+ Fail("\nFailed to call GetProcessHeap API!\n");
+ }
+
+ /* allocate a heap memory in specified size */
+ lpHeap = HeapAlloc(ProcessHeapHandle, /* HeapHandle */
+ 0, /* control flag */
+ HEAPSIZE); /* /specify the heap size */
+ if(NULL == lpHeap)
+ {
+ Fail("Failed to call HeapAlloc API!\n");
+ }
+
+ /* free the heap memory */
+ err = HeapFree(ProcessHeapHandle,
+ 0,
+ lpHeap);
+ if(0 == err)
+ {
+ Fail("Failed to call HeapFree API!\n");
+ }
+
+
+ /* allocate a heap memory in 1 byte size */
+ lpHeap = HeapAlloc(ProcessHeapHandle, /* HeapHandle */
+ 0, /* control flag */
+ 1); /* specify the heap size*/
+ if(NULL == lpHeap)
+ {
+ Fail("Failed to call HeapAlloc API to allocate one byte heap memory!\n");
+ }
+
+ /* free the heap memory */
+ err = HeapFree(ProcessHeapHandle,
+ 0,
+ lpHeap);
+ if(0 == err)
+ {
+ Fail("Failed to call HeapFree API!\n");
+ }
+
+ /* allocate a heap memory and initialize it to zero */
+ lpHeap = HeapAlloc(ProcessHeapHandle,/* HeapHandle */
+ HEAP_ZERO_MEMORY,/* control flag */
+ HEAPSIZE); /* specify the heap size */
+ if(NULL == lpHeap)
+ {
+ Fail("Failed to call HeapAlloc API with HEAP_ZERO_MEMORY control flag!\n");
+ }
+
+ /* free the heap memory */
+ err = HeapFree(ProcessHeapHandle,
+ 0,
+ lpHeap);
+ if(0 == err)
+ {
+ Fail("Failed to call HeapFree API!\n");
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/testinfo.dat
new file mode 100644
index 0000000000..9b6064349d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test1/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = HeapAlloc
+Name = Positive test for HeapAlloc API
+TYPE = DEFAULT
+EXE1 = heapalloc
+Description
+=Test the HeapAlloc by passing zero as the control flag
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/CMakeLists.txt
new file mode 100644
index 0000000000..5253110d8d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ HeapAlloc.c
+)
+
+add_executable(paltest_heapalloc_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_heapalloc_test2 coreclrpal)
+
+target_link_libraries(paltest_heapalloc_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.c
new file mode 100644
index 0000000000..5f4ff90498
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/HeapAlloc.c
@@ -0,0 +1,59 @@
+// 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: heapalloc.c
+**
+** Purpose: Positive test the HeapAlloc API.
+** Call HeapAlloc with HEAP_ZERO_MEMORY control flag
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define HEAPSIZE 64
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ HANDLE ProcessHeapHandle;
+ LPVOID lpHeap;
+
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Retrieve the calling process heap handle
+ ProcessHeapHandle = GetProcessHeap();
+
+ if(!ProcessHeapHandle)
+ {
+ Fail("\nFailed to call GetProcessHeap API!\n");
+ }
+
+ lpHeap = HeapAlloc(ProcessHeapHandle,//HeapHandle
+ HEAP_ZERO_MEMORY,//control flag
+ HEAPSIZE); //specify the heap size
+ if(NULL == lpHeap)
+ {
+ Fail("Failed to call HeapAlloc API!\n");
+ }
+
+ //free the heap memory
+ err = HeapFree(ProcessHeapHandle,
+ 0,
+ lpHeap);
+ if(0 == err)
+ {
+ Fail("Failed to call HeapFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/testinfo.dat
new file mode 100644
index 0000000000..5c6e77d2cc
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test2/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = HeapAlloc
+Name = Positive test for HeapAlloc API
+TYPE = DEFAULT
+EXE1 = heapalloc
+Description
+=Test the HeapAlloc with HEAP_ZERO_MEMORY control flag
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/CMakeLists.txt
new file mode 100644
index 0000000000..f0b89461d2
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ HeapAlloc.c
+)
+
+add_executable(paltest_heapalloc_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_heapalloc_test3 coreclrpal)
+
+target_link_libraries(paltest_heapalloc_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.c
new file mode 100644
index 0000000000..4a74fe8194
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/HeapAlloc.c
@@ -0,0 +1,62 @@
+// 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: heapalloc.c
+**
+** Purpose: Positive test the HeapAlloc API.
+** Call HeapAlloc asking for zero bytes
+** with HEAP_ZERO_MEMORY control flag
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define HEAPSIZE 0
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ HANDLE ProcessHeapHandle;
+ LPVOID lpHeap;
+
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Retrieve the calling process heap handle
+ ProcessHeapHandle = GetProcessHeap();
+
+ if(!ProcessHeapHandle)
+ {
+ Fail("\nFailed to call GetProcessHeap API!\n");
+ }
+
+ lpHeap = HeapAlloc(ProcessHeapHandle,//HeapHandle
+ HEAP_ZERO_MEMORY,//control flag
+ HEAPSIZE); //specify the heap size
+
+ //lpHeap should be non-NULL pointer
+ if(NULL == lpHeap)
+ {
+ Fail("Failed to call HeapAlloc API, when number of bytes to be allocated is zero!\n");
+ }
+
+ //free the heap memory
+ err = HeapFree(ProcessHeapHandle,
+ 0,
+ lpHeap);
+ if(0 == err)
+ {
+ Fail("Failed to call HeapFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/testinfo.dat
new file mode 100644
index 0000000000..c7d67d3b4f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapAlloc/test3/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = HeapAlloc
+Name = Positive test for HeapAlloc API
+TYPE = DEFAULT
+EXE1 = heapalloc
+Description
+=Test the HeapAlloc asking for zero bytes with HEAP_ZERO_MEMORY control flag
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/CMakeLists.txt
new file mode 100644
index 0000000000..f6aa0cb2d9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/CMakeLists.txt
new file mode 100644
index 0000000000..898047a9ad
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ HeapFree.c
+)
+
+add_executable(paltest_heapfree_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_heapfree_test1 coreclrpal)
+
+target_link_libraries(paltest_heapfree_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/HeapFree.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/HeapFree.c
new file mode 100644
index 0000000000..37b6b3bf60
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/HeapFree.c
@@ -0,0 +1,62 @@
+// 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: heapfree.c
+**
+** Purpose: Positive test the HeapFree API.
+** Call HeapFree to free a memory block
+** and try to free an invalid memory block
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define HEAPSIZE 64
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ HANDLE ProcessHeapHandle;
+ LPVOID lpHeap;
+
+
+ /* Initialize the PAL environment */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Retrieve the calling process heap handle */
+ ProcessHeapHandle = GetProcessHeap();
+
+ if(!ProcessHeapHandle)
+ {
+ Fail("\nFailed to call GetProcessHeap API!\n");
+ }
+
+
+ lpHeap = HeapAlloc(ProcessHeapHandle,/* HeapHandle */
+ HEAP_ZERO_MEMORY,/* control flag */
+ HEAPSIZE); /* specify the heap size */
+ if(NULL == lpHeap)
+ {
+ Fail("Failed to call HeapAlloc API!\n");
+ }
+
+
+ /* free a allocate heap memory */
+ err = HeapFree(ProcessHeapHandle,
+ 0,
+ lpHeap);
+
+ if(0 == err)
+ {
+ Fail("Failed to call HeapFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/testinfo.dat
new file mode 100644
index 0000000000..c6f18167e3
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapFree/test1/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = HeapFree
+Name = Positive test for HeapFree API to free an allocated heap block
+TYPE = DEFAULT
+EXE1 = heapfree
+Description
+=Test the HeapFree to free a memory block
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/CMakeLists.txt
new file mode 100644
index 0000000000..8083faf655
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+add_subdirectory(test4)
+add_subdirectory(test5)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/CMakeLists.txt
new file mode 100644
index 0000000000..1decb02c73
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test1.c
+)
+
+add_executable(paltest_heaprealloc_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_heaprealloc_test1 coreclrpal)
+
+target_link_libraries(paltest_heaprealloc_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/test1.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/test1.c
new file mode 100644
index 0000000000..497d208eca
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/test1.c
@@ -0,0 +1,72 @@
+// 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: test1.c
+**
+** Purpose: Allocate some memory. Then reallocate that memory. Ensure the
+** return values are correct, and also that data placed in the allocated
+** memory carries over to the reallocated block.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE TheHeap;
+ char* TheMemory;
+ char* ReAllocMemory;
+ int i;
+
+ if(PAL_Initialize(argc, argv) != 0)
+ {
+ return FAIL;
+ }
+
+ TheHeap = GetProcessHeap();
+
+ if(TheHeap == NULL)
+ {
+ Fail("ERROR: GetProcessHeap() returned NULL when it was called. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+ /* Allocate 100 bytes on the heap */
+ if((TheMemory = HeapAlloc(TheHeap, 0, 100)) == NULL)
+ {
+ Fail("ERROR: HeapAlloc returned NULL when it was called. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+ /* Set each byte of that memory block to 'x' */
+ memset(TheMemory, 'X', 100);
+
+ /* Reallocate the memory */
+ ReAllocMemory = HeapReAlloc(TheHeap, 0, TheMemory, 100);
+
+ if(ReAllocMemory == NULL)
+ {
+ Fail("ERROR: HeapReAlloc failed to reallocate the 100 bytes of "
+ "heap memory. GetLastError returns %d.",GetLastError());
+ }
+
+ /* Check that each byte of the memory Reallocated is 'x' */
+
+ for(i=0; i<100; ++i)
+ {
+ if(ReAllocMemory[i] != 'X')
+ {
+ Fail("ERROR: Byte number %d of the reallocated memory block "
+ "is not set to 'X' as it should be.",i);
+ }
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/testinfo.dat
new file mode 100644
index 0000000000..ad3a3ffc73
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test1/testinfo.dat
@@ -0,0 +1,14 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = HeapReAlloc
+Name = Positive test for HeapReAlloc to check normal behaviour
+TYPE = DEFAULT
+EXE1 = test1
+Description
+= Allocate some memory. Then reallocate that memory. Ensure the
+= return values are correct, and also that data placed in the allocated
+= memory carries over to the reallocated block.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/CMakeLists.txt
new file mode 100644
index 0000000000..6f5510387a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test2.c
+)
+
+add_executable(paltest_heaprealloc_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_heaprealloc_test2 coreclrpal)
+
+target_link_libraries(paltest_heaprealloc_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/test2.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/test2.c
new file mode 100644
index 0000000000..13e789f901
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/test2.c
@@ -0,0 +1,79 @@
+// 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: test2.c
+**
+** Purpose: Allocate some memory. Then reallocate that memory into less
+** space than the original amount. Ensure the
+** return values are correct, and also that data placed in the allocated
+** memory carries over to the reallocated block.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE TheHeap;
+ char* TheMemory;
+ char* ReAllocMemory;
+ int i;
+
+ if(PAL_Initialize(argc, argv) != 0)
+ {
+ return FAIL;
+ }
+
+ TheHeap = GetProcessHeap();
+
+ if(TheHeap == NULL)
+ {
+ Fail("ERROR: GetProcessHeap() returned NULL when it was called. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+ /* Allocate 200 bytes on the heap */
+ if((TheMemory = HeapAlloc(TheHeap, 0, 200)) == NULL)
+ {
+ Fail("ERROR: HeapAlloc returned NULL when it was called. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+ /* Set the first 100 bytes to 'X' */
+ memset(TheMemory, 'X', 100);
+
+ /* Set the second 100 bytes to 'Z' */
+ memset(TheMemory+100, 'Z', 100);
+
+ /* Reallocate the memory to 100 bytes */
+ ReAllocMemory = HeapReAlloc(TheHeap, 0, TheMemory, 100);
+
+ if(ReAllocMemory == NULL)
+ {
+ Fail("ERROR: HeapReAlloc failed to reallocate the 100 bytes of "
+ "heap memory. GetLastError returns %d.",GetLastError());
+ }
+
+ /* Check that each of the first 100 bytes hasn't lost any data.
+ Anything beyond the first 100 might still be valid, but we can't
+ gaurentee it.
+ */
+
+ for(i=0; i<100; ++i)
+ {
+ /* Note: Cast to char* so the function knows the size is 1 */
+ if(ReAllocMemory[i] != 'X')
+ {
+ Fail("ERROR: Byte number %d of the reallocated memory block "
+ "is not set to 'X' as it should be.",i);
+ }
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/testinfo.dat
new file mode 100644
index 0000000000..95a12aafd5
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test2/testinfo.dat
@@ -0,0 +1,15 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = HeapReAlloc
+Name = Positive test for HeapReAlloc to reallocate into a smaller space
+TYPE = DEFAULT
+EXE1 = test2
+Description
+= Allocate some memory. Then reallocate that memory into less
+= space than the origional amount. Ensure the
+= return values are correct, and also that data placed in the allocated
+= memory carries over to the reallocated block.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/CMakeLists.txt
new file mode 100644
index 0000000000..7ad836706a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test3.c
+)
+
+add_executable(paltest_heaprealloc_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_heaprealloc_test3 coreclrpal)
+
+target_link_libraries(paltest_heaprealloc_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/test3.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/test3.c
new file mode 100644
index 0000000000..dea9de348d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/test3.c
@@ -0,0 +1,78 @@
+// 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: test3.c
+**
+** Purpose: Allocate some memory. Then reallocate that memory into a
+** bigger space on the heap. Check that the first portion of the data is
+** unchanged. Then set the new portion to a value, to ensure that it is
+** properly writable memory.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE TheHeap;
+ char* TheMemory;
+ char* ReAllocMemory;
+ int i;
+
+ if(PAL_Initialize(argc, argv) != 0)
+ {
+ return FAIL;
+ }
+
+ TheHeap = GetProcessHeap();
+
+ if(TheHeap == NULL)
+ {
+ Fail("ERROR: GetProcessHeap() returned NULL when it was called. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+ /* Allocate 100 bytes on the heap */
+ if((TheMemory = HeapAlloc(TheHeap, 0, 100)) == NULL)
+ {
+ Fail("ERROR: HeapAlloc returned NULL when it was called. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+ /* Set the first 100 bytes to 'X' */
+ memset(TheMemory, 'X', 100);
+
+ /* Reallocate the memory to 200 bytes */
+ ReAllocMemory = HeapReAlloc(TheHeap, 0, TheMemory, 200);
+
+ if(ReAllocMemory == NULL)
+ {
+ Fail("ERROR: HeapReAlloc failed to reallocate the 100 bytes of "
+ "heap memory. GetLastError returns %d.",GetLastError());
+ }
+
+ /* Check that each of the first 100 bytes hasn't lost any data. */
+ for(i=0; i<100; ++i)
+ {
+
+ if(ReAllocMemory[i] != 'X')
+ {
+ Fail("ERROR: Byte number %d of the reallocated memory block "
+ "is not set to 'X' as it should be.",i);
+ }
+ }
+
+ /* Beyond the first 100 bytes is valid free memory. We'll set all this
+ memory to a value -- though, even if HeapReAlloc didn't work, it might
+ still be possible to memset this memory without raising an exception.
+ */
+ memset(ReAllocMemory+100, 'Z', 100);
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/testinfo.dat
new file mode 100644
index 0000000000..ed6da87c33
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test3/testinfo.dat
@@ -0,0 +1,16 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = HeapReAlloc
+Name = Positive test for HeapReAlloc to reallocate into a larger space
+TYPE = DEFAULT
+EXE1 = test3
+Description
+= Allocate some memory. Then reallocate that memory into a
+= bigger space on the heap. Check that the first portion of the data is
+= unchanged. Then set the new portion to a value, to ensure that it is
+= properly writable memory.
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/CMakeLists.txt
new file mode 100644
index 0000000000..024a4ef840
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test4.c
+)
+
+add_executable(paltest_heaprealloc_test4
+ ${SOURCES}
+)
+
+add_dependencies(paltest_heaprealloc_test4 coreclrpal)
+
+target_link_libraries(paltest_heaprealloc_test4
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/test4.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/test4.c
new file mode 100644
index 0000000000..cebf904501
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/test4.c
@@ -0,0 +1,80 @@
+// 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: test4.c
+**
+** Purpose: Call HeapReAlloc with a NULL pointer to memory. It should
+** return NULL.
+**
+**
+**============================================================*/
+
+/* Note: When attempted with a NULL Handle, this test crashes under win32.
+ As such, the behaviour isn't tested here.
+*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE TheHeap;
+ LPVOID TheMemory = NULL;
+
+ if(PAL_Initialize(argc, argv) != 0)
+ {
+ return FAIL;
+ }
+
+ TheHeap = GetProcessHeap();
+
+ if(TheHeap == NULL)
+ {
+ Fail("ERROR: GetProcessHeap() returned NULL when it was called. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+ /* Allocate 100 bytes on the heap */
+ if(HeapAlloc(TheHeap, 0, 100) == NULL)
+ {
+ Fail("ERROR: HeapAlloc returned NULL when it was called. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+ /* Call HeapReAlloc with a NULL memory pointer. It should fail */
+
+ if(HeapReAlloc(TheHeap, 0, TheMemory, 100) != NULL)
+ {
+ Fail("ERROR: HeapReAlloc was passed an invalid memory pointer. "
+ "It should have failed and returned NULL upon failure.");
+ }
+
+ if(GetLastError() != 0)
+ {
+ Fail("ERROR: GetLastError should be zero after passing a NULL "
+ "memory pointer to HeapReAlloc.\n");
+ }
+
+ /* Call HeapReAlloc with a size of 0 bytes on a NULL memory pointer.
+ It should still fail.
+ */
+
+ if(HeapReAlloc(TheHeap, 0, TheMemory, 0) != NULL)
+ {
+ Fail("ERROR: HeapReAlloc was passed an invalid memory pointer and "
+ "the amount of memory to reallocate was 0. "
+ "It should have failed and returned NULL upon failure.");
+ }
+
+ if(GetLastError() != 0)
+ {
+ Fail("ERROR: GetLastError should be zero after passing a NULL "
+ "memory pointer to HeapReAlloc.\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/testinfo.dat
new file mode 100644
index 0000000000..cfa5f5ceed
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test4/testinfo.dat
@@ -0,0 +1,15 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = HeapReAlloc
+Name = Negative test for HeapReAlloc
+TYPE = DEFAULT
+EXE1 = test4
+Description
+= Call HeapReAlloc with a NULL pointer to memory. It should
+= return NULL.
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/CMakeLists.txt
new file mode 100644
index 0000000000..3ab3ec16e8
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test5.c
+)
+
+add_executable(paltest_heaprealloc_test5
+ ${SOURCES}
+)
+
+add_dependencies(paltest_heaprealloc_test5 coreclrpal)
+
+target_link_libraries(paltest_heaprealloc_test5
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/test5.c b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/test5.c
new file mode 100644
index 0000000000..230e65e492
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/test5.c
@@ -0,0 +1,69 @@
+// 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: test5.c
+**
+** Purpose: Allocate some memory. Then call HeapRealloc with 0 as the
+** amount of memory to reallocate. This should work, essentially freeing
+** the memory (though we can't verfiy this)
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE TheHeap;
+ char* TheMemory;
+ char* ReAllocMemory;
+ char* ReAllocMemory2;
+
+ if(PAL_Initialize(argc, argv) != 0)
+ {
+ return FAIL;
+ }
+
+ TheHeap = GetProcessHeap();
+
+ if(TheHeap == NULL)
+ {
+ Fail("ERROR: GetProcessHeap() returned NULL when it was called. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+ /* Allocate 100 bytes on the heap */
+ if((TheMemory = HeapAlloc(TheHeap, 0, 100)) == NULL)
+ {
+ Fail("ERROR: HeapAlloc returned NULL when it was called. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+ /* Set each byte of that memory block to 'x' */
+ memset(TheMemory, 'X', 100);
+
+ /* Reallocate the memory into 0 bytes */
+ ReAllocMemory = HeapReAlloc(TheHeap, 0, TheMemory, 0);
+
+ if(ReAllocMemory == NULL)
+ {
+ Fail("ERROR: HeapReAlloc failed to reallocate the 100 bytes of "
+ "heap memory. GetLastError returns %d.",GetLastError());
+ }
+
+ /* Reallocate the memory we just put into 0 bytes, into 100 bytes. */
+ ReAllocMemory2 = HeapReAlloc(TheHeap, 0, ReAllocMemory, 100);
+
+ if(ReAllocMemory2 == NULL)
+ {
+ Fail("ERROR: HeapReAlloc failed to reallocate the 0 bytes of "
+ "heap memory into 100. GetLastError returns %d.",GetLastError());
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/testinfo.dat
new file mode 100644
index 0000000000..e36b9035c5
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/HeapReAlloc/test5/testinfo.dat
@@ -0,0 +1,15 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = HeapReAlloc
+Name = Positive test for HeapReAlloc to check behaviour with byte size 0
+TYPE = DEFAULT
+EXE1 = test5
+Description
+= Allocate some memory. Then call HeapRealloc with 0 as the
+= amount of memory to reallocate. This should work, essentially freeing
+= the memory (though we can't verfiy this)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/CMakeLists.txt
new file mode 100644
index 0000000000..f6aa0cb2d9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/CMakeLists.txt
new file mode 100644
index 0000000000..c96e00a170
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ LocalAlloc.c
+)
+
+add_executable(paltest_localalloc_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_localalloc_test1 coreclrpal)
+
+target_link_libraries(paltest_localalloc_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/LocalAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/LocalAlloc.c
new file mode 100644
index 0000000000..17afbc6020
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/LocalAlloc.c
@@ -0,0 +1,49 @@
+// 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: LocalAlloc.c
+**
+** Purpose: Positive test the LocalAlloc API.
+** Call LocalAlloc with zero as the allocation attribute
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ HLOCAL LocalHeap;
+ HLOCAL FreeHeap;
+ int err;
+ const SIZE_T heapSize = 64;
+
+ /*Initialize the PAL environment*/
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ return FAIL;
+ }
+
+ /*Allocate the specified number of bytes from the heap*/
+ /*with allocation attribute: zero which is required by PAL Doc*/
+ LocalHeap = LocalAlloc(0, heapSize);
+ if(!LocalHeap)
+ {
+ Fail("\nFailed to call LocalAlloc API, "
+ "error code=%u\n", GetLastError());
+ }
+
+ /*Free the allocated local heap memory*/
+ FreeHeap = LocalFree(LocalHeap);
+ if(FreeHeap)
+ {
+ Fail("Failed to call LocalFree API, "
+ "error code=%u\n", GetLastError());
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/testinfo.dat
new file mode 100644
index 0000000000..056d9ceb21
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalAlloc/test1/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = LocalAlloc
+Name = Positive test LocalAlloc API to Allocate the specified number of bytes from the heap
+TYPE = DEFAULT
+EXE1 = localalloc
+Description
+=Test the LocalAlloc with zero ad allocation attribute
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/CMakeLists.txt
new file mode 100644
index 0000000000..ef14ea5352
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/CMakeLists.txt
new file mode 100644
index 0000000000..47ad76ebe6
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ LocalFree.c
+)
+
+add_executable(paltest_localfree_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_localfree_test1 coreclrpal)
+
+target_link_libraries(paltest_localfree_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/LocalFree.c b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/LocalFree.c
new file mode 100644
index 0000000000..d9c062e761
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/LocalFree.c
@@ -0,0 +1,49 @@
+// 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: LocalFree.c
+**
+** Purpose: Positive test the LocalFree API.
+** Call LocalFree to free a specified local memory object
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ HLOCAL LocalHeap;
+ HLOCAL FreeHeap;
+ int err;
+ const SIZE_T heapSize = 64;
+
+ /*Initialize the PAL environment*/
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ return FAIL;
+ }
+
+ /*Allocate the specified number of bytes from the heap*/
+ /*with zero ad the allocation attribute*/
+ LocalHeap = LocalAlloc(0, heapSize);
+ if(!LocalHeap)
+ {
+ Fail("\nFailed to call LocalAlloc API, "
+ "error code=%u\n", GetLastError());
+ }
+
+ /*Free the allocated local heap memory*/
+ FreeHeap = LocalFree(LocalHeap);
+ if(FreeHeap)
+ {
+ Fail("Failed to call LocalFree API, "
+ "error code=%u\n", GetLastError());
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/testinfo.dat
new file mode 100644
index 0000000000..2c0611bdec
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test1/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = LocalFree
+Name = Positive test LocalFree API to free a specified local memory object
+TYPE = DEFAULT
+EXE1 = localfree
+Description
+=Test the LocalFree to free a specified local memory object
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/CMakeLists.txt
new file mode 100644
index 0000000000..ac7a11a05f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ LocalFree.c
+)
+
+add_executable(paltest_localfree_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_localfree_test2 coreclrpal)
+
+target_link_libraries(paltest_localfree_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/LocalFree.c b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/LocalFree.c
new file mode 100644
index 0000000000..4d4567dc3f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/LocalFree.c
@@ -0,0 +1,39 @@
+// 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: LocalFree.c
+**
+** Purpose: Positive test the LocalFree API.
+** call LocalFree by passing NULL as local memory
+** object handle
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ HLOCAL FreeHeap;
+ int err;
+
+ /*Initialize the PAL environment*/
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ return FAIL;
+ }
+
+ /*call LocalFree by passing NULL as local memory object handle*/
+ FreeHeap = LocalFree(NULL);
+ if(FreeHeap)
+ {
+ Fail("Failed to call LocalFree API, "
+ "error code=%u\n", GetLastError());
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/testinfo.dat
new file mode 100644
index 0000000000..1455fe93b7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LocalFree/test2/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = LocalFree
+Name = Positive test LocalFree API by passing NULL as local memory object handle
+TYPE = DEFAULT
+EXE1 = localfree
+Description
+=Test the LocalFree by passing NULL
+=as a local memory object handle
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/CMakeLists.txt
new file mode 100644
index 0000000000..19ee487a6a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+add_subdirectory(test4)
+add_subdirectory(test5)
+add_subdirectory(test6)
+add_subdirectory(test7)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/LockFile.h b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/LockFile.h
new file mode 100644
index 0000000000..2862b6c524
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/LockFile.h
@@ -0,0 +1,152 @@
+// 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: LockFile.h
+**
+** Purpose: This header file has a RunHelper method which will be used to
+** start a child proccess in many LockFile testcases. The CreateAndLockFile
+** method Creates a file and calls LockFile upon it. And the two Signal
+** methods are used for IPC.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+int RunHelper(char* Helper)
+{
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+ DWORD RetCode;
+
+ ZeroMemory( &si, sizeof(si) );
+ si.cb = sizeof(si);
+ ZeroMemory( &pi, sizeof(pi) );
+
+ if(!CreateProcess( NULL,Helper,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
+ {
+ Fail("ERROR: CreateProcess failed to load executable '%s'.",Helper);
+ }
+
+ if(WaitForSingleObject( pi.hProcess, INFINITE ) == WAIT_FAILED)
+ {
+ Fail("ERROR: WaitForSingleObject returned WAIT_FAILED when it was "
+ "called.");
+ }
+
+ /* Get the return value from the helper process */
+ if (GetExitCodeProcess(pi.hProcess, &RetCode) == 0)
+ {
+ Fail("ERROR: GetExitCodeProccess failed when attempting to retrieve "
+ "the exit code of the child process.");
+ }
+
+ if(CloseHandle( pi.hProcess ) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the process.");
+ }
+
+ if(CloseHandle( pi.hThread ) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the thread.");
+ }
+
+ return RetCode;
+}
+
+HANDLE CreateAndLockFile(HANDLE TheFile, char* FileName, char* WriteBuffer,
+ DWORD LockStart, DWORD LockLength)
+{
+ DWORD BytesWritten;
+
+ TheFile = CreateFile(FileName,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.",FileName,GetLastError());
+ }
+
+ if(WriteFile(TheFile, WriteBuffer,
+ strlen(WriteBuffer),&BytesWritten, NULL) == 0)
+ {
+ Fail("ERROR: WriteFile has failed. It returned 0 when we "
+ "attempted to write to the file '%s'. GetLastError() "
+ "returned %d.",FileName,GetLastError());
+ }
+
+ if(FlushFileBuffers(TheFile) == 0)
+ {
+ Fail("ERROR: FlushFileBuffers returned failure. GetLastError() "
+ "returned %d.",GetLastError());
+ }
+
+ if(LockFile(TheFile, LockStart, 0, LockLength, 0) == 0)
+ {
+ Fail("ERROR: LockFile failed. GetLastError returns %d.",
+ GetLastError());
+ }
+
+ return TheFile;
+}
+
+void SignalAndBusyWait(HANDLE TheFile)
+{
+ int size;
+ DWORD BytesWritten;
+
+ size = GetFileSize(TheFile,NULL)+1;
+
+ if(SetFilePointer(TheFile, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
+ {
+ Fail("ERROR: SetFilePointer was unable to set the pointer to the "
+ "end of the file. GetLastError() returned %d.",GetLastError());
+ }
+
+ if(WriteFile(TheFile, "x", 1,&BytesWritten, NULL) == 0)
+ {
+ Fail("ERROR: WriteFile was unable to write to the WaitFile. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+ if(FlushFileBuffers(TheFile) == 0)
+ {
+ Fail("ERROR: FlushFileBuffers failed when flushing the WaitFile. "
+ "GetLastError() returned %d.");
+ }
+
+ while(GetFileSize(TheFile,NULL) == size) { Sleep(100); }
+}
+
+void SignalFinish(HANDLE TheFile)
+{
+ DWORD BytesWritten;
+
+ if(SetFilePointer(TheFile, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
+ {
+ Fail("ERROR: SetFilePointer was unable to set the pointer to the "
+ "end of the WaitFile. GetLastError() returned %d.",
+ GetLastError());
+ }
+
+ if(WriteFile(TheFile, "x", 1,&BytesWritten, NULL) == 0)
+ {
+ Fail("ERROR: WriteFile was unable to write to the WaitFile. "
+ "GetLastError returned %d.",GetLastError());
+ }
+
+ if(FlushFileBuffers(TheFile) == 0)
+ {
+ Fail("ERROR: FlushFileBuffers failed when flushing the WaitFile. "
+ "GetLastError() returned %d.");
+ }
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/CMakeLists.txt
new file mode 100644
index 0000000000..0af09480ef
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/CMakeLists.txt
@@ -0,0 +1,36 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(TESTSOURCES
+ test1.c
+)
+
+add_executable(paltest_lockfile_test1
+ ${TESTSOURCES}
+)
+
+add_dependencies(paltest_lockfile_test1 coreclrpal)
+
+target_link_libraries(paltest_lockfile_test1
+ pthread
+ m
+ coreclrpal
+)
+
+
+set(HELPERSOURCES
+ helper.c
+)
+
+add_executable(paltest_lockfile_test1_helper
+ ${HELPERSOURCES}
+)
+
+add_dependencies(paltest_lockfile_test1_helper coreclrpal)
+
+target_link_libraries(paltest_lockfile_test1_helper
+ pthread
+ m
+ coreclrpal
+) \ No newline at end of file
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/helper.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/helper.c
new file mode 100644
index 0000000000..05b4b8451a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/helper.c
@@ -0,0 +1,86 @@
+// 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: helper.c
+**
+** Purpose: A child process which will attempt to read and write to files
+** which were locked in the parent.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+#define BUF_SIZE 128
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE TheFile;
+ int result = 0;
+ char DataBuffer[BUF_SIZE];
+ DWORD BytesRead, BytesWritten;
+ char fileName[] = "testfile.tmp";
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Open the same file that the parent has opened and locked */
+ TheFile = CreateFile(fileName,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile.",fileName);
+ }
+
+ /* Attempt to Read 5 bytes from this file. Since it is locked, this
+ should fail.
+ */
+
+ if(ReadFile(TheFile, DataBuffer, 5, &BytesRead, NULL) != 0)
+ {
+ Trace("ERROR: ReadFile should have failed! It was called on "
+ "a locked file. But, it returned non-zero indicating success.");
+ result = 1;
+ }
+
+ /* Attempt to Write 5 bytes to this file. Since it is locked this should
+ fail.
+ */
+
+ memset(DataBuffer,'X',BUF_SIZE);
+
+ if(WriteFile(TheFile, DataBuffer, 5,&BytesWritten, NULL) != 0)
+ {
+ Trace("ERROR: WriteFile should have failed! It was called on "
+ "a locked file. But, it returned non-zero indicating success.");
+ result = 1;
+ }
+
+ /* Check to ensure that the number of Bytes read/written is still 0,
+ since nothing should have been read or written.
+ */
+
+ if(BytesRead != 0 || BytesWritten !=0)
+ {
+ Trace("ERROR: The number of bytes read is %d and written is %d. "
+ "These should both be 0, as the file was locked.",
+ BytesRead,BytesWritten);
+ result = 1;
+ }
+
+ PAL_TerminateEx(result);
+ return result;
+}
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/test1.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/test1.c
new file mode 100644
index 0000000000..cee223ef81
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/test1.c
@@ -0,0 +1,140 @@
+// 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: test1.c
+**
+** Purpose: Open a file, and lock it from start to EOF. Then create a
+** new process, which will attempt to Read and Write from the file. Check
+** to ensure both of these operations fail.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+#include "../LockFile.h"
+
+#define HELPER "helper"
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE TheFile;
+ DWORD FileStart = 0;
+ DWORD FileEnd = 0;
+ const char lpBuffer[] = "This is a test file.";
+ DWORD bytesWritten;
+ BOOL bRc = TRUE;
+ char fileName[] = "testfile.tmp";
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Important to have sharing enabled, or there is no need for the lock. */
+ TheFile = CreateFile(fileName,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile.",fileName);
+ }
+
+ bRc = WriteFile(TheFile,
+ lpBuffer,
+ (DWORD)sizeof(lpBuffer),
+ &bytesWritten,
+ NULL);
+
+ if(!bRc)
+ {
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+
+ Fail("ERROR: Could not write to file '%s' with WriteFile.",fileName);
+ }
+ else if(bytesWritten != (DWORD)sizeof(lpBuffer))
+ {
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+
+ Fail("ERROR: Could not write the correct number of bytes to the "
+ "file '%s' with WriteFile.",fileName);
+ }
+
+ /* Find the value for the End of the file */
+ FileEnd = SetFilePointer(TheFile,0,NULL,FILE_END);
+
+ if(FileEnd == INVALID_SET_FILE_POINTER)
+ {
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+
+ Fail("ERROR: Could not set the file pointer to the end of the file "
+ "using SetFilePointer. It returned INVALID_SET_FILE_POINTER.");
+ }
+
+ /* Lock the file from Start to EOF */
+
+ if(LockFile(TheFile, FileStart, 0, FileEnd, 0) == 0)
+ {
+ Trace("ERROR: LockFile failed. GetLastError returns %d.",
+ GetLastError());
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ /* Launch another process, which will attempt to read and write from
+ the locked file.
+
+ If the helper program returns 1, then the test fails. More
+ specific errors are given by the Helper file itself.
+ */
+ if(RunHelper(HELPER))
+ {
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+
+ Fail("ERROR: The Helper program determined that the file was not "
+ "locked properly by LockFile.");
+ }
+
+ if(UnlockFile(TheFile, FileStart, 0, FileEnd, 0) == 0)
+ {
+ Trace("ERROR: UnlockFile failed. GetLastError returns %d.",
+ GetLastError());
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/testinfo.dat
new file mode 100644
index 0000000000..cbe4d94d40
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test1/testinfo.dat
@@ -0,0 +1,15 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = LockFile
+Name = Positive test for LockFile API
+TYPE = DEFAULT
+EXE1 = test1
+EXE2 = helper
+Description
+= Open a file, and lock it from start to EOF. Then create a
+= new process, which will attempt to Read and Write from the file. Check
+= to ensure both of these operations fail.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/CMakeLists.txt
new file mode 100644
index 0000000000..157c517e62
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test2.c
+)
+
+add_executable(paltest_lockfile_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_lockfile_test2 coreclrpal)
+
+target_link_libraries(paltest_lockfile_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/test2.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/test2.c
new file mode 100644
index 0000000000..8aef130ef4
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/test2.c
@@ -0,0 +1,94 @@
+// 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: test2.c
+**
+** Purpose: Open a file, and lock it from start to EOF. Check to ensure
+** the current process can still read and write from/to the file.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+#include "../LockFile.h"
+
+#define FILENAME "testfile.txt"
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE TheFile = NULL;
+ DWORD FileStart = 0;
+ DWORD FileEnd = 0;
+ DWORD BytesWritten = 0;
+ DWORD BytesRead = 0;
+ char WriteBuffer[] = "This is some test data.";
+ char DataBuffer[128];
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Call the helper function to Create a file, write 'WriteBuffer' to
+ the file, and lock the file.
+ */
+
+ FileEnd = strlen(WriteBuffer);
+ TheFile = CreateAndLockFile(TheFile, FILENAME, WriteBuffer,
+ FileStart, FileEnd);
+
+ /* Move the file pointer to the start of the file */
+ if(SetFilePointer(TheFile, 0, NULL, FILE_BEGIN) != 0)
+ {
+ Fail("ERROR: SetFilePointer failed to move the file pointer back "
+ "to the start of the file.");
+ }
+
+ /* Attempt to Read 5 bytes from this file. Since the lock does not
+ affect the calling process, this should succeed.
+ */
+
+ if(ReadFile(TheFile, DataBuffer, 5, &BytesRead, NULL) == 0)
+ {
+ Fail("ERROR: ReadFile has failed. Attempted to read in 5 bytes from "
+ "the file '%s' after it had LockFile called upon it, but within "
+ "the same process.",FILENAME);
+ }
+
+ if(strncmp(DataBuffer, WriteBuffer, 5) != 0)
+ {
+ Fail("ERROR: The data read in from ReadFile is not what should have "
+ "been written in the file. '%s' ",DataBuffer);
+ }
+
+ /* Attempt to Write 5 bytes to this file. Since the lock does not affect
+ the calling process, this should succeed.
+ */
+
+ memset(WriteBuffer, 'X', strlen(WriteBuffer));
+
+ if(WriteFile(TheFile, WriteBuffer, 5,&BytesWritten, NULL) == 0)
+ {
+ Fail("ERROR: WriteFile has failed. Attempted to write 5 bytes to "
+ "the file '%s' after it had LockFile called upon it, but within "
+ "the same process.",FILENAME);
+ }
+
+ if(UnlockFile(TheFile, FileStart, 0, FileEnd, 0) == 0)
+ {
+ Fail("ERROR: UnlockFile failed. GetLastError returns %d.",
+ GetLastError());
+ }
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/testinfo.dat
new file mode 100644
index 0000000000..c84e7c0a0a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test2/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = LockFile
+Name = Positive test for LockFile API
+TYPE = DEFAULT
+EXE1 = test2
+Description
+= Open a file, and lock it from start to EOF. Check to ensure
+= the current process can still read and write from/to the file.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/CMakeLists.txt
new file mode 100644
index 0000000000..69516de69b
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/CMakeLists.txt
@@ -0,0 +1,36 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(TESTSOURCES
+ test3.c
+)
+
+add_executable(paltest_lockfile_test3
+ ${TESTSOURCES}
+)
+
+add_dependencies(paltest_lockfile_test3 coreclrpal)
+
+target_link_libraries(paltest_lockfile_test3
+ pthread
+ m
+ coreclrpal
+)
+
+
+set(HELPERSOURCES
+ helper.c
+)
+
+add_executable(paltest_lockfile_test3_helper
+ ${HELPERSOURCES}
+)
+
+add_dependencies(paltest_lockfile_test3_helper coreclrpal)
+
+target_link_libraries(paltest_lockfile_test3_helper
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/helper.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/helper.c
new file mode 100644
index 0000000000..079417fce8
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/helper.c
@@ -0,0 +1,102 @@
+// 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: helper.c
+**
+** Purpose: A child process which will attempt to read and write to files
+** which were locked in the parent.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+#define FILENAME "testfile.txt"
+#define BUF_SIZE 128
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE TheFile;
+ int result = 0;
+ char DataBuffer[BUF_SIZE];
+ DWORD BytesRead, BytesWritten;
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Open the same file that the parent has opened and locked */
+ TheFile = CreateFile(FILENAME,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returns %d.",FILENAME,GetLastError());
+ }
+
+ /* Attempt to Read the first 3 bytes from this file.
+ Since it is unlocked, this should work properly.
+ */
+
+ if(ReadFile(TheFile, DataBuffer, 3, &BytesRead, NULL) == 0)
+ {
+ Trace("ERROR: ReadFile should have succeeded in reading the first "
+ "three bytes of the file, as these bytes were not locked. "
+ "GetLastError() returned %d.",GetLastError());
+ result = 1;
+ }
+
+ /* Now, read the next 10 bytes, which should be locked. Ensure that
+ ReadFile fails.
+ */
+
+ if(ReadFile(TheFile, DataBuffer,10, &BytesRead, NULL) != 0)
+ {
+ Trace("ERROR: ReadFile should have failed when attempting to read in "
+ "bytes between StartOfFile+3 and EndOfFile-3.");
+ result = 1;
+ }
+
+ /* Attempt to Write 10 bytes to this file. Since it is locked this should
+ fail.
+ */
+
+ memset(DataBuffer,'X',BUF_SIZE);
+
+ if(WriteFile(TheFile, DataBuffer, 10,&BytesWritten, NULL) != 0)
+ {
+ Trace("ERROR: WriteFile should have failed when attempting to write "
+ "bytes between StartOfFile+3 and EOF-3.");
+ result = 1;
+ }
+
+
+ /* Move the FilePointer to the EOF-3, where the lock ends */
+ if(SetFilePointer(TheFile,-3,NULL,FILE_END) == INVALID_SET_FILE_POINTER)
+ {
+ Fail("ERROR: Could not set the file pointer to the EOF-3 "
+ "using SetFilePointer. It returned INVALID_SET_FILE_POINTER.");
+ }
+
+ /* Attempt to write to those 3 unlocked bytes on the end of the file */
+ if(WriteFile(TheFile, DataBuffer, 3,&BytesWritten, NULL) == 0)
+ {
+ Trace("ERROR: WriteFile should have succeeded when attempting "
+ "to write the last three bytes of the file, as they were not "
+ "locked. GetLastError() returned %d.",GetLastError());
+ result = 1;
+ }
+
+ PAL_TerminateEx(result);
+ return result;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/test3.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/test3.c
new file mode 100644
index 0000000000..78662c5685
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/test3.c
@@ -0,0 +1,71 @@
+// 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: test3.c
+**
+** Purpose: Open a file, lock a region in the middle. Create a new process
+** and attempt to read and write directly before and after that region, which
+** should succeed. Also, check to see that reading/writing in the locked
+** region fails.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+#include "../LockFile.h"
+
+#define HELPER "helper"
+#define FILENAME "testfile.txt"
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE TheFile = NULL;
+ DWORD FileStart = 0;
+ DWORD FileEnd = 0;
+ char* WriteBuffer = "12345678901234567890123456";
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Call the helper function to Create a file, write 'WriteBuffer' to
+ the file, and lock the file.
+ */
+
+ FileEnd = strlen(WriteBuffer);
+ TheFile = CreateAndLockFile(TheFile,FILENAME, WriteBuffer,
+ FileStart+3, FileEnd-6);
+
+
+ /* Launch another process, which will attempt to read and write from
+ the locked file.
+
+ If the helper program returns 1, then the test fails. More
+ specific errors are given by the Helper file itself.
+ */
+ if(RunHelper(HELPER))
+ {
+ Fail("ERROR: The Helper program determined that the file was not "
+ "locked properly by LockFile.");
+ }
+
+ if(UnlockFile(TheFile, FileStart+3, 0, FileEnd-6, 0) == 0)
+ {
+ Fail("ERROR: UnlockFile failed. GetLastError returns %d.",
+ GetLastError());
+ }
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/testinfo.dat
new file mode 100644
index 0000000000..b64ec5ed03
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test3/testinfo.dat
@@ -0,0 +1,16 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = LockFile
+Name = Positive test for LockFile API
+TYPE = DEFAULT
+EXE1 = test3
+EXE2 = helper
+Description
+= Open a file, lock a region in the middle. Create a new process
+= and attempt to read and write directly before and after that region, which
+= should succeed. Also, check to see that reading/writing in the locked
+= region fails.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/CMakeLists.txt
new file mode 100644
index 0000000000..fb8f6745d4
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test4.c
+)
+
+add_executable(paltest_lockfile_test4
+ ${SOURCES}
+)
+
+add_dependencies(paltest_lockfile_test4 coreclrpal)
+
+target_link_libraries(paltest_lockfile_test4
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/test4.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/test4.c
new file mode 100644
index 0000000000..f5cd359fb5
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/test4.c
@@ -0,0 +1,231 @@
+// 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: test4.c
+**
+** Purpose:
+** - Attempt to call LockFile on a file without GENERIC_READ or
+** GENERIC_WRITE (this should fail)
+** - Attempt to overlap two locks, this should fail.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+char fileName[] = "testfile.tmp";
+
+void OverlapTest()
+{
+ HANDLE TheFile = NULL;
+ DWORD FileStart = 0;
+ const char lpBuffer[] = "This is a test file.";
+ DWORD bytesWritten;
+ BOOL bRc = TRUE;
+
+ TheFile = CreateFile(fileName,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.",fileName,GetLastError());
+ }
+
+ bRc = WriteFile(TheFile,
+ lpBuffer,
+ (DWORD)sizeof(lpBuffer),
+ &bytesWritten,
+ NULL);
+
+ if(!bRc)
+ {
+ Trace("ERROR: Could not write to file '%s' with WriteFile.",fileName);
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+
+ }
+ else if(bytesWritten != (DWORD)sizeof(lpBuffer))
+ {
+ Trace("ERROR: Could not write the correct number of bytes to the "
+ "file '%s' with WriteFile.",fileName);
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ /* Lock the First 5 bytes of the File */
+
+ if(LockFile(TheFile, FileStart, 0, 5, 0) == 0)
+ {
+ Trace("ERROR: LockFile failed in Overlap test. "
+ "GetLastError returns %d.",
+ GetLastError());
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ /* Lock from Byte 2 until 7 -- this overlaps and should return failure. */
+ if(LockFile(TheFile,FileStart+2, 0, 5, 0) != 0)
+ {
+ Trace("ERROR: LockFile returned success when it was overlapped on "
+ "an already locked region of the file.");
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ /* Unlock the file */
+ if(UnlockFile(TheFile, FileStart, 0, 5, 0) == 0)
+ {
+ Trace("ERROR: UnlockFile failed in Overlap test. GetLastError "
+ "returns %d.",GetLastError());
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ /* Close the File */
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file in the Overlap "
+ "test. GetLastError() returned %d.",GetLastError());
+ }
+}
+
+void FlagsTest(DWORD TheFlags, int ExpectedResult)
+{
+ HANDLE TheFile = NULL;
+ DWORD FileStart = 0;
+ int result;
+
+ TheFile = CreateFile(fileName,
+ TheFlags,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.",fileName,GetLastError());
+ }
+
+ /* Lock the First 5 bytes of the File. The result of this depends
+ upon which flags were set with the CreateFile.
+ */
+
+ result = LockFile(TheFile, FileStart, 0, 5, 0);
+
+ /* If the expected result is 1, check to ensure the result is non-zero,
+ as non-zero is returned on success
+ */
+ if(ExpectedResult == 1)
+ {
+ if(result == 0)
+ {
+ Trace("ERROR: LockFile returned zero when the expected result "
+ "was non-zero. It was passed the flag value %d.",
+ TheFlags);
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+ }
+ /* If the expected result is 0, check to ensure the result is 0 */
+ else
+ {
+ if(result != 0)
+ {
+ Trace("ERROR: LockFile returned %d when the expected result "
+ "was zero. It was passed the flag value %d.",
+ result, TheFlags);
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+ }
+
+ /* Only unlock the file if we expect it to be successfully locked */
+ if(ExpectedResult)
+ {
+ if(UnlockFile(TheFile,FileStart,0, 5, 0) == 0)
+ {
+ Fail("ERROR: UnlockFile failed in the Flags Test. GetLastError() "
+ "returned %d.",GetLastError());
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+ }
+
+ /* Close the File */
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file in the Flags "
+ "test. GetLastError() returned %d.",GetLastError());
+ }
+}
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* This test opens a file, then calls lock twice, overlapping the
+ regions and checking to ensure that this causes an error.
+ */
+ OverlapTest();
+
+ /* Test that LockFile fails if no flags are set */
+ FlagsTest(0,0);
+
+ /* Test that LockFile passes if only GENERIC_READ is set */
+ FlagsTest(GENERIC_READ,1);
+
+ /* Test that LockFile passes if only GENERIC_WRITE is set */
+ FlagsTest(GENERIC_WRITE,1);
+
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/testinfo.dat
new file mode 100644
index 0000000000..0600260d82
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test4/testinfo.dat
@@ -0,0 +1,14 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = LockFile
+Name = Negative test for LockFile API
+TYPE = DEFAULT
+EXE1 = test4
+Description
+= - Attempt to call LockFile on a file without GENERIC_READ or
+= GENERIC_WRITE (this should fail)
+= - Attempt to overlap two locks, this should fail.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/CMakeLists.txt
new file mode 100644
index 0000000000..cc4548a6f0
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/CMakeLists.txt
@@ -0,0 +1,36 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(TESTSOURCES
+ test5.c
+)
+
+add_executable(paltest_lockfile_test5
+ ${TESTSOURCES}
+)
+
+add_dependencies(paltest_lockfile_test5 coreclrpal)
+
+target_link_libraries(paltest_lockfile_test5
+ pthread
+ m
+ coreclrpal
+)
+
+
+set(HELPERSOURCES
+ helper.c
+)
+
+add_executable(paltest_lockfile_test5_helper
+ ${HELPERSOURCES}
+)
+
+add_dependencies(paltest_lockfile_test5_helper coreclrpal)
+
+target_link_libraries(paltest_lockfile_test5_helper
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/helper.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/helper.c
new file mode 100644
index 0000000000..1fc9b1a9a5
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/helper.c
@@ -0,0 +1,122 @@
+// 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: helper.c
+**
+** Purpose: A child process which will attempt to read and write to files
+** which were locked in the parent. It will also lock another region of the
+** same file.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+#include "../LockFile.h"
+
+#define FILENAME "testfile.txt"
+#define WAITFILENAME "waitfile"
+#define BUF_SIZE 128
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE TheFile, WaitFile;
+ int result = 0;
+ char DataBuffer[BUF_SIZE];
+ DWORD BytesRead;
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Open the same file that the parent has opened and locked */
+ TheFile = CreateFile(FILENAME,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Trace("ERROR: Could not open file '%s' with CreateFile.",FILENAME);
+ result = 1;
+ }
+
+ /* Open up the WaitFile that we're using for IPC */
+ WaitFile = CreateFile(WAITFILENAME,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (WaitFile == INVALID_HANDLE_VALUE)
+ {
+ Trace("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.",WAITFILENAME,GetLastError());
+ result = 1;
+ }
+
+ /* Lock the same file that the parent process locked, but the child
+ locks bytes 11 through 20
+ */
+
+ if(LockFile(TheFile, 11, 0, 10, 0) == 0)
+ {
+ Trace("ERROR: LockFile failed in the child proccess. "
+ "GetLastError returns %d.",
+ GetLastError());
+ result = 1;
+ }
+
+ /* Check to ensure the parent lock is respected */
+ if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) != 0)
+ {
+ Trace("ERROR: ReadFile returned success when it should "
+ "have failed. Attempted to read the first 10 bytes "
+ "of a file which was locked by the parent process.");
+ result = 1;
+ }
+
+ /* Check to ensure the lock put on by this proccess doesn't restrict
+ access
+ */
+
+ if(SetFilePointer(TheFile, 11, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
+ {
+ Trace("ERROR: SetFilePointer was unable to move the file pointer to "
+ "the 11th byte in the file, within the child proccess. "
+ "GetLastError() returned %d.",GetLastError());
+ result = 1;
+ }
+
+ if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) == 0)
+ {
+ Trace("ERROR: ReadFile failed when attempting to read a section of "
+ "the file which was locked by the current process. It should "
+ "have been able to read this. GetLastError() returned %d.",
+ GetLastError());
+ result = 1;
+ }
+
+ // Sleep for a bit to give the parent a chance to block before we do.
+ Sleep(1000);
+
+ /* Switch back to the parent, so it can check the child's locks */
+ SignalAndBusyWait(WaitFile);
+
+ if(UnlockFile(TheFile, 11, 0, 10, 0) == 0)
+ {
+ Fail("ERROR: Failed to Unlock bytes 11-20 in the file. "
+ "GetLastError returned %d.",GetLastError());
+ }
+
+ PAL_TerminateEx(result);
+ return result;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/test5.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/test5.c
new file mode 100644
index 0000000000..a02a3c5a49
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/test5.c
@@ -0,0 +1,161 @@
+// 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: test5.c
+**
+** Purpose:
+** Have two processes obtain a lock on a single file, but in different
+** regions of the file. Use Read/Write to ensure the locks are respected.
+** This requires some IPC, which is done here with a crude busy wait on a
+** file (waiting for the file size to change) to avoid too many more
+** dependencies.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+#include "../LockFile.h"
+
+#define HELPER "helper"
+#define FILENAME "testfile.txt"
+#define WAITFILENAME "waitfile"
+#define BUF_SIZE 128
+
+int RunTest(char* Helper, HANDLE TheFile, HANDLE WaitFile)
+{
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+ DWORD ChildRetCode = 0;
+ DWORD ParentRetCode = 0;
+ DWORD BytesRead;
+ char DataBuffer[BUF_SIZE];
+
+
+ ZeroMemory( &si, sizeof(si) );
+ si.cb = sizeof(si);
+ ZeroMemory( &pi, sizeof(pi) );
+
+ /* Load up the helper Process, and then Wait until it signals that it
+ is finished locking.
+ */
+ if(!CreateProcess( NULL,Helper,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
+ {
+ Fail("ERROR: CreateProcess failed to load executable '%s'.",Helper);
+ }
+
+ SignalAndBusyWait(WaitFile);
+
+ /* Now the child proccess has locked another section of the file, from
+ bytes 11 through 20. Let's check that the parent lock is still ignored
+ by the parent proccess and that the child's lock is respected.
+ */
+
+ if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) == 0)
+ {
+ Trace("ERROR: ReadFile failed when attempting to read a section of "
+ "the file which was locked by the current process. It should "
+ "have been able to read this. GetLastError() returned %d.",
+ GetLastError());
+ ParentRetCode = 1;
+ }
+
+ SetFilePointer(TheFile, 11, 0, FILE_BEGIN);
+
+ if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) != 0)
+ {
+ Trace("ERROR: ReadFile returned success when it should "
+ "have failed. Attempted to read 10 bytes of the file which "
+ "were locked by the child.");
+ ParentRetCode = 1;
+ }
+
+ /* We're finished testing. Let the child proccess know so it can clean
+ up, and the parent will wait until it is done.
+ */
+ SignalFinish(WaitFile);
+ WaitForSingleObject(pi.hProcess,INFINITE);
+
+ /* Get the return value from the helper process */
+ if (GetExitCodeProcess(pi.hProcess, &ChildRetCode) == 0)
+ {
+ Fail("ERROR: GetExitCodeProccess failed when attempting to retrieve "
+ "the exit code of the child process.");
+ }
+
+ if(CloseHandle( pi.hProcess ) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the process.");
+ }
+
+ if(CloseHandle( pi.hThread ) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the thread.");
+ }
+
+ return (ChildRetCode || ParentRetCode);
+}
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE TheFile = NULL;
+ HANDLE WaitFile = NULL;
+ char* WriteBuffer = "12345678901234567890123456";
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Open up the file we'll be using for some crude IPC */
+ WaitFile = CreateFile(WAITFILENAME,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (WaitFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.",WAITFILENAME,GetLastError());
+ }
+
+ /* Call the helper function to Create a file, write 'WriteBuffer' to
+ the file, and lock the file from bytes 0 to 10.
+ */
+ TheFile = CreateAndLockFile(TheFile, FILENAME, WriteBuffer,
+ 0, 10);
+
+ /* Run the test. Better errors are displayed by Trace throughout. */
+ if(RunTest(HELPER, TheFile, WaitFile))
+ {
+ Fail("ERROR: Attempting to have two processes lock different "
+ "sections of the same file has failed.");
+ }
+
+ /* Unlock the first 10 bytes which were locked by the parent proccess */
+ if(UnlockFile(TheFile, 0, 0, 10, 0) == 0)
+ {
+ Fail("ERROR: Failed to Unlock the first 10 bytes of the file. "
+ "GetLastError returned %d.",GetLastError());
+ }
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file used for "
+ "testing the locks. GetLastError() returns %d.",GetLastError());
+ }
+
+ if(CloseHandle(WaitFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the wait file. "
+ "GetLastError() returns %d.",GetLastError());
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/testinfo.dat
new file mode 100644
index 0000000000..f020933cd9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test5/testinfo.dat
@@ -0,0 +1,17 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = LockFile
+Name = Positive test for LockFile API
+TYPE = DEFAULT
+EXE1 = test5
+EXE2 = helper
+Description
+= Have two processes obtain a lock on a single file, but in different
+= regions of the file. Use Read/Write to ensure the locks are respected.
+= This requires some IPC, which is done here with a crude busy wait on a
+= file (waiting for the file size to change) to avoid too many more
+= dependencies.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/CMakeLists.txt
new file mode 100644
index 0000000000..5049977582
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/CMakeLists.txt
@@ -0,0 +1,36 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(TESTSOURCES
+ test6.c
+)
+
+add_executable(paltest_lockfile_test6
+ ${TESTSOURCES}
+)
+
+add_dependencies(paltest_lockfile_test6 coreclrpal)
+
+target_link_libraries(paltest_lockfile_test6
+ pthread
+ m
+ coreclrpal
+)
+
+
+set(HELPERSOURCES
+ helper.c
+)
+
+add_executable(paltest_lockfile_test6_helper
+ ${HELPERSOURCES}
+)
+
+add_dependencies(paltest_lockfile_test6_helper coreclrpal)
+
+target_link_libraries(paltest_lockfile_test6_helper
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/helper.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/helper.c
new file mode 100644
index 0000000000..98112fc4a5
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/helper.c
@@ -0,0 +1,71 @@
+// 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: helper.c
+**
+** Purpose: A child process which will attempt to append to the end of
+** a locked file.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+#define FILENAME "testfile.txt"
+#define BUF_SIZE 128
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE TheFile;
+ int result = 0;
+ char DataBuffer[BUF_SIZE];
+ DWORD BytesWritten;
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Open the same file that the parent has opened and locked */
+ TheFile = CreateFile(FILENAME,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Trace("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returns %d.",FILENAME,GetLastError());
+ result = -1;
+ }
+
+
+ /* Move the FilePointer to the EOF */
+ if(SetFilePointer(TheFile,0,NULL,FILE_END) == INVALID_SET_FILE_POINTER)
+ {
+ Trace("ERROR: Could not set the file pointer to the EOF "
+ "using SetFilePointer. It returned INVALID_SET_FILE_POINTER.");
+ result = -1;
+ }
+
+ memset(DataBuffer, 'X', BUF_SIZE);
+
+ /* Return the result of WriteFile -- we want to check in the parent that
+ this was successful. Note: WriteFile doesn't get run if something
+ failed during the setup, in that case -1 is returned.
+ */
+
+ if(result != -1)
+ {
+ result = WriteFile(TheFile, DataBuffer, 3,&BytesWritten, NULL);
+ }
+
+ PAL_TerminateEx(result);
+ return result;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/test6.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/test6.c
new file mode 100644
index 0000000000..ba01b9710a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/test6.c
@@ -0,0 +1,146 @@
+// 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: test6.c
+**
+** Purpose:
+** Append to a file which is locked until the end of the file, and
+** append to a file which is locked past the end of the file. (The first
+** should succeed, while the second should fail)
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+#include "../LockFile.h"
+
+#define HELPER "helper"
+#define FILENAME "testfile.txt"
+
+/* This test checks that you can append to a file which is locked from Start
+ to EOF.
+*/
+void Test1()
+{
+ HANDLE TheFile = NULL;
+ DWORD FileStart = 0;
+ DWORD FileEnd = 0;
+ int result;
+ char* WriteBuffer = "12345678901234567890123456";
+
+ /* Call the helper function to Create a file, write 'WriteBuffer' to
+ the file, and lock the file.
+ */
+
+ FileEnd = strlen(WriteBuffer);
+ TheFile = CreateAndLockFile(TheFile,FILENAME, WriteBuffer,
+ FileStart, FileEnd);
+
+
+ /*
+ Launch another proccess which will attempt to append to the
+ end of the file. Note: This returns -1 if the setup failed in some way.
+ */
+
+ result = RunHelper(HELPER);
+
+ if(result == -1)
+ {
+ Fail("ERROR: The Helper program failed in setting up the "
+ "test, so it could never be run.");
+ }
+ else if(result == 0)
+ {
+ Fail("ERROR: Failed to append to the file which was Locked from "
+ "start until EOF. Should have been able to append to this "
+ "file still. GetLastError() is %d.",GetLastError());
+ }
+
+ if(UnlockFile(TheFile, FileStart, 0, FileEnd, 0) == 0)
+ {
+ Fail("ERROR: UnlockFile failed. GetLastError returns %d.",
+ GetLastError());
+ }
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+}
+
+/* This test checks that you can't append to a file which is locked beyond
+ EOF.
+*/
+void Test2()
+{
+ HANDLE TheFile = NULL;
+ DWORD FileStart = 0;
+ DWORD FileEnd = 0;
+ int result;
+ char* WriteBuffer = "12345678901234567890123456";
+
+ /* Call the helper function to Create a file, write 'WriteBuffer' to
+ the file, and lock the file.
+ */
+
+ FileEnd = strlen(WriteBuffer);
+ TheFile = CreateAndLockFile(TheFile,FILENAME, WriteBuffer,
+ FileStart, FileEnd+20);
+
+
+ /*
+ Launch another proccess which will attempt to append to the
+ end of the file.
+ */
+
+ result = RunHelper(HELPER);
+
+ if(result == -1)
+ {
+ Fail("ERROR: The Helper program failed in setting up the "
+ "test, so it could never be run.");
+ }
+ else if(result > 0)
+ {
+ Fail("ERROR: The Helper program successfully appended to the "
+ "end of the file, even though it was locked beyond EOF. This "
+ "should have failed.");
+ }
+
+ if(UnlockFile(TheFile, FileStart, 0, FileEnd+20, 0) == 0)
+ {
+ Fail("ERROR: UnlockFile failed. GetLastError returns %d.",
+ GetLastError());
+ }
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file. "
+ "GetLastError() returned %d.",GetLastError());
+ }
+
+}
+
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Test a file which is locked until EOF to see if you can append */
+ Test1();
+
+ /* Test a file which is locked past EOF to ensure you can't append */
+ Test2();
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/testinfo.dat
new file mode 100644
index 0000000000..871a9a2756
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test6/testinfo.dat
@@ -0,0 +1,15 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = LockFile
+Name = Positive test for LockFile API
+TYPE = DEFAULT
+EXE1 = test6
+EXE2 = helper
+Description
+= Append to a file which is locked until the end of the file, and
+= append to a file which is locked past the end of the file. (The first
+= should succeed, while the second should fail)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/CMakeLists.txt
new file mode 100644
index 0000000000..e8434cc787
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test7.c
+)
+
+add_executable(paltest_lockfile_test7
+ ${SOURCES}
+)
+
+add_dependencies(paltest_lockfile_test7 coreclrpal)
+
+target_link_libraries(paltest_lockfile_test7
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/test7.c b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/test7.c
new file mode 100644
index 0000000000..c572a6e653
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/test7.c
@@ -0,0 +1,135 @@
+// 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: test7.c
+**
+** Purpose: Try locking an invalid HANDLE and a NULL Handle.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+#include "../LockFile.h"
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE TheFile = NULL;
+ DWORD FileEnd = 0;
+ const char lpBuffer[] = "This is a test file.";
+ DWORD bytesWritten;
+ BOOL bRc = TRUE;
+ char fileName[] = "testfile.tmp";
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ TheFile = CreateFile(fileName,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.",fileName,GetLastError());
+ }
+
+ bRc = WriteFile(
+ TheFile, // handle to file
+ lpBuffer, // data buffer
+ (DWORD)sizeof(lpBuffer), // number of bytes to write
+ &bytesWritten, // number of bytes written
+ NULL // overlapped buffer
+ );
+
+ if(!bRc)
+ {
+ Trace("ERROR: Could not write to file '%s' with WriteFile.",fileName);
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+
+ }
+ else if(bytesWritten != (DWORD)sizeof(lpBuffer))
+ {
+ Trace("ERROR: Could not write the correct number of bytes to the "
+ "file '%s' with WriteFile.",fileName);
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ /* Attempt to lock a region of this file beyond EOF, to ensure this
+ doesn't cause an error.
+ */
+ FileEnd = SetFilePointer(TheFile, 0, NULL, FILE_END);
+
+ if(LockFile(TheFile, FileEnd+10, 0, 10, 0) == 0)
+ {
+ Trace("ERROR: LockFile failed when attempting to lock a region "
+ "beyond the EOF. GetLastError() returned %d.",GetLastError());
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ if(UnlockFile(TheFile, FileEnd+10, 0, 10, 0) == 0)
+ {
+ Trace("ERROR: UnlockFile failed when attempting to unlock the region "
+ "which was locked beyond the EOF. GetLastError returned %d.",
+ GetLastError());
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: Failed to call CloseHandle. GetLastError "
+ "returned %d.",GetLastError());
+ }
+
+ /* Attempt to call Lockfile on an HANDLE which has been closed. This
+ should fail.
+ */
+ if(LockFile(TheFile, 0, 0, 5, 0) != 0)
+ {
+ Fail("ERROR: Attempted to Lock an invalid handle and the function "
+ "returned success.");
+ }
+
+ /* Attempt to call Lockfile by passing it NULL for a handle. This should
+ fail.
+ */
+
+ if(LockFile(NULL, 0, 0, 5, 0) != 0)
+ {
+ Fail("ERROR: Attempted to Lock a NULL handle and the function "
+ "returned success.");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/testinfo.dat
new file mode 100644
index 0000000000..74e7f00306
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/LockFile/test7/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = LockFile
+Name = Positive test for LockFile API
+TYPE = DEFAULT
+EXE1 = test7
+Description
+= Ensure that LockFile succeeds when the lock begins beyond
+= EOF. Try locking an invalid HANDLE and a NULL Handle.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/CMakeLists.txt
new file mode 100644
index 0000000000..7c20179353
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+add_subdirectory(test4)
+add_subdirectory(test5)
+add_subdirectory(test6)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/CMakeLists.txt
new file mode 100644
index 0000000000..ef9838d41e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ MapViewOfFile.c
+)
+
+add_executable(paltest_mapviewoffile_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_mapviewoffile_test1 coreclrpal)
+
+target_link_libraries(paltest_mapviewoffile_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/MapViewOfFile.c b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/MapViewOfFile.c
new file mode 100644
index 0000000000..6177e0decf
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/MapViewOfFile.c
@@ -0,0 +1,226 @@
+// 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: MapViewOfFile.c
+**
+**
+** Purpose: Positive test the MapViewOfFile API.
+** Call MapViewOfFile with access FILE_MAP_READ.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+#define MAPPINGSIZE 8192
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE hFile = INVALID_HANDLE_VALUE;
+ LPSTR buf = NULL;
+ CHAR ch[MAPPINGSIZE];
+ CHAR lpFileName[] = "test.tmp";
+ DWORD dwBytesWritten = 0;
+ DWORD dwInitialSize = 0;
+ DWORD dwFinalSize = 0;
+ BOOL bRetVal = FALSE;
+
+ HANDLE hFileMapping = 0;
+ LPVOID lpMapViewAddress = NULL;
+
+ /* Initialize the PAL environment.
+ */
+ if( 0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file handle with CreateFile.
+ */
+ hFile = CreateFile( lpFileName,
+ GENERIC_WRITE|GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING,
+ NULL);
+
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail( "ERROR: %u :unable to create file \"%s\".\n",
+ GetLastError(), lpFileName);
+ }
+
+ /* Get the initial size of file, for latter tests.
+ */
+ dwInitialSize = GetFileSize (hFile, NULL);
+ if ( INVALID_FILE_SIZE == dwInitialSize )
+ {
+ Fail("ERROR:%u: The created file \"%s\" has an invalid "
+ "file size.\n",GetLastError(),lpFileName);
+ }
+
+ /*
+ * An application must meet certain requirements when working
+ * with files opened with FILE_FLAG_NO_BUFFERING:
+ * File access must begin at byte offsets within the file that
+ * are integer multiples of the volume's sector size. To determine a
+ * volume's sector size, call the GetDiskFreeSpace function.
+ *
+ * File access must be for numbers of bytes that are integer
+ * multiples of the volume's sector size. For example, if the
+ * sector size is 512 bytes, an application can request reads and
+ * writes of 512, 1024, or 2048 bytes, but not of 335, 981, or 7171 bytes.
+ *
+ * Buffer addresses for read and write operations must be sector
+ * aligned (aligned on addresses in memory that are integer multiples
+ * of the volume's sector size). One way to sector align buffers is to use the
+ * VirtualAlloc function to allocate the buffers. This function allocates memory
+ * that is aligned on addresses that are integer multiples of the system's page size.
+ * Because both page and volume sector sizes are powers of 2, memory aligned by multiples
+ * of the system's page size is also aligned by multiples of the volume's sector size.
+ */
+ buf = (LPSTR)VirtualAlloc( NULL, /* Let the system decide the location. */
+ MAPPINGSIZE / 2, /* One page, the smallest you can request */
+ MEM_COMMIT, /* Reserve and commit in one pass */
+ PAGE_READWRITE ); /* Allow reading and writting. */
+
+ if ( NULL == buf )
+ {
+ Trace( "VirtualAlloc failed! LastError=%d\n", GetLastError() );
+ CloseHandle( hFile );
+ Fail("");
+ }
+
+
+ /*
+ * Write to the File handle.
+ * The reminder will be padded with zeros.
+ */
+ strncpy( buf,
+ "thats not a test string....THIS is a test string",
+ MAPPINGSIZE / 2 );
+
+ bRetVal = WriteFile(hFile,
+ buf,
+ MAPPINGSIZE / 2,
+ &dwBytesWritten,
+ NULL);
+
+ if ( FALSE == bRetVal )
+ {
+ Trace( "ERROR: %u :unable to write to file handle hFile=0x%lx\n",
+ GetLastError(), hFile);
+ CloseHandle(hFile);
+ VirtualFree( buf, 0, MEM_RELEASE );
+ Fail("");
+ }
+
+ /* Create a unnamed file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapping = CreateFileMapping( hFile,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read and wite*/
+ 0, /*high-order of object size*/
+ MAPPINGSIZE, /*low-orger of object size*/
+ NULL); /*unnamed object*/
+
+ if( NULL == hFileMapping )
+ {
+ Trace("ERROR:%u: Failed to create File Mapping.\n", GetLastError());
+ CloseHandle(hFile);
+ VirtualFree( buf, 0, MEM_RELEASE );
+ Fail("");
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewAddress = MapViewOfFile( hFileMapping,
+ FILE_MAP_READ, /* access code */
+ 0, /*high order offset*/
+ 0, /*low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if( NULL == lpMapViewAddress )
+ {
+ Trace( "ERROR:%u: Failed to call MapViewOfFile API to map"
+ " a view of file!\n", GetLastError());
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ VirtualFree( buf, 0, MEM_RELEASE );
+ Fail("");
+ }
+
+ /* Verify that the size of the file has increased to
+ * accomidate the MapView.
+ */
+ dwFinalSize = GetFileSize (hFile, NULL);
+ if ( (dwFinalSize <= dwInitialSize) && (dwFinalSize != MAPPINGSIZE))
+ {
+
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ VirtualFree( buf, 0, MEM_RELEASE );
+ UnmapViewOfFile(lpMapViewAddress);
+
+ Fail( "ERROR: Size of the file was expected to "
+ "increase from \"%d\", to \"%d\".\n ",
+ dwInitialSize,
+ dwFinalSize);
+ }
+
+ /* Copy the MapViewOfFile to buffer, so we can
+ * compare with value read from file directly.
+ */
+ memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE);
+ if (memcmp(ch, buf, strlen(buf)) != 0)
+ {
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ UnmapViewOfFile(lpMapViewAddress) ;
+ VirtualFree( buf, 0, MEM_RELEASE );
+
+ Fail( "ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ ch,
+ buf);
+ }
+
+ /* Unmap the view of file.
+ */
+ if( FALSE == UnmapViewOfFile(lpMapViewAddress) )
+ {
+ Trace( "\nFailed to call UnmapViewOfFile API to unmap the "
+ "view of a file, error code=%u\n", GetLastError());
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ VirtualFree( buf, 0, MEM_RELEASE );
+ Fail("");
+ }
+
+ /* Close handle to create file.
+ */
+ if( FALSE == CloseHandle(hFile) )
+ {
+ Trace( "ERROR:%u:Failed to call CloseHandle API to close a file handle.",
+ GetLastError());
+ CloseHandle(hFileMapping);
+ VirtualFree( buf, 0, MEM_RELEASE );
+ Fail("");
+ }
+
+ if( FALSE == CloseHandle(hFileMapping) )
+ {
+ Trace( "ERROR:%u:Failed to call CloseHandle API to close a "
+ "filemapping handle.",GetLastError());
+ VirtualFree( buf, 0, MEM_RELEASE );
+ Fail("");
+ }
+
+ VirtualFree( buf, 0, MEM_RELEASE );
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/testinfo.dat
new file mode 100644
index 0000000000..f1d8451efb
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test1/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = MapViewOfFile
+Name = Positive test MapViewOfFile API with access FILE_MAP_READ
+TYPE = DEFAULT
+EXE1 = mapviewoffile
+Description
+=Test the MapViewOfFile with access FILE_MAP_READ
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/CMakeLists.txt
new file mode 100644
index 0000000000..18a9d105b1
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ MapViewOfFile.c
+)
+
+add_executable(paltest_mapviewoffile_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_mapviewoffile_test2 coreclrpal)
+
+target_link_libraries(paltest_mapviewoffile_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/MapViewOfFile.c b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/MapViewOfFile.c
new file mode 100644
index 0000000000..c08f585c0e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/MapViewOfFile.c
@@ -0,0 +1,203 @@
+// 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: MapViewOfFile.c
+**
+** Purpose: Positive test the MapViewOfFile API.
+** Call MapViewOfFile with access FILE_MAP_WRITE.
+**
+** Depends: CreateFile,
+** GetFileSize,
+** memset,
+** CreateFileMapping,
+** CloseHandle,
+** memcpy,
+** ReadFile,
+** memcmp,
+** UnMapViewOfFile.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE hFile;
+ HANDLE hFileMapping;
+ LPVOID lpMapViewAddress;
+ char buf[] = "this is a test string";
+ const int MAPPINGSIZE = 2048;
+ char ch[2048];
+ char readString[2048];
+ char lpFileName[] = "test.tmp";
+ DWORD dwBytesRead;
+ DWORD dwInitialSize = 0;
+ DWORD dwFinalSize = 0;
+ BOOL bRetVal;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file handle with CreateFile.
+ */
+ hFile = CreateFile( lpFileName,
+ GENERIC_WRITE|GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: %u :unable to create file \"%s\".\n",
+ GetLastError(),
+ lpFileName);
+ }
+
+ /* Get the initial size of file, for latter tests.
+ */
+ dwInitialSize = GetFileSize (hFile, NULL);
+ if ( dwInitialSize == INVALID_FILE_SIZE )
+ {
+ Fail("ERROR:%u: The created file \"%s\" has an invalid "
+ "file size.\n",
+ GetLastError(),
+ lpFileName);
+ }
+
+ /* Initialize the buffers.
+ */
+ memset(ch, 0, MAPPINGSIZE);
+ memset(readString, 0, MAPPINGSIZE);
+
+ /* Create a unnamed file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read and wite*/
+ 0, /*high-order of object size*/
+ MAPPINGSIZE, /*low-orger of object size*/
+ NULL); /*unnamed object*/
+
+ if(NULL == hFileMapping)
+ {
+ Trace("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ CloseHandle(hFile);
+ Fail("");
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_WRITE, /* access code */
+ 0, /*high order offset*/
+ 0, /*low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile API to map a view"
+ " of file!\n",
+ GetLastError());
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ /* Verify that the size of the file has increased to
+ * accomidate the MapView.
+ */
+ dwFinalSize = GetFileSize (hFile, NULL);
+ if ( (dwFinalSize <= dwInitialSize) && (dwFinalSize != MAPPINGSIZE))
+ {
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("ERROR: Size of the file was expected to "
+ "increase from \"%d\", to \"%d\".\n ",
+ dwInitialSize,
+ MAPPINGSIZE);
+ }
+
+ /* Write to the MapView and copy the MapViewOfFile
+ * to buffer, so we can compare with value read from
+ * file directly.
+ */
+ memcpy(lpMapViewAddress, buf, strlen(buf));
+
+ /* Read from the File handle.
+ */
+ bRetVal = ReadFile(hFile,
+ readString,
+ strlen(buf),
+ &dwBytesRead,
+ NULL);
+
+ if (bRetVal == FALSE)
+ {
+ Trace("ERROR: %u :unable to read from file handle "
+ "hFile=0x%lx\n",
+ GetLastError(),
+ hFile);
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ if (memcmp(buf, readString, strlen(readString)) != 0)
+ {
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("ERROR: Read string from file \"%s\", is "
+ "not equal to string written through MapView "
+ "\"%s\".\n",
+ readString,
+ ch);
+ }
+
+ /* Unmap the view of file.
+ */
+ if(UnmapViewOfFile(lpMapViewAddress) == FALSE)
+ {
+ Trace("ERROR: Failed to call UnmapViewOfFile API to"
+ " unmap the view of a file, error code=%u\n",
+ GetLastError());
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ /* Close handle to create file.
+ */
+ if(CloseHandle(hFile) == FALSE)
+ {
+ Trace("ERROR:%u:Failed to call CloseHandle API "
+ "to close a file handle.",
+ GetLastError());
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ if(CloseHandle(hFileMapping) == FALSE)
+ {
+ Fail("ERROR:%u:Failed to call CloseHandle API "
+ "to close a file mapping handle.",
+ GetLastError());
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/testinfo.dat
new file mode 100644
index 0000000000..13b3f52cf1
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test2/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = MapViewOfFile
+Name = Positive test for MapViewOfFile API with access FILE_MAP_WRITE
+TYPE = DEFAULT
+EXE1 = mapviewoffile
+Description
+=Test the MapViewOfFile with access FILE_MAP_WRITE
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/CMakeLists.txt
new file mode 100644
index 0000000000..76bd3276a4
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ MapViewOfFile.c
+)
+
+add_executable(paltest_mapviewoffile_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_mapviewoffile_test3 coreclrpal)
+
+target_link_libraries(paltest_mapviewoffile_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/MapViewOfFile.c b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/MapViewOfFile.c
new file mode 100644
index 0000000000..63bee768f9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/MapViewOfFile.c
@@ -0,0 +1,209 @@
+// 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: MapViewOfFile.c
+**
+** Purpose: Positive test the MapViewOfFile API.
+** Call MapViewOfFile with access FILE_MAP_ALL_ACCESS.
+**
+** Depends: CreateFile,
+** GetFileSize,
+** memset,
+** memcpy,
+** memcmp,
+** ReadFile,
+** UnMapViewOfFile,
+** CreateFileMapping,
+** CloseHandle.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE hFile;
+ HANDLE hFileMapping;
+ LPVOID lpMapViewAddress;
+ char buf[] = "this is a test string";
+ const int MAPPINGSIZE = 2048;
+ char ch[2048];
+ char readString[2048];
+ char lpFileName[] = "test.tmp";
+ DWORD dwBytesRead;
+ DWORD dwInitialSize = 0;
+ DWORD dwFinalSize = 0;
+ BOOL bRetVal;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file handle with CreateFile.
+ */
+ hFile = CreateFile( lpFileName,
+ GENERIC_WRITE|GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: %u :unable to create file \"%s\".\n",
+ GetLastError(),
+ lpFileName);
+ }
+
+ /* Get the initial size of file, for latter tests.
+ */
+ dwInitialSize = GetFileSize (hFile, NULL);
+ if ( dwInitialSize == INVALID_FILE_SIZE )
+ {
+ Trace("ERROR:%u: The created file \"%s\" has an invalid "
+ "file size.\n",
+ GetLastError(),
+ lpFileName);
+ CloseHandle(hFile);
+ Fail("");
+ }
+
+ /* Initialize the buffers.
+ */
+ memset(ch, 0, MAPPINGSIZE);
+ memset(readString, 0, MAPPINGSIZE);
+
+ /* Create a unnamed file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read and wite*/
+ 0, /*high-order of object size*/
+ MAPPINGSIZE, /*low-orger of object size*/
+ NULL); /*unnamed object*/
+
+ if(NULL == hFileMapping)
+ {
+ Trace("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ CloseHandle(hFile);
+ Fail("");
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_ALL_ACCESS, /*access code*/
+ 0, /*high order offset*/
+ 0, /*low order offset*/
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile API to map a view"
+ " of file!\n",
+ GetLastError());
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ /* Verify that the size of the file has increased to
+ * accomidate the MapView.
+ */
+ dwFinalSize = GetFileSize (hFile, NULL);
+ if ( (dwFinalSize <= dwInitialSize) && (dwFinalSize != MAPPINGSIZE))
+ {
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("ERROR: Size of the file was expected to "
+ "increase from \"%d\", to \"%d\".\n ",
+ dwInitialSize,
+ MAPPINGSIZE);
+ }
+
+ /* Write to the MapView and copy the MapViewOfFile
+ * to buffer, so we can compare with value read from
+ * file directly.
+ */
+
+ memcpy(lpMapViewAddress, buf, strlen(buf));
+ memcpy(ch, (LPCSTR)lpMapViewAddress, MAPPINGSIZE);
+
+ /* Read from the File handle.
+ */
+ bRetVal = ReadFile(hFile,
+ readString,
+ strlen(buf),
+ &dwBytesRead,
+ NULL);
+
+ if (bRetVal == FALSE)
+ {
+ Trace("ERROR: %u :unable to read from file handle "
+ "hFile=0x%lx\n",
+ GetLastError(),
+ hFile);
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ if (memcmp(ch, readString, strlen(readString)) != 0)
+ {
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("ERROR: Read string from file \"%s\", is "
+ "not equal to string written through MapView "
+ "\"%s\".\n",
+ readString,
+ ch);
+ }
+
+ /* Unmap the view of file.
+ */
+ if(UnmapViewOfFile(lpMapViewAddress) == FALSE)
+ {
+ Trace("ERROR: Failed to call UnmapViewOfFile API to"
+ " unmap the view of a file, error code=%u\n",
+ GetLastError());
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ /* Close handle to create file.
+ */
+ if(CloseHandle(hFile) == FALSE)
+ {
+ Trace("ERROR:%u:Failed to call CloseHandle API "
+ "to close a file handle.",
+ GetLastError());
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ /* Close handle to file mapping.
+ */
+ if(CloseHandle(hFileMapping) == FALSE)
+ {
+ Fail("ERROR:%u:Failed to call CloseHandle API "
+ "to close a file handle.",
+ GetLastError());
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/testinfo.dat
new file mode 100644
index 0000000000..f76333e7ea
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test3/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = MapViewOfFile
+Name = Positive test MapViewOfFile API with access FILE_MAP_ALL_ACCESS
+TYPE = DEFAULT
+EXE1 = mapviewoffile
+Description
+=Test the MapViewOfFile with access FILE_MAP_ALL_ACCESS
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/CMakeLists.txt
new file mode 100644
index 0000000000..52381c510f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ mapviewoffile.c
+)
+
+add_executable(paltest_mapviewoffile_test4
+ ${SOURCES}
+)
+
+add_dependencies(paltest_mapviewoffile_test4 coreclrpal)
+
+target_link_libraries(paltest_mapviewoffile_test4
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/mapviewoffile.c b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/mapviewoffile.c
new file mode 100644
index 0000000000..7f3252144b
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/mapviewoffile.c
@@ -0,0 +1,166 @@
+// 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: MapViewOfFile.c
+**
+** Purpose: Negative test the MapViewOfFile API.
+** Call MapViewOfFile with all access modes, except
+** read-only, on a read only map.
+**
+** Depends: CreateFile,
+** CreateFileMapping,
+** CloseHandle,
+** UnMapViewOfFile.
+**
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE hFile;
+ BOOL err;
+ HANDLE hFileMapping;
+ LPVOID lpMapViewAddress;
+ DWORD dwBytesWritten;
+ const int MAPPINGSIZE = 2048;
+ char buf[] = "this is a test string";
+ char lpFileName[] = "test.tmp";
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file handle with CreateFile.
+ */
+ hFile = CreateFile( lpFileName,
+ GENERIC_WRITE|GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: %u :unable to create file \"%s\".\n",
+ GetLastError(),
+ lpFileName);
+ }
+
+ /* Write to the File handle.
+ */
+ err = WriteFile(hFile,
+ buf,
+ strlen(buf),
+ &dwBytesWritten,
+ NULL);
+
+ if ( !FlushFileBuffers( hFile ) )
+ {
+ CloseHandle(hFile);
+ Fail("ERROR: Unable to flush the buffers\n");
+ }
+
+ if (err == FALSE)
+ {
+ Trace("ERROR: %u :unable to write to file handle "
+ "hFile=0x%lx\n",
+ GetLastError(),
+ hFile);
+ CloseHandle(hFile);
+ Fail("");
+ }
+
+ /* Create a unnamed file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READONLY, /*read and wite*/
+ 0, /*high-order of object size*/
+ 0, /*low-orger of object size*/
+ NULL); /*unnamed object*/
+
+ if(NULL == hFileMapping)
+ {
+ Trace("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ CloseHandle(hFile);
+ Fail("");
+ }
+
+ /* map a writeable view of a file to a read-only file map.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_WRITE, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL != lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Able to create a writeable MapViewOfFile"
+ " to a read-only file.\n",
+ GetLastError());
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ UnmapViewOfFile(lpMapViewAddress);
+ Fail("");
+ }
+
+ /* map an all access view of a file to a read-only file map.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL != lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Able to create an all access MapViewOfFile"
+ " to a read-only file.\n",
+ GetLastError());
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ UnmapViewOfFile(lpMapViewAddress);
+ Fail("");
+ }
+
+ /* map an copy view of a file to a read-only file map.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_COPY, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL != lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Able to create a copy access MapViewOfFile "
+ "to a read-only file.\n",
+ GetLastError());
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ /* Clean-up and Teminate. */
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/testinfo.dat
new file mode 100644
index 0000000000..37655eda5b
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test4/testinfo.dat
@@ -0,0 +1,14 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = MapViewOfFile
+Name = Negative test MapViewOfFile API
+TYPE = DEFAULT
+EXE1 = mapviewoffile
+Description
+= Negative test the MapViewOfFile API.
+= Call MapViewOfFile with all access modes,
+= except read-only, on a read only map.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/CMakeLists.txt
new file mode 100644
index 0000000000..f98a4b7779
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ mapviewoffile.c
+)
+
+add_executable(paltest_mapviewoffile_test5
+ ${SOURCES}
+)
+
+add_dependencies(paltest_mapviewoffile_test5 coreclrpal)
+
+target_link_libraries(paltest_mapviewoffile_test5
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.c b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.c
new file mode 100644
index 0000000000..219b3fa12a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/mapviewoffile.c
@@ -0,0 +1,131 @@
+// 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: MapViewOfFile.c
+**
+** Purpose: Negative test the MapViewOfFile API.
+** Passing invalid values for the hFileMappingObject.
+**
+** Depends: CreatePipe,
+** CreateFile,
+** CreateFileMapping,
+** CloseHandle.
+**
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ const int MAPPINGSIZE = 2048;
+ HANDLE hFileMapping;
+ LPVOID lpMapViewAddress;
+ HANDLE hReadPipe = NULL;
+ HANDLE hWritePipe = NULL;
+ BOOL bRetVal;
+
+ SECURITY_ATTRIBUTES lpPipeAttributes;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+
+ /* Attempt to create a MapViewOfFile with a NULL handle.
+ */
+ hFileMapping = NULL;
+
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_WRITE, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if((NULL != lpMapViewAddress) &&
+ (GetLastError() != ERROR_INVALID_HANDLE))
+ {
+ Trace("ERROR:%u: Able to create a MapViewOfFile with "
+ "hFileMapping=0x%lx.\n",
+ GetLastError());
+ UnmapViewOfFile(lpMapViewAddress);
+ Fail("");
+ }
+
+ /* Attempt to create a MapViewOfFile with an invalid handle.
+ */
+ hFileMapping = INVALID_HANDLE_VALUE;
+
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_WRITE, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if((NULL != lpMapViewAddress) &&
+ (GetLastError() != ERROR_INVALID_HANDLE))
+ {
+ Trace("ERROR:%u: Able to create a MapViewOfFile with "
+ "hFileMapping=0x%lx.\n",
+ GetLastError());
+ UnmapViewOfFile(lpMapViewAddress);
+ Fail("");
+ }
+
+ /* Setup SECURITY_ATTRIBUTES structure for CreatePipe.
+ */
+ lpPipeAttributes.nLength = sizeof(lpPipeAttributes);
+ lpPipeAttributes.lpSecurityDescriptor = NULL;
+ lpPipeAttributes.bInheritHandle = TRUE;
+
+ /* Create a Pipe.
+ */
+ bRetVal = CreatePipe(&hReadPipe, /* read handle*/
+ &hWritePipe, /* write handle */
+ &lpPipeAttributes,/* security attributes*/
+ 0); /* pipe size*/
+ if (bRetVal == FALSE)
+ {
+ Fail("ERROR: %ld :Unable to create pipe\n",
+ GetLastError());
+ }
+
+ /* Attempt creating a MapViewOfFile with a Pipe Handle.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ hReadPipe,
+ FILE_MAP_WRITE, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if((NULL != lpMapViewAddress) &&
+ (GetLastError() != ERROR_INVALID_HANDLE))
+ {
+ Trace("ERROR:%u: Able to create a MapViewOfFile with "
+ "hFileMapping=0x%lx.\n",
+ GetLastError());
+ CloseHandle(hReadPipe);
+ CloseHandle(hWritePipe);
+ UnmapViewOfFile(lpMapViewAddress);
+ Fail("");
+ }
+
+ /* Clean-up and Terminate the PAL.
+ */
+ CloseHandle(hReadPipe);
+ CloseHandle(hWritePipe);
+ PAL_Terminate();
+ return PASS;
+}
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/testinfo.dat
new file mode 100644
index 0000000000..e3ecb32772
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test5/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = MapViewOfFile
+Name = Negative test for MapViewOfFile API.
+TYPE = DEFAULT
+EXE1 = mapviewoffile
+Description
+= Negative test the MapViewOfFile API.
+= Passing invalid values for the hFileMappingObject.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/CMakeLists.txt
new file mode 100644
index 0000000000..dad03aaf80
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ mapviewoffile.c
+)
+
+add_executable(paltest_mapviewoffile_test6
+ ${SOURCES}
+)
+
+add_dependencies(paltest_mapviewoffile_test6 coreclrpal)
+
+target_link_libraries(paltest_mapviewoffile_test6
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/mapviewoffile.c b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/mapviewoffile.c
new file mode 100644
index 0000000000..f7d7302a4c
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/mapviewoffile.c
@@ -0,0 +1,85 @@
+// 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: MapViewOfFile.c
+**
+** Purpose: Positivve test the MapViewOfFile API.
+** Mapping a pagefile allocation into memory
+**
+** Depends: CreateFileMappingW,
+** UnmapViewOfFile
+** CloseHandle.
+**
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ const int MAPPINGSIZE = 2048;
+ HANDLE hFileMapping;
+ LPVOID lpMapViewAddress;
+ char *p;
+ int i;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ hFileMapping = CreateFileMappingW(INVALID_HANDLE_VALUE,
+ NULL,
+ PAGE_READWRITE,
+ 0,
+ MAPPINGSIZE,
+ NULL);
+
+ if (hFileMapping == NULL) {
+ Trace("ERROR:%u: CreateFileMappingW() failed\n", GetLastError());
+ Fail("");
+ }
+
+
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_WRITE, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ MAPPINGSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: MapViewOfFile() failed.\n",
+ GetLastError());
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ p = (char *)lpMapViewAddress;
+ for (i=0; i<MAPPINGSIZE; ++i) {
+ /* Confirm that the memory is zero-initialized */
+ if (p[i] != 0)
+ {
+ Fail("MapViewOfFile() of pagefile didn't return 0-filled data "
+ "(Offset %d has value 0x%x)\n", i, p[i]);
+ }
+ /* Confirm that it is writable */
+ *(char *)lpMapViewAddress = 0xcc;
+ }
+
+ /* Clean-up and Terminate the PAL.
+ */
+ CloseHandle(hFileMapping);
+ UnmapViewOfFile(lpMapViewAddress);
+ PAL_Terminate();
+ return PASS;
+}
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/testinfo.dat
new file mode 100644
index 0000000000..020827d2fe
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/MapViewOfFile/test6/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = MapViewOfFile
+Name = Positive test for MapViewOfFile API.
+TYPE = DEFAULT
+EXE1 = mapviewoffile
+Description
+= Positive test the MapViewOfFile API.
+= Mapping in a section of anonymous pagefile
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/CMakeLists.txt
new file mode 100644
index 0000000000..1962ade358
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/CMakeLists.txt
new file mode 100644
index 0000000000..b286924864
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ OpenFileMappingA.c
+)
+
+add_executable(paltest_openfilemappinga_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_openfilemappinga_test1 coreclrpal)
+
+target_link_libraries(paltest_openfilemappinga_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/OpenFileMappingA.c b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/OpenFileMappingA.c
new file mode 100644
index 0000000000..9087285112
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/OpenFileMappingA.c
@@ -0,0 +1,157 @@
+// 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: openfilemappinga.c (test 1)
+**
+** Purpose: Positive test the OpenFileMapping API.
+** Call OpenFileMapping to open a named file-mapping
+** object with FILE_MAP_ALL_ACCESS access
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE FileMappingHandle;
+ HANDLE OpenFileMappingHandle;
+ HANDLE lpMapViewAddress;
+ const int LOWORDERSIZE = 1024;
+ char buf[] = "this is a test";
+ char MapObject[] = "myMappingObject";
+ char ch[1024];
+ int err;
+ int RetVal = PASS;
+
+ /* Initialize the PAL environment.
+ */
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ return FAIL;
+ }
+
+
+ /* Create a named file-mapping object with
+ * file handle FileHandle.
+ */
+ FileMappingHandle = CreateFileMapping(
+ INVALID_HANDLE_VALUE,
+ NULL, /* not inherited */
+ PAGE_READWRITE, /* read and write */
+ 0, /* high-order size */
+ LOWORDERSIZE, /* low-order size */
+ MapObject); /* named object */
+
+ if(NULL == FileMappingHandle)
+ {
+ Fail("ERROR:%u:Failed to call CreateFileMapping to "
+ "create a mapping object.\n",
+ GetLastError());
+ }
+ if(GetLastError() == ERROR_ALREADY_EXISTS)
+ {
+ Trace("ERROR:File mapping object already exists\n");
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Open a named file-mapping object with
+ * FILE_MAP_ALL_ACCESS access.
+ */
+ OpenFileMappingHandle = OpenFileMapping(
+ FILE_MAP_ALL_ACCESS,
+ TRUE,
+ MapObject );
+
+ if(NULL == OpenFileMappingHandle)
+ {
+ Trace("ERROR:%u:Failed to Call OpenFileMapping API!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Test the opened map view.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ OpenFileMappingHandle,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ LOWORDERSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Write to the Map View.
+ */
+ memcpy(lpMapViewAddress, buf, strlen(buf));
+
+ /* Read from the Map View.
+ */
+ memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE);
+
+ /* Compare what was written to the Map View,
+ * to what was read.
+ */
+ if (memcmp(ch, buf, strlen(buf))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ ch, buf);
+ RetVal = FAIL;
+ goto CleanUpThree;
+
+ }
+
+CleanUpThree:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Close Handle to opend file mapping.
+ */
+ if ( CloseHandle(OpenFileMappingHandle) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ OpenFileMappingHandle);
+ RetVal = FAIL;
+ }
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(FileMappingHandle) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ FileMappingHandle);
+ RetVal = FAIL;
+ }
+
+
+ /* Terminat the PAL.*/
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/testinfo.dat
new file mode 100644
index 0000000000..010f2fe279
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test1/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = OpenFileMappingA
+Name = Positive test for OpenFileMappingA API with FILE_MAP_ALL_ACCESS access
+TYPE = DEFAULT
+EXE1 = openfilemappinga
+Description
+=Test the OpenFileMappingA with FILE_MAP_ALL_ACCESS access
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/CMakeLists.txt
new file mode 100644
index 0000000000..3a0eff04a7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ OpenFileMappingA.c
+)
+
+add_executable(paltest_openfilemappinga_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_openfilemappinga_test2 coreclrpal)
+
+target_link_libraries(paltest_openfilemappinga_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/OpenFileMappingA.c b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/OpenFileMappingA.c
new file mode 100644
index 0000000000..5e41a92024
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/OpenFileMappingA.c
@@ -0,0 +1,214 @@
+// 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: openfilemappinga.c (test 2)
+**
+** Purpose: Positive test the OpenFileMapping API.
+** Call OpenFileMapping to open a named file-mapping
+** object with FILE_MAP_WRITE access
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE FileMappingHandle;
+ HANDLE OpenFileMappingHandle;
+ HANDLE lpMapViewAddress;
+ HANDLE OpenFileMappingHandle2;
+ HANDLE lpMapViewAddress2;
+ const int LOWORDERSIZE = 1024;
+ char MapObject[] = "myMappingObject";
+ char buf[] = "this is a test";
+ char ch[1024];
+ int RetVal = PASS;
+
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a named file-mapping object with file handle FileHandle.
+ */
+ FileMappingHandle = CreateFileMapping(
+ INVALID_HANDLE_VALUE,
+ NULL, /* not inherited */
+ PAGE_READWRITE, /* read and write */
+ 0, /* high-order size */
+ LOWORDERSIZE, /* low-order size */
+ MapObject); /* named object */
+
+
+ if(NULL == FileMappingHandle)
+ {
+ Fail("\nFailed to call CreateFileMapping to create "
+ "a mapping object!\n");
+ }
+ if(GetLastError() == ERROR_ALREADY_EXISTS)
+ {
+ Trace("\nFile mapping object already exists!\n");
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Open a named file-mapping object with FILE_MAP_WRITE access.
+ */
+ OpenFileMappingHandle = OpenFileMapping(
+ FILE_MAP_WRITE,
+ FALSE,
+ MapObject);
+
+ if(NULL == OpenFileMappingHandle)
+ {
+ Trace("\nFailed to Call OpenFileMapping API!\n");
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Open a named file-mapping object with
+ * FILE_MAP_ALL_ACCESS access, to verify
+ * the FILE_MAP_WRITE access map.
+ */
+ OpenFileMappingHandle2 = OpenFileMapping(
+ FILE_MAP_ALL_ACCESS,
+ FALSE,
+ MapObject);
+
+ if(NULL == OpenFileMappingHandle2)
+ {
+ Trace("\nFailed to Call OpenFileMapping API!\n");
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Create map view of the open mapping that has
+ * FILE_MAP_WRITE access.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ OpenFileMappingHandle,
+ FILE_MAP_WRITE, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ LOWORDERSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+ /* Create map view of the open mapping that has
+ * FILE_MAP_ALL_ACCESS access.
+ */
+ lpMapViewAddress2 = MapViewOfFile(
+ OpenFileMappingHandle2,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ LOWORDERSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress2)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpFour;
+ }
+
+ /* Write to the Map View.
+ */
+ memcpy(lpMapViewAddress, buf, strlen(buf));
+
+ /* Read from the Map View.
+ */
+ memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE);
+
+ /* Compare what was written to the Map View,
+ * to what was read.
+ */
+ if (memcmp(ch, buf, strlen(buf))!= 0)
+ {
+ Fail("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ ch, buf);
+ RetVal = FAIL;
+ goto CleanUpFive;
+ }
+
+CleanUpFive:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress2);
+ RetVal = FAIL;
+ }
+
+CleanUpFour:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress);
+ RetVal = FAIL;
+ }
+
+CleanUpThree:
+
+ /* Close Handle to opened file mapping.
+ */
+ if ( CloseHandle(OpenFileMappingHandle2) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ OpenFileMappingHandle2);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Close Handle to opened file mapping.
+ */
+ if ( CloseHandle(OpenFileMappingHandle) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ OpenFileMappingHandle);
+ RetVal = FAIL;
+ }
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(FileMappingHandle) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ FileMappingHandle);
+ RetVal = FAIL;
+ }
+
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/testinfo.dat
new file mode 100644
index 0000000000..2a02128b68
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test2/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = OpenFileMappingA
+Name = Positive test for OpenFileMappingA API with FILE_MAP_WRITE access
+TYPE = DEFAULT
+EXE1 = openfilemappinga
+Description
+=Test the OpenFileMappingA with FILE_MAP_WRITE access
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/CMakeLists.txt
new file mode 100644
index 0000000000..599a09ffc7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ OpenFileMappingA.c
+)
+
+add_executable(paltest_openfilemappinga_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_openfilemappinga_test3 coreclrpal)
+
+target_link_libraries(paltest_openfilemappinga_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/OpenFileMappingA.c b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/OpenFileMappingA.c
new file mode 100644
index 0000000000..b01a3e8c0b
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/OpenFileMappingA.c
@@ -0,0 +1,217 @@
+// 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: openfilemappinga.c
+**
+** Purpose: Positive test the OpenFileMapping API.
+** Call OpenFileMapping to open a named file-mapping
+** object with FILE_MAP_READ access
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE FileMappingHandle;
+ HANDLE OpenFileMappingHandle;
+ HANDLE OpenFileMappingHandle2;
+ HANDLE lpMapViewAddress;
+ HANDLE lpMapViewAddress2;
+ const int LOWORDERSIZE = 1024;
+ char buf[] = "this is a test";
+ char MapObject[] = "myMappingObject";
+ char ch[1024];
+ int RetVal = PASS;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a named file-mapping object with file handle FileHandle.
+ */
+ FileMappingHandle = CreateFileMapping(
+ INVALID_HANDLE_VALUE,
+ NULL, /* Not inherited */
+ PAGE_READWRITE, /* Read only */
+ 0, /* High-order size */
+ LOWORDERSIZE, /* Must be none 0 */
+ MapObject); /* Named object */
+
+
+ if(NULL == FileMappingHandle)
+ {
+ Fail("ERROR:%u:Failed to call CreateFileMapping to create "
+ "mapping object = \"%s\".\n",
+ GetLastError(),
+ MapObject);
+ }
+ if(GetLastError() == ERROR_ALREADY_EXISTS)
+ {
+ Trace("ERROR:File mapping object \"%s\" already exists!\n",
+ MapObject);
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Open a named file-mapping object with
+ * FILE_MAP_READ access.
+ */
+ OpenFileMappingHandle = OpenFileMapping(
+ FILE_MAP_READ,
+ 0,
+ MapObject);
+
+ if(NULL == OpenFileMappingHandle)
+ {
+ Trace("ERROR:%u: Failed to Call OpenFileMapping API.\n");
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Open a named file-mapping object with
+ * FILE_MAP_ALL_ACCESS access, to verify the
+ * READ-ONLY Map view.
+ */
+ OpenFileMappingHandle2 = OpenFileMapping(
+ FILE_MAP_ALL_ACCESS,
+ 0,
+ MapObject);
+
+ if(NULL == OpenFileMappingHandle2)
+ {
+ Trace("Failed to Call OpenFileMapping API!\n");
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Test the opened map view.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ OpenFileMappingHandle,
+ FILE_MAP_READ, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ LOWORDERSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+ /* Open the second Map view to verify the writing
+ * of the READ-ONLY Map view.
+ */
+ lpMapViewAddress2 = MapViewOfFile(
+ OpenFileMappingHandle2,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ LOWORDERSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress2)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpFour;
+ }
+
+ /* Write to the ALL_ACCESS Map View.
+ */
+ memcpy(lpMapViewAddress2, buf, strlen(buf));
+
+ /* Read from the READ-ONLY Map View.
+ */
+ memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE);
+
+ /* Compare what was written to the Map View,
+ * to what was read.
+ */
+ if (memcmp(ch, buf, strlen(buf))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ ch, buf);
+ RetVal = FAIL;
+ goto CleanUpFive;
+ }
+
+CleanUpFive:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress2);
+ RetVal = FAIL;
+ }
+
+CleanUpFour:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress);
+ RetVal = FAIL;
+ }
+
+CleanUpThree:
+
+ /* Close Handle to opened file mapping.
+ */
+ if ( CloseHandle(OpenFileMappingHandle2) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ OpenFileMappingHandle2);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Close Handle to opened file mapping.
+ */
+ if ( CloseHandle(OpenFileMappingHandle) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ OpenFileMappingHandle);
+ RetVal = FAIL;
+ }
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(FileMappingHandle) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ FileMappingHandle);
+ RetVal = FAIL;
+ }
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/testinfo.dat
new file mode 100644
index 0000000000..4aff853f91
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingA/test3/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = OpenFileMappingA
+Name = Positive test for OpenFileMappingA API with FILE_MAP_READ access
+TYPE = DEFAULT
+EXE1 = openfilemappinga
+Description
+=Test the OpenFileMappingA with FILE_MAP_READ access
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/CMakeLists.txt
new file mode 100644
index 0000000000..1962ade358
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/CMakeLists.txt
new file mode 100644
index 0000000000..04e9e47ef0
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ OpenFileMappingW.c
+)
+
+add_executable(paltest_openfilemappingw_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_openfilemappingw_test1 coreclrpal)
+
+target_link_libraries(paltest_openfilemappingw_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/OpenFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/OpenFileMappingW.c
new file mode 100644
index 0000000000..079af4a5c0
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/OpenFileMappingW.c
@@ -0,0 +1,155 @@
+// 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: openfilemappingw.c (test 1)
+**
+** Purpose: Positive test the OpenFileMapping API.
+** Call OpenFileMapping to open a named file-mapping
+** object with FILE_MAP_ALL_ACCESS access
+**
+**
+**============================================================*/
+
+#define UNICODE
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ HANDLE lpMapViewAddress;
+ char buf[] = "this is a test";
+ char ch[1024];
+
+ HANDLE FileMappingHandle;
+ HANDLE OpenFileMappingHandle;
+ const int LOWORDERSIZE = 1024;
+ int RetVal = PASS;
+ WCHAR wpMappingFileObject[] = {'m','y','O','b','j','e','c','t','\0'};
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a unnamed file-mapping object with file handle FileHandle.
+ */
+ FileMappingHandle = CreateFileMapping(
+ INVALID_HANDLE_VALUE,
+ NULL, /* Not inherited*/
+ PAGE_READWRITE, /* Read and write*/
+ 0, /* High-order size*/
+ LOWORDERSIZE, /* Low-order size*/
+ wpMappingFileObject);/* Named object*/
+
+
+ if(NULL == FileMappingHandle)
+ {
+ Fail("\nFailed to call CreateFileMapping to create a "
+ "mapping object!\n");
+ }
+ if(GetLastError() == ERROR_ALREADY_EXISTS)
+ {
+ Trace("\nFile mapping object already exists!\n");
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Open a named file-mapping object with FILE_MAP_ALL_ACCESS access.
+ */
+ OpenFileMappingHandle = OpenFileMapping(
+ FILE_MAP_ALL_ACCESS,
+ FALSE,
+ wpMappingFileObject);
+
+ if(NULL == OpenFileMappingHandle)
+ {
+ Trace("\nFailed to Call OpenFileMapping API!\n");
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Test the opened map view.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ OpenFileMappingHandle,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ LOWORDERSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Write to the Map View.
+ */
+ memcpy(lpMapViewAddress, buf, strlen(buf));
+
+ /* Read from the Map View.
+ */
+ memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE);
+
+ /* Compare what was written to the Map View,
+ * to what was read.
+ */
+ if (memcmp(ch, buf, strlen(buf))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ ch, buf);
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+CleanUpThree:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Close Handle to opend file mapping.
+ */
+ if ( CloseHandle(OpenFileMappingHandle) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ OpenFileMappingHandle);
+ RetVal = FAIL;
+ }
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(FileMappingHandle) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ FileMappingHandle);
+ RetVal = FAIL;
+ }
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/testinfo.dat
new file mode 100644
index 0000000000..e67f4775f4
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test1/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = OpenFileMappingW
+Name = Positive test for OpenFileMappingW API
+TYPE = DEFAULT
+EXE1 = openfilemappingw
+Description
+=Test the OpenFileMappingW with FILE_MAP_ALL_ACCESS access
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/CMakeLists.txt
new file mode 100644
index 0000000000..22e960b788
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ OpenFileMappingW.c
+)
+
+add_executable(paltest_openfilemappingw_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_openfilemappingw_test2 coreclrpal)
+
+target_link_libraries(paltest_openfilemappingw_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/OpenFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/OpenFileMappingW.c
new file mode 100644
index 0000000000..e6a69651fa
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/OpenFileMappingW.c
@@ -0,0 +1,217 @@
+// 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: openfilemappingw.c (test 2)
+**
+** Purpose: Positive test the OpenFileMapping API.
+** Call OpenFileMapping to open a named file-mapping
+** object with FILE_MAP_WRITE access
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE FileMappingHandle;
+ HANDLE OpenFileMappingHandle;
+ HANDLE lpMapViewAddress;
+ HANDLE OpenFileMappingHandle2;
+ HANDLE lpMapViewAddress2;
+ const int LOWORDERSIZE = 1024;
+ WCHAR MapObject[] = {'m','y','O','b','j','e','c','t','\0'};
+ char buf[] = "this is a test";
+ char ch[1024];
+ int RetVal = PASS;
+
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a named file-mapping object with file handle FileHandle.
+ */
+ FileMappingHandle = CreateFileMapping(
+ INVALID_HANDLE_VALUE,
+ NULL, /* not inherited */
+ PAGE_READWRITE, /* read and wite */
+ 0, /* high-order size */
+ LOWORDERSIZE, /* low-order size */
+ MapObject); /* named object */
+
+ if(NULL == FileMappingHandle)
+ {
+ Fail("\nFailed to call CreateFileMapping to "
+ "create a mapping object!\n");
+ }
+ if(GetLastError() == ERROR_ALREADY_EXISTS)
+ {
+ Trace("\nFile mapping object already exists!\n");
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Open a named file-mapping object with FILE_MAP_WRITE access.
+ */
+ OpenFileMappingHandle = OpenFileMapping(
+ FILE_MAP_WRITE,
+ FALSE,
+ MapObject);
+
+ if(NULL == OpenFileMappingHandle)
+ {
+ Trace("\nFailed to Call OpenFileMappingW API!\n");
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Open a named file-mapping object with
+ * FILE_MAP_ALL_ACCESS access, to verify
+ * the FILE_MAP_WRITE access map.
+ */
+ OpenFileMappingHandle2 = OpenFileMapping(
+ FILE_MAP_ALL_ACCESS,
+ FALSE,
+ MapObject);
+
+ if(NULL == OpenFileMappingHandle2)
+ {
+ Trace("\nFailed to Call OpenFileMappingW API!\n");
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Create map view of the open mapping that has
+ * FILE_MAP_WRITE access.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ OpenFileMappingHandle,
+ FILE_MAP_WRITE, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ LOWORDERSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+ /* Create map view of the open mapping that has
+ * FILE_MAP_ALL_ACCESS access.
+ */
+
+ lpMapViewAddress2 = MapViewOfFile(
+ OpenFileMappingHandle2,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ LOWORDERSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress2)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpFour;
+ }
+
+ /* Write to the Map View.
+ */
+ memcpy(lpMapViewAddress, buf, strlen(buf));
+
+ /* Read from the Map View.
+ */
+ memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE);
+
+ /* Compare what was written to the Map View,
+ * to what was read.
+ */
+ if (memcmp(ch, buf, strlen(buf))!= 0)
+ {
+
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ ch, buf);
+ RetVal = FAIL;
+ goto CleanUpFive;
+ }
+
+
+CleanUpFive:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress2);
+ RetVal = FAIL;
+ }
+
+CleanUpFour:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress);
+ RetVal = FAIL;
+ }
+
+CleanUpThree:
+
+ /* Close Handle to opened file mapping.
+ */
+ if ( CloseHandle(OpenFileMappingHandle2) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ OpenFileMappingHandle2);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Close Handle to opened file mapping.
+ */
+ if ( CloseHandle(OpenFileMappingHandle) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ OpenFileMappingHandle);
+ RetVal = FAIL;
+ }
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(FileMappingHandle) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ FileMappingHandle);
+ RetVal = FAIL;
+ }
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/testinfo.dat
new file mode 100644
index 0000000000..d481560a0d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test2/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = OpenFileMappingW
+Name = Positive test for OpenFileMappingW API
+TYPE = DEFAULT
+EXE1 = openfilemappingw
+Description
+=Test the OpenFileMappingW with FILE_MAP_WRITE access
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/CMakeLists.txt
new file mode 100644
index 0000000000..5a54368110
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ OpenFileMappingW.c
+)
+
+add_executable(paltest_openfilemappingw_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_openfilemappingw_test3 coreclrpal)
+
+target_link_libraries(paltest_openfilemappingw_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/OpenFileMappingW.c b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/OpenFileMappingW.c
new file mode 100644
index 0000000000..9c83491f6b
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/OpenFileMappingW.c
@@ -0,0 +1,210 @@
+// 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: openfilemappingw.c (test 3)
+**
+** Purpose: Positive test the OpenFileMappingW API.
+** Call OpenFileMappingW to open a named file-mapping
+** object with FILE_MAP_READ access
+**
+**
+**============================================================*/
+#define UNICODE
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ char buf[] = "this is a test";
+ char ch[1024];
+ HANDLE FileMappingHandle;
+ HANDLE OpenFileMappingHandle;
+ HANDLE OpenFileMappingHandle2;
+ HANDLE lpMapViewAddress;
+ HANDLE lpMapViewAddress2;
+ const int LOWORDERSIZE = 1024;
+ int RetVal = PASS;
+ WCHAR wpMappingFileObject[] = {'m','y','O','b','j','e','c','t','\0'};
+
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a unnamed file-mapping object with file handle FileHandle.
+ */
+ FileMappingHandle = CreateFileMapping(
+ INVALID_HANDLE_VALUE,
+ NULL, /* not inherited */
+ PAGE_READWRITE, /* read and wite */
+ 0, /* high-order size */
+ LOWORDERSIZE, /* must be non-zero */
+ wpMappingFileObject);/* named object */
+
+ if(NULL == FileMappingHandle)
+ {
+ Fail("\nFailed to call CreateFileMapping to create mapping object!\n");
+ }
+ if(GetLastError() == ERROR_ALREADY_EXISTS)
+ {
+ Trace("\nFile mapping object already exists!\n");
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Open a named file-mapping object with FILE_MAP_ALL_ACCESS access.
+ */
+ OpenFileMappingHandle = OpenFileMapping(
+ FILE_MAP_READ,
+ FALSE,
+ wpMappingFileObject);
+
+ if(NULL == OpenFileMappingHandle)
+ {
+ Trace("\nFailed to Call OpenFileMapping API!\n");
+ RetVal = FAIL;
+ goto CleanUpOne;
+ }
+
+ /* Open a file mapping with FILE_MAP_ALL_ACCESS access,
+ * to verify the FILE_MAP_READ.
+ */
+ OpenFileMappingHandle2 = OpenFileMapping(
+ FILE_MAP_ALL_ACCESS,
+ FALSE,
+ wpMappingFileObject);
+
+ if(NULL == OpenFileMappingHandle2)
+ {
+ Trace("\nFailed to Call OpenFileMapping API!\n");
+ RetVal = FAIL;
+ goto CleanUpTwo;
+ }
+
+ /* Test the opened map view.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ OpenFileMappingHandle,
+ FILE_MAP_READ, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ LOWORDERSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpThree;
+ }
+
+ /* Open a map view with FILE_MAP_ALL_ACCESS to verify,
+ * the FILE_MAP_READ view.
+ */
+ lpMapViewAddress2 = MapViewOfFile(
+ OpenFileMappingHandle2,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ LOWORDERSIZE); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress2)
+ {
+ Trace("2ERROR:%u: Failed to call MapViewOfFile "
+ "API to map a view of file!\n",
+ GetLastError());
+ RetVal = FAIL;
+ goto CleanUpFour;
+ }
+
+ /* Write to the Map View.
+ */
+ memcpy(lpMapViewAddress2, buf, strlen(buf));
+ /* Read from the Map View.
+ */
+ memcpy(ch, (LPCSTR)lpMapViewAddress, LOWORDERSIZE);
+
+ /* Compare what was written to the Map View,
+ * to what was read.
+ */
+ if (memcmp(ch, buf, strlen(buf))!= 0)
+ {
+ Trace("ERROR: MapViewOfFile not equal to file contents "
+ "retrieved \"%s\", expected \"%s\".\n",
+ ch,
+ buf);
+ RetVal = FAIL;
+ goto CleanUpFive;
+ }
+
+CleanUpFive:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress2) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress2);
+ RetVal = FAIL;
+ }
+
+CleanUpFour:
+
+ /* Unmap the view of file.
+ */
+ if ( UnmapViewOfFile(lpMapViewAddress) == FALSE )
+ {
+ Trace("ERROR:%u: Failed to UnmapViewOfFile of \"%0x%lx\".\n",
+ GetLastError(),
+ lpMapViewAddress);
+ RetVal = FAIL;
+ }
+
+CleanUpThree:
+
+ /* Close Handle to opened file mapping.
+ */
+ if ( CloseHandle(OpenFileMappingHandle2) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ OpenFileMappingHandle2);
+ RetVal = FAIL;
+ }
+
+CleanUpTwo:
+
+ /* Close Handle to opened file mapping.
+ */
+ if ( CloseHandle(OpenFileMappingHandle) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ OpenFileMappingHandle);
+ RetVal = FAIL;
+ }
+
+CleanUpOne:
+
+ /* Close Handle to create file mapping.
+ */
+ if ( CloseHandle(FileMappingHandle) == 0 )
+ {
+ Trace("ERROR:%u: Failed to CloseHandle \"0x%lx\".\n",
+ GetLastError(),
+ FileMappingHandle);
+ RetVal = FAIL;
+ }
+
+ /* Terminate the PAL.
+ */
+ PAL_TerminateEx(RetVal);
+ return RetVal;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/testinfo.dat
new file mode 100644
index 0000000000..b4ac69ec36
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/OpenFileMappingW/test3/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = OpenFileMappingW
+Name = Positive test for OpenFileMappingW API with FILE_MAP_READ access
+TYPE = DEFAULT
+EXE1 = openfilemappingw
+Description
+=Test the OpenFileMappingW with FILE_MAP_READ access
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/CMakeLists.txt
new file mode 100644
index 0000000000..d2ae61f923
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(ReadProcessMemory_neg1)
+add_subdirectory(test1)
+add_subdirectory(test2)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/CMakeLists.txt
new file mode 100644
index 0000000000..400c9219f6
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ ReadProcessMemory_neg.c
+)
+
+add_executable(paltest_readprocessmemory_readprocessmemory_neg1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_readprocessmemory_readprocessmemory_neg1 coreclrpal)
+
+target_link_libraries(paltest_readprocessmemory_readprocessmemory_neg1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/ReadProcessMemory_neg.c b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/ReadProcessMemory_neg.c
new file mode 100644
index 0000000000..aecd5ad576
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/ReadProcessMemory_neg.c
@@ -0,0 +1,127 @@
+// 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: ReadProcessMemory_neg.c
+**
+** Purpose: Negative test the ReadProcessMemory API.
+** Call ReadProcessMemory to read unreadabel memory area
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define REGIONSIZE 1024
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ BOOL bResult;
+ HANDLE ProcessHandle;
+ DWORD ProcessID;
+ LPVOID lpProcessAddress = NULL;
+ char ProcessBuffer[REGIONSIZE];
+ ULONG_PTR size = 0;
+
+
+ /*Initialize the PAL environment*/
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ return FAIL;
+ }
+
+ /*retrieve the current process ID*/
+ ProcessID = GetCurrentProcessId();
+
+ /*retrieve the current process handle*/
+ ProcessHandle = OpenProcess(
+ PROCESS_ALL_ACCESS,
+ FALSE, /*not inherited*/
+ ProcessID);
+
+ if(NULL == ProcessHandle)
+ {
+ Fail("\nFailed to call OpenProcess API to retrieve "
+ "current process handle error code=%u\n",
+ GetLastError());
+ }
+
+
+
+ /*allocate the virtual memory*/
+ lpProcessAddress = VirtualAlloc(
+ NULL, /*system determine where to allocate the region*/
+ REGIONSIZE, /*specify the size*/
+ MEM_RESERVE, /*allocation type*/
+ PAGE_READONLY); /*access protection*/
+
+ if(NULL == lpProcessAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API to allocate "
+ "virtual memory, error code=%u\n", GetLastError());
+ }
+
+ /*zero the memory*/
+ memset(ProcessBuffer, 0, REGIONSIZE);
+ /*try to retrieve the unreadable memory area*/
+ bResult = ReadProcessMemory(
+ ProcessHandle, /*current process handle*/
+ lpProcessAddress, /*base of memory area*/
+ (LPVOID)ProcessBuffer,
+ REGIONSIZE, /*buffer length in bytes*/
+ &size);
+
+
+ /*check the return value*/
+ if(0 != bResult)
+ {
+ Trace("\nFailed to call ReadProcessMemory API for a negative test, "
+ "Try to read an unreadable memory area will cause fail "
+ "but it successes\n");
+
+ err = CloseHandle(ProcessHandle);
+ if(0 == err)
+ {
+ Trace("\nFailed to call CloseHandle API, error code=%u\n",
+ GetLastError());
+ }
+
+ /*decommit the specified region*/
+ err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Trace("\nFailed to call VirtualFree API, error code=%u\n",
+ GetLastError());
+ }
+ Fail("");
+ }
+
+ err = CloseHandle(ProcessHandle);
+ if(0 == err)
+ {
+ Trace("\nFailed to call CloseHandle API, error code = %u\n",
+ GetLastError());
+
+ err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Trace("\nFailed to call VirtualFree API, error code=%u\n",
+ GetLastError());
+ }
+
+ Fail("");
+ }
+ /*decommit the specified region*/
+ err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API, error code=%u\n",
+ GetLastError());
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/testinfo.dat
new file mode 100644
index 0000000000..08c8f3291d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/ReadProcessMemory_neg1/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = ReadProcessMemory
+Name = Negative test ReadProcessMemory API to read unreadable memory area
+TYPE = DEFAULT
+EXE1 = readprocessmemory_neg
+Description
+=Test the ReadProcessMemory to read unreadable memory area
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/CMakeLists.txt
new file mode 100644
index 0000000000..8c21f01562
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ ReadProcessMemory.c
+)
+
+add_executable(paltest_readprocessmemory_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_readprocessmemory_test1 coreclrpal)
+
+target_link_libraries(paltest_readprocessmemory_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/ReadProcessMemory.c b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/ReadProcessMemory.c
new file mode 100644
index 0000000000..c9475f13f1
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/ReadProcessMemory.c
@@ -0,0 +1,126 @@
+// 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: ReadProcessMemory.c
+**
+** Purpose: Positive test the ReadProcessMemory API.
+** Call ReadProcessMemory to read memory contents
+** inside current process.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define REGIONSIZE 1024
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ BOOL bResult;
+ HANDLE ProcessHandle;
+ DWORD ProcessID;
+ LPVOID lpProcessAddress = NULL;
+ char ProcessBuffer[REGIONSIZE];
+ ULONG_PTR size = 0;
+
+
+ /*Initialize the PAL environment*/
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ return FAIL;
+ }
+
+ /*retrieve the current process ID*/
+ ProcessID = GetCurrentProcessId();
+
+ /*retrieve the current process handle*/
+ ProcessHandle = OpenProcess(
+ PROCESS_VM_READ,/*access flag*/
+ FALSE, /*not inherited*/
+ ProcessID);
+
+ if(NULL == ProcessHandle)
+ {
+ Fail("\nFailed to call OpenProcess API to retrieve "
+ "current process handle error code=%u\n",
+ GetLastError());
+ }
+
+ /*allocate the virtual memory*/
+ lpProcessAddress = VirtualAlloc(
+ NULL, /*system determine where to allocate the region*/
+ REGIONSIZE, /*specify the size*/
+ MEM_COMMIT, /*allocation type*/
+ PAGE_READONLY); /*access protection*/
+
+ if(NULL == lpProcessAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API to allocate "
+ "virtual memory, error code=%u!\n", GetLastError());
+ }
+
+ /*zero the memory*/
+ memset(ProcessBuffer, 0, REGIONSIZE);
+
+ /*retrieve the memory contents*/
+ bResult = ReadProcessMemory(
+ ProcessHandle, /*current process handle*/
+ lpProcessAddress, /*base of memory area*/
+ (LPVOID)ProcessBuffer,
+ REGIONSIZE, /*buffer length in bytes*/
+ &size);
+
+ if(!bResult || REGIONSIZE != size)
+ {
+ Trace("\nFailed to call ReadProcessMemory API "
+ "to retrieve the memory contents, error code=%u\n",
+ GetLastError());
+
+ err = CloseHandle(ProcessHandle);
+ if(0 == err)
+ {
+ Trace("\nFailed to call CloseHandle API, error code=%u\n",
+ GetLastError());
+ }
+
+ /*decommit the specified region*/
+ err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Trace("\nFailed to call VirtualFree API, error code=%u\n",
+ GetLastError());
+ }
+ Fail("");
+ }
+
+ err = CloseHandle(ProcessHandle);
+ if(0 == err)
+ {
+ Trace("\nFailed to call CloseHandle API, error code = %u\n",
+ GetLastError());
+
+ err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Trace("\nFailed to call VirtualFree API, error code=%u\n",
+ GetLastError());
+ }
+
+ Fail("");
+ }
+
+ /*decommit the specified region*/
+ err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API, error code=%u\n",
+ GetLastError());
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/testinfo.dat
new file mode 100644
index 0000000000..c56920d206
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test1/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = ReadProcessMemory
+Name = Positive test for ReadProcessMemory API to read memory contents
+TYPE = DEFAULT
+EXE1 = readprocessmemory
+Description
+=Test the ReadProcessMemory to read the memory contents
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/CMakeLists.txt
new file mode 100644
index 0000000000..9e0de95a0a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/CMakeLists.txt
@@ -0,0 +1,36 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(TESTSOURCES
+ test2.c
+)
+
+add_executable(paltest_readprocessmemory_test2
+ ${TESTSOURCES}
+)
+
+add_dependencies(paltest_readprocessmemory_test2 coreclrpal)
+
+target_link_libraries(paltest_readprocessmemory_test2
+ pthread
+ m
+ coreclrpal
+)
+
+
+set(HELPERSOURCES
+ helper.c
+)
+
+add_executable(paltest_readprocessmemory_test2_helper
+ ${HELPERSOURCES}
+)
+
+add_dependencies(paltest_readprocessmemory_test2_helper coreclrpal)
+
+target_link_libraries(paltest_readprocessmemory_test2_helper
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/commonconsts.h b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/commonconsts.h
new file mode 100644
index 0000000000..433d820f0f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/commonconsts.h
@@ -0,0 +1,48 @@
+// 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: commonconsts.h
+**
+**
+**============================================================*/
+
+#ifndef _COMMONCONSTS_H_
+#define _COMMONCONSTS_H_
+
+#include <pal.h>
+#define REGIONSIZE 1024
+
+const int TIMEOUT = 40000;
+
+const WCHAR szcToHelperEvName[] = { 'T', 'o', '\0' };
+const WCHAR szcFromHelperEvName[] = { 'F', 'r', 'o', 'm', '\0' };
+
+const char initialValue = '-';
+const char nextValue = '|';
+const char guardValue = '*';
+const char *commsFileName = "AddrNLen.dat";
+
+
+/* PEDANTIC and PEDANTIC0 is a helper macro that just grumps about any
+ * zero return codes in a generic way. with little typing */
+#define PEDANTIC(function, parameters) \
+{ \
+ if (! (function parameters) ) \
+ { \
+ Trace("%s: NonFatal failure of %s%s for reasons %u and %u\n", \
+ __FILE__, #function, #parameters, GetLastError(), errno); \
+ } \
+}
+#define PEDANTIC1(function, parameters) \
+{ \
+ if ( (function parameters) ) \
+ { \
+ Trace("%s: NonFatal failure of %s%s for reasons %u and %u\n", \
+ __FILE__, #function, #parameters, GetLastError(), errno); \
+ } \
+}
+
+#endif
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/helper.c b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/helper.c
new file mode 100644
index 0000000000..59e882fc1f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/helper.c
@@ -0,0 +1,249 @@
+// 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: helper.c
+**
+** Purpose: This helper process sets up a several blocks of memory,
+** then uses a file to tell its parent process where that memory is
+** So it can do a WriteProcessMemory on it. When the parent process is done
+** we check here that it was written properly.
+**
+**
+**============================================================*/
+
+#include "commonconsts.h"
+
+#include <palsuite.h>
+
+#if defined(BIT64) && defined(PLATFORM_UNIX)
+#define LLFORMAT "%I64u"
+#else
+#define LLFORMAT "%u"
+#endif
+
+struct allhandles_t
+{
+ HANDLE hEvToHelper;
+ HANDLE hEvFromHelper;
+ char *valuesFileName;
+};
+
+
+/* function: wpmDoIt
+ *
+ * This is a general WriteProcessMemory testing function that sets up
+ * the RAM pointed to and tells the companion process on the other end
+ * of the handles in 'Comms' to attempt to alter 'lenDest' bytes at
+ * '*pDest'.
+ *
+ * '*pBuffer'[0..'lenBuffer'] is expected to be a guard region
+ * surrounding the '*pDest'[0..'lenDest'] region so that this function
+ * can verify that only the proper bytes were altered.
+ */
+
+int wpmDoIt(struct allhandles_t Comms,
+ char * pBuffer, unsigned int lenBuffer,
+ char * pDest, unsigned int lenDest,
+ const char* storageDescription)
+{
+ char *pCurr;
+ FILE *commsFile;
+ DWORD dwRet;
+
+ if (pBuffer > pDest || lenDest > lenBuffer)
+ {
+ Trace("WriteProcessMemory::DoIt() test implementation: "
+ "(pBuffer > pDest || lenDest > lenBuffer)\n");
+ return FALSE;
+ }
+
+ /* set up the storage */
+ memset(pBuffer, guardValue, lenBuffer);
+ memset(pDest, initialValue, lenDest);
+
+ /* tell the parent what RAM to adjust */
+ if(!(commsFile = fopen(Comms.valuesFileName, "w")))
+ {
+ Trace("WriteProcessMemory: fopen of '%S' failed (%u). \n",
+ Comms.valuesFileName, GetLastError());
+ return FALSE;
+ }
+ if (!fprintf(commsFile, LLFORMAT " " LLFORMAT " '%s'\n",
+ pDest, lenDest, storageDescription))
+ {
+ Trace("WriteProcessMemory: fprintf to '%S' failed (%u). \n",
+ Comms.valuesFileName, GetLastError());
+ return FALSE;
+ }
+ PEDANTIC1(fclose, (commsFile));
+
+ /* Tell the parent the data is ready for it to adjust */
+ PEDANTIC(ResetEvent, (Comms.hEvToHelper));
+ PEDANTIC(SetEvent, (Comms.hEvFromHelper));
+
+ dwRet = WaitForSingleObject(Comms.hEvToHelper, TIMEOUT); /* parent is done */
+ if (dwRet != WAIT_OBJECT_0)
+ {
+ Trace("helper WaitForSingleObjectTest: WaitForSingleObject "
+ "failed (%u)\n", GetLastError());
+ return FALSE;
+ }
+
+ /* check the stuff that SHOULD have changed */
+ for (pCurr = pDest; pCurr < (pDest + lenDest); pCurr++)
+ {
+ if ( *pCurr != nextValue)
+ {
+ Trace("When testing '%s': alteration test failed "
+ "at " LLFORMAT " offset " LLFORMAT " Found '%c' instead of '%c'\n.",
+ storageDescription, pDest, pCurr - pDest, *pCurr, nextValue);
+ Trace(" 'Altered' string: '%.*s'\n",lenBuffer, pBuffer);
+ return FALSE;
+ }
+ }
+ /* check the stuff that should NOT have changed */
+ for (pCurr = pBuffer; pCurr < pDest; pCurr++ )
+ {
+ if ( *pCurr != guardValue)
+ {
+ Trace("When testing '%s': leading guard zone test failed "
+ "at " LLFORMAT " offset " LLFORMAT ". Found '%c' instead of '%c'\n.",
+ storageDescription, pDest, pCurr - pBuffer, *pCurr, guardValue);
+ Trace(" 'Altered' string: '%.*s'\n",lenBuffer, pBuffer);
+ return FALSE;
+ }
+ }
+ for (pCurr = pDest + lenDest; pCurr < (pBuffer + lenBuffer); pCurr++ )
+ {
+ if ( *pCurr != guardValue)
+ {
+ Trace("When testing '%s': trailing guard zone test failed "
+ "at " LLFORMAT " offset " LLFORMAT ". Found '%c' instead of '%c'\n.",
+ storageDescription, pDest + lenDest, pCurr - pBuffer, *pCurr, guardValue);
+ Trace(" 'Altered' string: '%.*s'\n",lenBuffer, pBuffer);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ BOOL success = TRUE; /* assume success */
+ struct allhandles_t Comms = {0,0,0} ;
+
+ /* variables to track storage to alter */
+ char *pTarget = NULL;
+ unsigned int sizeTarget;
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* hook up with the events created by the parent */
+ Comms.hEvToHelper = OpenEventW(EVENT_ALL_ACCESS, 0, szcToHelperEvName);
+ if (!Comms.hEvToHelper)
+ {
+ Fail("WriteProcessMemory: OpenEvent of '%S' failed (%u). "
+ "(the event should already exist!)\n",
+ szcToHelperEvName, GetLastError());
+ }
+ Comms.hEvFromHelper = OpenEventW(EVENT_ALL_ACCESS, 0, szcFromHelperEvName);
+ if (!Comms.hEvToHelper)
+ {
+ Trace("WriteProcessMemory: OpenEvent of '%S' failed (%u). "
+ "(the event should already exist!)\n",
+ szcFromHelperEvName, GetLastError());
+ success = FALSE;
+ goto EXIT;
+ }
+ Comms.valuesFileName = argv[1];
+
+ {
+ char autoAllocatedOnStack[51];
+
+ /* Get the parent process to write to the local stack */
+ success &= wpmDoIt(Comms, autoAllocatedOnStack,
+ sizeof(autoAllocatedOnStack),
+ autoAllocatedOnStack + sizeof(int),
+ sizeof(autoAllocatedOnStack) - 2 * sizeof(int),
+ "const size array on stack with int sized guards");
+ }
+
+ /* Get the parent process to write to stuff on the heap */
+ sizeTarget = 2 * sizeof(int) + 23 ; /* 23 is just a random prime > 16 */
+ if (!(pTarget = malloc(sizeTarget)))
+ {
+ Trace("WriteProcessMemory helper: unable to allocate '%s'->%d bytes of memory"
+ "(%u).\n",
+ argv[3], sizeTarget, GetLastError());
+ success = FALSE;
+ goto EXIT;
+
+ }
+ success &= wpmDoIt(Comms, pTarget, sizeTarget,
+ pTarget + sizeof(int),
+ sizeTarget - 2 * sizeof(int),
+ "array on heap with int sized guards");
+
+ /* just to be nice try something 16 - 2 * sizeof(int) bytes long */
+ {
+ char autoAllocatedOnStack[16];
+
+ /* Get the parent process to write to the local stack */
+ success &= wpmDoIt(Comms, autoAllocatedOnStack,
+ sizeof(autoAllocatedOnStack),
+ autoAllocatedOnStack + sizeof(int),
+ sizeof(autoAllocatedOnStack) - 2 * sizeof(int),
+ "another 16 byte array on stack with int sized guards inside");
+ }
+
+ /* NOTE: Don't try 0 bytes long. Win32 WriteProcessMemory claims
+ * it writes 8 bytes in that case! */
+
+ /* and 1 byte long... */
+ {
+ char autoAllocatedOnStack[1+ 2 * sizeof(int)];
+
+ /* Get the parent process to write to the local stack */
+ success &= wpmDoIt(Comms, autoAllocatedOnStack,
+ sizeof(autoAllocatedOnStack),
+ autoAllocatedOnStack + sizeof(int),
+ 1,
+ "no bytes with int sized guards outside on stack");
+ }
+
+
+EXIT:
+ /* Tell the parent that we are done */
+ if (!DeleteFile(Comms.valuesFileName))
+ {
+ Trace("helper: DeleteFile failed so parent (test1) is unlikely "
+ "to exit cleanly\n");
+ }
+ PEDANTIC(ResetEvent, (Comms.hEvToHelper));
+ if (!SetEvent(Comms.hEvFromHelper))
+ {
+ Trace("helper: SetEvent failed so parent (test1) is unlikely "
+ "to exit cleanly\n");
+ }
+
+ free(pTarget);
+ PEDANTIC(CloseHandle, (Comms.hEvToHelper));
+ PEDANTIC(CloseHandle, (Comms.hEvFromHelper));
+
+ if (!success)
+ {
+ Fail("");
+ }
+
+ PAL_Terminate();
+
+ return success ? PASS : FAIL;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/test2.c b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/test2.c
new file mode 100644
index 0000000000..eda40599ce
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/test2.c
@@ -0,0 +1,258 @@
+// 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: test2.c
+**
+** Purpose: Create a child process and some events for communications with it.
+** When the child gets back to us with a memory location and a length,
+** Call WriteProcessMemory on this location and check to see that it
+** writes successfully. Then call ReadProcessMemory to check if the
+** contents read are same as those written
+**
+**
+**============================================================*/
+
+#define UNICODE
+
+#include "commonconsts.h"
+
+#include <palsuite.h>
+
+#if defined(BIT64) && defined(PLATFORM_UNIX)
+#define LLFORMAT "%I64u"
+#else
+#define LLFORMAT "%u"
+#endif
+
+int __cdecl main(int argc, char *argv[])
+{
+
+ PROCESS_INFORMATION pi;
+ STARTUPINFO si;
+ HANDLE hEvToHelper;
+ HANDLE hEvFromHelper;
+ DWORD dwExitCode;
+
+ DWORD dwRet;
+ char cmdComposeBuf[MAX_PATH];
+ PWCHAR uniString;
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Create the signals we need for cross process communication */
+ hEvToHelper = CreateEvent(NULL, TRUE, FALSE, szcToHelperEvName);
+ if (!hEvToHelper)
+ {
+ Fail("WriteProcessMemory: CreateEvent of '%S' failed. "
+ "GetLastError() returned %d.\n", szcToHelperEvName,
+ GetLastError());
+ }
+ if (GetLastError() == ERROR_ALREADY_EXISTS)
+ {
+ Fail("WriteProcessMemory: CreateEvent of '%S' failed. "
+ "(already exists!)\n", szcToHelperEvName);
+ }
+ hEvFromHelper = CreateEvent(NULL, TRUE, FALSE, szcFromHelperEvName);
+ if (!hEvToHelper)
+ {
+ Fail("WriteProcessMemory: CreateEvent of '%S' failed. "
+ "GetLastError() returned %d.\n", szcFromHelperEvName,
+ GetLastError());
+ }
+ if (GetLastError() == ERROR_ALREADY_EXISTS)
+ {
+ Fail("WriteProcessMemory: CreateEvent of '%S' failed. "
+ "(already exists!)\n", szcFromHelperEvName);
+ }
+ ResetEvent(hEvFromHelper);
+ ResetEvent(hEvToHelper);
+
+ if (!sprintf(cmdComposeBuf, "helper %s", commsFileName))
+ {
+ Fail("Could not convert command line\n");
+ }
+ uniString = convert(cmdComposeBuf);
+
+ ZeroMemory( &si, sizeof(si) );
+ si.cb = sizeof(si);
+ ZeroMemory( &pi, sizeof(pi) );
+
+ /* Create a new process. This is the process that will ask for
+ * memory munging */
+ if(!CreateProcess( NULL, uniString, NULL, NULL,
+ FALSE, 0, NULL, NULL, &si, &pi))
+ {
+ Trace("ERROR: CreateProcess failed to load executable '%S'. "
+ "GetLastError() returned %u.\n",
+ uniString, GetLastError());
+ free(uniString);
+ Fail("");
+ }
+ free(uniString);
+
+
+ while(1)
+ {
+ FILE *commsFile;
+ char* pSrcMemory;
+ char* pDestMemory;
+ SIZE_T Count;
+ SIZE_T wpmCount;
+ char incomingCMDBuffer[MAX_PATH + 1];
+
+ int err;
+ HANDLE readProcessHandle;
+ DWORD readProcessID;
+ char readProcessBuffer[REGIONSIZE]; // size 1024
+ BOOL bResult;
+ size_t size = 0;
+
+ readProcessID = pi.dwProcessId;
+
+ /* wait until the helper tells us that it has given us
+ * something to do */
+ dwRet = WaitForSingleObject(hEvFromHelper, TIMEOUT);
+ if (dwRet != WAIT_OBJECT_0)
+ {
+ Trace("test1 WaitForSingleObjectTest: WaitForSingleObject "
+ "failed (%u)\n", GetLastError());
+ break; /* no more work incoming */
+ }
+
+ /* get the parameters to test WriteProcessMemory with */
+ if (!(commsFile = fopen(commsFileName, "r")))
+ {
+ /* no file means there is no more work */
+ break;
+ }
+ if ( NULL == fgets(incomingCMDBuffer, MAX_PATH, commsFile))
+ {
+ Fail ("unable to read from communication file %s "
+ "for reasons %u & %u\n",
+ errno, GetLastError());
+ }
+ PEDANTIC1(fclose,(commsFile));
+ sscanf(incomingCMDBuffer, LLFORMAT " " LLFORMAT, &pDestMemory, &Count);
+ if (argc > 1)
+ {
+ Trace("Preparing to write to " LLFORMAT " bytes @ " LLFORMAT "('%s')\n",
+ Count, pDestMemory, incomingCMDBuffer);
+ }
+
+ /* compose some data to write to the client process */
+ if (!(pSrcMemory = malloc(Count)))
+ {
+ Trace("could not dynamically allocate memory to copy from "
+ "for reasons %u & %u\n",
+ errno, GetLastError());
+ goto doneIteration;
+ }
+ memset(pSrcMemory, nextValue, Count);
+ Trace("Preparing to write to " LLFORMAT " bytes @ " LLFORMAT " ('%s')[%u]\n",
+ Count, pDestMemory, incomingCMDBuffer, pSrcMemory);
+
+ /* do the work */
+ dwRet = WriteProcessMemory(pi.hProcess,
+ pDestMemory,
+ pSrcMemory,
+ Count,
+ &wpmCount);
+
+ if (!dwRet)
+ {
+ Trace("%s: Problem: on a write to "LLFORMAT " bytes @ " LLFORMAT " ('%s')\n",
+ argv[0], Count, pDestMemory, incomingCMDBuffer);
+ Trace("test1 WriteProcessMemory returned a (!=0) (GLE=%u)\n",
+ GetLastError());
+ }
+ if(Count != wpmCount)
+ {
+ Trace("%s: Problem: on a write to " LLFORMAT " bytes @ " LLFORMAT " ('%s')\n",
+ argv[0], Count, pDestMemory, incomingCMDBuffer);
+ Trace("The number of bytes written should have been "
+ LLFORMAT ", but was reported as " LLFORMAT " \n", Count, wpmCount);
+ }
+
+ readProcessHandle = OpenProcess(
+ PROCESS_VM_READ,
+ FALSE,
+ readProcessID);
+
+ if(NULL == readProcessHandle)
+ {
+ Fail("\nFailed to call OpenProcess API to retrieve "
+ "current process handle error code=%u\n",
+ GetLastError());
+ }
+
+ /*zero the memory*/
+ memset(readProcessBuffer, 0, size);
+
+ /*retrieve the memory contents*/
+ bResult = ReadProcessMemory(
+ readProcessHandle, /*current process handle*/
+ pDestMemory, /*base of memory area*/
+ (LPVOID)readProcessBuffer,
+ Count, /*buffer length in bytes*/
+ &size);
+
+
+ if( !bResult || (Count != size) )
+ {
+ Trace("\nFailed to call ReadProcessMemory API "
+ "to retrieve the memory contents, error code=%u; Bresult[%u] Count[" LLFORMAT "], Size[%d]\n",
+ GetLastError(), bResult, Count, size);
+
+ err = CloseHandle(readProcessHandle);
+
+ if(0 == err)
+ {
+ Trace("\nFailed to call CloseHandle API, error code=%u\n",
+ GetLastError());
+ }
+ dwExitCode = FAIL;
+ }
+
+ if( !memcmp (pDestMemory, readProcessBuffer, Count ) )
+ {
+ Trace("Difference in memory contents, expected [%s], but received [%s]\n", pDestMemory, readProcessBuffer);
+ dwExitCode = FAIL;
+ }
+
+ Trace("ReadProcessBuffer contains [%s]\n", readProcessBuffer);
+ err = CloseHandle(readProcessHandle);
+
+ free(pSrcMemory);
+
+ doneIteration:
+ PEDANTIC(ResetEvent, (hEvFromHelper));
+ PEDANTIC(SetEvent, (hEvToHelper));
+ }
+
+ /* wait for the child process to complete */
+ WaitForSingleObject ( pi.hProcess, TIMEOUT );
+ /* this may return a failure code on a success path */
+
+ /* check the exit code from the process */
+ if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) )
+ {
+ Trace( "GetExitCodeProcess call failed with error code %u\n",
+ GetLastError() );
+ dwExitCode = FAIL;
+ }
+
+
+ PEDANTIC(CloseHandle, (hEvToHelper));
+ PEDANTIC(CloseHandle, (hEvFromHelper));
+ PEDANTIC(CloseHandle, (pi.hThread));
+ PEDANTIC(CloseHandle, (pi.hProcess));
+
+ PAL_TerminateEx(dwExitCode);
+ return dwExitCode;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/testinfo.dat
new file mode 100644
index 0000000000..58a9935a08
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/ReadProcessMemory/test2/testinfo.dat
@@ -0,0 +1,18 @@
+# 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.
+
+Version = 1.0
+Section = Debug
+Function = ReadProcessMemory
+Name = Check that writing/reading text to/from process memory succeeds.
+TYPE = DEFAULT
+EXE1 = test2
+EXE2 = helper
+Description
+= Create a child process and attempt to write to its memory
+= at the places and lengths it specifies via a data file.
+= the child verifies that all the specified memory was altered
+= with no overruns. Parent then tries to read memory from child
+= and does memory compare to ensure it read memory contents
+= correctly
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/CMakeLists.txt
new file mode 100644
index 0000000000..393074b4ee
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test3)
+add_subdirectory(test4)
+add_subdirectory(test5)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/CMakeLists.txt
new file mode 100644
index 0000000000..987c413d03
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test1.c
+)
+
+add_executable(paltest_rtlmovememory_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_rtlmovememory_test1 coreclrpal)
+
+target_link_libraries(paltest_rtlmovememory_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/test1.c b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/test1.c
new file mode 100644
index 0000000000..7fc56510d8
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/test1.c
@@ -0,0 +1,56 @@
+// 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: test1.c
+**
+** Purpose: Simple test -- have two 128 blocks of memory allocated. Then
+** move one block to the other and check to see that the data was not
+** corrupted.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+enum Memory
+{
+ MEMORY_AMOUNT = 128
+};
+
+int __cdecl main(int argc, char *argv[])
+{
+ char NewAddress[MEMORY_AMOUNT];
+ char OldAddress[MEMORY_AMOUNT];
+ int i;
+ char temp;
+
+ if(PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Put some data into the block we'll be moving */
+ memset(OldAddress, 'X', MEMORY_AMOUNT);
+
+ /* Move the block to the NewAddress */
+ RtlMoveMemory(NewAddress, OldAddress, MEMORY_AMOUNT);
+
+ /* Check to ensure the data didn't get corrupted */
+ for(i=0; i<MEMORY_AMOUNT; ++i)
+ {
+ if(NewAddress[i] != 'X')
+ {
+ temp = NewAddress[i];
+ Fail("ERROR: When the memory was moved to a new location, the "
+ "data which was stored in it was somehow corrupted. "
+ "Character %d should have been 'X' but instead is %c.\n",
+ i, temp);
+ }
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/testinfo.dat
new file mode 100644
index 0000000000..645d46c968
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test1/testinfo.dat
@@ -0,0 +1,15 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = RtlMoveMemory
+Name = Positive test for RtlMoveMemory API
+TYPE = DEFAULT
+EXE1 = test1
+Description
+= Simple test -- have two 128 blocks of memory allocated. Then
+= move one block to the other and check to see that the data was not
+= corrupted.
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/CMakeLists.txt
new file mode 100644
index 0000000000..14098a8dc1
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test3.c
+)
+
+add_executable(paltest_rtlmovememory_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_rtlmovememory_test3 coreclrpal)
+
+target_link_libraries(paltest_rtlmovememory_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/test3.c b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/test3.c
new file mode 100644
index 0000000000..279c0c1199
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/test3.c
@@ -0,0 +1,72 @@
+// 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: test3.c
+**
+** Purpose: Allocate 128 bytes of memory and store data in it. Move 10
+** other bytes of memory to that location. Check that the first 10 bytes
+** carried over their data and that the other 118 were unchanged.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+enum Memory
+{
+ NEW_MEMORY_AMOUNT = 128,
+ OLD_MEMORY_AMOUNT = 10
+};
+
+int __cdecl main(int argc, char *argv[])
+{
+ char NewAddress[NEW_MEMORY_AMOUNT];
+ char OldAddress[OLD_MEMORY_AMOUNT];
+ int i;
+
+
+ if(PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Put some data into the block we'll be moving */
+ memset(OldAddress, 'X', OLD_MEMORY_AMOUNT);
+
+ /* Put some data into the block we're moving to */
+ memset(NewAddress, 'Z', NEW_MEMORY_AMOUNT);
+
+ /* Move the block to the NewAddress */
+ RtlMoveMemory(NewAddress, OldAddress, OLD_MEMORY_AMOUNT);
+
+ /* Check to ensure the moved data didn't get corrupted */
+ for(i=0; i<OLD_MEMORY_AMOUNT; ++i)
+ {
+ if(NewAddress[i] != 'X')
+ {
+ Fail("ERROR: When the memory was moved to a new location, the "
+ "data which was stored in it was somehow corrupted. "
+ "Character %d should have been 'X' but instead is %c.\n",
+ i, NewAddress[i]);
+ }
+ }
+
+ /* Check to ensure the memory which didn't move didn't get corrupted */
+ for(i=OLD_MEMORY_AMOUNT; i<NEW_MEMORY_AMOUNT; ++i)
+ {
+ if(NewAddress[i] != 'Z')
+ {
+ Fail("ERROR: When the memory was moved to a new location, the "
+ "data which was stored in it was somehow corrupted. "
+ "Character %d should have been 'Z' but instead is %c.\n",
+ i, NewAddress[i]);
+ }
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/testinfo.dat
new file mode 100644
index 0000000000..fb56f2e985
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test3/testinfo.dat
@@ -0,0 +1,17 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = RtlMoveMemory
+Name = Positive test for RtlMoveMemory API, move a small block to large
+TYPE = DEFAULT
+EXE1 = test3
+Description
+= Allocate 128 bytes of memory and store data in it. Move 10
+= other bytes of memory to that location. Check that the first 10 bytes
+= carried over their data and that the other 118 were unchanged.
+
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/CMakeLists.txt
new file mode 100644
index 0000000000..00aec7e8f7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test4.c
+)
+
+add_executable(paltest_rtlmovememory_test4
+ ${SOURCES}
+)
+
+add_dependencies(paltest_rtlmovememory_test4 coreclrpal)
+
+target_link_libraries(paltest_rtlmovememory_test4
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/test4.c b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/test4.c
new file mode 100644
index 0000000000..b6e1ecd6f7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/test4.c
@@ -0,0 +1,76 @@
+// 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: test4.c
+**
+** Purpose: Test simple overlapping. Move the first 50 bytes of a
+** piece of memory to the latter 50 bytes. ie i -> i+50 Check to make sure
+** no data is lost.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+enum Memory
+{
+ MEMORY_AMOUNT = 128
+};
+
+int __cdecl main(int argc, char *argv[])
+{
+ char* NewAddress;
+ char OldAddress[MEMORY_AMOUNT];
+ int i;
+
+ if(PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ NewAddress = OldAddress+50;
+
+ /* Put some data into the block we'll be moving
+ The first 50 byes will be 'X' and the rest set to 'Z'
+ */
+ memset(OldAddress, 'X', 50);
+ memset(NewAddress, 'Z', MEMORY_AMOUNT-50);
+
+ /* Move the first 50 bytes of OldAddress to OldAddress+50. This
+ is to test that the source and destination addresses can overlap.
+ */
+ RtlMoveMemory(NewAddress, OldAddress, 50);
+
+ /* Check to ensure the moved data didn't get corrupted
+ The first 50 bytes should be 'X'
+ */
+ for(i=0; i<50; ++i)
+ {
+ if(NewAddress[i] != 'X')
+ {
+ Fail("ERROR: When the memory was moved to a new location, the "
+ "data which was stored in it was somehow corrupted. "
+ "Character %d should have been 'X' but instead is %c.\n",
+ i, NewAddress[i]);
+ }
+ }
+
+ /* The rest of the memory should be 'Z' */
+ for(i=50; i<MEMORY_AMOUNT-50; ++i)
+ {
+ if(NewAddress[i] != 'Z')
+ {
+
+ Fail("ERROR: When the memory was moved to a new location, the "
+ "data which was stored in it was somehow corrupted. "
+ "Character %d should have been 'Z' but instead is %c.\n",
+ i, NewAddress[i]);
+ }
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/testinfo.dat
new file mode 100644
index 0000000000..56b82f2083
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test4/testinfo.dat
@@ -0,0 +1,18 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = RtlMoveMemory
+Name = Positive test for RtlMoveMemory API, test that overlapping works
+TYPE = DEFAULT
+EXE1 = test4
+Description
+= Test simple overlapping. Move the first 50 bytes of a
+= piece of memory to the latter 50 bytes. ie i -> i+50 Check to make sure
+= no data is lost.
+
+
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/CMakeLists.txt
new file mode 100644
index 0000000000..f2de78216e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test5.c
+)
+
+add_executable(paltest_rtlmovememory_test5
+ ${SOURCES}
+)
+
+add_dependencies(paltest_rtlmovememory_test5 coreclrpal)
+
+target_link_libraries(paltest_rtlmovememory_test5
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/test5.c b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/test5.c
new file mode 100644
index 0000000000..affcb0abc9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/test5.c
@@ -0,0 +1,63 @@
+// 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: test5.c
+**
+** Purpose: Do more complex overlapping. Move a section of memory back so
+** that it actually ends up overlapping itself.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+enum Memory
+{
+ MEMORY_AMOUNT = 128
+};
+
+int __cdecl main(int argc, char *argv[])
+{
+ char* NewAddress;
+ char* SectionToMove;
+ char TheMemory[MEMORY_AMOUNT];
+ int i;
+
+ if(PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ NewAddress = TheMemory;
+ SectionToMove = TheMemory+50;
+
+ /* Put some data into the first 50 bytes */
+ memset(TheMemory, 'X', 50);
+
+ /* Put some data into the rest of the memory */
+ memset(SectionToMove, 'Z', MEMORY_AMOUNT-50);
+
+ /* Move the section in the middle of TheMemory back to the start of
+ TheMemory -- but have it also overlap itself. (ie. the section
+ to be move is overlapping itself)
+ */
+ RtlMoveMemory(NewAddress, SectionToMove, MEMORY_AMOUNT-50);
+
+ /* Check to ensure the moved data didn't get corrupted */
+ for(i=0; i<MEMORY_AMOUNT-50; ++i)
+ {
+ if(NewAddress[i] != 'Z')
+ {
+ Fail("ERROR: When the memory was moved to a new location, the "
+ "data which was stored in it was somehow corrupted. "
+ "Character %d should have been 'Z' but instead is %c.\n",
+ i, NewAddress[i]);
+ }
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/testinfo.dat
new file mode 100644
index 0000000000..a4ba99a29d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/RtlMoveMemory/test5/testinfo.dat
@@ -0,0 +1,18 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = RtlMoveMemory
+Name = Positive test for RtlMoveMemory API, test that overlapping works
+TYPE = DEFAULT
+EXE1 = test5
+Description
+= Do more complex overlapping. Move a section of memory back so
+= that it actually ends up overlapping itself.
+
+
+
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/CMakeLists.txt
new file mode 100644
index 0000000000..a3847f8ca9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+add_subdirectory(test4)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/UnlockFile.h b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/UnlockFile.h
new file mode 100644
index 0000000000..8fce2695a7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/UnlockFile.h
@@ -0,0 +1,112 @@
+// 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: UnLockFile.h
+**
+** Purpose: This header file has a RunHelper method which will be used to
+** start a child proccess in many LockFile testcases. The CreateAndLockFile
+** method Creates a file and calls LockFile upon it. And the two Signal
+** methods are used for IPC.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+
+HANDLE CreateAndLockFile(HANDLE TheFile, char* FileName, char* WriteBuffer,
+ DWORD LockStart, DWORD LockLength)
+{
+ DWORD BytesWritten;
+
+ TheFile = CreateFile(FileName,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.\n",FileName,GetLastError());
+ }
+
+ if(WriteFile(TheFile, WriteBuffer,
+ strlen(WriteBuffer),&BytesWritten, NULL) == 0)
+ {
+ Fail("ERROR: WriteFile has failed. It returned 0 when we "
+ "attempted to write to the file '%s'. GetLastError() "
+ "returned %d.\n",FileName,GetLastError());
+ }
+
+ if(FlushFileBuffers(TheFile) == 0)
+ {
+ Fail("ERROR: FlushFileBuffers returned failure. GetLastError() "
+ "returned %d.\n",GetLastError());
+ }
+
+ if(LockFile(TheFile, LockStart, 0, LockLength, 0) == 0)
+ {
+ Fail("ERROR: LockFile failed. GetLastError returns %d.\n",
+ GetLastError());
+ }
+
+ return TheFile;
+}
+
+void SignalAndBusyWait(HANDLE TheFile)
+{
+ int size;
+ DWORD BytesWritten;
+
+ size = GetFileSize(TheFile,NULL)+1;
+
+ if(SetFilePointer(TheFile, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
+ {
+ Fail("ERROR: SetFilePointer was unable to set the pointer to the "
+ "end of the file. GetLastError() returned %d.\n",GetLastError());
+ }
+
+ if(WriteFile(TheFile, "x", 1,&BytesWritten, NULL) == 0)
+ {
+ Fail("ERROR: WriteFile was unable to write to the WaitFile. "
+ "GetLastError() returned %d.\n",GetLastError());
+ }
+
+ if(FlushFileBuffers(TheFile) == 0)
+ {
+ Fail("ERROR: FlushFileBuffers failed when flushing the WaitFile. "
+ "GetLastError() returned %d.\n");
+ }
+
+ while(GetFileSize(TheFile,NULL) == size) {}
+}
+
+void SignalFinish(HANDLE TheFile)
+{
+ DWORD BytesWritten;
+
+ if(SetFilePointer(TheFile, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
+ {
+ Fail("ERROR: SetFilePointer was unable to set the pointer to the "
+ "end of the WaitFile. GetLastError() returned %d.\n",
+ GetLastError());
+ }
+
+ if(WriteFile(TheFile, "x", 1,&BytesWritten, NULL) == 0)
+ {
+ Fail("ERROR: WriteFile was unable to write to the WaitFile. "
+ "GetLastError returned %d.\n",GetLastError());
+ }
+
+ if(FlushFileBuffers(TheFile) == 0)
+ {
+ Fail("ERROR: FlushFileBuffers failed when flushing the WaitFile. "
+ "GetLastError() returned %d.\n");
+ }
+
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/CMakeLists.txt
new file mode 100644
index 0000000000..0e6d6fef4c
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/CMakeLists.txt
@@ -0,0 +1,36 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(TESTSOURCES
+ test1.c
+)
+
+add_executable(paltest_unlockfile_test1
+ ${TESTSOURCES}
+)
+
+add_dependencies(paltest_unlockfile_test1 coreclrpal)
+
+target_link_libraries(paltest_unlockfile_test1
+ pthread
+ m
+ coreclrpal
+)
+
+
+set(HELPERSOURCES
+ helper.c
+)
+
+add_executable(paltest_unlockfile_test1_helper
+ ${HELPERSOURCES}
+)
+
+add_dependencies(paltest_unlockfile_test1_helper coreclrpal)
+
+target_link_libraries(paltest_unlockfile_test1_helper
+ pthread
+ m
+ coreclrpal
+) \ No newline at end of file
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/helper.c b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/helper.c
new file mode 100644
index 0000000000..c2ef5a6736
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/helper.c
@@ -0,0 +1,92 @@
+// 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: helper.c
+**
+** Purpose: A child process which will attempt to read from the
+** locked file to ensure it is locked. After it has been unlocked, it
+** will then read again to check that Unlock worked.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+#include "../UnlockFile.h"
+
+#define FILENAME "testfile.txt"
+#define WAITFILENAME "waitfile"
+#define BUF_SIZE 128
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE TheFile, WaitFile;
+ int result = 0;
+ char DataBuffer[BUF_SIZE];
+ DWORD BytesRead;
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Open the same file that the parent has opened and locked */
+ TheFile = CreateFile(FILENAME,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Trace("ERROR: Could not open file '%s' with CreateFile.\n",FILENAME);
+ result = 1;
+ }
+
+ /* Open up the WaitFile that we're using for IPC */
+ WaitFile = CreateFile(WAITFILENAME,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (WaitFile == INVALID_HANDLE_VALUE)
+ {
+ Trace("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.\n",WAITFILENAME,GetLastError());
+ result = 1;
+ }
+
+
+ /* Check to ensure the parent lock is respected */
+ if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) != 0)
+ {
+ Trace("ERROR: ReadFile returned success when it should "
+ "have failed. Attempted to read the first 10 bytes "
+ "of a file which was locked by the parent process.\n");
+ result = 1;
+ }
+
+ // Sleep for a bit to give the parent a chance to block before we do.
+ Sleep(1000);
+
+ /* Switch back to the parent, so it can unlock the file */
+ SignalAndBusyWait(WaitFile);
+
+ if(ReadFile(TheFile, DataBuffer, 10, &BytesRead, NULL) == 0)
+ {
+ Trace("ERROR: ReadFile was unable to read from the file after it "
+ "had been unlocked. Attempted to read 10 bytes and ReadFile "
+ "returned 0. GetLastError() returned %d.\n",GetLastError());
+ result = 1;
+ }
+
+ PAL_TerminateEx(result);
+ return result;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/test1.c b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/test1.c
new file mode 100644
index 0000000000..14634c7f7a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/test1.c
@@ -0,0 +1,154 @@
+// 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: test1.c
+**
+** Purpose:
+** Have the parent Lock a file, then have the child check the lock, then
+** have the parent unlock the file, and the child check again.
+** This requires some IPC, which is done here with a crude busy wait on a
+** file (waiting for the file size to change) to avoid too many more
+** dependencies.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+#include "../UnlockFile.h"
+
+#define HELPER "helper"
+#define FILENAME "testfile.txt"
+#define WAITFILENAME "waitfile"
+#define BUF_SIZE 128
+
+int RunTest(char* Helper, HANDLE TheFile, HANDLE WaitFile)
+{
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+ DWORD ChildRetCode = 0;
+ DWORD ParentRetCode = 0;
+ DWORD FileEnd;
+
+ ZeroMemory( &si, sizeof(si) );
+ si.cb = sizeof(si);
+ ZeroMemory( &pi, sizeof(pi) );
+
+ /* Load up the helper Process, and then Wait until it signals that it
+ is finished locking.
+ */
+ if(!CreateProcess( NULL, Helper, NULL,
+ NULL, FALSE, 0,
+ NULL, NULL, &si, &pi))
+ {
+ Fail("ERROR: CreateProcess failed to load executable '%s'.\n",Helper);
+ }
+
+ SignalAndBusyWait(WaitFile);
+
+ /* When the child proccess is finished verifying the lock, find the end
+ of the file and unlock the file.
+ */
+
+ FileEnd = SetFilePointer(TheFile, 0, NULL, FILE_END);
+
+ if(FileEnd == INVALID_SET_FILE_POINTER)
+ {
+ Trace("ERROR: SetFilePointer failed to set the file pointer to the "
+ "end of the file. GetLastError() returned %d.\n",
+ GetLastError());
+ ParentRetCode = 1;
+ }
+
+ if(UnlockFile(TheFile, 0, 0, FileEnd, 0) == 0)
+ {
+ Trace("ERROR: The call to UnlockFile returned 0 when attempting to "
+ "unlock the file within the parent. This should have "
+ "succeeded. GetLastError returned %d.\n",GetLastError());
+ ParentRetCode = 1;
+ }
+
+ /* Switch back to the child so that it can ensure the unlock worked
+ properly.
+ */
+
+ SignalFinish(WaitFile);
+ WaitForSingleObject(pi.hProcess,INFINITE);
+
+ /* Get the return value from the helper process */
+ if (GetExitCodeProcess(pi.hProcess, &ChildRetCode) == 0)
+ {
+ Fail("ERROR: GetExitCodeProccess failed when attempting to retrieve "
+ "the exit code of the child process.\n");
+ }
+
+ if(CloseHandle( pi.hProcess ) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the process.\n");
+ }
+
+ if(CloseHandle( pi.hThread ) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the thread.\n");
+ }
+
+ return (ChildRetCode || ParentRetCode);
+}
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE TheFile = NULL;
+ HANDLE WaitFile = NULL;
+ char* WriteBuffer = "12345678901234567890123456";
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Open up the file we'll be using for some crude IPC */
+ WaitFile = CreateFile(WAITFILENAME,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (WaitFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.\n",WAITFILENAME,GetLastError());
+ }
+
+ /* Call the helper function to Create a file, write 'WriteBuffer' to
+ the file, and lock the file from start to end.
+ */
+ TheFile = CreateAndLockFile(TheFile, FILENAME, WriteBuffer,
+ 0, strlen(WriteBuffer));
+
+ /* Run the test. Better errors are displayed by Trace throughout. */
+ if(RunTest(HELPER, TheFile, WaitFile))
+ {
+ Fail("ERROR: Checking to ensure that Unlock successfully unlocked "
+ "a file failed.\n");
+ }
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file used for "
+ "testing the locks. GetLastError() returns %d.\n",
+ GetLastError());
+ }
+
+ if(CloseHandle(WaitFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the wait file. "
+ "GetLastError() returns %d.\n",GetLastError());
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/testinfo.dat
new file mode 100644
index 0000000000..4d0ad6afc9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test1/testinfo.dat
@@ -0,0 +1,17 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = UnlockFile
+Name = Positive test for UnlockFile API
+TYPE = DEFAULT
+EXE1 = test1
+EXE2 = helper
+Description
+= Have the parent Lock a file, then have the child check the lock, then
+= have the parent unlock the file, and the child check again.
+= This requires some IPC, which is done here with a crude busy wait on a
+= file (waiting for the file size to change) to avoid too many more
+= dependencies.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/CMakeLists.txt
new file mode 100644
index 0000000000..142b2763cb
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test2.c
+)
+
+add_executable(paltest_unlockfile_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_unlockfile_test2 coreclrpal)
+
+target_link_libraries(paltest_unlockfile_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/test2.c b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/test2.c
new file mode 100644
index 0000000000..22c2cce2fb
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/test2.c
@@ -0,0 +1,154 @@
+// 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: test2.c
+**
+** Purpose: Open a file, and call Unlock on the file, even though it has yet
+** to be locked. Then lock a portion of the file, and attempt to call unlock
+** on a larger portion of the file. Also, try to unlock a smaller portion
+** than was locked.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+#include "../UnlockFile.h"
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE TheFile = NULL;
+ const char lpBuffer[] = "This is a test file.";
+ DWORD bytesWritten;
+ BOOL bRc = TRUE;
+ char fileName[] = "testfile.tmp";
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Open a file which is in the directory */
+ TheFile = CreateFile(fileName,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.\n",fileName,GetLastError());
+ }
+
+ bRc = WriteFile(
+ TheFile, // handle to file
+ lpBuffer, // data buffer
+ (DWORD)sizeof(lpBuffer), // number of bytes to write
+ &bytesWritten, // number of bytes written
+ NULL // overlapped buffer
+ );
+
+ if(!bRc)
+ {
+ Trace("ERROR: Could not write to file '%s' with WriteFile.",fileName);
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+
+ }
+ else if(bytesWritten != (DWORD)sizeof(lpBuffer))
+ {
+ Trace("ERROR: Could not write the correct number of bytes to the "
+ "file '%s' with WriteFile.",fileName);
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ /* Call unlock file on an unlocked file, this should return 0 */
+ if(UnlockFile(TheFile, 0, 0, 5, 0) != 0)
+ {
+ Trace("ERROR: Attempted to unlock a file which was not locked and "
+ "the UnlockFile call was successful.\n");
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ /* Lock the file */
+ if(LockFile(TheFile, 0, 0, 5, 0) == 0)
+ {
+ Trace("ERROR: Failed to call LockFile on a valid file handle. "
+ "GetLastError returned %d.\n",GetLastError());
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ /* Try to unlock more of the file than was locked by LockFile */
+ if(UnlockFile(TheFile, 0, 0, 10, 0) != 0)
+ {
+ Trace("ERROR: Attempted to unlock bytes 0 to 9, but only bytes "
+ "0 to 4 are locked. But, UnlockFile was successful, when it "
+ "should have failed.\n");
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ /* Try to unlock less of the file than was locked by LockFile */
+ if(UnlockFile(TheFile, 0, 0, 3, 0) != 0)
+ {
+ Trace("ERROR: Attempted to unlock bytes 0 to 2, but the bytes 0 to "
+ "4 were locked by LockFile. Unlockfile should have failed "
+ "when attempting this operation.\n");
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ /* Properly unlock the file */
+ if(UnlockFile(TheFile, 0, 0, 5, 0) == 0)
+ {
+ Trace("ERROR: UnlockFile failed to unlock bytes 0 to 4 of the file. "
+ "GetLastError returned %d.\n",GetLastError());
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/testinfo.dat
new file mode 100644
index 0000000000..932a4a2b8a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test2/testinfo.dat
@@ -0,0 +1,16 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = UnlockFile
+Name = Positive test for UnlockFile API
+TYPE = DEFAULT
+EXE1 = test2
+Description
+= Open a file, and call Unlock on the file, even though it has yet
+= to be locked. Then lock a portion of the file, and attempt to call unlock
+= on a larger portion of the file. Also, try to unlock a smaller portion
+= than was locked.
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/CMakeLists.txt
new file mode 100644
index 0000000000..b4ec37c88c
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/CMakeLists.txt
@@ -0,0 +1,36 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(TESTSOURCES
+ test3.c
+)
+
+add_executable(paltest_unlockfile_test3
+ ${TESTSOURCES}
+)
+
+add_dependencies(paltest_unlockfile_test3 coreclrpal)
+
+target_link_libraries(paltest_unlockfile_test3
+ pthread
+ m
+ coreclrpal
+)
+
+
+set(HELPERSOURCES
+ helper.c
+)
+
+add_executable(paltest_unlockfile_test3_helper
+ ${HELPERSOURCES}
+)
+
+add_dependencies(paltest_unlockfile_test3_helper coreclrpal)
+
+target_link_libraries(paltest_unlockfile_test3_helper
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/helper.c b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/helper.c
new file mode 100644
index 0000000000..650abf49ad
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/helper.c
@@ -0,0 +1,103 @@
+// 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: helper.c
+**
+** Purpose: A child process which will lock a portion of the file,
+** then try to unlock a portion of the file which was locked by the parent.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+#include "../UnlockFile.h"
+
+#define FILENAME "testfile.txt"
+#define WAITFILENAME "waitfile"
+#define BUF_SIZE 128
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE TheFile, WaitFile;
+ int result = 0;
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Open the same file that the parent has opened and locked */
+ TheFile = CreateFile(FILENAME,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Trace("ERROR: Could not open file '%s' with CreateFile.\n",FILENAME);
+ result = 1;
+ }
+
+ /* Open up the WaitFile that we're using for IPC */
+ WaitFile = CreateFile(WAITFILENAME,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (WaitFile == INVALID_HANDLE_VALUE)
+ {
+ Trace("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.\n",WAITFILENAME,GetLastError());
+ result = 1;
+ }
+
+ /* Lock a section of the file different from which was locked in the
+ parent proccess
+ */
+ if(LockFile(TheFile, 10, 0, 10, 0) == 0)
+ {
+ Trace("ERROR: The LockFile call within the child failed to lock "
+ "the file. GetLastError() returned %d.\n",GetLastError());
+ result = 1;
+ }
+
+ /* Attempt to unlock the portion of the file which was locked within the
+ parent process.
+ */
+ if(UnlockFile(TheFile, 0, 0, 10, 0) != 0)
+ {
+ Trace("ERROR: The UnlockFile call within the child succeeded in "
+ "calling UnlockFile on the portion of the file which was "
+ "locked by the parent.\n");
+ result = 1;
+ }
+
+ // Sleep for a bit to give the parent a chance to block before we do.
+ Sleep(1000);
+
+ /* Switch back to the parent, so it can check the child lock */
+ SignalAndBusyWait(WaitFile);
+
+ /* Finally, clean up the lock which was done within this proccess and
+ exit.
+ */
+ if(UnlockFile(TheFile, 10, 0, 10, 0) == 0)
+ {
+ Trace("ERROR: The UnlockFile call within the child failed to unlock "
+ "the portion of the file which was locked by the child. "
+ "GetLastError() returned %d.\n", GetLastError());
+ result = 1;
+ }
+
+ PAL_TerminateEx(result);
+ return result;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/test3.c b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/test3.c
new file mode 100644
index 0000000000..cf27aba0a3
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/test3.c
@@ -0,0 +1,142 @@
+// 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: test3.c
+**
+** Purpose:
+** Lock a portion of the file with the parent. Then have the child lock
+** another portion. Have the child attempt to call Unlock on the parent's
+** locked data, and the parent do the same to the child. Ensure that the
+** locks are respected.
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+#include "../UnlockFile.h"
+
+#define HELPER "helper"
+#define FILENAME "testfile.txt"
+#define WAITFILENAME "waitfile"
+#define BUF_SIZE 128
+
+int RunTest(char* Helper, HANDLE TheFile, HANDLE WaitFile)
+{
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+ DWORD ChildRetCode = 0;
+ DWORD ParentRetCode = 0;
+
+ ZeroMemory( &si, sizeof(si) );
+ si.cb = sizeof(si);
+ ZeroMemory( &pi, sizeof(pi) );
+
+ /* Load up the helper Process, and then Wait until it signals that it
+ is finished locking.
+ */
+ if(!CreateProcess( NULL, Helper, NULL,
+ NULL, FALSE, 0,
+ NULL, NULL, &si, &pi))
+ {
+ Fail("ERROR: CreateProcess failed to load executable '%s'.\n",Helper);
+ }
+
+ SignalAndBusyWait(WaitFile);
+
+ /* When the child proccess is finished setting its lock and testing the
+ parent lock, then the parent can test the child's lock.
+ */
+
+ if(UnlockFile(TheFile, 10, 0, 10, 0) != 0)
+ {
+ Trace("ERROR: The parent proccess called Unlock on the child "
+ "proccesses lock, and the function returned non-zero, when "
+ "it should have failed.\n");
+ ParentRetCode = 1;
+ }
+
+ /* Switch back to the child so that it can unlock its portion and
+ cleanup.
+ */
+
+ SignalFinish(WaitFile);
+ WaitForSingleObject(pi.hProcess,INFINITE);
+
+ /* Get the return value from the helper process */
+ if (GetExitCodeProcess(pi.hProcess, &ChildRetCode) == 0)
+ {
+ Fail("ERROR: GetExitCodeProccess failed when attempting to retrieve "
+ "the exit code of the child process.\n");
+ }
+
+ if(CloseHandle( pi.hProcess ) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the process.\n");
+ }
+
+ if(CloseHandle( pi.hThread ) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the thread.\n");
+ }
+
+ return (ChildRetCode || ParentRetCode);
+}
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE TheFile = NULL;
+ HANDLE WaitFile = NULL;
+ char* WriteBuffer = "12345678901234567890123456";
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Open up the file we'll be using for some crude IPC */
+ WaitFile = CreateFile(WAITFILENAME,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (WaitFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.\n",WAITFILENAME,GetLastError());
+ }
+
+ /* Call the helper function to Create a file, write 'WriteBuffer' to
+ the file, and lock the file from bytes 0-9.
+ */
+ TheFile = CreateAndLockFile(TheFile, FILENAME, WriteBuffer,
+ 0, 10);
+
+ /* Run the test. Better errors are displayed by Trace throughout. */
+ if(RunTest(HELPER, TheFile, WaitFile))
+ {
+ Fail("ERROR: The test to check that the Unlock will not work on "
+ "on locks set by other proccesses failed.\n");
+ }
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file used for "
+ "testing the locks. GetLastError() returns %d.\n",
+ GetLastError());
+ }
+
+ if(CloseHandle(WaitFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the wait file. "
+ "GetLastError() returns %d.\n",GetLastError());
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/testinfo.dat
new file mode 100644
index 0000000000..bf7ec5f809
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test3/testinfo.dat
@@ -0,0 +1,17 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = UnlockFile
+Name = Positive test for UnlockFile API
+TYPE = DEFAULT
+EXE1 = test3
+EXE2 = helper
+Description
+= Lock a portion of the file with the parent. Then have the child lock
+= another portion. Have the child attempt to call Unlock on the parent's
+= locked data, and the parent do the same to the child. Ensure that the
+= locks are respected.
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/CMakeLists.txt
new file mode 100644
index 0000000000..d6bee307c2
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test4.c
+)
+
+add_executable(paltest_unlockfile_test4
+ ${SOURCES}
+)
+
+add_dependencies(paltest_unlockfile_test4 coreclrpal)
+
+target_link_libraries(paltest_unlockfile_test4
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/test4.c b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/test4.c
new file mode 100644
index 0000000000..55abcd24bc
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/test4.c
@@ -0,0 +1,187 @@
+// 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: test4.c
+**
+** Purpose: Pass an invalid handle to UnlockFile. Pass a null handle to
+** UnlockFile. Create a file and lock two consecuative regions and call
+** UnlockFile on the whole region (this should fail, see msdn)
+**
+**
+**============================================================*/
+
+#include <palsuite.h>
+#include "../UnlockFile.h"
+
+int __cdecl main(int argc, char *argv[])
+{
+ HANDLE TheFile = NULL;
+ const char lpBuffer[] = "This is a test file.";
+ DWORD bytesWritten;
+ BOOL bRc = TRUE;
+ char fileName[] = "testfile.tmp";
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return FAIL;
+ }
+
+ /* Open a file which is in the directory */
+ TheFile = CreateFile(fileName,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.\n",fileName,GetLastError());
+ }
+
+ bRc = WriteFile(
+ TheFile, // handle to file
+ lpBuffer, // data buffer
+ (DWORD)sizeof(lpBuffer), // number of bytes to write
+ &bytesWritten, // number of bytes written
+ NULL // overlapped buffer
+ );
+
+ if(!bRc)
+ {
+ Trace("ERROR: Could not write to file '%s' with WriteFile.",fileName);
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+
+ }
+ else if(bytesWritten != (DWORD)sizeof(lpBuffer))
+ {
+ Trace("ERROR: Could not write the correct number of bytes to the "
+ "file '%s' with WriteFile.",fileName);
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.\n");
+ }
+
+
+ /* Test an invalid handle and a NULL handle */
+ if(UnlockFile(TheFile, 0, 0, 0, 0) != 0)
+ {
+ Fail("ERROR: Called UnlockFile on an invalid HANDLE and it "
+ "returned a success value.\n");
+ }
+
+ if(UnlockFile(NULL, 0, 0, 0, 0) != 0)
+ {
+ Fail("ERROR: Called UnlockFile with NULL passed for the HANDLE and "
+ "it returned a success value.\n");
+ }
+
+ /* Re-open the file */
+ TheFile = CreateFile(fileName,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (TheFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: Could not open file '%s' with CreateFile. "
+ "GetLastError() returned %d.\n",fileName,GetLastError());
+ }
+
+ /* Lock two consecuative regions of this file */
+ if(LockFile(TheFile, 0, 0, 5, 0) == 0)
+ {
+ Trace("ERROR: LockFile failed attempting to lock bytes 0-4. "
+ "GetLastError() returned %d.\n",GetLastError());
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ if(LockFile(TheFile, 5, 0, 5, 0) == 0)
+ {
+ Fail("ERROR: LockFile failed attempting to lock bytes 5-9. "
+ "GetLastError() returned %d.\n",GetLastError());
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ /* Attempt to unlock the entire region which was locked with one
+ call to UnlockFile. This should fail.
+ */
+ if(UnlockFile(TheFile, 0, 0, 10, 0) != 0)
+ {
+ Fail("ERROR: Called UnlockFile on bytes 0-9 which were locked with "
+ "two seperate LockFile calls. This should have failed. "
+ "UnlockFile will not unlock consecuative locked regions.\n");
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+
+ /* Now, unlock the regions one at a time. */
+ if(UnlockFile(TheFile, 0, 0, 5, 0) == 0)
+ {
+ Fail("ERROR: UnlockFile failed when attempting to unlock bytes "
+ "0-4 of the file. GetLastError() returned %d.\n",GetLastError());
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ if(UnlockFile(TheFile, 5, 0, 5, 0) == 0)
+ {
+ Fail("ERROR: UnlockFile failed when attempting to unlock bytes "
+ "5-9 of the file. GetLastError() returned %d.\n",GetLastError());
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.");
+ }
+ Fail("");
+ }
+
+ if(CloseHandle(TheFile) == 0)
+ {
+ Fail("ERROR: CloseHandle failed to close the file.\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/testinfo.dat
new file mode 100644
index 0000000000..4f3885b978
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnlockFile/test4/testinfo.dat
@@ -0,0 +1,16 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = UnlockFile
+Name = Positive test for UnlockFile API
+TYPE = DEFAULT
+EXE1 = test4
+Description
+= Pass an invalid handle to UnlockFile. Pass a null handle to
+= UnlockFile. Create a file and lock two consecuative regions and call
+= UnlockFile on the whole region (this should fail, see msdn)
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/CMakeLists.txt
new file mode 100644
index 0000000000..ef14ea5352
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/CMakeLists.txt
new file mode 100644
index 0000000000..5ebda77ba6
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ UnmapViewOfFile.c
+)
+
+add_executable(paltest_unmapviewoffile_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_unmapviewoffile_test1 coreclrpal)
+
+target_link_libraries(paltest_unmapviewoffile_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/UnmapViewOfFile.c b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/UnmapViewOfFile.c
new file mode 100644
index 0000000000..a970ccc3b5
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/UnmapViewOfFile.c
@@ -0,0 +1,184 @@
+// 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: UnMapViewOfFile.c
+**
+** Purpose: Positive test the MapViewOfFile API.
+** Call MapViewOfFile with access FILE_MAP_ALL_ACCESS.
+**
+** Depends: CreateFile,
+** GetFileSize,
+** memset,
+** memcpy,
+** memcmp,
+** ReadFile,
+** UnMapViewOfFile,
+** CreateFileMapping,
+** CloseHandle.
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ const int MappingSize = 2048;
+ HANDLE hFile;
+ HANDLE hFileMapping;
+ LPVOID lpMapViewAddress;
+ char buf[] = "this is a test string";
+ char ch[2048];
+ char readString[2048];
+ char lpFileName[] = "test.tmp";
+ DWORD dwBytesRead;
+ BOOL bRetVal;
+
+ /* Initialize the PAL environment.
+ */
+ if(0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* Create a file handle with CreateFile.
+ */
+ hFile = CreateFile( lpFileName,
+ GENERIC_WRITE|GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Fail("ERROR: %u :unable to create file \"%s\".\n",
+ GetLastError(),
+ lpFileName);
+ }
+
+ /* Initialize the buffers.
+ */
+ memset(ch, 0, MappingSize);
+ memset(readString, 0, MappingSize);
+
+ /* Create a unnamed file-mapping object with file handle FileHandle
+ * and with PAGE_READWRITE protection.
+ */
+ hFileMapping = CreateFileMapping(
+ hFile,
+ NULL, /*not inherited*/
+ PAGE_READWRITE, /*read and wite*/
+ 0, /*high-order of object size*/
+ MappingSize, /*low-orger of object size*/
+ NULL); /*unnamed object*/
+
+ if(NULL == hFileMapping)
+ {
+ Trace("ERROR:%u: Failed to create File Mapping.\n",
+ GetLastError());
+ CloseHandle(hFile);
+ Fail("");
+ }
+
+ /* maps a view of a file into the address space of the calling process.
+ */
+ lpMapViewAddress = MapViewOfFile(
+ hFileMapping,
+ FILE_MAP_ALL_ACCESS, /* access code */
+ 0, /* high order offset */
+ 0, /* low order offset */
+ MappingSize); /* number of bytes for map */
+
+ if(NULL == lpMapViewAddress)
+ {
+ Trace("ERROR:%u: Failed to call MapViewOfFile API to map a view"
+ " of file!\n",
+ GetLastError());
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ /* Write to the MapView and copy the MapViewOfFile
+ * to buffer, so we can compare with value read from
+ * file directly.
+ */
+
+ memcpy(lpMapViewAddress, buf, strlen(buf));
+ memcpy(ch, (LPCSTR)lpMapViewAddress, MappingSize);
+
+ /* Read from the File handle.
+ */
+ bRetVal = ReadFile(hFile,
+ readString,
+ strlen(buf),
+ &dwBytesRead,
+ NULL);
+
+ if (bRetVal == FALSE)
+ {
+ Trace("ERROR: %u :unable to read from file handle "
+ "hFile=0x%lx\n",
+ GetLastError(),
+ hFile);
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ if (memcmp(ch, readString, strlen(readString)) != 0)
+ {
+ Trace("ERROR: Read string from file \"%s\", is "
+ "not equal to string written through MapView "
+ "\"%s\".\n",
+ readString,
+ ch);
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ /* Unmap the view of file.
+ */
+ if(UnmapViewOfFile(lpMapViewAddress) == FALSE)
+ {
+ Trace("ERROR: Failed to call UnmapViewOfFile API to"
+ " unmap the view of a file, error code=%u\n",
+ GetLastError());
+ CloseHandle(hFile);
+ CloseHandle(hFileMapping);
+ Fail("");
+ }
+
+ /* Re-initialize the buffer.
+ */
+ memset(ch, 0, MappingSize);
+
+ /* Close handle to created file mapping.
+ */
+ if(CloseHandle(hFileMapping) == FALSE)
+ {
+ Trace("ERROR:%u:Failed to call CloseHandle API "
+ "to close a file mapping handle.",
+ GetLastError());
+ CloseHandle(hFile);
+ Fail("");
+ }
+
+ /* Close handle to create file.
+ */
+ if(CloseHandle(hFile) == FALSE)
+ {
+ Fail("ERROR:%u:Failed to call CloseHandle API "
+ "to close a file handle.",
+ GetLastError());
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/testinfo.dat
new file mode 100644
index 0000000000..8418015360
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test1/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = UnmapViewOfFile
+Name = Positive test UnmapViewOfFile API to unmap a view of file
+TYPE = DEFAULT
+EXE1 = unmapviewoffile
+LANG = cpp
+Description
+= Test the UnmapViewOfFile to unmap a view of file.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/CMakeLists.txt
new file mode 100644
index 0000000000..5c12cf9825
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ unmapviewoffile.c
+)
+
+add_executable(paltest_unmapviewoffile_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_unmapviewoffile_test2 coreclrpal)
+
+target_link_libraries(paltest_unmapviewoffile_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/testinfo.dat
new file mode 100644
index 0000000000..29e847a82f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = UnmapViewOfFile
+Name = Negative test UnmapViewOfFile API to unmap a view of file
+TYPE = DEFAULT
+EXE1 = unmapviewoffile
+Description
+= Test the UnmapViewOfFile to unmap a view of file
+= negative test by passing a NULL mapping address.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/unmapviewoffile.c b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/unmapviewoffile.c
new file mode 100644
index 0000000000..2ca185d234
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/UnmapViewOfFile/test2/unmapviewoffile.c
@@ -0,0 +1,42 @@
+// 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: UnmapViewOfFile.c (test 2)
+**
+** Purpose: Negative test the UnmapViewOfFile API.
+** Call UnmapViewOfFile to unmap a view of
+** NULL.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+
+ /*Initialize the PAL environment*/
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ return FAIL;
+ }
+
+ /* Negative test the UnmapViewOfFile by passing a NULL*/
+ /* mapping address handle*/
+ err = UnmapViewOfFile(NULL);
+ if(0 != err)
+ {
+ Fail("ERROR: Able to call UnmapViewOfFile API "
+ "by passing a NULL mapping address.\n" );
+
+ }
+
+ /* Terminate the PAL.
+ */
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/CMakeLists.txt
new file mode 100644
index 0000000000..eafaa66856
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/CMakeLists.txt
@@ -0,0 +1,24 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test10)
+add_subdirectory(test11)
+add_subdirectory(test12)
+add_subdirectory(test13)
+add_subdirectory(test14)
+add_subdirectory(test15)
+add_subdirectory(test16)
+add_subdirectory(test17)
+add_subdirectory(test18)
+add_subdirectory(test19)
+add_subdirectory(test2)
+add_subdirectory(test20)
+add_subdirectory(test21)
+add_subdirectory(test3)
+add_subdirectory(test4)
+add_subdirectory(test5)
+add_subdirectory(test6)
+add_subdirectory(test7)
+add_subdirectory(test8)
+add_subdirectory(test9)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/CMakeLists.txt
new file mode 100644
index 0000000000..90ba41bd79
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test1 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/VirtualAlloc.c
new file mode 100644
index 0000000000..26ee942ba1
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/VirtualAlloc.c
@@ -0,0 +1,50 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_COMMIT allocation type
+** and PAGE_READONLY access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_READONLY); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/testinfo.dat
new file mode 100644
index 0000000000..5b8311a05d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test1/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT allocation type
+=and PAGE_READONLY access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/CMakeLists.txt
new file mode 100644
index 0000000000..51b0e1d92e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test10
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test10 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test10
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/VirtualAlloc.c
new file mode 100644
index 0000000000..ac06b9b5c8
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/VirtualAlloc.c
@@ -0,0 +1,48 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_RESERVE allocation type
+** and PAGE_EXECUTE_READ access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_RESERVE, //allocation type
+ PAGE_EXECUTE_READ); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/testinfo.dat
new file mode 100644
index 0000000000..960f2265d5
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test10/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_RESERVE allocation type
+=and PAGE_EXECUTE_READ access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/CMakeLists.txt
new file mode 100644
index 0000000000..adff47087b
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test11
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test11 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test11
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/VirtualAlloc.c
new file mode 100644
index 0000000000..a3df39b634
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/VirtualAlloc.c
@@ -0,0 +1,49 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_RESERVE allocation type
+** and PAGE_READONLY access protection
+**
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_RESERVE, //allocation type
+ PAGE_EXECUTE_READWRITE); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/testinfo.dat
new file mode 100644
index 0000000000..5d9f0ad880
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test11/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_RESERVE allocation type
+=and PAGE_EXECUTE_READWRITE access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/CMakeLists.txt
new file mode 100644
index 0000000000..26f303573e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test12
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test12 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test12
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/VirtualAlloc.c
new file mode 100644
index 0000000000..8b3508635f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/VirtualAlloc.c
@@ -0,0 +1,48 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_RESERVE allocation type
+** and PAGE_NOACCESS access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_RESERVE, //allocation type
+ PAGE_NOACCESS); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/testinfo.dat
new file mode 100644
index 0000000000..ac2b91c0dc
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test12/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT allocation type
+=and PAGE_NOACCESS access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/CMakeLists.txt
new file mode 100644
index 0000000000..f85cbdc694
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test13
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test13 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test13
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/VirtualAlloc.c
new file mode 100644
index 0000000000..d2109c0339
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/VirtualAlloc.c
@@ -0,0 +1,48 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type
+** and PAGE_READONLY access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT|MEM_TOP_DOWN, //allocation type
+ PAGE_READONLY); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/testinfo.dat
new file mode 100644
index 0000000000..a571e9f8d2
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test13/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type
+=and PAGE_READONLY access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/CMakeLists.txt
new file mode 100644
index 0000000000..41ed0ca208
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test14
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test14 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test14
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/VirtualAlloc.c
new file mode 100644
index 0000000000..49bd21875e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/VirtualAlloc.c
@@ -0,0 +1,48 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type
+** and PAGE_READWRITE access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT|MEM_TOP_DOWN, //allocation type
+ PAGE_READWRITE); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/testinfo.dat
new file mode 100644
index 0000000000..60decb8461
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test14/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type
+=and PAGE_READWRITE access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/CMakeLists.txt
new file mode 100644
index 0000000000..87b29108b2
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test15
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test15 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test15
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/VirtualAlloc.c
new file mode 100644
index 0000000000..3cf1502f26
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/VirtualAlloc.c
@@ -0,0 +1,48 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type
+** and PAGE_EXECUTE access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT|MEM_TOP_DOWN, //allocation type
+ PAGE_EXECUTE); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/testinfo.dat
new file mode 100644
index 0000000000..2d9845ded6
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test15/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type
+=and PAGE_EXECUTE access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/CMakeLists.txt
new file mode 100644
index 0000000000..90e3f3bdb2
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test16
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test16 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test16
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/VirtualAlloc.c
new file mode 100644
index 0000000000..ce61b9aa39
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/VirtualAlloc.c
@@ -0,0 +1,48 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type
+** and PAGE_EXECUTE_READ access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT|MEM_TOP_DOWN, //allocation type
+ PAGE_EXECUTE_READ); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/testinfo.dat
new file mode 100644
index 0000000000..1389f1f92e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test16/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type
+=and PAGE_EXECUTE_READ access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/CMakeLists.txt
new file mode 100644
index 0000000000..461b48ccc0
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test17
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test17 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test17
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/VirtualAlloc.c
new file mode 100644
index 0000000000..eb609f14e4
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/VirtualAlloc.c
@@ -0,0 +1,49 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type
+** and PAGE_READONLY access protection
+**
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT|MEM_TOP_DOWN, //allocation type
+ PAGE_EXECUTE_READWRITE); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/testinfo.dat
new file mode 100644
index 0000000000..49ced63836
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test17/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type
+=and PAGE_EXECUTE_READWRITE access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/CMakeLists.txt
new file mode 100644
index 0000000000..69823be14b
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test18
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test18 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test18
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/VirtualAlloc.c
new file mode 100644
index 0000000000..e46da851db
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/VirtualAlloc.c
@@ -0,0 +1,49 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type
+** and PAGE_NOACCESS access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT|MEM_TOP_DOWN, //allocation type
+ PAGE_NOACCESS); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/testinfo.dat
new file mode 100644
index 0000000000..1fd4ac6f14
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test18/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT|MEM_TOP_DOWN allocation type
+=and PAGE_NOACCESS access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/CMakeLists.txt
new file mode 100644
index 0000000000..fa65b4fa46
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test19
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test19 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test19
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/VirtualAlloc.c
new file mode 100644
index 0000000000..5cbe48b15e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/VirtualAlloc.c
@@ -0,0 +1,51 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc to reserve and commit
+** simultaneously with MEM_COMMIT|MEM_RESERVE|MEM_TOP_DOWN
+** allocation type and PAGE_READONLY access
+** protection
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //reserve and commit simultaneously by using MEM_COMMIT|MEM_RESERVE
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT|MEM_RESERVE|MEM_TOP_DOWN, //allocation type
+ PAGE_READONLY); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/testinfo.dat
new file mode 100644
index 0000000000..6e427da15a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test19/testinfo.dat
@@ -0,0 +1,14 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc to reserve and commit
+=simultaneously by using MEM_COMMIT|MEM_RESERVE|MEM_TOP_DOWN
+=allocation type and PAGE_READONLY access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/CMakeLists.txt
new file mode 100644
index 0000000000..1753b1edc5
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test2 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/VirtualAlloc.c
new file mode 100644
index 0000000000..99cf76a523
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/VirtualAlloc.c
@@ -0,0 +1,49 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_COMMIT allocation type
+** and PAGE_READWRITE access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_READWRITE); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/testinfo.dat
new file mode 100644
index 0000000000..c7d8b6783d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test2/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT allocation type
+=and PAGE_READWRITE access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/CMakeLists.txt
new file mode 100644
index 0000000000..2c55071149
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ virtualalloc.c
+)
+
+add_executable(paltest_virtualalloc_test20
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test20 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test20
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/testinfo.dat
new file mode 100644
index 0000000000..6010a18c8a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test VirtualAlloc to ensure that re-committed memory is not changed.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/virtualalloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/virtualalloc.c
new file mode 100644
index 0000000000..7aec3c7f55
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test20/virtualalloc.c
@@ -0,0 +1,50 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Ensure that memory re-committed through VirtualAlloc
+** is not changed.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ int *ptr;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ ptr = (int *) VirtualAlloc(NULL, 4096, MEM_COMMIT | MEM_RESERVE,
+ PAGE_READWRITE);
+ if (ptr == NULL)
+ {
+ Fail("First VirtualAlloc failed!\n");
+ }
+
+ *ptr = 123;
+
+ ptr = (int *) VirtualAlloc(ptr, 4096, MEM_COMMIT, PAGE_READWRITE);
+ if (ptr == NULL)
+ {
+ Fail("Second VirtualAlloc failed!\n");
+ }
+ if (*ptr != 123)
+ {
+ Fail("VirtualAlloc modified (probably zeroed) re-committed memory!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/CMakeLists.txt
new file mode 100644
index 0000000000..f97c32af75
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ virtualalloc.c
+)
+
+add_executable(paltest_virtualalloc_test21
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test21 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test21
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/testinfo.dat
new file mode 100644
index 0000000000..c32d352d19
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test VirtualAlloc to ensure that freed memory that is committed again is zeroed.
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/virtualalloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/virtualalloc.c
new file mode 100644
index 0000000000..065a2ff5c8
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test21/virtualalloc.c
@@ -0,0 +1,54 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Ensure that memory committed through VirtualAlloc,
+** then freed, then committed again is zeroed.
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ int *ptr;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ ptr = (int *) VirtualAlloc(NULL, 4096, MEM_COMMIT | MEM_RESERVE,
+ PAGE_READWRITE);
+ if (ptr == NULL)
+ {
+ Fail("First VirtualAlloc failed!\n");
+ }
+ *ptr = 123;
+
+ if (!VirtualFree(ptr, 4096, MEM_DECOMMIT))
+ {
+ Fail("VirtualFree failed!\n");
+ }
+
+ ptr = (int *) VirtualAlloc(ptr, 4096, MEM_COMMIT, PAGE_READWRITE);
+ if (ptr == NULL)
+ {
+ Fail("Second VirtualAlloc failed!\n");
+ }
+ if (*ptr != 0)
+ {
+ Fail("VirtualAlloc failed to zero its memory!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/CMakeLists.txt
new file mode 100644
index 0000000000..035594bd79
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test3 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/VirtualAlloc.c
new file mode 100644
index 0000000000..5c57ec337f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/VirtualAlloc.c
@@ -0,0 +1,48 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_COMMIT allocation type
+** and PAGE_EXECUTE access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_EXECUTE); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/testinfo.dat
new file mode 100644
index 0000000000..a3d5401493
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test3/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT allocation type
+=and PAGE_EXECUTE access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/CMakeLists.txt
new file mode 100644
index 0000000000..5ce80bf52f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test4
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test4 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test4
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/VirtualAlloc.c
new file mode 100644
index 0000000000..c134a14eb1
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/VirtualAlloc.c
@@ -0,0 +1,49 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_COMMIT allocation type
+** and PAGE_EXECUTE_READ access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_EXECUTE_READ); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/testinfo.dat
new file mode 100644
index 0000000000..0e84e7a3ba
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test4/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT allocation type
+=and PAGE_EXECUTE_READ access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/CMakeLists.txt
new file mode 100644
index 0000000000..138d9c9727
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test5
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test5 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test5
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/VirtualAlloc.c
new file mode 100644
index 0000000000..8c4f9dcdb6
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/VirtualAlloc.c
@@ -0,0 +1,50 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_COMMIT allocation type
+** and PAGE_READONLY access protection
+**
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_EXECUTE_READWRITE); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/testinfo.dat
new file mode 100644
index 0000000000..332b88b071
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test5/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT allocation type
+=and PAGE_EXECUTE_READWRITE access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/CMakeLists.txt
new file mode 100644
index 0000000000..c61add9db4
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test6
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test6 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test6
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/VirtualAlloc.c
new file mode 100644
index 0000000000..e9c33d86df
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/VirtualAlloc.c
@@ -0,0 +1,48 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_COMMIT allocation type
+** and PAGE_NOACCESS access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_NOACCESS); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/testinfo.dat
new file mode 100644
index 0000000000..ac2b91c0dc
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test6/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT allocation type
+=and PAGE_NOACCESS access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/CMakeLists.txt
new file mode 100644
index 0000000000..b5452a0c48
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test7
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test7 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test7
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/VirtualAlloc.c
new file mode 100644
index 0000000000..bee2735c9f
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/VirtualAlloc.c
@@ -0,0 +1,53 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_RESERVE allocation type
+** and PAGE_READONLY access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_RESERVE, //allocation type
+ PAGE_READONLY); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ PAL_Terminate();
+ return 1;
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ PAL_Terminate();
+ return 1;
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/testinfo.dat
new file mode 100644
index 0000000000..2edcb56d3b
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test7/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_RESERVE allocation type
+=and PAGE_READONLY access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/CMakeLists.txt
new file mode 100644
index 0000000000..584a0c505a
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test8
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test8 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test8
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/VirtualAlloc.c
new file mode 100644
index 0000000000..d548e0c8db
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/VirtualAlloc.c
@@ -0,0 +1,48 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_RESERVE allocation type
+** and PAGE_READWRITE access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_RESERVE, //allocation type
+ PAGE_READWRITE); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/testinfo.dat
new file mode 100644
index 0000000000..c0ee6b6a69
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test8/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_RESERVE allocation type
+=and PAGE_READWRITE access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/CMakeLists.txt
new file mode 100644
index 0000000000..aee950b2e4
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualAlloc.c
+)
+
+add_executable(paltest_virtualalloc_test9
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test9 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test9
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/VirtualAlloc.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/VirtualAlloc.c
new file mode 100644
index 0000000000..2711addacc
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/VirtualAlloc.c
@@ -0,0 +1,48 @@
+// 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: virtualalloc.c
+**
+** Purpose: Positive test the VirtualAlloc API.
+** Call VirtualAlloc with MEM_RESERVE allocation type
+** and PAGE_EXECUTE access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_RESERVE, //allocation type
+ PAGE_EXECUTE); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/testinfo.dat
new file mode 100644
index 0000000000..1e83744bba
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test9/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Positive test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_RESERVE allocation type
+=and PAGE_EXECUTE access protection
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/CMakeLists.txt
new file mode 100644
index 0000000000..1962ade358
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/CMakeLists.txt
new file mode 100644
index 0000000000..1914f76fe6
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualFree.c
+)
+
+add_executable(paltest_virtualfree_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualfree_test1 coreclrpal)
+
+target_link_libraries(paltest_virtualfree_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/VirtualFree.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/VirtualFree.c
new file mode 100644
index 0000000000..0f4f144aa5
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/VirtualFree.c
@@ -0,0 +1,48 @@
+// 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: virtualfree.c
+**
+** Purpose: Positive test the VirtualFree API.
+** Call VirtualFree with MEM_DECOMMIT
+** free operation type
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_READONLY); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,1024,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/testinfo.dat
new file mode 100644
index 0000000000..2848635681
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test1/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualFree
+Name = Positive test for VirtualFree API
+TYPE = DEFAULT
+EXE1 = virtualfree
+Description
+=Test the VirtualFree with MEM_DECOMMIT free
+=operation type
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/CMakeLists.txt
new file mode 100644
index 0000000000..a288b37154
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualFree.c
+)
+
+add_executable(paltest_virtualfree_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualfree_test2 coreclrpal)
+
+target_link_libraries(paltest_virtualfree_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/VirtualFree.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/VirtualFree.c
new file mode 100644
index 0000000000..70064a3bf9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/VirtualFree.c
@@ -0,0 +1,54 @@
+// 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: virtualfree.c
+**
+** Purpose: Positive test the VirtualFree API.
+** Call VirtualFree with MEM_RELEASE
+** free operation type
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ 1024, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_READONLY); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ PAL_Terminate();
+ return 1;
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,//base address
+ 0, //must be zero with MEM_RELEASE
+ MEM_RELEASE);//free operation
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ PAL_Terminate();
+ return 1;
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/testinfo.dat
new file mode 100644
index 0000000000..ea380c3676
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test2/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualFree
+Name = Positive test for VirtualFree API
+TYPE = DEFAULT
+EXE1 = virtualfree
+Description
+=Test the VirtualFree with MEM_RELEASE free
+=operation type
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/CMakeLists.txt
new file mode 100644
index 0000000000..993189c1aa
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualFree.c
+)
+
+add_executable(paltest_virtualfree_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualfree_test3 coreclrpal)
+
+target_link_libraries(paltest_virtualfree_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/VirtualFree.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/VirtualFree.c
new file mode 100644
index 0000000000..27f1936be7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/VirtualFree.c
@@ -0,0 +1,53 @@
+// 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: virtualfree.c
+**
+** Purpose: Positive test the VirtualFree API.
+** Call VirtualFree with MEM_RELEASE
+** and MEM_DECOMMIT free operation type
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define VIRTUALSIZE 1024
+
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ VIRTUALSIZE, //specify the size
+ MEM_RESERVE, //allocation type
+ PAGE_NOACCESS); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //decommit and release the specified region
+ err = VirtualFree(lpVirtualAddress, //base address
+ VIRTUALSIZE, //decommited size
+ MEM_DECOMMIT|MEM_RELEASE);//free operation
+ if(0 != err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/testinfo.dat
new file mode 100644
index 0000000000..c27b7ad3e5
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualFree/test3/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualFree
+Name = Positive test for VirtualFree API
+TYPE = DEFAULT
+EXE1 = virtualfree
+Description
+=Test the VirtualFree with MEM_DECOMMIT|MEM_RELEASE free
+=operation type
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/CMakeLists.txt
new file mode 100644
index 0000000000..cac5452ec9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+add_subdirectory(test4)
+add_subdirectory(test6)
+add_subdirectory(test7)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/CMakeLists.txt
new file mode 100644
index 0000000000..214cf460ae
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualProtect.c
+)
+
+add_executable(paltest_virtualprotect_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualprotect_test1 coreclrpal)
+
+target_link_libraries(paltest_virtualprotect_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/VirtualProtect.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/VirtualProtect.c
new file mode 100644
index 0000000000..1a28bd156d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/VirtualProtect.c
@@ -0,0 +1,69 @@
+// 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: virtualprotect.c
+**
+** Purpose: Positive test the VirtualProtect API.
+** Call VirtualProtect to set new protect as
+** PAGE_READWRITE
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define REGIONSIZE 1024
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+ DWORD OldProtect;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+ REGIONSIZE, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_READONLY); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ OldProtect = PAGE_READONLY;
+ //Set new access protection
+ err = VirtualProtect(lpVirtualAddress,
+ REGIONSIZE, //specify the region size
+ PAGE_READWRITE,//desied access protection
+ &OldProtect);//old access protection
+ if(0 == err)
+ {
+ Trace("\nFailed to call VirtualProtect API!\n");
+ err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+ Fail("");
+ }
+
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/testinfo.dat
new file mode 100644
index 0000000000..6b78c079e7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test1/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualProtect
+Name = Positive test for VirtualProtect - with PAGE_READWRITE
+TYPE = DEFAULT
+EXE1 = virtualprotect
+Description
+=Test the VirtualProtect to set new access protection
+=as PAGE_READWRITE
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/CMakeLists.txt
new file mode 100644
index 0000000000..27f43477ea
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualProtect.c
+)
+
+add_executable(paltest_virtualprotect_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualprotect_test2 coreclrpal)
+
+target_link_libraries(paltest_virtualprotect_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/VirtualProtect.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/VirtualProtect.c
new file mode 100644
index 0000000000..64a08d7885
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/VirtualProtect.c
@@ -0,0 +1,69 @@
+// 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: virtualprotect.c
+**
+** Purpose: Positive test the VirtualProtect API.
+** Call VirtualProtect to set new protect as
+** PAGE_EXECUTE
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define REGIONSIZE 1024
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+ DWORD OldProtect;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region
+ REGIONSIZE, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_READONLY); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ OldProtect = PAGE_READONLY;
+ //Set new access protection
+ err = VirtualProtect(lpVirtualAddress,
+ REGIONSIZE, //specify the region size
+ PAGE_EXECUTE,//desied access protection
+ &OldProtect);//old access protection
+ if(0 == err)
+ {
+ Trace("\nFailed to call VirtualProtect API!\n");
+ err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+ Fail("");
+ }
+
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/testinfo.dat
new file mode 100644
index 0000000000..d5fa0cfbc2
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test2/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualProtect
+Name = Positive test for VirtualProtect - with PAGE_EXECUTE
+TYPE = DEFAULT
+EXE1 = virtualprotect
+Description
+=Test the VirtualProtect to set new access protection
+=as PAGE_EXECUTE
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/CMakeLists.txt
new file mode 100644
index 0000000000..994d4e2f41
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualProtect.c
+)
+
+add_executable(paltest_virtualprotect_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualprotect_test3 coreclrpal)
+
+target_link_libraries(paltest_virtualprotect_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/VirtualProtect.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/VirtualProtect.c
new file mode 100644
index 0000000000..0f738630ee
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/VirtualProtect.c
@@ -0,0 +1,69 @@
+// 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: virtualprotect.c
+**
+** Purpose: Positive test the VirtualProtect API.
+** Call VirtualProtect to set new protect as
+** PAGE_EXECUTE_READ
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define REGIONSIZE 1024
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+ DWORD OldProtect;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region
+ REGIONSIZE, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_READONLY); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ OldProtect = PAGE_READONLY;
+ //Set new access protection
+ err = VirtualProtect(lpVirtualAddress,
+ REGIONSIZE, //specify the region size
+ PAGE_EXECUTE_READ,//desied access protection
+ &OldProtect);//old access protection
+ if(0 == err)
+ {
+ Trace("\nFailed to call VirtualProtect API!\n");
+ err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+ Fail("");
+ }
+
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/testinfo.dat
new file mode 100644
index 0000000000..7c64c3092e
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test3/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualProtect
+Name = Positive test for VirtualProtect - with PAGE_EXECUTE_READ
+TYPE = DEFAULT
+EXE1 = virtualprotect
+Description
+=Test the VirtualProtect to set new access protection
+=as PAGE_EXECUTE_READ
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/CMakeLists.txt
new file mode 100644
index 0000000000..2e0fba50bb
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualProtect.c
+)
+
+add_executable(paltest_virtualprotect_test4
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualprotect_test4 coreclrpal)
+
+target_link_libraries(paltest_virtualprotect_test4
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/VirtualProtect.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/VirtualProtect.c
new file mode 100644
index 0000000000..926d501d0d
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/VirtualProtect.c
@@ -0,0 +1,68 @@
+// 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: virtualprotect.c
+**
+** Purpose: Positive test the VirtualProtect API.
+** Call VirtualProtect to set new protect as
+** PAGE_EXECUTE_READWRITE
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define REGIONSIZE 1024
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+ DWORD OldProtect;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region
+ REGIONSIZE, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_READONLY); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ OldProtect = PAGE_READONLY;
+ //Set new access protection
+ err = VirtualProtect(lpVirtualAddress,
+ REGIONSIZE, //specify the region size
+ PAGE_EXECUTE_READWRITE,//desied access protection
+ &OldProtect);//old access protection
+ if(0 == err)
+ {
+ Trace("\nFailed to call VirtualProtect API!\n");
+ err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+ Fail("");
+ }
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/testinfo.dat
new file mode 100644
index 0000000000..c344073113
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test4/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualProtect
+Name = Positive test for VirtualProtect - with PAGE_EXECUTE_READWRITE
+TYPE = DEFAULT
+EXE1 = virtualprotect
+Description
+=Test the VirtualProtect to set new access protection
+=as PAGE_EXECUTE_READWRITE
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/CMakeLists.txt
new file mode 100644
index 0000000000..6d6fd07df8
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualProtect.c
+)
+
+add_executable(paltest_virtualprotect_test6
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualprotect_test6 coreclrpal)
+
+target_link_libraries(paltest_virtualprotect_test6
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/VirtualProtect.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/VirtualProtect.c
new file mode 100644
index 0000000000..d60b323ec6
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/VirtualProtect.c
@@ -0,0 +1,68 @@
+// 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: virtualprotect.c
+**
+** Purpose: Positive test the VirtualProtect API.
+** Call VirtualProtect to set new protect as
+** PAGE_NOACCESS
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define REGIONSIZE 1024
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+ DWORD OldProtect;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region
+ REGIONSIZE, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_READONLY); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ OldProtect = PAGE_READONLY;
+ //Set new access protection
+ err = VirtualProtect(lpVirtualAddress,
+ REGIONSIZE, //specify the region size
+ PAGE_NOACCESS,//desied access protection
+ &OldProtect);//old access protection
+ if(0 == err)
+ {
+ Trace("\nFailed to call VirtualProtect API!\n");
+ err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+ Fail("");
+ }
+
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/testinfo.dat
new file mode 100644
index 0000000000..71ccad5639
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test6/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualProtect
+Name = Positive test for VirtualProtect - with PAGE_NOACCESS
+TYPE = DEFAULT
+EXE1 = virtualprotect
+Description
+=Test the VirtualProtect to set new access protection
+=as PAGE_NOACCESS
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/CMakeLists.txt
new file mode 100644
index 0000000000..06af860559
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualProtect.c
+)
+
+add_executable(paltest_virtualprotect_test7
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualprotect_test7 coreclrpal)
+
+target_link_libraries(paltest_virtualprotect_test7
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/VirtualProtect.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/VirtualProtect.c
new file mode 100644
index 0000000000..edc37711f4
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/VirtualProtect.c
@@ -0,0 +1,69 @@
+// 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: virtualprotect.c
+**
+** Purpose: Positive test the VirtualProtect API.
+** Call VirtualProtect to set new protect as
+** PAGE_READONLY
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define REGIONSIZE 1024
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+ DWORD OldProtect;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region
+ REGIONSIZE, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_READWRITE); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ OldProtect = PAGE_READONLY;
+ //Set new access protection
+ err = VirtualProtect(lpVirtualAddress,
+ REGIONSIZE, //specify the region size
+ PAGE_READONLY,//desied access protection
+ &OldProtect);//old access protection
+ if(0 == err)
+ {
+ Trace("\nFailed to call VirtualProtect API!\n");
+ err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+ Fail("");
+ }
+
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress,REGIONSIZE,MEM_DECOMMIT);
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/testinfo.dat
new file mode 100644
index 0000000000..6b6eb58b34
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualProtect/test7/testinfo.dat
@@ -0,0 +1,13 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualProtect
+Name = Positive test for VirtualProtect - with PAGE_READONLY
+TYPE = DEFAULT
+EXE1 = virtualprotect
+Description
+=Test the VirtualProtect to set new access protection
+=as PAGE_READONLY
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/CMakeLists.txt
new file mode 100644
index 0000000000..f6aa0cb2d9
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/CMakeLists.txt
new file mode 100644
index 0000000000..4f4e4bc5f0
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ VirtualQuery.c
+)
+
+add_executable(paltest_virtualquery_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_virtualquery_test1 coreclrpal)
+
+target_link_libraries(paltest_virtualquery_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/VirtualQuery.c b/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/VirtualQuery.c
new file mode 100644
index 0000000000..44216ae563
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/VirtualQuery.c
@@ -0,0 +1,68 @@
+// 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: virtualquery.c
+**
+** Purpose: Positive test the VirtualQuery API.
+** Call VirtualQuery to get the virtual
+** page info
+**
+**
+**============================================================*/
+#include <palsuite.h>
+
+#define VIRTUALMEMORYSIZE 1024
+
+int __cdecl main(int argc, char *argv[])
+{
+ int err;
+ LPVOID lpVirtualAddress;
+ MEMORY_BASIC_INFORMATION PageInfo;
+ DWORD dwBufferSize;
+
+ //Initialize the PAL environment
+ err = PAL_Initialize(argc, argv);
+ if(0 != err)
+ {
+ ExitProcess(FAIL);
+ }
+
+ //Allocate the physical storage in memory or in the paging file on disk
+ lpVirtualAddress = VirtualAlloc(NULL,//determine where to allocate the region
+ VIRTUALMEMORYSIZE, //specify the size
+ MEM_COMMIT, //allocation type
+ PAGE_READONLY); //access protection
+ if(NULL == lpVirtualAddress)
+ {
+ Fail("\nFailed to call VirtualAlloc API!\n");
+ }
+
+ //get the virtual page info
+ dwBufferSize =
+ VirtualQuery(lpVirtualAddress,&PageInfo,sizeof(MEMORY_BASIC_INFORMATION));
+
+ if(dwBufferSize <= 0 ||
+ PageInfo.RegionSize <=0 ||
+ PAGE_READONLY != PageInfo.AllocationProtect ||
+ MEM_COMMIT != PageInfo.State)
+ {
+ Fail("\nFailed to call VirtualQuery API!\n");
+ }
+
+
+
+ //decommit the specified region
+ err = VirtualFree(lpVirtualAddress, //virtual page base address
+ VIRTUALMEMORYSIZE,//specify the size
+ MEM_DECOMMIT);//free operation
+ if(0 == err)
+ {
+ Fail("\nFailed to call VirtualFree API!\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/testinfo.dat
new file mode 100644
index 0000000000..b3462cd2f7
--- /dev/null
+++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualQuery/test1/testinfo.dat
@@ -0,0 +1,12 @@
+# 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.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualQuery
+Name = Positive test for VirtualQuery API
+TYPE = DEFAULT
+EXE1 = virtualquery
+Description
+=Test the VirtualQuery to get the virtual page info