src.ctf.lttng-live: remove some goto error-handling
[babeltrace.git] / src / compat / mman.h
CommitLineData
5d620f61 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
5d620f61 3 *
0235b0db 4 * Copyright (C) 2015-2016 Michael Jeanson <mjeanson@efficios.com>
5d620f61
MJ
5 */
6
0235b0db
MJ
7#ifndef _BABELTRACE_COMPAT_MMAN_H
8#define _BABELTRACE_COMPAT_MMAN_H
9
04394229 10#ifdef __MINGW32__
8f76831a
MJ
11
12#include <sys/types.h>
44b756ef 13#include "common/macros.h"
8f76831a
MJ
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
2f5a009b
JG
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 */
31cc85a3 33BT_EXTERN_C void *bt_mmap(size_t length, int prot, int flags, int fd,
95c324a4 34 off_t offset, int log_level);
8f76831a 35
087cd0f5 36BT_EXTERN_C int bt_munmap(void *addr, size_t length);
04394229 37
3b16a19b
MJ
38/*
39 * On Windows the memory mapping offset must be aligned to the memory
40 * allocator allocation granularity and not the page size.
41 */
087cd0f5 42BT_EXTERN_C size_t bt_mmap_get_offset_align_size(int log_level);
3b16a19b 43
04394229
MJ
44#else /* __MINGW32__ */
45
46#include <sys/mman.h>
3b16a19b 47#include "common/common.h"
04394229
MJ
48
49static inline
31cc85a3 50void *bt_mmap(size_t length, int prot, int flags, int fd,
ecd7492f 51 off_t offset, int log_level __attribute__((unused)))
04394229 52{
31cc85a3 53 return (void *) mmap(NULL, length, prot, flags, fd, offset);
04394229
MJ
54}
55
56static inline
57int bt_munmap(void *addr, size_t length)
58{
59 return munmap(addr, length);
60}
3b16a19b
MJ
61
62/*
63 * On other platforms the memory mapping offset must be aligned to the
64 * page size.
65 */
66static inline
67size_t bt_mmap_get_offset_align_size(int log_level)
68{
69 return bt_common_get_page_size(log_level);
70}
8f76831a
MJ
71#endif /* __MINGW32__ */
72
5d620f61
MJ
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.090615 seconds and 4 git commands to generate.