0053e3071cf7dbcdeb8512eddd821a26827b042d
[babeltrace.git] / src / compat / mman.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2015-2016 Michael Jeanson <mjeanson@efficios.com>
5 */
6
7 #ifndef _BABELTRACE_COMPAT_MMAN_H
8 #define _BABELTRACE_COMPAT_MMAN_H
9
10 #ifdef __MINGW32__
11
12 #include <sys/types.h>
13 #include "common/macros.h"
14
15 #define PROT_NONE 0x0
16 #define PROT_READ 0x1
17 #define PROT_WRITE 0x2
18 #define PROT_EXEC 0x4
19
20 #define MAP_FILE 0
21 #define MAP_SHARED 1
22 #define MAP_PRIVATE 2
23 #define MAP_TYPE 0xF
24 #define MAP_FIXED 0x10
25 #define MAP_ANONYMOUS 0x20
26 #define MAP_ANON MAP_ANONYMOUS
27 #define MAP_FAILED ((void *) -1)
28
29 /*
30 * Note that some platforms (e.g. Windows) do not allow read-only
31 * mappings to exceed the file's size (even within a page).
32 */
33 BT_EXTERN_C void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
34 off_t offset, int log_level);
35
36 BT_EXTERN_C int bt_munmap(void *addr, size_t length);
37
38 /*
39 * On Windows the memory mapping offset must be aligned to the memory
40 * allocator allocation granularity and not the page size.
41 */
42 BT_EXTERN_C size_t bt_mmap_get_offset_align_size(int log_level);
43
44 #else /* __MINGW32__ */
45
46 #include <sys/mman.h>
47 #include "common/common.h"
48
49 static inline
50 void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd,
51 off_t offset, int log_level)
52 {
53 return (void *) mmap(addr, length, prot, flags, fd, offset);
54 }
55
56 static inline
57 int bt_munmap(void *addr, size_t length)
58 {
59 return munmap(addr, length);
60 }
61
62 /*
63 * On other platforms the memory mapping offset must be aligned to the
64 * page size.
65 */
66 static inline
67 size_t bt_mmap_get_offset_align_size(int log_level)
68 {
69 return bt_common_get_page_size(log_level);
70 }
71 #endif /* __MINGW32__ */
72
73 #ifndef MAP_ANONYMOUS
74 # ifdef MAP_ANON
75 # define MAP_ANONYMOUS MAP_ANON
76 # endif
77 #endif
78
79 #endif /* _BABELTRACE_COMPAT_MMAN_H */
This page took 0.03041 seconds and 4 git commands to generate.