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