Apply clang-format to folly/portability/
[folly.git] / folly / portability / SysMman.h
1 /*
2  * Copyright 2017 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
21 #include <sys/mman.h>
22
23 // MAP_ANONYMOUS is named MAP_ANON on OSX/BSD.
24 #if defined(__APPLE__) || defined(__FreeBSD__)
25 #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
26 #define MAP_ANONYMOUS MAP_ANON
27 #endif
28 #endif
29
30 #else
31
32 #include <cstdint>
33
34 #include <sys/types.h>
35
36 #define MAP_ANONYMOUS 1
37 #define MAP_ANON MAP_ANONYMOUS
38 #define MAP_SHARED 2
39 #define MAP_PRIVATE 4
40 #define MAP_POPULATE 8
41 #define MAP_NORESERVE 16
42 #define MAP_FIXED 32
43
44 #define MAP_FAILED ((void*)-1)
45
46 #define PROT_NONE 0
47 #define PROT_READ 1
48 #define PROT_WRITE 2
49 #define PROT_EXEC 4
50
51 #define MADV_NORMAL 0
52 #define MADV_DONTNEED 0
53 #define MADV_SEQUENTIAL 0
54
55 extern "C" {
56 int madvise(const void* addr, size_t len, int advise);
57 int mlock(const void* addr, size_t len);
58 void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t off);
59 int mprotect(void* addr, size_t size, int prot);
60 int munlock(const void* addr, size_t length);
61 int munmap(void* addr, size_t length);
62 }
63
64 #endif