1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author            Notes
8  * 2017/11/30     Bernard           The first version.
9  * 2024/03/29     TroyMitchelle     Add comments for all macros
10  */
11 
12 #ifndef __SYS_MMAN_H__
13 #define __SYS_MMAN_H__
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 #include <sys/types.h>
20 
21 #define MAP_FAILED     ((void *) -1)
22 
23 /* mmap flags */
24 #define MAP_SHARED     0x01      /**< Share the mapping with other processes. */
25 #define MAP_PRIVATE    0x02      /**< Create a private copy-on-write mapping. */
26 #define MAP_TYPE       0x0f      /**< Mask for type of mapping. */
27 #define MAP_FIXED      0x10      /**< Interpret addr exactly. */
28 #define MAP_ANON       0x20      /**< Anonymous mapping. */
29 #define MAP_ANONYMOUS  MAP_ANON  /**< Synonym for MAP_ANON. */
30 #define MAP_NORESERVE  0x4000    /**< Don't reserve swap space for this mapping. */
31 #define MAP_GROWSDOWN  0x0100    /**< Stack-like segment. */
32 #define MAP_DENYWRITE  0x0800    /**< ETXTBSY. */
33 #define MAP_EXECUTABLE 0x1000    /**< Mark it as an executable. */
34 #define MAP_LOCKED     0x2000    /**< Lock the mapping's pages. */
35 #define MAP_POPULATE   0x8000    /**< Populate (prefault) pagetables. */
36 #define MAP_NONBLOCK   0x10000   /**< Do not block on IO. */
37 #define MAP_STACK      0x20000   /**< Allocation is a stack segment. */
38 #define MAP_HUGETLB    0x40000   /**< Create a huge page mapping. */
39 #define MAP_FILE       0         /**< Compatibility */
40 
41 /* mmap protections */
42 #define PROT_NONE      0         /**< No access. */
43 #define PROT_READ      1         /**< Page can be read. */
44 #define PROT_WRITE     2         /**< Page can be written. */
45 #define PROT_EXEC      4         /**< Page can be executed. */
46 #define PROT_GROWSDOWN 0x01000000/**< Extend change to start of growsdown vma (mprotect only). */
47 #define PROT_GROWSUP   0x02000000/**< Extend change to start of growsup vma (mprotect only). */
48 
49 /* msync flags */
50 #define MS_ASYNC       1         /**< Perform asynchronous writes. */
51 #define MS_INVALIDATE  2         /**< Invalidate mappings after writing. */
52 #define MS_SYNC        4         /**< Perform synchronous writes. */
53 
54 /* mlockall flags */
55 #define MCL_CURRENT    1         /**< Lock all pages which are currently mapped into the address space of the process. */
56 #define MCL_FUTURE     2         /**< Lock all pages which will become mapped into the address space of the process in the future. */
57 #define MCL_ONFAULT    4         /**< Lock all pages which are currently mapped into the address space of the process on access. */
58 
59 
60 void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off);
61 int munmap (void *start, size_t len);
62 
63 #ifdef __cplusplus
64 }
65 #endif
66 #endif
67