xref: /illumos-gate/usr/src/uts/common/sys/mman.h (revision fec04708)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5bfe60e20Sdamico  * Common Development and Distribution License (the "License").
6bfe60e20Sdamico  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21019c3c43Sraf 
221b3b16f3STheo Schlossnagle /* Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved. */
237c478bd9Sstevel@tonic-gate /*
24ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
25ba3594baSGarrett D'Amore  *
26019c3c43Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
289d12795fSRobert Mustacchi  * Copyright 2015 Joyent, Inc.  All rights reserved.
29*df5cd018SRobert Mustacchi  * Copyright 2022 Oxide Computer Company
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
337c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
377c478bd9Sstevel@tonic-gate  * The Regents of the University of California
387c478bd9Sstevel@tonic-gate  * All Rights Reserved
397c478bd9Sstevel@tonic-gate  *
407c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
417c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
427c478bd9Sstevel@tonic-gate  * contributors.
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #ifndef	_SYS_MMAN_H
467c478bd9Sstevel@tonic-gate #define	_SYS_MMAN_H
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
497c478bd9Sstevel@tonic-gate 
50*df5cd018SRobert Mustacchi /*
51*df5cd018SRobert Mustacchi  * <sys/mman.h> has had a bit of a tortured symbol visibility history. In
52*df5cd018SRobert Mustacchi  * particular, when things were honored under __EXTENSIONS__ or not in the past
53*df5cd018SRobert Mustacchi  * wasn't very consistent. As this was not a header that was part of ISO-C it
54*df5cd018SRobert Mustacchi  * traditionally just checked around XOPEN/POSIX related feature tests. This
55*df5cd018SRobert Mustacchi  * makes the use of the standard _STRICT_POSIX something that actually is more
56*df5cd018SRobert Mustacchi  * restrictive than previously was used.
57*df5cd018SRobert Mustacchi  */
58*df5cd018SRobert Mustacchi 
597c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
607c478bd9Sstevel@tonic-gate extern "C" {
617c478bd9Sstevel@tonic-gate #endif
627c478bd9Sstevel@tonic-gate 
6331c6c9d8SMichael Corcoran #if	!defined(_ASM) && !defined(_KERNEL)
6431c6c9d8SMichael Corcoran #include <sys/types.h>
6531c6c9d8SMichael Corcoran #endif	/* !_ASM && !_KERNEL */
6631c6c9d8SMichael Corcoran 
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate  * Protections are chosen from these bits, or-ed together.
697c478bd9Sstevel@tonic-gate  * Note - not all implementations literally provide all possible
707c478bd9Sstevel@tonic-gate  * combinations.  PROT_WRITE is often implemented as (PROT_READ |
717c478bd9Sstevel@tonic-gate  * PROT_WRITE) and (PROT_EXECUTE as PROT_READ | PROT_EXECUTE).
727c478bd9Sstevel@tonic-gate  * However, no implementation will permit a write to succeed
737c478bd9Sstevel@tonic-gate  * where PROT_WRITE has not been set.  Also, no implementation will
747c478bd9Sstevel@tonic-gate  * allow any access to succeed where prot is specified as PROT_NONE.
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate #define	PROT_READ	0x1		/* pages can be read */
777c478bd9Sstevel@tonic-gate #define	PROT_WRITE	0x2		/* pages can be written */
787c478bd9Sstevel@tonic-gate #define	PROT_EXEC	0x4		/* pages can be executed */
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
81*df5cd018SRobert Mustacchi #define	PROT_USER	0x8		/* pages are user accessible */
827c478bd9Sstevel@tonic-gate #define	PROT_ZFOD	(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_USER)
837c478bd9Sstevel@tonic-gate #define	PROT_ALL	(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_USER)
847c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #define	PROT_NONE	0x0		/* pages cannot be accessed */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /* sharing types:  must choose either SHARED or PRIVATE */
897c478bd9Sstevel@tonic-gate #define	MAP_SHARED	1		/* share changes */
907c478bd9Sstevel@tonic-gate #define	MAP_PRIVATE	2		/* changes are private */
917c478bd9Sstevel@tonic-gate #define	MAP_TYPE	0xf		/* mask for share type */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /* other flags to mmap (or-ed in to MAP_SHARED or MAP_PRIVATE) */
94ccd5347fSJames Blachly #define	MAP_FILE	0		/* map from file (default) */
957c478bd9Sstevel@tonic-gate #define	MAP_FIXED	0x10		/* user assigns address */
96d2a70789SRichard Lowe /* Not implemented */
97d2a70789SRichard Lowe #define	MAP_RENAME	0x20		/* rename private pages to file */
987c478bd9Sstevel@tonic-gate #define	MAP_NORESERVE	0x40		/* don't reserve needed swap area */
99d2a70789SRichard Lowe /* Note that 0x80 is _MAP_LOW32, defined below */
1007c478bd9Sstevel@tonic-gate #define	MAP_ANON	0x100		/* map anonymous pages directly */
1017c478bd9Sstevel@tonic-gate #define	MAP_ANONYMOUS	MAP_ANON	/* (source compatibility) */
1027c478bd9Sstevel@tonic-gate #define	MAP_ALIGN	0x200		/* addr specifies alignment */
1037c478bd9Sstevel@tonic-gate #define	MAP_TEXT	0x400		/* map code segment */
1047c478bd9Sstevel@tonic-gate #define	MAP_INITDATA	0x800		/* map data segment */
1057c478bd9Sstevel@tonic-gate 
106*df5cd018SRobert Mustacchi /*
107*df5cd018SRobert Mustacchi  * Internal to the kernel, extensions to mmap flags.
108*df5cd018SRobert Mustacchi  */
1092cb27123Saguzovsk #ifdef _KERNEL
1102cb27123Saguzovsk #define	_MAP_TEXTREPL	0x1000
111d2a70789SRichard Lowe #define	_MAP_RANDOMIZE	0x2000
1122cb27123Saguzovsk #endif /* _KERNEL */
1132cb27123Saguzovsk 
114*df5cd018SRobert Mustacchi /*
115*df5cd018SRobert Mustacchi  * Extensions to mmap flags. These are available in the default compilation
116*df5cd018SRobert Mustacchi  * environment, but not in a strict environment.
117*df5cd018SRobert Mustacchi  */
118*df5cd018SRobert Mustacchi #if !defined(_STRICT_POSIX)
1191b3b16f3STheo Schlossnagle #define	_MAP_LOW32	0x80	/* force mapping in lower 4G of address space */
1201b3b16f3STheo Schlossnagle #define	MAP_32BIT	_MAP_LOW32
1211b3b16f3STheo Schlossnagle 
1227c478bd9Sstevel@tonic-gate /*
1237c478bd9Sstevel@tonic-gate  * For the sake of backward object compatibility, we use the _MAP_NEW flag.
1247c478bd9Sstevel@tonic-gate  * This flag will be automatically or'ed in by the C library for all
1257c478bd9Sstevel@tonic-gate  * new mmap calls.  Previous binaries with old mmap calls will continue
1267c478bd9Sstevel@tonic-gate  * to get 0 or -1 for return values.  New mmap calls will get the mapped
1277c478bd9Sstevel@tonic-gate  * address as the return value if successful and -1 on errors.  By default,
1287c478bd9Sstevel@tonic-gate  * new mmap calls automatically have the kernel assign the map address
1297c478bd9Sstevel@tonic-gate  * unless the MAP_FIXED flag is given.
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate #define	_MAP_NEW	0x80000000	/* users should not need to use this */
132*df5cd018SRobert Mustacchi #endif	/* !defined(_STRICT_POSIX) */
1337c478bd9Sstevel@tonic-gate 
134*df5cd018SRobert Mustacchi #if !defined(_STRICT_POSIX)
1350616c1c3SMichael Corcoran /* External flags for mmapobj syscall (Exclusive of MAP_* flags above) */
1360616c1c3SMichael Corcoran #define	MMOBJ_PADDING		0x10000
1370616c1c3SMichael Corcoran #define	MMOBJ_INTERPRET		0x20000
1380616c1c3SMichael Corcoran 
1390616c1c3SMichael Corcoran #define	MMOBJ_ALL_FLAGS		(MMOBJ_PADDING | MMOBJ_INTERPRET)
1400616c1c3SMichael Corcoran 
1410616c1c3SMichael Corcoran /*
1420616c1c3SMichael Corcoran  * Values for mr_flags field of mmapobj_result_t below.
1430616c1c3SMichael Corcoran  * The bottom 16 bits are mutually exclusive and thus only one
1440616c1c3SMichael Corcoran  * of them can be set at a time.  Use MR_GET_TYPE below to check this value.
1450616c1c3SMichael Corcoran  * The top 16 bits are used for flags which are not mutually exclusive and
1460616c1c3SMichael Corcoran  * thus more than one of these flags can be set for a given mmapobj_result_t.
1470616c1c3SMichael Corcoran  *
1480616c1c3SMichael Corcoran  * MR_PADDING being set indicates that this memory range represents the user
1490616c1c3SMichael Corcoran  * requested padding.
1500616c1c3SMichael Corcoran  *
1510616c1c3SMichael Corcoran  * MR_HDR_ELF being set indicates that the ELF header of the mapped object
1520616c1c3SMichael Corcoran  * is mapped at mr_addr + mr_offset.
1530616c1c3SMichael Corcoran  */
1540616c1c3SMichael Corcoran 
1550616c1c3SMichael Corcoran /*
1560616c1c3SMichael Corcoran  * External flags for mr_flags field below.
1570616c1c3SMichael Corcoran  */
1580616c1c3SMichael Corcoran #define	MR_PADDING	0x1
1590616c1c3SMichael Corcoran #define	MR_HDR_ELF	0x2
1600616c1c3SMichael Corcoran 
1610616c1c3SMichael Corcoran /*
1620616c1c3SMichael Corcoran  * Internal flags for mr_flags field below.
1630616c1c3SMichael Corcoran  */
1640616c1c3SMichael Corcoran #ifdef	_KERNEL
1650616c1c3SMichael Corcoran #define	MR_RESV	0x80000000	/* overmapped /dev/null */
1660616c1c3SMichael Corcoran #endif	/* _KERNEL */
1670616c1c3SMichael Corcoran 
1680616c1c3SMichael Corcoran #define	MR_TYPE_MASK 0x0000ffff
1690616c1c3SMichael Corcoran #define	MR_GET_TYPE(val)	((val) & MR_TYPE_MASK)
1700616c1c3SMichael Corcoran 
1710616c1c3SMichael Corcoran #if	!defined(_ASM)
1720616c1c3SMichael Corcoran typedef struct mmapobj_result {
1730616c1c3SMichael Corcoran 	caddr_t		mr_addr;	/* mapping address */
1740616c1c3SMichael Corcoran 	size_t		mr_msize;	/* mapping size */
1750616c1c3SMichael Corcoran 	size_t		mr_fsize;	/* file size */
1760616c1c3SMichael Corcoran 	size_t		mr_offset;	/* offset into file */
1770616c1c3SMichael Corcoran 	uint_t		mr_prot;	/* the protections provided */
1780616c1c3SMichael Corcoran 	uint_t		mr_flags;	/* info on the mapping */
1790616c1c3SMichael Corcoran } mmapobj_result_t;
1800616c1c3SMichael Corcoran 
1810616c1c3SMichael Corcoran #if defined(_KERNEL) || defined(_SYSCALL32)
1820616c1c3SMichael Corcoran typedef struct mmapobj_result32 {
1830616c1c3SMichael Corcoran 	caddr32_t	mr_addr;	/* mapping address */
1840616c1c3SMichael Corcoran 	size32_t	mr_msize;	/* mapping size */
1850616c1c3SMichael Corcoran 	size32_t	mr_fsize;	/* file size */
1860616c1c3SMichael Corcoran 	size32_t	mr_offset;	/* offset into file */
1870616c1c3SMichael Corcoran 	uint_t		mr_prot;	/* the protections provided */
1880616c1c3SMichael Corcoran 	uint_t		mr_flags;	/* info on the mapping */
1890616c1c3SMichael Corcoran } mmapobj_result32_t;
1900616c1c3SMichael Corcoran #endif	/* defined(_KERNEL) || defined(_SYSCALL32) */
1910616c1c3SMichael Corcoran #endif	/* !defined(_ASM) */
192*df5cd018SRobert Mustacchi #endif	/* !defined(_STRICT_POSIX) */
1930616c1c3SMichael Corcoran 
1940616c1c3SMichael Corcoran #if	!defined(_ASM) && !defined(_KERNEL)
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate  * large file compilation environment setup
1977c478bd9Sstevel@tonic-gate  *
1987c478bd9Sstevel@tonic-gate  * In the LP64 compilation environment, map large file interfaces
1997c478bd9Sstevel@tonic-gate  * back to native versions where possible.
2007c478bd9Sstevel@tonic-gate  */
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
2037c478bd9Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
2047c478bd9Sstevel@tonic-gate #pragma redefine_extname	mmap	mmap64
2057c478bd9Sstevel@tonic-gate #else
2067c478bd9Sstevel@tonic-gate #define	mmap			mmap64
2077c478bd9Sstevel@tonic-gate #endif
2087c478bd9Sstevel@tonic-gate #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
2117c478bd9Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
2127c478bd9Sstevel@tonic-gate #pragma	redefine_extname	mmap64	mmap
2137c478bd9Sstevel@tonic-gate #else
2147c478bd9Sstevel@tonic-gate #define	mmap64			mmap
2157c478bd9Sstevel@tonic-gate #endif
2167c478bd9Sstevel@tonic-gate #endif	/* _LP64 && _LARGEFILE64_SOURCE */
2177c478bd9Sstevel@tonic-gate 
21802bc52beSkchow #ifdef __PRAGMA_REDEFINE_EXTNAME
21902bc52beSkchow #pragma redefine_extname	getpagesizes	getpagesizes2
22002bc52beSkchow #else
22102bc52beSkchow #define	getpagesizes	getpagesizes2
22202bc52beSkchow #endif
22302bc52beSkchow 
2247c478bd9Sstevel@tonic-gate /*
225*df5cd018SRobert Mustacchi  * Except for old binaries mmap() will return the resultant address of mapping
226*df5cd018SRobert Mustacchi  * on success and (void *)-1 on error.  illumos traditionally used a 'caddr_t'
227*df5cd018SRobert Mustacchi  * instead of a void * and did not require certain addresses to be const.
228*df5cd018SRobert Mustacchi  *
229*df5cd018SRobert Mustacchi  * Note, the following group of symbols are always visible since we have always
230*df5cd018SRobert Mustacchi  * exposed them and they appear to have been defined in most relevant versions
231*df5cd018SRobert Mustacchi  * of the specifications. While these are not strictly defined in ISO C, this
232*df5cd018SRobert Mustacchi  * header isn't a part of it and it isn't our job to guard against that.
2337c478bd9Sstevel@tonic-gate  */
2347c478bd9Sstevel@tonic-gate extern void *mmap(void *, size_t, int, int, int, off_t);
2357c478bd9Sstevel@tonic-gate extern int munmap(void *, size_t);
2367c478bd9Sstevel@tonic-gate extern int mprotect(void *, size_t, int);
2377c478bd9Sstevel@tonic-gate extern int msync(void *, size_t, int);
238*df5cd018SRobert Mustacchi 
2397c478bd9Sstevel@tonic-gate #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
2407c478bd9Sstevel@tonic-gate 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
2417c478bd9Sstevel@tonic-gate extern void *mmap64(void *, size_t, int, int, int, off64_t);
242*df5cd018SRobert Mustacchi #endif  /* _LARGEFILE64_SOURCE... */
243*df5cd018SRobert Mustacchi 
244*df5cd018SRobert Mustacchi /*
245*df5cd018SRobert Mustacchi  * These functions were all part of the older POSIX realtime suite and didn't
246*df5cd018SRobert Mustacchi  * make it into XPG until v5.
247*df5cd018SRobert Mustacchi  */
248*df5cd018SRobert Mustacchi 
249*df5cd018SRobert Mustacchi #if !defined(_STRICT_POSIX) || (_POSIX_C_SOURCE > 2) || defined(_XPG5)
250*df5cd018SRobert Mustacchi extern int mlock(const void *, size_t);
251*df5cd018SRobert Mustacchi extern int munlock(const void *, size_t);
252*df5cd018SRobert Mustacchi extern int mlockall(int);
253*df5cd018SRobert Mustacchi extern int munlockall(void);
254*df5cd018SRobert Mustacchi extern int shm_open(const char *, int, mode_t);
255*df5cd018SRobert Mustacchi extern int shm_unlink(const char *);
256*df5cd018SRobert Mustacchi #endif	/* !_STRICT_POSIX || _POSIX_C_SOURCE > 2 || _XPG5 */
257*df5cd018SRobert Mustacchi 
258*df5cd018SRobert Mustacchi #if !defined(_STRICT_POSIX) || defined(_XPG6)
259*df5cd018SRobert Mustacchi extern int posix_madvise(void *, size_t, int);
260*df5cd018SRobert Mustacchi #endif
261*df5cd018SRobert Mustacchi 
262*df5cd018SRobert Mustacchi /*
263*df5cd018SRobert Mustacchi  * The following are extensions that we have added.
264*df5cd018SRobert Mustacchi  */
265*df5cd018SRobert Mustacchi #if !defined(_STRICT_POSIX)
2667c478bd9Sstevel@tonic-gate extern int mincore(caddr_t, size_t, char *);
267*df5cd018SRobert Mustacchi extern int memcntl(void *, size_t, int, void *, int, int);
268*df5cd018SRobert Mustacchi extern int madvise(void *, size_t, int);
2697c478bd9Sstevel@tonic-gate extern int getpagesizes(size_t *, int);
27002bc52beSkchow extern int getpagesizes2(size_t *, int);
27131c6c9d8SMichael Corcoran extern int mmapobj(int, uint_t, mmapobj_result_t *, uint_t *, void *);
2727c478bd9Sstevel@tonic-gate /* guard visibility of uint64_t */
2737c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
2747c478bd9Sstevel@tonic-gate extern int meminfo(const uint64_t *, int, const uint_t *, int, uint64_t *,
2757c478bd9Sstevel@tonic-gate 	uint_t *);
2767c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
277*df5cd018SRobert Mustacchi #endif /* !defined(_STRICT_POSIX) */
2787c478bd9Sstevel@tonic-gate 
279019c3c43Sraf 
2807c478bd9Sstevel@tonic-gate /* mmap failure value */
2817c478bd9Sstevel@tonic-gate #define	MAP_FAILED	((void *) -1)
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate #endif	/* !_ASM && !_KERNEL */
2847c478bd9Sstevel@tonic-gate 
285*df5cd018SRobert Mustacchi #if !defined(_STRICT_POSIX)
2867c478bd9Sstevel@tonic-gate #if !defined(_ASM)
2877c478bd9Sstevel@tonic-gate /*
2887c478bd9Sstevel@tonic-gate  * structure for memcntl hat advise operations.
2897c478bd9Sstevel@tonic-gate  */
2907c478bd9Sstevel@tonic-gate struct memcntl_mha {
291*df5cd018SRobert Mustacchi 	uint_t		mha_cmd;	/* command(s) */
2927c478bd9Sstevel@tonic-gate 	uint_t		mha_flags;
2937c478bd9Sstevel@tonic-gate 	size_t		mha_pagesize;
2947c478bd9Sstevel@tonic-gate };
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
2977c478bd9Sstevel@tonic-gate struct memcntl_mha32 {
298*df5cd018SRobert Mustacchi 	uint_t		mha_cmd;	/* command(s) */
2997c478bd9Sstevel@tonic-gate 	uint_t		mha_flags;
3007c478bd9Sstevel@tonic-gate 	size32_t	mha_pagesize;
3017c478bd9Sstevel@tonic-gate };
3027c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
3037c478bd9Sstevel@tonic-gate #endif	/* !defined(_ASM) */
3047c478bd9Sstevel@tonic-gate 
3059d12795fSRobert Mustacchi /*
3069d12795fSRobert Mustacchi  * advice to madvise
3079d12795fSRobert Mustacchi  *
3089d12795fSRobert Mustacchi  * Note, if more than 4 bits worth of advice (eg. 16) are specified then
3099d12795fSRobert Mustacchi  * changes will be necessary to the struct vpage.
3109d12795fSRobert Mustacchi  */
3117c478bd9Sstevel@tonic-gate #define	MADV_NORMAL		0	/* no further special treatment */
3127c478bd9Sstevel@tonic-gate #define	MADV_RANDOM		1	/* expect random page references */
3137c478bd9Sstevel@tonic-gate #define	MADV_SEQUENTIAL		2	/* expect sequential page references */
3147c478bd9Sstevel@tonic-gate #define	MADV_WILLNEED		3	/* will need these pages */
3157c478bd9Sstevel@tonic-gate #define	MADV_DONTNEED		4	/* don't need these pages */
3167c478bd9Sstevel@tonic-gate #define	MADV_FREE		5	/* contents can be freed */
3177c478bd9Sstevel@tonic-gate #define	MADV_ACCESS_DEFAULT	6	/* default access */
3187c478bd9Sstevel@tonic-gate #define	MADV_ACCESS_LWP		7	/* next LWP to access heavily */
3197c478bd9Sstevel@tonic-gate #define	MADV_ACCESS_MANY	8	/* many processes to access heavily */
3208905f42cSBryan Cantrill #define	MADV_PURGE		9	/* contents will be purged */
3219d12795fSRobert Mustacchi 
322*df5cd018SRobert Mustacchi #endif	/* !defined(_STRICT_POSIX) */
3237c478bd9Sstevel@tonic-gate 
324*df5cd018SRobert Mustacchi #if !defined(_STRICT_POSIX) || defined(_XPG6)
325019c3c43Sraf /* advice to posix_madvise */
326019c3c43Sraf /* these values must be kept in sync with the MADV_* values, above */
327019c3c43Sraf #define	POSIX_MADV_NORMAL	0	/* MADV_NORMAL */
328019c3c43Sraf #define	POSIX_MADV_RANDOM	1	/* MADV_RANDOM */
329019c3c43Sraf #define	POSIX_MADV_SEQUENTIAL	2	/* MADV_SEQUENTIAL */
330019c3c43Sraf #define	POSIX_MADV_WILLNEED	3	/* MADV_WILLNEED */
331019c3c43Sraf #define	POSIX_MADV_DONTNEED	4	/* MADV_DONTNEED */
332019c3c43Sraf #endif
333019c3c43Sraf 
334*df5cd018SRobert Mustacchi /* flags to msync, always visible to match the function */
3357c478bd9Sstevel@tonic-gate #define	MS_OLDSYNC	0x0		/* old value of MS_SYNC */
3367c478bd9Sstevel@tonic-gate 					/* modified for UNIX98 compliance */
3377c478bd9Sstevel@tonic-gate #define	MS_SYNC		0x4		/* wait for msync */
3387c478bd9Sstevel@tonic-gate #define	MS_ASYNC	0x1		/* return immediately */
3397c478bd9Sstevel@tonic-gate #define	MS_INVALIDATE	0x2		/* invalidate caches */
3407c478bd9Sstevel@tonic-gate 
341*df5cd018SRobert Mustacchi #if !defined(_STRICT_POSIX) || (_POSIX_C_SOURCE > 2) || defined(_XPG5)
342*df5cd018SRobert Mustacchi /* flags to mlockall */
343*df5cd018SRobert Mustacchi #define	MCL_CURRENT	0x1		/* lock current mappings */
344*df5cd018SRobert Mustacchi #define	MCL_FUTURE	0x2		/* lock future mappings */
345*df5cd018SRobert Mustacchi #endif	/* !_STRICT_POSIX || _POSIX_C_SOURCE > 2 || _XPG5 */
346*df5cd018SRobert Mustacchi 
347*df5cd018SRobert Mustacchi /*
348*df5cd018SRobert Mustacchi  * The following flags are older variants used by memcntl that if more generally
349*df5cd018SRobert Mustacchi  * visible under more generous rules basically conflict all over the place due
350*df5cd018SRobert Mustacchi  * to the use of common words. As such, these retain their original feature
351*df5cd018SRobert Mustacchi  * guards, as weird as they may be.
352*df5cd018SRobert Mustacchi  */
353*df5cd018SRobert Mustacchi #if	(_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2)
354*df5cd018SRobert Mustacchi #define	SHARED		0x10	/* Use MEMCNTL_SHARED */
355*df5cd018SRobert Mustacchi #define	PRIVATE		0x20	/* Use MEMCNTL_PRIVATE */
356*df5cd018SRobert Mustacchi #define	VALID_ATTR	(PROT_READ|PROT_WRITE|PROT_EXEC|SHARED|PRIVATE)
357*df5cd018SRobert Mustacchi #endif	/* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) */
358*df5cd018SRobert Mustacchi 
359*df5cd018SRobert Mustacchi #if !defined(_STRICT_POSIX)
360*df5cd018SRobert Mustacchi /* these flags are used by memcntl */
361*df5cd018SRobert Mustacchi #define	PROC_TEXT		(PROT_EXEC | PROT_READ)
362*df5cd018SRobert Mustacchi #define	PROC_DATA		(PROT_READ | PROT_WRITE | PROT_EXEC)
363*df5cd018SRobert Mustacchi #define	MEMCNTL_SHARED		0x10
364*df5cd018SRobert Mustacchi #define	MENCNTL_PRIVATE		0x20
365*df5cd018SRobert Mustacchi #define	MEMCNTL_VALID_ATTR	(PROT_READ |PROT_WRITE |PROT_EXEC | \
366*df5cd018SRobert Mustacchi 				    MEMCNTL_SHARED | MEMCNTL_PRIVATE)
367*df5cd018SRobert Mustacchi 
368*df5cd018SRobert Mustacchi /* functions to memcntl */
3697c478bd9Sstevel@tonic-gate #define	MC_SYNC		1		/* sync with backing store */
3707c478bd9Sstevel@tonic-gate #define	MC_LOCK		2		/* lock pages in memory */
3717c478bd9Sstevel@tonic-gate #define	MC_UNLOCK	3		/* unlock pages from memory */
3727c478bd9Sstevel@tonic-gate #define	MC_ADVISE	4		/* give advice to management */
3737c478bd9Sstevel@tonic-gate #define	MC_LOCKAS	5		/* lock address space in memory */
3747c478bd9Sstevel@tonic-gate #define	MC_UNLOCKAS	6		/* unlock address space from memory */
3757c478bd9Sstevel@tonic-gate #define	MC_HAT_ADVISE	7		/* advise hat map size */
3769d12795fSRobert Mustacchi #define	MC_INHERIT_ZERO	8		/* zero out regions on fork() */
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate /* sub-commands for MC_HAT_ADVISE */
3797c478bd9Sstevel@tonic-gate #define	MHA_MAPSIZE_VA		0x1	/* set preferred page size */
3807c478bd9Sstevel@tonic-gate #define	MHA_MAPSIZE_BSSBRK	0x2	/* set preferred page size */
3817c478bd9Sstevel@tonic-gate 					/* for last bss adjacent to */
3827c478bd9Sstevel@tonic-gate 					/* brk area and brk area itself */
3837c478bd9Sstevel@tonic-gate #define	MHA_MAPSIZE_STACK	0x4	/* set preferred page size */
3847c478bd9Sstevel@tonic-gate 					/* processes main stack */
3857c478bd9Sstevel@tonic-gate /* definitions for meminfosys syscall */
3867c478bd9Sstevel@tonic-gate #define	MISYS_MEMINFO		0x0
3877c478bd9Sstevel@tonic-gate 
388ba3594baSGarrett D'Amore #if !defined(_ASM)
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate #if defined(_INT64_TYPE)
3917c478bd9Sstevel@tonic-gate /* private structure for meminfo */
3927c478bd9Sstevel@tonic-gate typedef struct meminfo {
3937c478bd9Sstevel@tonic-gate 	const uint64_t *mi_inaddr;	/* array of input addresses */
3947c478bd9Sstevel@tonic-gate 	const uint_t *mi_info_req;	/* array of types of info requested */
3957c478bd9Sstevel@tonic-gate 	uint64_t *mi_outdata;		/* array of results are placed */
3967c478bd9Sstevel@tonic-gate 	uint_t *mi_validity;		/* array of bitwise result codes */
3977c478bd9Sstevel@tonic-gate 	int mi_info_count;		/* number of pieces of info requested */
3987c478bd9Sstevel@tonic-gate } meminfo_t;
3997c478bd9Sstevel@tonic-gate #endif /* defined(_INT64_TYPE) */
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
4027c478bd9Sstevel@tonic-gate typedef struct meminfo32 {
4037c478bd9Sstevel@tonic-gate 	caddr32_t mi_inaddr;	/* array of input addresses */
4047c478bd9Sstevel@tonic-gate 	caddr32_t mi_info_req;	/* array of types of information requested */
4057c478bd9Sstevel@tonic-gate 	caddr32_t mi_outdata;	/* array of results are placed */
4067c478bd9Sstevel@tonic-gate 	caddr32_t mi_validity;	/* array of bitwise result codes */
4077c478bd9Sstevel@tonic-gate 	int32_t mi_info_count;	/* number of pieces of information requested */
4087c478bd9Sstevel@tonic-gate } meminfo32_t;
4097c478bd9Sstevel@tonic-gate #endif /* defined(_SYSCALL32) */
4107c478bd9Sstevel@tonic-gate 
411ba3594baSGarrett D'Amore #endif /* !defined(_ASM) */
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate /*
4147c478bd9Sstevel@tonic-gate  * info_req request type definitions for meminfo
4157c478bd9Sstevel@tonic-gate  * request types starting with MEMINFO_V are used for Virtual addresses
4167c478bd9Sstevel@tonic-gate  * and should not be mixed with MEMINFO_PLGRP which is targeted for Physical
4177c478bd9Sstevel@tonic-gate  * addresses
4187c478bd9Sstevel@tonic-gate  */
4197c478bd9Sstevel@tonic-gate #define	MEMINFO_SHIFT		16
4207c478bd9Sstevel@tonic-gate #define	MEMINFO_MASK		(0xFF << MEMINFO_SHIFT)
4217c478bd9Sstevel@tonic-gate #define	MEMINFO_VPHYSICAL	(0x01 << MEMINFO_SHIFT)	/* get physical addr */
4227c478bd9Sstevel@tonic-gate #define	MEMINFO_VLGRP		(0x02 << MEMINFO_SHIFT) /* get lgroup */
4237c478bd9Sstevel@tonic-gate #define	MEMINFO_VPAGESIZE	(0x03 << MEMINFO_SHIFT) /* size of phys page */
4247c478bd9Sstevel@tonic-gate #define	MEMINFO_VREPLCNT	(0x04 << MEMINFO_SHIFT) /* no. of replica */
4257c478bd9Sstevel@tonic-gate #define	MEMINFO_VREPL		(0x05 << MEMINFO_SHIFT) /* physical replica */
4267c478bd9Sstevel@tonic-gate #define	MEMINFO_VREPL_LGRP	(0x06 << MEMINFO_SHIFT) /* lgrp of replica */
4277c478bd9Sstevel@tonic-gate #define	MEMINFO_PLGRP		(0x07 << MEMINFO_SHIFT) /* lgroup for paddr */
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate /* maximum number of addresses meminfo() can process at a time */
4307c478bd9Sstevel@tonic-gate #define	MAX_MEMINFO_CNT	256
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate /* maximum number of request types */
4337c478bd9Sstevel@tonic-gate #define	MAX_MEMINFO_REQ	31
4347c478bd9Sstevel@tonic-gate 
435*df5cd018SRobert Mustacchi #endif /* !defined(_STRICT_POSIX) */
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4387c478bd9Sstevel@tonic-gate }
4397c478bd9Sstevel@tonic-gate #endif
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate #endif	/* _SYS_MMAN_H */
442