Update ms-test-suite
[mono-project.git] / mono / utils / mono-mmap-windows-uwp.c
blob347fb70e89fa38d99faff71fc181b02ef8f633d4
1 /*
2 * mono-dl-windows-uwp.c: UWP dl support for Mono.
4 * Copyright 2016 Microsoft
5 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
6 */
7 #include <config.h>
8 #include <glib.h>
9 #include "mono/utils/mono-compiler.h"
11 #if G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT)
12 #include <windows.h>
13 #include <mono/utils/mono-mmap-windows-internals.h>
15 void*
16 mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_handle)
18 void *ptr;
19 int mflags = 0;
20 HANDLE file, mapping;
21 int prot = mono_mmap_win_prot_from_flags (flags);
23 mflags = FILE_MAP_READ;
24 if (flags & MONO_MMAP_WRITE)
25 mflags = FILE_MAP_COPY;
27 file = (HANDLE) _get_osfhandle (fd);
28 mapping = CreateFileMappingFromApp (file, NULL, prot, length, NULL);
30 if (mapping == NULL)
31 return NULL;
33 ptr = MapViewOfFileFromApp (mapping, mflags, offset, length);
35 if (ptr == NULL) {
36 CloseHandle (mapping);
37 return NULL;
40 *ret_handle = (void*)mapping;
41 return ptr;
44 int
45 mono_file_unmap (void *addr, void *handle)
47 UnmapViewOfFile (addr);
48 CloseHandle ((HANDLE)handle);
49 return 0;
52 #else /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */
54 MONO_EMPTY_SOURCE_FILE (mono_mmap_windows_uwp);
55 #endif /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */