xref: /unit/src/nxt_mem_map.h (revision 2084:7d479274f334)
1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) NGINX, Inc.
5  */
6 
7 #ifndef _NXT_UNIX_MEM_MAP_H_INCLUDED_
8 #define _NXT_UNIX_MEM_MAP_H_INCLUDED_
9 
10 
11 #define NXT_MEM_MAP_FAILED    MAP_FAILED
12 
13 
14 #define NXT_MEM_MAP_READ      PROT_READ
15 #define NXT_MEM_MAP_WRITE     PROT_WRITE
16 
17 
18 #if (NXT_HAVE_MAP_ANONYMOUS)
19 #define NXT_MEM_MAP_ANON      MAP_ANONYMOUS
20 #else
21 #define NXT_MEM_MAP_ANON      MAP_ANON
22 #endif
23 
24 #define NXT_MEM_MAP_SHARED    (MAP_SHARED | NXT_MEM_MAP_ANON)
25 
26 
27 #if (NXT_HAVE_MAP_POPULATE)
28 /*
29  * Linux MAP_POPULATE reads ahead and wires pages.
30  * (MAP_POPULATE | MAP_NONBLOCK) wires only resident pages
31  * without read ahead but it does not work since Linux 2.6.23.
32  */
33 #define NXT_MEM_MAP_PREFAULT  MAP_POPULATE
34 
35 #elif (NXT_HAVE_MAP_PREFAULT_READ)
36 /* FreeBSD MAP_PREFAULT_READ wires resident pages without read ahead. */
37 #define NXT_MEM_MAP_PREFAULT  MAP_PREFAULT_READ
38 
39 #else
40 #define NXT_MEM_MAP_PREFAULT  0
41 #endif
42 
43 #define NXT_MEM_MAP_FILE      (MAP_SHARED | NXT_MEM_MAP_PREFAULT)
44 
45 
46 #define     nxt_mem_map_file_ctx_t(ctx)
47 
48 
49 #define nxt_mem_map(addr, ctx, len, protection, flags, fd, offset)            \
50     nxt_mem_mmap(addr, len, protection, flags, fd, offset)
51 
52 
53 #define nxt_mem_unmap(addr, ctx, len)                                         \
54     nxt_mem_munmap(addr, len)
55 
56 
57 NXT_EXPORT void *nxt_mem_mmap(void *addr, size_t len, nxt_uint_t protection,
58     nxt_uint_t flags, nxt_fd_t fd, nxt_off_t offset);
59 NXT_EXPORT void nxt_mem_munmap(void *addr, size_t len);
60 
61 
62 #endif /* _NXT_UNIX_MEM_MAP_H_INCLUDED_ */
63