xref: /titanic_52/usr/src/uts/common/sys/mman.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #ifndef	_SYS_MMAN_H
41 #define	_SYS_MMAN_H
42 
43 #pragma ident	"%Z%%M%	%I%	%E% SMI"
44 
45 #include <sys/feature_tests.h>
46 
47 #ifdef	__cplusplus
48 extern "C" {
49 #endif
50 
51 /*
52  * Protections are chosen from these bits, or-ed together.
53  * Note - not all implementations literally provide all possible
54  * combinations.  PROT_WRITE is often implemented as (PROT_READ |
55  * PROT_WRITE) and (PROT_EXECUTE as PROT_READ | PROT_EXECUTE).
56  * However, no implementation will permit a write to succeed
57  * where PROT_WRITE has not been set.  Also, no implementation will
58  * allow any access to succeed where prot is specified as PROT_NONE.
59  */
60 #define	PROT_READ	0x1		/* pages can be read */
61 #define	PROT_WRITE	0x2		/* pages can be written */
62 #define	PROT_EXEC	0x4		/* pages can be executed */
63 
64 #ifdef	_KERNEL
65 #define	PROT_USER	0x8		/* pages are user accessable */
66 #define	PROT_ZFOD	(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_USER)
67 #define	PROT_ALL	(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_USER)
68 #endif	/* _KERNEL */
69 
70 #define	PROT_NONE	0x0		/* pages cannot be accessed */
71 
72 /* sharing types:  must choose either SHARED or PRIVATE */
73 #define	MAP_SHARED	1		/* share changes */
74 #define	MAP_PRIVATE	2		/* changes are private */
75 #define	MAP_TYPE	0xf		/* mask for share type */
76 
77 /* other flags to mmap (or-ed in to MAP_SHARED or MAP_PRIVATE) */
78 #define	MAP_FIXED	0x10		/* user assigns address */
79 #define	MAP_NORESERVE	0x40		/* don't reserve needed swap area */
80 #define	MAP_ANON	0x100		/* map anonymous pages directly */
81 #define	MAP_ANONYMOUS	MAP_ANON	/* (source compatibility) */
82 #define	MAP_ALIGN	0x200		/* addr specifies alignment */
83 #define	MAP_TEXT	0x400		/* map code segment */
84 #define	MAP_INITDATA	0x800		/* map data segment */
85 
86 /* these flags not yet implemented */
87 #define	MAP_RENAME	0x20		/* rename private pages to file */
88 
89 #if	(_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2)
90 /* these flags are used by memcntl */
91 #define	PROC_TEXT	(PROT_EXEC | PROT_READ)
92 #define	PROC_DATA	(PROT_READ | PROT_WRITE | PROT_EXEC)
93 #define	SHARED		0x10
94 #define	PRIVATE		0x20
95 #define	VALID_ATTR  (PROT_READ|PROT_WRITE|PROT_EXEC|SHARED|PRIVATE)
96 #endif	/* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) */
97 
98 #if	(_POSIX_C_SOURCE <= 2) || defined(_XPG4_2)
99 #ifdef	_KERNEL
100 #define	PROT_EXCL	0x20
101 #define	_MAP_LOW32	0x80	/* force mapping in lower 4G of address space */
102 #endif	/* _KERNEL */
103 
104 /*
105  * For the sake of backward object compatibility, we use the _MAP_NEW flag.
106  * This flag will be automatically or'ed in by the C library for all
107  * new mmap calls.  Previous binaries with old mmap calls will continue
108  * to get 0 or -1 for return values.  New mmap calls will get the mapped
109  * address as the return value if successful and -1 on errors.  By default,
110  * new mmap calls automatically have the kernel assign the map address
111  * unless the MAP_FIXED flag is given.
112  */
113 #define	_MAP_NEW	0x80000000	/* users should not need to use this */
114 #endif	/* (_POSIX_C_SOURCE <= 2) */
115 
116 #if	!defined(_ASM) && !defined(_KERNEL)
117 
118 #include <sys/types.h>
119 
120 /*
121  * large file compilation environment setup
122  *
123  * In the LP64 compilation environment, map large file interfaces
124  * back to native versions where possible.
125  */
126 
127 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
128 #ifdef	__PRAGMA_REDEFINE_EXTNAME
129 #pragma redefine_extname	mmap	mmap64
130 #else
131 #define	mmap			mmap64
132 #endif
133 #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
134 
135 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
136 #ifdef	__PRAGMA_REDEFINE_EXTNAME
137 #pragma	redefine_extname	mmap64	mmap
138 #else
139 #define	mmap64			mmap
140 #endif
141 #endif	/* _LP64 && _LARGEFILE64_SOURCE */
142 
143 /*
144  * Except for old binaries mmap() will return the resultant
145  * address of mapping on success and (caddr_t)-1 on error.
146  */
147 #ifdef	__STDC__
148 #if (_POSIX_C_SOURCE > 2) || defined(_XPG4_2)
149 extern void *mmap(void *, size_t, int, int, int, off_t);
150 extern int munmap(void *, size_t);
151 extern int mprotect(void *, size_t, int);
152 extern int msync(void *, size_t, int);
153 #if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__)
154 extern int mlock(const void *, size_t);
155 extern int munlock(const void *, size_t);
156 extern int shm_open(const char *, int, mode_t);
157 extern int shm_unlink(const char *);
158 #endif	/* (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2))... */
159 /* transitional large file interface version */
160 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
161 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
162 extern void *mmap64(void *, size_t, int, int, int, off64_t);
163 #endif	/* _LARGEFILE64_SOURCE... */
164 #else	/* (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) */
165 extern caddr_t mmap(caddr_t, size_t, int, int, int, off_t);
166 extern int munmap(caddr_t, size_t);
167 extern int mprotect(caddr_t, size_t, int);
168 extern int msync(caddr_t, size_t, int);
169 extern int mlock(caddr_t, size_t);
170 extern int munlock(caddr_t, size_t);
171 extern int mincore(caddr_t, size_t, char *);
172 extern int memcntl(caddr_t, size_t, int, caddr_t, int, int);
173 extern int madvise(caddr_t, size_t, int);
174 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
175 extern int getpagesizes(size_t *, int);
176 /* guard visibility of uint64_t */
177 #if defined(_INT64_TYPE)
178 extern int meminfo(const uint64_t *, int, const uint_t *, int, uint64_t *,
179 	uint_t *);
180 #endif /* defined(_INT64_TYPE) */
181 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
182 /* transitional large file interface version */
183 #ifdef	_LARGEFILE64_SOURCE
184 extern caddr_t mmap64(caddr_t, size_t, int, int, int, off64_t);
185 #endif
186 #endif	/* (_POSIX_C_SOURCE > 2)  || defined(_XPG4_2) */
187 
188 #if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__)
189 extern int mlockall(int);
190 extern int munlockall(void);
191 #endif
192 
193 /* mmap failure value */
194 #define	MAP_FAILED	((void *) -1)
195 
196 #else	/* __STDC__ */
197 extern caddr_t mmap();
198 extern int munmap();
199 extern int mprotect();
200 extern int mincore();
201 extern int memcntl();
202 extern int msync();
203 extern int madvise();
204 extern int getpagesizes();
205 extern int mlock();
206 extern int mlockall();
207 extern int munlock();
208 extern int munlockall();
209 extern int meminfo();
210 /* transitional large file interface version */
211 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
212 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
213 extern caddr_t mmap64();
214 #endif	/* _LARGEFILE64_SOURCE... */
215 #endif	/* __STDC__ */
216 
217 
218 #endif	/* !_ASM && !_KERNEL */
219 
220 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
221 #if !defined(_ASM)
222 /*
223  * structure for memcntl hat advise operations.
224  */
225 struct memcntl_mha {
226 	uint_t 		mha_cmd;	/* command(s) */
227 	uint_t		mha_flags;
228 	size_t		mha_pagesize;
229 };
230 
231 #if defined(_SYSCALL32)
232 struct memcntl_mha32 {
233 	uint_t 		mha_cmd;	/* command(s) */
234 	uint_t		mha_flags;
235 	size32_t	mha_pagesize;
236 };
237 #endif	/* _SYSCALL32 */
238 #endif	/* !defined(_ASM) */
239 #endif	/* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
240 
241 #if	(_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) || defined(__EXTENSIONS__)
242 /* advice to madvise */
243 #define	MADV_NORMAL		0	/* no further special treatment */
244 #define	MADV_RANDOM		1	/* expect random page references */
245 #define	MADV_SEQUENTIAL		2	/* expect sequential page references */
246 #define	MADV_WILLNEED		3	/* will need these pages */
247 #define	MADV_DONTNEED		4	/* don't need these pages */
248 #define	MADV_FREE		5	/* contents can be freed */
249 #define	MADV_ACCESS_DEFAULT	6	/* default access */
250 #define	MADV_ACCESS_LWP		7	/* next LWP to access heavily */
251 #define	MADV_ACCESS_MANY	8	/* many processes to access heavily */
252 #endif	/* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) ...  */
253 
254 /* flags to msync */
255 #define	MS_OLDSYNC	0x0		/* old value of MS_SYNC */
256 					/* modified for UNIX98 compliance */
257 #define	MS_SYNC		0x4		/* wait for msync */
258 #define	MS_ASYNC	0x1		/* return immediately */
259 #define	MS_INVALIDATE	0x2		/* invalidate caches */
260 
261 #if	(_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) || defined(__EXTENSIONS__)
262 /* functions to mctl */
263 #define	MC_SYNC		1		/* sync with backing store */
264 #define	MC_LOCK		2		/* lock pages in memory */
265 #define	MC_UNLOCK	3		/* unlock pages from memory */
266 #define	MC_ADVISE	4		/* give advice to management */
267 #define	MC_LOCKAS	5		/* lock address space in memory */
268 #define	MC_UNLOCKAS	6		/* unlock address space from memory */
269 #define	MC_HAT_ADVISE	7		/* advise hat map size */
270 
271 /* sub-commands for MC_HAT_ADVISE */
272 #define	MHA_MAPSIZE_VA		0x1	/* set preferred page size */
273 #define	MHA_MAPSIZE_BSSBRK	0x2	/* set preferred page size */
274 					/* for last bss adjacent to */
275 					/* brk area and brk area itself */
276 #define	MHA_MAPSIZE_STACK	0x4	/* set preferred page size */
277 					/* processes main stack */
278 
279 #endif	/* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) ... */
280 
281 #if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__)
282 /* flags to mlockall */
283 #define	MCL_CURRENT	0x1		/* lock current mappings */
284 #define	MCL_FUTURE	0x2		/* lock future mappings */
285 #endif /* (!defined(_XPG4_2) || (_POSIX_C_SOURCE)) || defined(__EXTENSIONS__) */
286 
287 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
288 
289 /* definitions for meminfosys syscall */
290 #define	MISYS_MEMINFO		0x0
291 
292 #if !defined(_ASM) && defined(__STDC__)
293 
294 #if defined(_INT64_TYPE)
295 /* private structure for meminfo */
296 typedef struct meminfo {
297 	const uint64_t *mi_inaddr;	/* array of input addresses */
298 	const uint_t *mi_info_req;	/* array of types of info requested */
299 	uint64_t *mi_outdata;		/* array of results are placed */
300 	uint_t *mi_validity;		/* array of bitwise result codes */
301 	int mi_info_count;		/* number of pieces of info requested */
302 } meminfo_t;
303 #endif /* defined(_INT64_TYPE) */
304 
305 #if defined(_SYSCALL32)
306 typedef struct meminfo32 {
307 	caddr32_t mi_inaddr;	/* array of input addresses */
308 	caddr32_t mi_info_req;	/* array of types of information requested */
309 	caddr32_t mi_outdata;	/* array of results are placed */
310 	caddr32_t mi_validity;	/* array of bitwise result codes */
311 	int32_t mi_info_count;	/* number of pieces of information requested */
312 } meminfo32_t;
313 #endif /* defined(_SYSCALL32) */
314 
315 #endif /* !defined(_ASM) && defined(__STDC__) */
316 
317 /*
318  * info_req request type definitions for meminfo
319  * request types starting with MEMINFO_V are used for Virtual addresses
320  * and should not be mixed with MEMINFO_PLGRP which is targeted for Physical
321  * addresses
322  */
323 #define	MEMINFO_SHIFT		16
324 #define	MEMINFO_MASK		(0xFF << MEMINFO_SHIFT)
325 #define	MEMINFO_VPHYSICAL	(0x01 << MEMINFO_SHIFT)	/* get physical addr */
326 #define	MEMINFO_VLGRP		(0x02 << MEMINFO_SHIFT) /* get lgroup */
327 #define	MEMINFO_VPAGESIZE	(0x03 << MEMINFO_SHIFT) /* size of phys page */
328 #define	MEMINFO_VREPLCNT	(0x04 << MEMINFO_SHIFT) /* no. of replica */
329 #define	MEMINFO_VREPL		(0x05 << MEMINFO_SHIFT) /* physical replica */
330 #define	MEMINFO_VREPL_LGRP	(0x06 << MEMINFO_SHIFT) /* lgrp of replica */
331 #define	MEMINFO_PLGRP		(0x07 << MEMINFO_SHIFT) /* lgroup for paddr */
332 
333 /* maximum number of addresses meminfo() can process at a time */
334 #define	MAX_MEMINFO_CNT	256
335 
336 /* maximum number of request types */
337 #define	MAX_MEMINFO_REQ	31
338 
339 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
340 
341 #ifdef	__cplusplus
342 }
343 #endif
344 
345 #endif	/* _SYS_MMAN_H */
346