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 */
92267901Skib#define	MAP_EXCL	 0x00004000 /* for MAP_FIXED, fail if address is used */
9357550Sps#define	MAP_NOCORE	 0x00020000 /* dont include these pages in a coredump */
94211937Salc#define	MAP_PREFAULT_READ 0x00040000 /* prefault mapping for reading */
95255426Sjhb#ifdef __LP64__
96255426Sjhb#define	MAP_32BIT	 0x00080000 /* map in the low 2GB of address space */
97255426Sjhb#endif
98254430Sjhb
99254430Sjhb/*
100254430Sjhb * Request specific alignment (n == log2 of the desired alignment).
101254430Sjhb *
102254430Sjhb * MAP_ALIGNED_SUPER requests optimal superpage alignment, but does
103254430Sjhb * not enforce a specific alignment.
104254430Sjhb */
105254430Sjhb#define	MAP_ALIGNED(n)	 ((n) << MAP_ALIGNMENT_SHIFT)
106254430Sjhb#define	MAP_ALIGNMENT_SHIFT	24
107254430Sjhb#define	MAP_ALIGNMENT_MASK	MAP_ALIGNED(0xff)
108254430Sjhb#define	MAP_ALIGNED_SUPER	MAP_ALIGNED(1) /* align on a superpage */
109102325Smike#endif /* __BSD_VISIBLE */
11057550Sps
111102325Smike#if __POSIX_VISIBLE >= 199309
1121541Srgrimes/*
11334030Sdufault * Process memory locking
11434030Sdufault */
11534030Sdufault#define MCL_CURRENT	0x0001	/* Lock only current memory */
11634030Sdufault#define MCL_FUTURE	0x0002	/* Lock all future memory as well */
117102325Smike#endif
11834030Sdufault
11934030Sdufault/*
12020346Salex * Error return from mmap()
12120346Salex */
12232131Salex#define MAP_FAILED	((void *)-1)
12320346Salex
12420346Salex/*
1257358Sdg * msync() flags
1267358Sdg */
12731497Sdyson#define	MS_SYNC		0x0000	/* msync synchronously */
1287358Sdg#define MS_ASYNC	0x0001	/* return immediately */
1297358Sdg#define MS_INVALIDATE	0x0002	/* invalidate all cached data */
1307358Sdg
1317358Sdg/*
1321541Srgrimes * Advice to madvise
1331541Srgrimes */
134144531Sdas#define	_MADV_NORMAL	0	/* no further special treatment */
135144531Sdas#define	_MADV_RANDOM	1	/* expect random page references */
136144531Sdas#define	_MADV_SEQUENTIAL 2	/* expect sequential page references */
137144531Sdas#define	_MADV_WILLNEED	3	/* will need these pages */
138144531Sdas#define	_MADV_DONTNEED	4	/* dont need these pages */
139144531Sdas
140144531Sdas#if __BSD_VISIBLE
141144531Sdas#define	MADV_NORMAL	_MADV_NORMAL
142144531Sdas#define	MADV_RANDOM	_MADV_RANDOM
143144531Sdas#define	MADV_SEQUENTIAL _MADV_SEQUENTIAL
144144531Sdas#define	MADV_WILLNEED	_MADV_WILLNEED
145144531Sdas#define	MADV_DONTNEED	_MADV_DONTNEED
14615873Sdyson#define	MADV_FREE	5	/* dont need these pages, and junk contents */
14754467Sdillon#define	MADV_NOSYNC	6	/* try to avoid flushes to physical media */
14854467Sdillon#define	MADV_AUTOSYNC	7	/* revert to default flushing strategy */
14957550Sps#define	MADV_NOCORE	8	/* do not include these pages in a core file */
15057550Sps#define	MADV_CORE	9	/* revert to including pages in a core file */
151112881Swes#define	MADV_PROTECT	10	/* protect process from pageout kill */
1521541Srgrimes
15315819Sdyson/*
15415819Sdyson * Return bits from mincore
15515819Sdyson */
15615819Sdyson#define	MINCORE_INCORE	 	 0x1 /* Page is incore */
15715819Sdyson#define	MINCORE_REFERENCED	 0x2 /* Page has been referenced by us */
15815819Sdyson#define	MINCORE_MODIFIED	 0x4 /* Page has been modified by us */
15915819Sdyson#define	MINCORE_REFERENCED_OTHER 0x8 /* Page has been referenced */
16015819Sdyson#define	MINCORE_MODIFIED_OTHER	0x10 /* Page has been modified */
161177680Sps#define	MINCORE_SUPER		0x20 /* Page is a "super" page */
162175164Sjhb
163175164Sjhb/*
164175164Sjhb * Anonymous object constant for shm_open().
165175164Sjhb */
166175164Sjhb#define	SHM_ANON		((char *)1)
167102325Smike#endif /* __BSD_VISIBLE */
16815819Sdyson
169102325Smike/*
170118684Sbms * XXX missing POSIX_TYPED_MEM_* macros and
171102325Smike * posix_typed_mem_info structure.
172102325Smike */
173118684Sbms#if __POSIX_VISIBLE >= 200112
174144531Sdas#define	POSIX_MADV_NORMAL	_MADV_NORMAL
175144531Sdas#define	POSIX_MADV_RANDOM	_MADV_RANDOM
176144531Sdas#define	POSIX_MADV_SEQUENTIAL	_MADV_SEQUENTIAL
177144531Sdas#define	POSIX_MADV_WILLNEED	_MADV_WILLNEED
178144531Sdas#define	POSIX_MADV_DONTNEED	_MADV_DONTNEED
179118684Sbms#endif
180102325Smike
181102325Smike#ifndef _MODE_T_DECLARED
182102325Smiketypedef	__mode_t	mode_t;
183102325Smike#define	_MODE_T_DECLARED
184102325Smike#endif
185102325Smike
186102325Smike#ifndef _OFF_T_DECLARED
187102325Smiketypedef	__off_t		off_t;
188102325Smike#define	_OFF_T_DECLARED
189102325Smike#endif
190102325Smike
191102325Smike#ifndef _SIZE_T_DECLARED
192102325Smiketypedef	__size_t	size_t;
193102325Smike#define	_SIZE_T_DECLARED
194102325Smike#endif
195102325Smike
196233760Sjhb#if defined(_KERNEL) || defined(_WANT_FILE)
197254603Skib#include <sys/lock.h>
198254603Skib#include <sys/mutex.h>
199254603Skib#include <sys/queue.h>
200254603Skib#include <sys/rangelock.h>
201175164Sjhb#include <vm/vm.h>
2021541Srgrimes
203228509Sjhbstruct file;
204228509Sjhb
205175164Sjhbstruct shmfd {
206175164Sjhb	size_t		shm_size;
207175164Sjhb	vm_object_t	shm_object;
208175164Sjhb	int		shm_refs;
209175164Sjhb	uid_t		shm_uid;
210175164Sjhb	gid_t		shm_gid;
211175164Sjhb	mode_t		shm_mode;
212228509Sjhb	int		shm_kmappings;
213175164Sjhb
214175164Sjhb	/*
215175164Sjhb	 * Values maintained solely to make this a better-behaved file
216175164Sjhb	 * descriptor for fstat() to run on.
217175164Sjhb	 */
218175164Sjhb	struct timespec	shm_atime;
219175164Sjhb	struct timespec	shm_mtime;
220175164Sjhb	struct timespec	shm_ctime;
221175164Sjhb	struct timespec	shm_birthtime;
222271399Sjhb	ino_t		shm_ino;
223175164Sjhb
224175164Sjhb	struct label	*shm_label;		/* MAC label */
225233760Sjhb	const char	*shm_path;
226254603Skib
227254603Skib	struct rangelock shm_rl;
228254603Skib	struct mtx	shm_mtx;
229175164Sjhb};
230233760Sjhb#endif
231175164Sjhb
232233760Sjhb#ifdef _KERNEL
233175164Sjhbint	shm_mmap(struct shmfd *shmfd, vm_size_t objsize, vm_ooffset_t foff,
234175164Sjhb	    vm_object_t *obj);
235228509Sjhbint	shm_map(struct file *fp, size_t size, off_t offset, void **memp);
236228509Sjhbint	shm_unmap(struct file *fp, void *mem, size_t size);
237233760Sjhbvoid	shm_path(struct shmfd *shmfd, char *path, size_t size);
238175164Sjhb
239175164Sjhb#else /* !_KERNEL */
240175164Sjhb
2411541Srgrimes__BEGIN_DECLS
242102325Smike/*
243128680Smux * XXX not yet implemented: posix_mem_offset(), posix_typed_mem_get_info(),
244128680Smux * posix_typed_mem_open().
245102325Smike */
246102325Smike#if __BSD_VISIBLE
247197331Salcint	getpagesizes(size_t *, int);
248102325Smikeint	madvise(void *, size_t, int);
249102325Smikeint	mincore(const void *, size_t, char *);
250102325Smikeint	minherit(void *, size_t, int);
251102325Smike#endif
252102325Smikeint	mlock(const void *, size_t);
25324896Sbde#ifndef _MMAP_DECLARED
25424896Sbde#define	_MMAP_DECLARED
25592719Salfredvoid *	mmap(void *, size_t, int, int, int, off_t);
25624896Sbde#endif
25792719Salfredint	mprotect(const void *, size_t, int);
25892719Salfredint	msync(void *, size_t, int);
25992719Salfredint	munlock(const void *, size_t);
26092719Salfredint	munmap(void *, size_t);
261118684Sbms#if __POSIX_VISIBLE >= 200112
262118684Sbmsint	posix_madvise(void *, size_t, int);
263118684Sbms#endif
264102325Smike#if __POSIX_VISIBLE >= 199309
265118771Sbmsint	mlockall(int);
266118771Sbmsint	munlockall(void);
267102325Smikeint	shm_open(const char *, int, mode_t);
268102325Smikeint	shm_unlink(const char *);
26934030Sdufault#endif
2701541Srgrimes__END_DECLS
2711541Srgrimes
27255205Speter#endif /* !_KERNEL */
2732165Spaul
274102325Smike#endif /* !_SYS_MMAN_H_ */
275