mman.h revision 118771
11541Srgrimes/*-
210937Swollman * Copyright (c) 1982, 1986, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
3310937Swollman *	@(#)mman.h	8.2 (Berkeley) 1/9/95
3437183Sjhay * $FreeBSD: head/sys/sys/mman.h 118771 2003-08-11 07:14:08Z bms $
351541Srgrimes */
361541Srgrimes
372169Spaul#ifndef _SYS_MMAN_H_
382169Spaul#define _SYS_MMAN_H_
391541Srgrimes
401541Srgrimes#include <sys/cdefs.h>
411541Srgrimes#include <sys/_types.h>
421541Srgrimes
431541Srgrimes#if __BSD_VISIBLE
441541Srgrimes/*
4532821Sdg * Inheritance for minherit()
461541Srgrimes */
471541Srgrimes#define INHERIT_SHARE	0
481541Srgrimes#define INHERIT_COPY	1
491541Srgrimes#define INHERIT_NONE	2
5032821Sdg#endif
5132821Sdg
5232821Sdg/*
5332821Sdg * Protections are chosen from these bits, or-ed together
5432821Sdg */
5532821Sdg#define	PROT_NONE	0x00	/* no permissions */
5611187Swollman#define	PROT_READ	0x01	/* pages can be read */
5711187Swollman#define	PROT_WRITE	0x02	/* pages can be written */
581541Srgrimes#define	PROT_EXEC	0x04	/* pages can be executed */
591541Srgrimes
601541Srgrimes/*
611541Srgrimes * Flags contain sharing type and options.
621541Srgrimes * Sharing types; choose one.
631541Srgrimes */
641541Srgrimes#define	MAP_SHARED	0x0001		/* share changes */
651541Srgrimes#define	MAP_PRIVATE	0x0002		/* changes are private */
661541Srgrimes#define	MAP_COPY	MAP_PRIVATE	/* Obsolete */
671541Srgrimes
686247Swollman#if __BSD_VISIBLE
696247Swollman/*
706247Swollman * Other flags
716247Swollman */
726247Swollman#define	MAP_FIXED	 0x0010	/* map addr must be exactly as requested */
7312045Solah#define	MAP_RENAME	 0x0020	/* Sun: rename private pages to file */
7432821Sdg#define	MAP_NORESERVE	 0x0040	/* Sun: don't reserve needed swap area */
751541Srgrimes#define	MAP_RESERVED0080 0x0080	/* previously misimplemented MAP_INHERIT */
761541Srgrimes#define	MAP_RESERVED0100 0x0100	/* previously unimplemented MAP_NOEXTEND */
7732821Sdg#define	MAP_HASSEMAPHORE 0x0200	/* region may contain semaphores */
7832821Sdg#define	MAP_STACK	 0x0400	/* region grows down, like a stack */
7932821Sdg#define	MAP_NOSYNC	 0x0800 /* page to but do not sync underlying file */
801541Srgrimes
811541Srgrimes/*
8232821Sdg * Mapping type
831541Srgrimes */
841541Srgrimes#define	MAP_FILE	 0x0000	/* map from file (default) */
851541Srgrimes#define	MAP_ANON	 0x1000	/* allocated from memory, swap space */
8632821Sdg
8732821Sdg/*
8832821Sdg * Extended flags
8932821Sdg */
901541Srgrimes#define	MAP_NOCORE	 0x00020000 /* dont include these pages in a coredump */
911541Srgrimes#endif /* __BSD_VISIBLE */
9232821Sdg
9332821Sdg#if __POSIX_VISIBLE >= 199309
941541Srgrimes/*
9513765Smpp * Process memory locking
961541Srgrimes */
971541Srgrimes#define MCL_CURRENT	0x0001	/* Lock only current memory */
981541Srgrimes#define MCL_FUTURE	0x0002	/* Lock all future memory as well */
9932821Sdg#endif
10032821Sdg
10111187Swollman/*
10232821Sdg * Error return from mmap()
10311187Swollman */
1041541Srgrimes#define MAP_FAILED	((void *)-1)
10532821Sdg
10632821Sdg/*
10732821Sdg * msync() flags
10811187Swollman */
10911187Swollman#define	MS_SYNC		0x0000	/* msync synchronously */
11032821Sdg#define MS_ASYNC	0x0001	/* return immediately */
11132821Sdg#define MS_INVALIDATE	0x0002	/* invalidate all cached data */
11211187Swollman
11332821Sdg#if __BSD_VISIBLE
1141541Srgrimes/*
1151541Srgrimes * Advice to madvise
11632821Sdg */
1171541Srgrimes#define	MADV_NORMAL	0	/* no further special treatment */
1181541Srgrimes#define	MADV_RANDOM	1	/* expect random page references */
1191541Srgrimes#define	MADV_SEQUENTIAL	2	/* expect sequential page references */
1201541Srgrimes#define	MADV_WILLNEED	3	/* will need these pages */
1211541Srgrimes#define	MADV_DONTNEED	4	/* dont need these pages */
1221541Srgrimes#define	MADV_FREE	5	/* dont need these pages, and junk contents */
1231541Srgrimes#define	MADV_NOSYNC	6	/* try to avoid flushes to physical media */
1241541Srgrimes#define	MADV_AUTOSYNC	7	/* revert to default flushing strategy */
1251541Srgrimes#define	MADV_NOCORE	8	/* do not include these pages in a core file */
1261541Srgrimes#define	MADV_CORE	9	/* revert to including pages in a core file */
1271541Srgrimes#define	MADV_PROTECT	10	/* protect process from pageout kill */
12832821Sdg
1291541Srgrimes/*
1301541Srgrimes * Return bits from mincore
1316247Swollman */
1326247Swollman#define	MINCORE_INCORE	 	 0x1 /* Page is incore */
1336247Swollman#define	MINCORE_REFERENCED	 0x2 /* Page has been referenced by us */
1341541Srgrimes#define	MINCORE_MODIFIED	 0x4 /* Page has been modified by us */
1351541Srgrimes#define	MINCORE_REFERENCED_OTHER 0x8 /* Page has been referenced */
1366247Swollman#define	MINCORE_MODIFIED_OTHER	0x10 /* Page has been modified */
1376247Swollman#endif /* __BSD_VISIBLE */
1386247Swollman
1396247Swollman/*
1406247Swollman * XXX missing POSIX_TYPED_MEM_* macros and
1416247Swollman * posix_typed_mem_info structure.
1426247Swollman */
1436247Swollman#if __POSIX_VISIBLE >= 200112
1446247Swollman#define	POSIX_MADV_NORMAL	MADV_NORMAL
1456247Swollman#define	POSIX_MADV_RANDOM	MADV_RANDOM
1466247Swollman#define	POSIX_MADV_SEQUENTIAL	MADV_SEQUENTIAL
1476247Swollman#define	POSIX_MADV_WILLNEED	MADV_WILLNEED
1486247Swollman#define	POSIX_MADV_DONTNEED	MADV_DONTNEED
1496247Swollman#endif
1506247Swollman
1516247Swollman#ifndef _MODE_T_DECLARED
1526247Swollmantypedef	__mode_t	mode_t;
1536247Swollman#define	_MODE_T_DECLARED
1546247Swollman#endif
1556247Swollman
1566247Swollman#ifndef _OFF_T_DECLARED
1576247Swollmantypedef	__off_t		off_t;
1586247Swollman#define	_OFF_T_DECLARED
1596247Swollman#endif
1606247Swollman
1616247Swollman#ifndef _SIZE_T_DECLARED
1626247Swollmantypedef	__size_t	size_t;
1636247Swollman#define	_SIZE_T_DECLARED
1646247Swollman#endif
1656247Swollman
1666247Swollman#ifndef _KERNEL
1676247Swollman
1686247Swollman__BEGIN_DECLS
1696283Swollman/*
1706247Swollman * XXX not yet implemented: mlockall(), munlockall(),
1711541Srgrimes * posix_mem_offset(), posix_typed_mem_get_info(), posix_typed_mem_open().
1721541Srgrimes */
1731541Srgrimes#if __BSD_VISIBLE
1741541Srgrimesint	madvise(void *, size_t, int);
1751541Srgrimesint	mincore(const void *, size_t, char *);
1761541Srgrimesint	minherit(void *, size_t, int);
1771541Srgrimes#endif
1781541Srgrimesint	mlock(const void *, size_t);
1791541Srgrimes#ifndef _MMAP_DECLARED
1801541Srgrimes#define	_MMAP_DECLARED
1811541Srgrimesvoid *	mmap(void *, size_t, int, int, int, off_t);
1821541Srgrimes#endif
18314753Swollmanint	mprotect(const void *, size_t, int);
18414753Swollmanint	msync(void *, size_t, int);
18514753Swollmanint	munlock(const void *, size_t);
18614753Swollmanint	munmap(void *, size_t);
18714753Swollman#if __POSIX_VISIBLE >= 200112
1881541Srgrimesint	posix_madvise(void *, size_t, int);
1891541Srgrimes#endif
1901541Srgrimes#if __POSIX_VISIBLE >= 199309
1911541Srgrimesint	mlockall(int);
1921541Srgrimesint	munlockall(void);
1931541Srgrimesint	shm_open(const char *, int, mode_t);
1941541Srgrimesint	shm_unlink(const char *);
1951541Srgrimes#endif
1961541Srgrimes__END_DECLS
1971541Srgrimes
1981541Srgrimes#endif /* !_KERNEL */
19914753Swollman
20014753Swollman#endif /* !_SYS_MMAN_H_ */
20114753Swollman