Create the sys/mman.h portability header
[folly.git] / folly / portability / SysMman.h
1 /*
2  * Copyright 2016 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #ifndef _WIN32
20 #include <sys/mman.h>
21
22 // MAP_ANONYMOUS is named MAP_ANON on OSX/BSD.
23 #if defined(__APPLE__) || defined(__FreeBSD__)
24 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
25 #  define MAP_ANONYMOUS MAP_ANON
26 # endif
27 #endif
28 #else
29 #include <cstdint>
30 #include <sys/types.h>
31
32 #define MAP_ANONYMOUS 1
33 #define MAP_ANON MAP_ANONYMOUS
34 #define MAP_SHARED 2
35 #define MAP_PRIVATE 4
36 #define MAP_POPULATE 8
37 #define MAP_NORESERVE 16
38 #define MAP_FIXED 32
39
40 #define MAP_FAILED ((void*)-1)
41
42 #define PROT_NONE 0
43 #define PROT_READ 1
44 #define PROT_WRITE 2
45 #define PROT_EXEC 4
46
47 #define MADV_DONTNEED 0
48 #define MADV_SEQUENTIAL 0
49
50 extern "C" {
51 int madvise(const void* addr, size_t len, int advise);
52 int mlock(const void* addr, size_t len);
53 void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t off);
54 int mprotect(void* addr, size_t size, int prot);
55 int munlock(const void* addr, size_t length);
56 int munmap(void* addr, size_t length);
57 }
58 #endif