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