11541Srgrimes/*-
21541Srgrimes * 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 * 4. Neither the name of the University nor the names of its contributors
141541Srgrimes *    may be used to endorse or promote products derived from this software
151541Srgrimes *    without specific prior written permission.
161541Srgrimes *
171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271541Srgrimes * SUCH DAMAGE.
281541Srgrimes *
2914482Shsu *	@(#)mman.h	8.2 (Berkeley) 1/9/95
3050477Speter * $FreeBSD$
311541Srgrimes */
321541Srgrimes
332165Spaul#ifndef _SYS_MMAN_H_
342165Spaul#define _SYS_MMAN_H_
352165Spaul
36102325Smike#include <sys/cdefs.h>
37102325Smike#include <sys/_types.h>
3834319Sdufault
39102325Smike#if __BSD_VISIBLE
401541Srgrimes/*
4182295Sdillon * Inheritance for minherit()
4282295Sdillon */
4382295Sdillon#define INHERIT_SHARE	0
4482295Sdillon#define INHERIT_COPY	1
4582295Sdillon#define INHERIT_NONE	2
46102325Smike#endif
4782295Sdillon
4882295Sdillon/*
491541Srgrimes * Protections are chosen from these bits, or-ed together
501541Srgrimes */
5114482Shsu#define	PROT_NONE	0x00	/* no permissions */
521541Srgrimes#define	PROT_READ	0x01	/* pages can be read */
531541Srgrimes#define	PROT_WRITE	0x02	/* pages can be written */
541541Srgrimes#define	PROT_EXEC	0x04	/* pages can be executed */
551541Srgrimes
561541Srgrimes/*
571541Srgrimes * Flags contain sharing type and options.
581541Srgrimes * Sharing types; choose one.
591541Srgrimes */
609507Sdg#define	MAP_SHARED	0x0001		/* share changes */
619507Sdg#define	MAP_PRIVATE	0x0002		/* changes are private */
62144531Sdas#if __BSD_VISIBLE
639507Sdg#define	MAP_COPY	MAP_PRIVATE	/* Obsolete */
64144531Sdas#endif
651541Srgrimes
661541Srgrimes/*
671541Srgrimes * Other flags
681541Srgrimes */
691541Srgrimes#define	MAP_FIXED	 0x0010	/* map addr must be exactly as requested */
70144531Sdas
71144531Sdas#if __BSD_VISIBLE
721541Srgrimes#define	MAP_RENAME	 0x0020	/* Sun: rename private pages to file */
731541Srgrimes#define	MAP_NORESERVE	 0x0040	/* Sun: don't reserve needed swap area */
7482295Sdillon#define	MAP_RESERVED0080 0x0080	/* previously misimplemented MAP_INHERIT */
7582285Sdillon#define	MAP_RESERVED0100 0x0100	/* previously unimplemented MAP_NOEXTEND */
761541Srgrimes#define	MAP_HASSEMAPHORE 0x0200	/* region may contain semaphores */
7742360Sjulian#define	MAP_STACK	 0x0400	/* region grows down, like a stack */
7857550Sps#define	MAP_NOSYNC	 0x0800 /* page to but do not sync underlying file */
791541Srgrimes
8057550Sps/*
81102325Smike * Mapping type
82102325Smike */
83102325Smike#define	MAP_FILE	 0x0000	/* map from file (default) */
84102325Smike#define	MAP_ANON	 0x1000	/* allocated from memory, swap space */
85198973Sed#ifndef _KERNEL
86198973Sed#define	MAP_ANONYMOUS	 MAP_ANON /* For compatibility. */
87198973Sed#endif /* !_KERNEL */
88102325Smike
89102325Smike/*
9057550Sps * Extended flags
9157550Sps */
9257550Sps#define	MAP_NOCORE	 0x00020000 /* dont include these pages in a coredump */
93211937Salc#define	MAP_PREFAULT_READ 0x00040000 /* prefault mapping for reading */
94255426Sjhb#ifdef __LP64__
95255426Sjhb#define	MAP_32BIT	 0x00080000 /* map in the low 2GB of address space */
96255426Sjhb#endif
97254430Sjhb
98254430Sjhb/*
99254430Sjhb * Request specific alignment (n == log2 of the desired alignment).
100254430Sjhb *
101254430Sjhb * MAP_ALIGNED_SUPER requests optimal superpage alignment, but does
102254430Sjhb * not enforce a specific alignment.
103254430Sjhb */
104254430Sjhb#define	MAP_ALIGNED(n)	 ((n) << MAP_ALIGNMENT_SHIFT)
105254430Sjhb#define	MAP_ALIGNMENT_SHIFT	24
106254430Sjhb#define	MAP_ALIGNMENT_MASK	MAP_ALIGNED(0xff)
107254430Sjhb#define	MAP_ALIGNED_SUPER	MAP_ALIGNED(1) /* align on a superpage */
108102325Smike#endif /* __BSD_VISIBLE */
10957550Sps
110102325Smike#if __POSIX_VISIBLE >= 199309
1111541Srgrimes/*
11234030Sdufault * Process memory locking
11334030Sdufault */
11434030Sdufault#define MCL_CURRENT	0x0001	/* Lock only current memory */
11534030Sdufault#define MCL_FUTURE	0x0002	/* Lock all future memory as well */
116102325Smike#endif
11734030Sdufault
11834030Sdufault/*
11920346Salex * Error return from mmap()
12020346Salex */
12132131Salex#define MAP_FAILED	((void *)-1)
12220346Salex
12320346Salex/*
1247358Sdg * msync() flags
1257358Sdg */
12631497Sdyson#define	MS_SYNC		0x0000	/* msync synchronously */
1277358Sdg#define MS_ASYNC	0x0001	/* return immediately */
1287358Sdg#define MS_INVALIDATE	0x0002	/* invalidate all cached data */
1297358Sdg
1307358Sdg/*
1311541Srgrimes * Advice to madvise
1321541Srgrimes */
133144531Sdas#define	_MADV_NORMAL	0	/* no further special treatment */
134144531Sdas#define	_MADV_RANDOM	1	/* expect random page references */
135144531Sdas#define	_MADV_SEQUENTIAL 2	/* expect sequential page references */
136144531Sdas#define	_MADV_WILLNEED	3	/* will need these pages */
137144531Sdas#define	_MADV_DONTNEED	4	/* dont need these pages */
138144531Sdas
139144531Sdas#if __BSD_VISIBLE
140144531Sdas#define	MADV_NORMAL	_MADV_NORMAL
141144531Sdas#define	MADV_RANDOM	_MADV_RANDOM
142144531Sdas#define	MADV_SEQUENTIAL _MADV_SEQUENTIAL
143144531Sdas#define	MADV_WILLNEED	_MADV_WILLNEED
144144531Sdas#define	MADV_DONTNEED	_MADV_DONTNEED
14515873Sdyson#define	MADV_FREE	5	/* dont need these pages, and junk contents */
14654467Sdillon#define	MADV_NOSYNC	6	/* try to avoid flushes to physical media */
14754467Sdillon#define	MADV_AUTOSYNC	7	/* revert to default flushing strategy */
14857550Sps#define	MADV_NOCORE	8	/* do not include these pages in a core file */
14957550Sps#define	MADV_CORE	9	/* revert to including pages in a core file */
150112881Swes#define	MADV_PROTECT	10	/* protect process from pageout kill */
1511541Srgrimes
15215819Sdyson/*
15315819Sdyson * Return bits from mincore
15415819Sdyson */
15515819Sdyson#define	MINCORE_INCORE	 	 0x1 /* Page is incore */
15615819Sdyson#define	MINCORE_REFERENCED	 0x2 /* Page has been referenced by us */
15715819Sdyson#define	MINCORE_MODIFIED	 0x4 /* Page has been modified by us */
15815819Sdyson#define	MINCORE_REFERENCED_OTHER 0x8 /* Page has been referenced */
15915819Sdyson#define	MINCORE_MODIFIED_OTHER	0x10 /* Page has been modified */
160177680Sps#define	MINCORE_SUPER		0x20 /* Page is a "super" page */
161175164Sjhb
162175164Sjhb/*
163175164Sjhb * Anonymous object constant for shm_open().
164175164Sjhb */
165175164Sjhb#define	SHM_ANON		((char *)1)
166102325Smike#endif /* __BSD_VISIBLE */
16715819Sdyson
168102325Smike/*
169118684Sbms * XXX missing POSIX_TYPED_MEM_* macros and
170102325Smike * posix_typed_mem_info structure.
171102325Smike */
172118684Sbms#if __POSIX_VISIBLE >= 200112
173144531Sdas#define	POSIX_MADV_NORMAL	_MADV_NORMAL
174144531Sdas#define	POSIX_MADV_RANDOM	_MADV_RANDOM
175144531Sdas#define	POSIX_MADV_SEQUENTIAL	_MADV_SEQUENTIAL
176144531Sdas#define	POSIX_MADV_WILLNEED	_MADV_WILLNEED
177144531Sdas#define	POSIX_MADV_DONTNEED	_MADV_DONTNEED
178118684Sbms#endif
179102325Smike
180102325Smike#ifndef _MODE_T_DECLARED
181102325Smiketypedef	__mode_t	mode_t;
182102325Smike#define	_MODE_T_DECLARED
183102325Smike#endif
184102325Smike
185102325Smike#ifndef _OFF_T_DECLARED
186102325Smiketypedef	__off_t		off_t;
187102325Smike#define	_OFF_T_DECLARED
188102325Smike#endif
189102325Smike
190102325Smike#ifndef _SIZE_T_DECLARED
191102325Smiketypedef	__size_t	size_t;
192102325Smike#define	_SIZE_T_DECLARED
193102325Smike#endif
194102325Smike
195233760Sjhb#if defined(_KERNEL) || defined(_WANT_FILE)
196254603Skib#include <sys/lock.h>
197254603Skib#include <sys/mutex.h>
198254603Skib#include <sys/queue.h>
199254603Skib#include <sys/rangelock.h>
200175164Sjhb#include <vm/vm.h>
2011541Srgrimes
202228509Sjhbstruct file;
203228509Sjhb
204175164Sjhbstruct shmfd {
205175164Sjhb	size_t		shm_size;
206175164Sjhb	vm_object_t	shm_object;
207175164Sjhb	int		shm_refs;
208175164Sjhb	uid_t		shm_uid;
209175164Sjhb	gid_t		shm_gid;
210175164Sjhb	mode_t		shm_mode;
211228509Sjhb	int		shm_kmappings;
212175164Sjhb
213175164Sjhb	/*
214175164Sjhb	 * Values maintained solely to make this a better-behaved file
215175164Sjhb	 * descriptor for fstat() to run on.
216175164Sjhb	 */
217175164Sjhb	struct timespec	shm_atime;
218175164Sjhb	struct timespec	shm_mtime;
219175164Sjhb	struct timespec	shm_ctime;
220175164Sjhb	struct timespec	shm_birthtime;
221175164Sjhb
222175164Sjhb	struct label	*shm_label;		/* MAC label */
223233760Sjhb	const char	*shm_path;
224254603Skib
225254603Skib	struct rangelock shm_rl;
226254603Skib	struct mtx	shm_mtx;
227175164Sjhb};
228233760Sjhb#endif
229175164Sjhb
230233760Sjhb#ifdef _KERNEL
231175164Sjhbint	shm_mmap(struct shmfd *shmfd, vm_size_t objsize, vm_ooffset_t foff,
232175164Sjhb	    vm_object_t *obj);
233228509Sjhbint	shm_map(struct file *fp, size_t size, off_t offset, void **memp);
234228509Sjhbint	shm_unmap(struct file *fp, void *mem, size_t size);
235233760Sjhbvoid	shm_path(struct shmfd *shmfd, char *path, size_t size);
236175164Sjhb
237175164Sjhb#else /* !_KERNEL */
238175164Sjhb
2391541Srgrimes__BEGIN_DECLS
240102325Smike/*
241128680Smux * XXX not yet implemented: posix_mem_offset(), posix_typed_mem_get_info(),
242128680Smux * posix_typed_mem_open().
243102325Smike */
244102325Smike#if __BSD_VISIBLE
245197331Salcint	getpagesizes(size_t *, int);
246102325Smikeint	madvise(void *, size_t, int);
247102325Smikeint	mincore(const void *, size_t, char *);
248102325Smikeint	minherit(void *, size_t, int);
249102325Smike#endif
250102325Smikeint	mlock(const void *, size_t);
25124896Sbde#ifndef _MMAP_DECLARED
25224896Sbde#define	_MMAP_DECLARED
25392719Salfredvoid *	mmap(void *, size_t, int, int, int, off_t);
25424896Sbde#endif
25592719Salfredint	mprotect(const void *, size_t, int);
25692719Salfredint	msync(void *, size_t, int);
25792719Salfredint	munlock(const void *, size_t);
25892719Salfredint	munmap(void *, size_t);
259118684Sbms#if __POSIX_VISIBLE >= 200112
260118684Sbmsint	posix_madvise(void *, size_t, int);
261118684Sbms#endif
262102325Smike#if __POSIX_VISIBLE >= 199309
263118771Sbmsint	mlockall(int);
264118771Sbmsint	munlockall(void);
265102325Smikeint	shm_open(const char *, int, mode_t);
266102325Smikeint	shm_unlink(const char *);
26734030Sdufault#endif
2681541Srgrimes__END_DECLS
2691541Srgrimes
27055205Speter#endif /* !_KERNEL */
2712165Spaul
272102325Smike#endif /* !_SYS_MMAN_H_ */
273