xref: /titanic_50/usr/src/uts/common/sys/mman.h (revision 70818f5837509317d1f5dac4d82d7b5a2d547c29)
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  #ifdef _KERNEL
86  #define	_MAP_TEXTREPL	0x1000
87  #endif /* _KERNEL */
88  
89  /* these flags not yet implemented */
90  #define	MAP_RENAME	0x20		/* rename private pages to file */
91  
92  #if	(_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2)
93  /* these flags are used by memcntl */
94  #define	PROC_TEXT	(PROT_EXEC | PROT_READ)
95  #define	PROC_DATA	(PROT_READ | PROT_WRITE | PROT_EXEC)
96  #define	SHARED		0x10
97  #define	PRIVATE		0x20
98  #define	VALID_ATTR  (PROT_READ|PROT_WRITE|PROT_EXEC|SHARED|PRIVATE)
99  #endif	/* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) */
100  
101  #if	(_POSIX_C_SOURCE <= 2) || defined(_XPG4_2)
102  #ifdef	_KERNEL
103  #define	PROT_EXCL	0x20
104  #define	_MAP_LOW32	0x80	/* force mapping in lower 4G of address space */
105  #endif	/* _KERNEL */
106  
107  /*
108   * For the sake of backward object compatibility, we use the _MAP_NEW flag.
109   * This flag will be automatically or'ed in by the C library for all
110   * new mmap calls.  Previous binaries with old mmap calls will continue
111   * to get 0 or -1 for return values.  New mmap calls will get the mapped
112   * address as the return value if successful and -1 on errors.  By default,
113   * new mmap calls automatically have the kernel assign the map address
114   * unless the MAP_FIXED flag is given.
115   */
116  #define	_MAP_NEW	0x80000000	/* users should not need to use this */
117  #endif	/* (_POSIX_C_SOURCE <= 2) */
118  
119  #if	!defined(_ASM) && !defined(_KERNEL)
120  
121  #include <sys/types.h>
122  
123  /*
124   * large file compilation environment setup
125   *
126   * In the LP64 compilation environment, map large file interfaces
127   * back to native versions where possible.
128   */
129  
130  #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
131  #ifdef	__PRAGMA_REDEFINE_EXTNAME
132  #pragma redefine_extname	mmap	mmap64
133  #else
134  #define	mmap			mmap64
135  #endif
136  #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
137  
138  #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
139  #ifdef	__PRAGMA_REDEFINE_EXTNAME
140  #pragma	redefine_extname	mmap64	mmap
141  #else
142  #define	mmap64			mmap
143  #endif
144  #endif	/* _LP64 && _LARGEFILE64_SOURCE */
145  
146  #ifdef __PRAGMA_REDEFINE_EXTNAME
147  #pragma redefine_extname	getpagesizes	getpagesizes2
148  #else
149  #define	getpagesizes	getpagesizes2
150  #endif
151  
152  /*
153   * Except for old binaries mmap() will return the resultant
154   * address of mapping on success and (caddr_t)-1 on error.
155   */
156  #ifdef	__STDC__
157  #if (_POSIX_C_SOURCE > 2) || defined(_XPG4_2)
158  extern void *mmap(void *, size_t, int, int, int, off_t);
159  extern int munmap(void *, size_t);
160  extern int mprotect(void *, size_t, int);
161  extern int msync(void *, size_t, int);
162  #if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__)
163  extern int mlock(const void *, size_t);
164  extern int munlock(const void *, size_t);
165  #endif	/* (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2))... */
166  /* transitional large file interface version */
167  #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
168  	    !defined(__PRAGMA_REDEFINE_EXTNAME))
169  extern void *mmap64(void *, size_t, int, int, int, off64_t);
170  #endif	/* _LARGEFILE64_SOURCE... */
171  #else	/* (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) */
172  extern caddr_t mmap(caddr_t, size_t, int, int, int, off_t);
173  extern int munmap(caddr_t, size_t);
174  extern int mprotect(caddr_t, size_t, int);
175  extern int msync(caddr_t, size_t, int);
176  extern int mlock(caddr_t, size_t);
177  extern int munlock(caddr_t, size_t);
178  extern int mincore(caddr_t, size_t, char *);
179  extern int memcntl(caddr_t, size_t, int, caddr_t, int, int);
180  extern int madvise(caddr_t, size_t, int);
181  #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
182  extern int getpagesizes(size_t *, int);
183  extern int getpagesizes2(size_t *, int);
184  /* guard visibility of uint64_t */
185  #if defined(_INT64_TYPE)
186  extern int meminfo(const uint64_t *, int, const uint_t *, int, uint64_t *,
187  	uint_t *);
188  #endif /* defined(_INT64_TYPE) */
189  #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
190  /* transitional large file interface version */
191  #ifdef	_LARGEFILE64_SOURCE
192  extern caddr_t mmap64(caddr_t, size_t, int, int, int, off64_t);
193  #endif
194  #endif	/* (_POSIX_C_SOURCE > 2)  || defined(_XPG4_2) */
195  
196  #if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__)
197  extern int mlockall(int);
198  extern int munlockall(void);
199  extern int shm_open(const char *, int, mode_t);
200  extern int shm_unlink(const char *);
201  #endif
202  
203  /* mmap failure value */
204  #define	MAP_FAILED	((void *) -1)
205  
206  #else	/* __STDC__ */
207  extern caddr_t mmap();
208  extern int munmap();
209  extern int mprotect();
210  extern int mincore();
211  extern int memcntl();
212  extern int msync();
213  extern int madvise();
214  extern int getpagesizes();
215  extern int getpagesizes2();
216  extern int mlock();
217  extern int mlockall();
218  extern int munlock();
219  extern int munlockall();
220  extern int meminfo();
221  extern int shm_open();
222  extern int shm_unlink();
223  
224  /* transitional large file interface version */
225  #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
226  	    !defined(__PRAGMA_REDEFINE_EXTNAME))
227  extern caddr_t mmap64();
228  #endif	/* _LARGEFILE64_SOURCE... */
229  #endif	/* __STDC__ */
230  
231  
232  #endif	/* !_ASM && !_KERNEL */
233  
234  #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
235  #if !defined(_ASM)
236  /*
237   * structure for memcntl hat advise operations.
238   */
239  struct memcntl_mha {
240  	uint_t 		mha_cmd;	/* command(s) */
241  	uint_t		mha_flags;
242  	size_t		mha_pagesize;
243  };
244  
245  #if defined(_SYSCALL32)
246  struct memcntl_mha32 {
247  	uint_t 		mha_cmd;	/* command(s) */
248  	uint_t		mha_flags;
249  	size32_t	mha_pagesize;
250  };
251  #endif	/* _SYSCALL32 */
252  #endif	/* !defined(_ASM) */
253  #endif	/* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
254  
255  #if	(_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) || defined(__EXTENSIONS__)
256  /* advice to madvise */
257  #define	MADV_NORMAL		0	/* no further special treatment */
258  #define	MADV_RANDOM		1	/* expect random page references */
259  #define	MADV_SEQUENTIAL		2	/* expect sequential page references */
260  #define	MADV_WILLNEED		3	/* will need these pages */
261  #define	MADV_DONTNEED		4	/* don't need these pages */
262  #define	MADV_FREE		5	/* contents can be freed */
263  #define	MADV_ACCESS_DEFAULT	6	/* default access */
264  #define	MADV_ACCESS_LWP		7	/* next LWP to access heavily */
265  #define	MADV_ACCESS_MANY	8	/* many processes to access heavily */
266  #endif	/* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) ...  */
267  
268  /* flags to msync */
269  #define	MS_OLDSYNC	0x0		/* old value of MS_SYNC */
270  					/* modified for UNIX98 compliance */
271  #define	MS_SYNC		0x4		/* wait for msync */
272  #define	MS_ASYNC	0x1		/* return immediately */
273  #define	MS_INVALIDATE	0x2		/* invalidate caches */
274  
275  #if	(_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) || defined(__EXTENSIONS__)
276  /* functions to mctl */
277  #define	MC_SYNC		1		/* sync with backing store */
278  #define	MC_LOCK		2		/* lock pages in memory */
279  #define	MC_UNLOCK	3		/* unlock pages from memory */
280  #define	MC_ADVISE	4		/* give advice to management */
281  #define	MC_LOCKAS	5		/* lock address space in memory */
282  #define	MC_UNLOCKAS	6		/* unlock address space from memory */
283  #define	MC_HAT_ADVISE	7		/* advise hat map size */
284  
285  /* sub-commands for MC_HAT_ADVISE */
286  #define	MHA_MAPSIZE_VA		0x1	/* set preferred page size */
287  #define	MHA_MAPSIZE_BSSBRK	0x2	/* set preferred page size */
288  					/* for last bss adjacent to */
289  					/* brk area and brk area itself */
290  #define	MHA_MAPSIZE_STACK	0x4	/* set preferred page size */
291  					/* processes main stack */
292  
293  #endif	/* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) ... */
294  
295  #if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__)
296  /* flags to mlockall */
297  #define	MCL_CURRENT	0x1		/* lock current mappings */
298  #define	MCL_FUTURE	0x2		/* lock future mappings */
299  #endif /* (!defined(_XPG4_2) || (_POSIX_C_SOURCE)) || defined(__EXTENSIONS__) */
300  
301  #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
302  
303  /* definitions for meminfosys syscall */
304  #define	MISYS_MEMINFO		0x0
305  
306  #if !defined(_ASM) && defined(__STDC__)
307  
308  #if defined(_INT64_TYPE)
309  /* private structure for meminfo */
310  typedef struct meminfo {
311  	const uint64_t *mi_inaddr;	/* array of input addresses */
312  	const uint_t *mi_info_req;	/* array of types of info requested */
313  	uint64_t *mi_outdata;		/* array of results are placed */
314  	uint_t *mi_validity;		/* array of bitwise result codes */
315  	int mi_info_count;		/* number of pieces of info requested */
316  } meminfo_t;
317  #endif /* defined(_INT64_TYPE) */
318  
319  #if defined(_SYSCALL32)
320  typedef struct meminfo32 {
321  	caddr32_t mi_inaddr;	/* array of input addresses */
322  	caddr32_t mi_info_req;	/* array of types of information requested */
323  	caddr32_t mi_outdata;	/* array of results are placed */
324  	caddr32_t mi_validity;	/* array of bitwise result codes */
325  	int32_t mi_info_count;	/* number of pieces of information requested */
326  } meminfo32_t;
327  #endif /* defined(_SYSCALL32) */
328  
329  #endif /* !defined(_ASM) && defined(__STDC__) */
330  
331  /*
332   * info_req request type definitions for meminfo
333   * request types starting with MEMINFO_V are used for Virtual addresses
334   * and should not be mixed with MEMINFO_PLGRP which is targeted for Physical
335   * addresses
336   */
337  #define	MEMINFO_SHIFT		16
338  #define	MEMINFO_MASK		(0xFF << MEMINFO_SHIFT)
339  #define	MEMINFO_VPHYSICAL	(0x01 << MEMINFO_SHIFT)	/* get physical addr */
340  #define	MEMINFO_VLGRP		(0x02 << MEMINFO_SHIFT) /* get lgroup */
341  #define	MEMINFO_VPAGESIZE	(0x03 << MEMINFO_SHIFT) /* size of phys page */
342  #define	MEMINFO_VREPLCNT	(0x04 << MEMINFO_SHIFT) /* no. of replica */
343  #define	MEMINFO_VREPL		(0x05 << MEMINFO_SHIFT) /* physical replica */
344  #define	MEMINFO_VREPL_LGRP	(0x06 << MEMINFO_SHIFT) /* lgrp of replica */
345  #define	MEMINFO_PLGRP		(0x07 << MEMINFO_SHIFT) /* lgroup for paddr */
346  
347  /* maximum number of addresses meminfo() can process at a time */
348  #define	MAX_MEMINFO_CNT	256
349  
350  /* maximum number of request types */
351  #define	MAX_MEMINFO_REQ	31
352  
353  #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
354  
355  #ifdef	__cplusplus
356  }
357  #endif
358  
359  #endif	/* _SYS_MMAN_H */
360