17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
5bfe60e2damico * Common Development and Distribution License (the "License").
6bfe60e2damico * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
21019c3c4raf
221b3b16fTheo Schlossnagle/* Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved. */
237c478bdstevel@tonic-gate/*
24ba3594bGarrett D'Amore * Copyright 2014 Garrett D'Amore <garrett@damore.org>
25ba3594bGarrett D'Amore *
26019c3c4raf * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
277c478bdstevel@tonic-gate * Use is subject to license terms.
289d12795Robert Mustacchi * Copyright 2015 Joyent, Inc.  All rights reserved.
297c478bdstevel@tonic-gate */
307c478bdstevel@tonic-gate
317c478bdstevel@tonic-gate/*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
327c478bdstevel@tonic-gate/*	  All Rights Reserved	*/
337c478bdstevel@tonic-gate
347c478bdstevel@tonic-gate/*
357c478bdstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
367c478bdstevel@tonic-gate * The Regents of the University of California
377c478bdstevel@tonic-gate * All Rights Reserved
387c478bdstevel@tonic-gate *
397c478bdstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
407c478bdstevel@tonic-gate * software developed by the University of California, Berkeley, and its
417c478bdstevel@tonic-gate * contributors.
427c478bdstevel@tonic-gate */
437c478bdstevel@tonic-gate
447c478bdstevel@tonic-gate#ifndef	_SYS_MMAN_H
457c478bdstevel@tonic-gate#define	_SYS_MMAN_H
467c478bdstevel@tonic-gate
477c478bdstevel@tonic-gate#include <sys/feature_tests.h>
487c478bdstevel@tonic-gate
497c478bdstevel@tonic-gate#ifdef	__cplusplus
507c478bdstevel@tonic-gateextern "C" {
517c478bdstevel@tonic-gate#endif
527c478bdstevel@tonic-gate
5331c6c9dMichael Corcoran#if	!defined(_ASM) && !defined(_KERNEL)
5431c6c9dMichael Corcoran#include <sys/types.h>
5531c6c9dMichael Corcoran#endif	/* !_ASM && !_KERNEL */
5631c6c9dMichael Corcoran
577c478bdstevel@tonic-gate/*
587c478bdstevel@tonic-gate * Protections are chosen from these bits, or-ed together.
597c478bdstevel@tonic-gate * Note - not all implementations literally provide all possible
607c478bdstevel@tonic-gate * combinations.  PROT_WRITE is often implemented as (PROT_READ |
617c478bdstevel@tonic-gate * PROT_WRITE) and (PROT_EXECUTE as PROT_READ | PROT_EXECUTE).
627c478bdstevel@tonic-gate * However, no implementation will permit a write to succeed
637c478bdstevel@tonic-gate * where PROT_WRITE has not been set.  Also, no implementation will
647c478bdstevel@tonic-gate * allow any access to succeed where prot is specified as PROT_NONE.
657c478bdstevel@tonic-gate */
667c478bdstevel@tonic-gate#define	PROT_READ	0x1		/* pages can be read */
677c478bdstevel@tonic-gate#define	PROT_WRITE	0x2		/* pages can be written */
687c478bdstevel@tonic-gate#define	PROT_EXEC	0x4		/* pages can be executed */
697c478bdstevel@tonic-gate
707c478bdstevel@tonic-gate#ifdef	_KERNEL
717c478bdstevel@tonic-gate#define	PROT_USER	0x8		/* pages are user accessable */
727c478bdstevel@tonic-gate#define	PROT_ZFOD	(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_USER)
737c478bdstevel@tonic-gate#define	PROT_ALL	(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_USER)
747c478bdstevel@tonic-gate#endif	/* _KERNEL */
757c478bdstevel@tonic-gate
767c478bdstevel@tonic-gate#define	PROT_NONE	0x0		/* pages cannot be accessed */
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gate/* sharing types:  must choose either SHARED or PRIVATE */
797c478bdstevel@tonic-gate#define	MAP_SHARED	1		/* share changes */
807c478bdstevel@tonic-gate#define	MAP_PRIVATE	2		/* changes are private */
817c478bdstevel@tonic-gate#define	MAP_TYPE	0xf		/* mask for share type */
827c478bdstevel@tonic-gate
837c478bdstevel@tonic-gate/* other flags to mmap (or-ed in to MAP_SHARED or MAP_PRIVATE) */
84ccd5347James Blachly#define	MAP_FILE	0		/* map from file (default) */
857c478bdstevel@tonic-gate#define	MAP_FIXED	0x10		/* user assigns address */
86d2a7078Richard Lowe/* Not implemented */
87d2a7078Richard Lowe#define	MAP_RENAME	0x20		/* rename private pages to file */
887c478bdstevel@tonic-gate#define	MAP_NORESERVE	0x40		/* don't reserve needed swap area */
89d2a7078Richard Lowe/* Note that 0x80 is _MAP_LOW32, defined below */
907c478bdstevel@tonic-gate#define	MAP_ANON	0x100		/* map anonymous pages directly */
917c478bdstevel@tonic-gate#define	MAP_ANONYMOUS	MAP_ANON	/* (source compatibility) */
927c478bdstevel@tonic-gate#define	MAP_ALIGN	0x200		/* addr specifies alignment */
937c478bdstevel@tonic-gate#define	MAP_TEXT	0x400		/* map code segment */
947c478bdstevel@tonic-gate#define	MAP_INITDATA	0x800		/* map data segment */
957c478bdstevel@tonic-gate
962cb2712aguzovsk#ifdef _KERNEL
972cb2712aguzovsk#define	_MAP_TEXTREPL	0x1000
98d2a7078Richard Lowe#define	_MAP_RANDOMIZE	0x2000
992cb2712aguzovsk#endif /* _KERNEL */
1002cb2712aguzovsk
1017c478bdstevel@tonic-gate#if	(_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2)
1027c478bdstevel@tonic-gate/* these flags are used by memcntl */
1037c478bdstevel@tonic-gate#define	PROC_TEXT	(PROT_EXEC | PROT_READ)
1047c478bdstevel@tonic-gate#define	PROC_DATA	(PROT_READ | PROT_WRITE | PROT_EXEC)
1057c478bdstevel@tonic-gate#define	SHARED		0x10
1067c478bdstevel@tonic-gate#define	PRIVATE		0x20
1077c478bdstevel@tonic-gate#define	VALID_ATTR  (PROT_READ|PROT_WRITE|PROT_EXEC|SHARED|PRIVATE)
1087c478bdstevel@tonic-gate#endif	/* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) */
1097c478bdstevel@tonic-gate
1107c478bdstevel@tonic-gate#if	(_POSIX_C_SOURCE <= 2) || defined(_XPG4_2)
1117c478bdstevel@tonic-gate#ifdef	_KERNEL
1127c478bdstevel@tonic-gate#define	PROT_EXCL	0x20
1137c478bdstevel@tonic-gate#endif	/* _KERNEL */
1147c478bdstevel@tonic-gate
1151b3b16fTheo Schlossnagle#define	_MAP_LOW32	0x80	/* force mapping in lower 4G of address space */
1161b3b16fTheo Schlossnagle#define	MAP_32BIT	_MAP_LOW32
1171b3b16fTheo Schlossnagle
1187c478bdstevel@tonic-gate/*
1197c478bdstevel@tonic-gate * For the sake of backward object compatibility, we use the _MAP_NEW flag.
1207c478bdstevel@tonic-gate * This flag will be automatically or'ed in by the C library for all
1217c478bdstevel@tonic-gate * new mmap calls.  Previous binaries with old mmap calls will continue
1227c478bdstevel@tonic-gate * to get 0 or -1 for return values.  New mmap calls will get the mapped
1237c478bdstevel@tonic-gate * address as the return value if successful and -1 on errors.  By default,
1247c478bdstevel@tonic-gate * new mmap calls automatically have the kernel assign the map address
1257c478bdstevel@tonic-gate * unless the MAP_FIXED flag is given.
1267c478bdstevel@tonic-gate */
1277c478bdstevel@tonic-gate#define	_MAP_NEW	0x80000000	/* users should not need to use this */
1287c478bdstevel@tonic-gate#endif	/* (_POSIX_C_SOURCE <= 2) */
1297c478bdstevel@tonic-gate
1300616c1cMichael Corcoran
13131c6c9dMichael Corcoran#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
1320616c1cMichael Corcoran/* External flags for mmapobj syscall (Exclusive of MAP_* flags above) */
1330616c1cMichael Corcoran#define	MMOBJ_PADDING		0x10000
1340616c1cMichael Corcoran#define	MMOBJ_INTERPRET		0x20000
1350616c1cMichael Corcoran
1360616c1cMichael Corcoran#define	MMOBJ_ALL_FLAGS		(MMOBJ_PADDING | MMOBJ_INTERPRET)
1370616c1cMichael Corcoran
1380616c1cMichael Corcoran/*
1390616c1cMichael Corcoran * Values for mr_flags field of mmapobj_result_t below.
1400616c1cMichael Corcoran * The bottom 16 bits are mutually exclusive and thus only one
1410616c1cMichael Corcoran * of them can be set at a time.  Use MR_GET_TYPE below to check this value.
1420616c1cMichael Corcoran * The top 16 bits are used for flags which are not mutually exclusive and
1430616c1cMichael Corcoran * thus more than one of these flags can be set for a given mmapobj_result_t.
1440616c1cMichael Corcoran *
1450616c1cMichael Corcoran * MR_PADDING being set indicates that this memory range represents the user
1460616c1cMichael Corcoran * requested padding.
1470616c1cMichael Corcoran *
1480616c1cMichael Corcoran * MR_HDR_ELF being set indicates that the ELF header of the mapped object
1490616c1cMichael Corcoran * is mapped at mr_addr + mr_offset.
1500616c1cMichael Corcoran *
1510616c1cMichael Corcoran * MR_HDR_AOUT being set indicates that the AOUT (4.x) header of the mapped
1520616c1cMichael Corcoran * object is mapped at mr_addr + mr_offset.
1530616c1cMichael Corcoran */
1540616c1cMichael Corcoran
1550616c1cMichael Corcoran/*
1560616c1cMichael Corcoran * External flags for mr_flags field below.
1570616c1cMichael Corcoran */
1580616c1cMichael Corcoran#define	MR_PADDING	0x1
1590616c1cMichael Corcoran#define	MR_HDR_ELF	0x2
1600616c1cMichael Corcoran#define	MR_HDR_AOUT	0x3
1610616c1cMichael Corcoran
1620616c1cMichael Corcoran/*
1630616c1cMichael Corcoran * Internal flags for mr_flags field below.
1640616c1cMichael Corcoran */
1650616c1cMichael Corcoran#ifdef	_KERNEL
1660616c1cMichael Corcoran#define	MR_RESV	0x80000000	/* overmapped /dev/null */
1670616c1cMichael Corcoran#endif	/* _KERNEL */
1680616c1cMichael Corcoran
1690616c1cMichael Corcoran#define	MR_TYPE_MASK 0x0000ffff
1700616c1cMichael Corcoran#define	MR_GET_TYPE(val)	((val) & MR_TYPE_MASK)
1710616c1cMichael Corcoran
1720616c1cMichael Corcoran#if	!defined(_ASM)
1730616c1cMichael Corcorantypedef struct mmapobj_result {
1740616c1cMichael Corcoran	caddr_t		mr_addr;	/* mapping address */
1750616c1cMichael Corcoran	size_t		mr_msize;	/* mapping size */
1760616c1cMichael Corcoran	size_t		mr_fsize;	/* file size */
1770616c1cMichael Corcoran	size_t		mr_offset;	/* offset into file */
1780616c1cMichael Corcoran	uint_t		mr_prot;	/* the protections provided */
1790616c1cMichael Corcoran	uint_t		mr_flags;	/* info on the mapping */
1800616c1cMichael Corcoran} mmapobj_result_t;
1810616c1cMichael Corcoran
1820616c1cMichael Corcoran#if defined(_KERNEL) || defined(_SYSCALL32)
1830616c1cMichael Corcorantypedef struct mmapobj_result32 {
1840616c1cMichael Corcoran	caddr32_t	mr_addr;	/* mapping address */
1850616c1cMichael Corcoran	size32_t	mr_msize;	/* mapping size */
1860616c1cMichael Corcoran	size32_t	mr_fsize;	/* file size */
1870616c1cMichael Corcoran	size32_t	mr_offset;	/* offset into file */
1880616c1cMichael Corcoran	uint_t		mr_prot;	/* the protections provided */
1890616c1cMichael Corcoran	uint_t		mr_flags;	/* info on the mapping */
1900616c1cMichael Corcoran} mmapobj_result32_t;
1910616c1cMichael Corcoran#endif	/* defined(_KERNEL) || defined(_SYSCALL32) */
1920616c1cMichael Corcoran#endif	/* !defined(_ASM) */
19331c6c9dMichael Corcoran#endif	/* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
1940616c1cMichael Corcoran
1950616c1cMichael Corcoran#if	!defined(_ASM) && !defined(_KERNEL)
1967c478bdstevel@tonic-gate/*
1977c478bdstevel@tonic-gate * large file compilation environment setup
1987c478bdstevel@tonic-gate *
1997c478bdstevel@tonic-gate * In the LP64 compilation environment, map large file interfaces
2007c478bdstevel@tonic-gate * back to native versions where possible.
2017c478bdstevel@tonic-gate */
2027c478bdstevel@tonic-gate
2037c478bdstevel@tonic-gate#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
2047c478bdstevel@tonic-gate#ifdef	__PRAGMA_REDEFINE_EXTNAME
2057c478bdstevel@tonic-gate#pragma redefine_extname	mmap	mmap64
2067c478bdstevel@tonic-gate#else
2077c478bdstevel@tonic-gate#define	mmap			mmap64
2087c478bdstevel@tonic-gate#endif
2097c478bdstevel@tonic-gate#endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
2107c478bdstevel@tonic-gate
2117c478bdstevel@tonic-gate#if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
2127c478bdstevel@tonic-gate#ifdef	__PRAGMA_REDEFINE_EXTNAME
2137c478bdstevel@tonic-gate#pragma	redefine_extname	mmap64	mmap
2147c478bdstevel@tonic-gate#else
2157c478bdstevel@tonic-gate#define	mmap64			mmap
2167c478bdstevel@tonic-gate#endif
2177c478bdstevel@tonic-gate#endif	/* _LP64 && _LARGEFILE64_SOURCE */
2187c478bdstevel@tonic-gate
21902bc52bkchow#ifdef __PRAGMA_REDEFINE_EXTNAME
22002bc52bkchow#pragma redefine_extname	getpagesizes	getpagesizes2
22102bc52bkchow#else
22202bc52bkchow#define	getpagesizes	getpagesizes2
22302bc52bkchow#endif
22402bc52bkchow
2257c478bdstevel@tonic-gate/*
2267c478bdstevel@tonic-gate * Except for old binaries mmap() will return the resultant
2277c478bdstevel@tonic-gate * address of mapping on success and (caddr_t)-1 on error.
2287c478bdstevel@tonic-gate */
2297c478bdstevel@tonic-gate#if (_POSIX_C_SOURCE > 2) || defined(_XPG4_2)
2307c478bdstevel@tonic-gateextern void *mmap(void *, size_t, int, int, int, off_t);
2317c478bdstevel@tonic-gateextern int munmap(void *, size_t);
2327c478bdstevel@tonic-gateextern int mprotect(void *, size_t, int);
2337c478bdstevel@tonic-gateextern int msync(void *, size_t, int);
2347c478bdstevel@tonic-gate#if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__)
2357c478bdstevel@tonic-gateextern int mlock(const void *, size_t);
2367c478bdstevel@tonic-gateextern int munlock(const void *, size_t);
2377c478bdstevel@tonic-gate#endif	/* (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2))... */
2387c478bdstevel@tonic-gate/* transitional large file interface version */
2397c478bdstevel@tonic-gate#if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
2407c478bdstevel@tonic-gate	    !defined(__PRAGMA_REDEFINE_EXTNAME))
2417c478bdstevel@tonic-gateextern void *mmap64(void *, size_t, int, int, int, off64_t);
2427c478bdstevel@tonic-gate#endif	/* _LARGEFILE64_SOURCE... */
2437c478bdstevel@tonic-gate#else	/* (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) */
2447c478bdstevel@tonic-gateextern caddr_t mmap(caddr_t, size_t, int, int, int, off_t);
2457c478bdstevel@tonic-gateextern int munmap(caddr_t, size_t);
2467c478bdstevel@tonic-gateextern int mprotect(caddr_t, size_t, int);
2477c478bdstevel@tonic-gateextern int msync(caddr_t, size_t, int);
2487c478bdstevel@tonic-gateextern int mlock(caddr_t, size_t);
2497c478bdstevel@tonic-gateextern int munlock(caddr_t, size_t);
2507c478bdstevel@tonic-gateextern int mincore(caddr_t, size_t, char *);
2517c478bdstevel@tonic-gateextern int memcntl(caddr_t, size_t, int, caddr_t, int, int);
2527c478bdstevel@tonic-gateextern int madvise(caddr_t, size_t, int);
2537c478bdstevel@tonic-gate#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
2547c478bdstevel@tonic-gateextern int getpagesizes(size_t *, int);
25502bc52bkchowextern int getpagesizes2(size_t *, int);
25631c6c9dMichael Corcoranextern int mmapobj(int, uint_t, mmapobj_result_t *, uint_t *, void *);
2577c478bdstevel@tonic-gate/* guard visibility of uint64_t */
2587c478bdstevel@tonic-gate#if defined(_INT64_TYPE)
2597c478bdstevel@tonic-gateextern int meminfo(const uint64_t *, int, const uint_t *, int, uint64_t *,
2607c478bdstevel@tonic-gate	uint_t *);
2617c478bdstevel@tonic-gate#endif /* defined(_INT64_TYPE) */
2627c478bdstevel@tonic-gate#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
2637c478bdstevel@tonic-gate/* transitional large file interface version */
2647c478bdstevel@tonic-gate#ifdef	_LARGEFILE64_SOURCE
2657c478bdstevel@tonic-gateextern caddr_t mmap64(caddr_t, size_t, int, int, int, off64_t);
2667c478bdstevel@tonic-gate#endif
2677c478bdstevel@tonic-gate#endif	/* (_POSIX_C_SOURCE > 2)  || defined(_XPG4_2) */
2687c478bdstevel@tonic-gate
2697c478bdstevel@tonic-gate#if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__)
2707c478bdstevel@tonic-gateextern int mlockall(int);
2717c478bdstevel@tonic-gateextern int munlockall(void);
272bfe60e2damicoextern int shm_open(const char *, int, mode_t);
273bfe60e2damicoextern int shm_unlink(const char *);
2747c478bdstevel@tonic-gate#endif
2757c478bdstevel@tonic-gate
276019c3c4raf#if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
277019c3c4rafextern int posix_madvise(void *, size_t, int);
278019c3c4raf#endif
279019c3c4raf
2807c478bdstevel@tonic-gate/* mmap failure value */
2817c478bdstevel@tonic-gate#define	MAP_FAILED	((void *) -1)
2827c478bdstevel@tonic-gate
2837c478bdstevel@tonic-gate
2847c478bdstevel@tonic-gate#endif	/* !_ASM && !_KERNEL */
2857c478bdstevel@tonic-gate
2867c478bdstevel@tonic-gate#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
2877c478bdstevel@tonic-gate#if !defined(_ASM)
2887c478bdstevel@tonic-gate/*
2897c478bdstevel@tonic-gate * structure for memcntl hat advise operations.
2907c478bdstevel@tonic-gate */
2917c478bdstevel@tonic-gatestruct memcntl_mha {
2927c478bdstevel@tonic-gate	uint_t 		mha_cmd;	/* command(s) */
2937c478bdstevel@tonic-gate	uint_t		mha_flags;
2947c478bdstevel@tonic-gate	size_t		mha_pagesize;
2957c478bdstevel@tonic-gate};
2967c478bdstevel@tonic-gate
2977c478bdstevel@tonic-gate#if defined(_SYSCALL32)
2987c478bdstevel@tonic-gatestruct memcntl_mha32 {
2997c478bdstevel@tonic-gate	uint_t 		mha_cmd;	/* command(s) */
3007c478bdstevel@tonic-gate	uint_t		mha_flags;
3017c478bdstevel@tonic-gate	size32_t	mha_pagesize;
3027c478bdstevel@tonic-gate};
3037c478bdstevel@tonic-gate#endif	/* _SYSCALL32 */
3047c478bdstevel@tonic-gate#endif	/* !defined(_ASM) */
3057c478bdstevel@tonic-gate#endif	/* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
3067c478bdstevel@tonic-gate
3077c478bdstevel@tonic-gate#if	(_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) || defined(__EXTENSIONS__)
3089d12795Robert Mustacchi/*
3099d12795Robert Mustacchi * advice to madvise
3109d12795Robert Mustacchi *
3119d12795Robert Mustacchi * Note, if more than 4 bits worth of advice (eg. 16) are specified then
3129d12795Robert Mustacchi * changes will be necessary to the struct vpage.
3139d12795Robert Mustacchi */
3147c478bdstevel@tonic-gate#define	MADV_NORMAL		0	/* no further special treatment */
3157c478bdstevel@tonic-gate#define	MADV_RANDOM		1	/* expect random page references */
3167c478bdstevel@tonic-gate#define	MADV_SEQUENTIAL		2	/* expect sequential page references */
3177c478bdstevel@tonic-gate#define	MADV_WILLNEED		3	/* will need these pages */
3187c478bdstevel@tonic-gate#define	MADV_DONTNEED		4	/* don't need these pages */
3197c478bdstevel@tonic-gate#define	MADV_FREE		5	/* contents can be freed */
3207c478bdstevel@tonic-gate#define	MADV_ACCESS_DEFAULT	6	/* default access */
3217c478bdstevel@tonic-gate#define	MADV_ACCESS_LWP		7	/* next LWP to access heavily */
3227c478bdstevel@tonic-gate#define	MADV_ACCESS_MANY	8	/* many processes to access heavily */
3238905f42Bryan Cantrill#define	MADV_PURGE		9	/* contents will be purged */
3249d12795Robert Mustacchi
3257c478bdstevel@tonic-gate#endif	/* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) ...  */
3267c478bdstevel@tonic-gate
327019c3c4raf#if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
328019c3c4raf/* advice to posix_madvise */
329019c3c4raf/* these values must be kept in sync with the MADV_* values, above */
330019c3c4raf#define	POSIX_MADV_NORMAL	0	/* MADV_NORMAL */
331019c3c4raf#define	POSIX_MADV_RANDOM	1	/* MADV_RANDOM */
332019c3c4raf#define	POSIX_MADV_SEQUENTIAL	2	/* MADV_SEQUENTIAL */
333019c3c4raf#define	POSIX_MADV_WILLNEED	3	/* MADV_WILLNEED */
334019c3c4raf#define	POSIX_MADV_DONTNEED	4	/* MADV_DONTNEED */
335019c3c4raf#endif
336019c3c4raf
3377c478bdstevel@tonic-gate/* flags to msync */
3387c478bdstevel@tonic-gate#define	MS_OLDSYNC	0x0		/* old value of MS_SYNC */
3397c478bdstevel@tonic-gate					/* modified for UNIX98 compliance */
3407c478bdstevel@tonic-gate#define	MS_SYNC		0x4		/* wait for msync */
3417c478bdstevel@tonic-gate#define	MS_ASYNC	0x1		/* return immediately */
3427c478bdstevel@tonic-gate#define	MS_INVALIDATE	0x2		/* invalidate caches */
3437c478bdstevel@tonic-gate
3447c478bdstevel@tonic-gate#if	(_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) || defined(__EXTENSIONS__)
3457c478bdstevel@tonic-gate/* functions to mctl */
3467c478bdstevel@tonic-gate#define	MC_SYNC		1		/* sync with backing store */
3477c478bdstevel@tonic-gate#define	MC_LOCK		2		/* lock pages in memory */
3487c478bdstevel@tonic-gate#define	MC_UNLOCK	3		/* unlock pages from memory */
3497c478bdstevel@tonic-gate#define	MC_ADVISE	4		/* give advice to management */
3507c478bdstevel@tonic-gate#define	MC_LOCKAS	5		/* lock address space in memory */
3517c478bdstevel@tonic-gate#define	MC_UNLOCKAS	6		/* unlock address space from memory */
3527c478bdstevel@tonic-gate#define	MC_HAT_ADVISE	7		/* advise hat map size */
3539d12795Robert Mustacchi#define	MC_INHERIT_ZERO	8		/* zero out regions on fork() */
3547c478bdstevel@tonic-gate
3557c478bdstevel@tonic-gate/* sub-commands for MC_HAT_ADVISE */
3567c478bdstevel@tonic-gate#define	MHA_MAPSIZE_VA		0x1	/* set preferred page size */
3577c478bdstevel@tonic-gate#define	MHA_MAPSIZE_BSSBRK	0x2	/* set preferred page size */
3587c478bdstevel@tonic-gate					/* for last bss adjacent to */
3597c478bdstevel@tonic-gate					/* brk area and brk area itself */
3607c478bdstevel@tonic-gate#define	MHA_MAPSIZE_STACK	0x4	/* set preferred page size */
3617c478bdstevel@tonic-gate					/* processes main stack */
3627c478bdstevel@tonic-gate
3637c478bdstevel@tonic-gate#endif	/* (_POSIX_C_SOURCE <= 2) && !defined(_XPG4_2) ... */
3647c478bdstevel@tonic-gate
3657c478bdstevel@tonic-gate#if (!defined(_XPG4_2) || (_POSIX_C_SOURCE > 2)) || defined(__EXTENSIONS__)
3667c478bdstevel@tonic-gate/* flags to mlockall */
3677c478bdstevel@tonic-gate#define	MCL_CURRENT	0x1		/* lock current mappings */
3687c478bdstevel@tonic-gate#define	MCL_FUTURE	0x2		/* lock future mappings */
3697c478bdstevel@tonic-gate#endif /* (!defined(_XPG4_2) || (_POSIX_C_SOURCE)) || defined(__EXTENSIONS__) */
3707c478bdstevel@tonic-gate
3717c478bdstevel@tonic-gate#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
3727c478bdstevel@tonic-gate
3737c478bdstevel@tonic-gate/* definitions for meminfosys syscall */
3747c478bdstevel@tonic-gate#define	MISYS_MEMINFO		0x0
3757c478bdstevel@tonic-gate
376ba3594bGarrett D'Amore#if !defined(_ASM)
3777c478bdstevel@tonic-gate
3787c478bdstevel@tonic-gate#if defined(_INT64_TYPE)
3797c478bdstevel@tonic-gate/* private structure for meminfo */
3807c478bdstevel@tonic-gatetypedef struct meminfo {
3817c478bdstevel@tonic-gate	const uint64_t *mi_inaddr;	/* array of input addresses */
3827c478bdstevel@tonic-gate	const uint_t *mi_info_req;	/* array of types of info requested */
3837c478bdstevel@tonic-gate	uint64_t *mi_outdata;		/* array of results are placed */
3847c478bdstevel@tonic-gate	uint_t *mi_validity;		/* array of bitwise result codes */
3857c478bdstevel@tonic-gate	int mi_info_count;		/* number of pieces of info requested */
3867c478bdstevel@tonic-gate} meminfo_t;
3877c478bdstevel@tonic-gate#endif /* defined(_INT64_TYPE) */
3887c478bdstevel@tonic-gate
3897c478bdstevel@tonic-gate#if defined(_SYSCALL32)
3907c478bdstevel@tonic-gatetypedef struct meminfo32 {
3917c478bdstevel@tonic-gate	caddr32_t mi_inaddr;	/* array of input addresses */
3927c478bdstevel@tonic-gate	caddr32_t mi_info_req;	/* array of types of information requested */
3937c478bdstevel@tonic-gate	caddr32_t mi_outdata;	/* array of results are placed */
3947c478bdstevel@tonic-gate	caddr32_t mi_validity;	/* array of bitwise result codes */
3957c478bdstevel@tonic-gate	int32_t mi_info_count;	/* number of pieces of information requested */
3967c478bdstevel@tonic-gate} meminfo32_t;
3977c478bdstevel@tonic-gate#endif /* defined(_SYSCALL32) */
3987c478bdstevel@tonic-gate
399ba3594bGarrett D'Amore#endif /* !defined(_ASM) */
4007c478bdstevel@tonic-gate
4017c478bdstevel@tonic-gate/*
4027c478bdstevel@tonic-gate * info_req request type definitions for meminfo
4037c478bdstevel@tonic-gate * request types starting with MEMINFO_V are used for Virtual addresses
4047c478bdstevel@tonic-gate * and should not be mixed with MEMINFO_PLGRP which is targeted for Physical
4057c478bdstevel@tonic-gate * addresses
4067c478bdstevel@tonic-gate */
4077c478bdstevel@tonic-gate#define	MEMINFO_SHIFT		16
4087c478bdstevel@tonic-gate#define	MEMINFO_MASK		(0xFF << MEMINFO_SHIFT)
4097c478bdstevel@tonic-gate#define	MEMINFO_VPHYSICAL	(0x01 << MEMINFO_SHIFT)	/* get physical addr */
4107c478bdstevel@tonic-gate#define	MEMINFO_VLGRP		(0x02 << MEMINFO_SHIFT) /* get lgroup */
4117c478bdstevel@tonic-gate#define	MEMINFO_VPAGESIZE	(0x03 << MEMINFO_SHIFT) /* size of phys page */
4127c478bdstevel@tonic-gate#define	MEMINFO_VREPLCNT	(0x04 << MEMINFO_SHIFT) /* no. of replica */
4137c478bdstevel@tonic-gate#define	MEMINFO_VREPL		(0x05 << MEMINFO_SHIFT) /* physical replica */
4147c478bdstevel@tonic-gate#define	MEMINFO_VREPL_LGRP	(0x06 << MEMINFO_SHIFT) /* lgrp of replica */
4157c478bdstevel@tonic-gate#define	MEMINFO_PLGRP		(0x07 << MEMINFO_SHIFT) /* lgroup for paddr */
4167c478bdstevel@tonic-gate
4177c478bdstevel@tonic-gate/* maximum number of addresses meminfo() can process at a time */
4187c478bdstevel@tonic-gate#define	MAX_MEMINFO_CNT	256
4197c478bdstevel@tonic-gate
4207c478bdstevel@tonic-gate/* maximum number of request types */
4217c478bdstevel@tonic-gate#define	MAX_MEMINFO_REQ	31
4227c478bdstevel@tonic-gate
4237c478bdstevel@tonic-gate#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
4247c478bdstevel@tonic-gate
4257c478bdstevel@tonic-gate#ifdef	__cplusplus
4267c478bdstevel@tonic-gate}
4277c478bdstevel@tonic-gate#endif
4287c478bdstevel@tonic-gate
4297c478bdstevel@tonic-gate#endif	/* _SYS_MMAN_H */
430