Build mono runtime under none desktop Windows API family, adjustments and cleanup.
[mono.git] / mono / utils / mono-mmap-windows-uwp.c
1 /*
2  * mono-dl-windows-uwp.c: UWP dl support for Mono.
3  *
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"
10
11 #if G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT)
12 #include <windows.h>
13 #include <mono/utils/mono-mmap-windows-internals.h>
14
15 void*
16 mono_file_map (size_t length, int flags, int fd, guint64 offset, void **ret_handle)
17 {
18         void *ptr;
19         int mflags = 0;
20         HANDLE file, mapping;
21         int prot = mono_mmap_win_prot_from_flags (flags);
22
23         mflags = FILE_MAP_READ;
24         if (flags & MONO_MMAP_WRITE)
25                 mflags = FILE_MAP_COPY;
26
27         file = (HANDLE) _get_osfhandle (fd);
28         mapping = CreateFileMappingFromApp (file, NULL, prot, length, NULL);
29
30         if (mapping == NULL)
31                 return NULL;
32
33         ptr = MapViewOfFileFromApp (mapping, mflags, offset, length);
34
35         if (ptr == NULL) {
36                 CloseHandle (mapping);
37                 return NULL;
38         }
39
40         *ret_handle = (void*)mapping;
41         return ptr;
42 }
43
44 int
45 mono_file_unmap (void *addr, void *handle)
46 {
47         UnmapViewOfFile (addr);
48         CloseHandle ((HANDLE)handle);
49         return 0;
50 }
51
52 #else /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */
53
54 MONO_EMPTY_SOURCE_FILE (mono_mmap_windows_uwp);
55 #endif /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */