1139825Simp/*	$OpenBSD: mman.h,v 1.35 2022/10/07 14:59:39 deraadt Exp $	*/
2103620Sgrehan/*	$NetBSD: mman.h,v 1.11 1995/03/26 20:24:23 jtc Exp $	*/
3103620Sgrehan
4103620Sgrehan/*-
5103620Sgrehan * Copyright (c) 1982, 1986, 1993
6103620Sgrehan *	The Regents of the University of California.  All rights reserved.
7103620Sgrehan *
8103620Sgrehan * Redistribution and use in source and binary forms, with or without
9103620Sgrehan * modification, are permitted provided that the following conditions
10103620Sgrehan * are met:
11103620Sgrehan * 1. Redistributions of source code must retain the above copyright
12103620Sgrehan *    notice, this list of conditions and the following disclaimer.
13103620Sgrehan * 2. Redistributions in binary form must reproduce the above copyright
14103620Sgrehan *    notice, this list of conditions and the following disclaimer in the
15103620Sgrehan *    documentation and/or other materials provided with the distribution.
16103620Sgrehan * 3. Neither the name of the University nor the names of its contributors
17103620Sgrehan *    may be used to endorse or promote products derived from this software
18103620Sgrehan *    without specific prior written permission.
19103620Sgrehan *
20103620Sgrehan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21103620Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22103620Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23103620Sgrehan * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24103620Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25103620Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26103620Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27103620Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28103620Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29103620Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30103620Sgrehan * SUCH DAMAGE.
31103620Sgrehan *
32103620Sgrehan *	@(#)mman.h	8.1 (Berkeley) 6/2/93
33103620Sgrehan */
34103620Sgrehan
35103620Sgrehan#ifndef _KERNEL
36103620Sgrehan#include <sys/cdefs.h>
37103620Sgrehan#endif
38103620Sgrehan
39103620Sgrehan/*
40103620Sgrehan * Protections are chosen from these bits, or-ed together
41103620Sgrehan */
42103620Sgrehan#define	PROT_NONE	0x00	/* no permissions */
43103620Sgrehan#define	PROT_READ	0x01	/* pages can be read */
44103620Sgrehan#define	PROT_WRITE	0x02	/* pages can be written */
45103620Sgrehan#define	PROT_EXEC	0x04	/* pages can be executed */
46103620Sgrehan
47103620Sgrehan/*
48103620Sgrehan * Flags contain sharing type and options.
49103620Sgrehan * Sharing types; choose one.
50160722Smarcel */
51160722Smarcel#define	MAP_SHARED	0x0001	/* share changes */
52103620Sgrehan#define	MAP_PRIVATE	0x0002	/* changes are private */
53160722Smarcel
54103620Sgrehan/*
55160722Smarcel * Other flags
56103620Sgrehan */
57160722Smarcel#define	MAP_FIXED	0x0010	/* map addr must be exactly as requested */
58160722Smarcel#define	__MAP_NOREPLACE	0x0800	/* fail if address not available */
59160722Smarcel#define	MAP_ANON	0x1000	/* allocated from memory, swap space */
60103620Sgrehan#define	MAP_ANONYMOUS	MAP_ANON	/* alternate POSIX spelling */
61103620Sgrehan#define	__MAP_NOFAULT	0x2000
62103620Sgrehan#define	MAP_STACK	0x4000	/* mapping is used for a stack */
63103620Sgrehan#define	MAP_CONCEAL	0x8000	/* omit from dumps */
64160722Smarcel
65160722Smarcel#define	MAP_FLAGMASK	0xfff7
66160722Smarcel
67160722Smarcel#ifndef _KERNEL
68103620Sgrehan/*
69103620Sgrehan * Legacy defines for userland source compatibility.
70103620Sgrehan * Can be removed once no longer needed in base and ports.
71160722Smarcel */
72103620Sgrehan#define	MAP_COPY		MAP_PRIVATE	/* "copy" region at mmap time */
73160722Smarcel#define	MAP_FILE		0	/* map from file (default) */
74160722Smarcel#define	MAP_HASSEMAPHORE	0	/* region may contain semaphores */
75103620Sgrehan#define	MAP_INHERIT		0	/* region is retained after exec */
76160722Smarcel#define	MAP_NOEXTEND		0	/* for MAP_FILE, don't change file size */
77103620Sgrehan#define	MAP_NORESERVE		0	/* Sun: don't reserve needed swap area */
78103620Sgrehan#define	MAP_RENAME		0	/* Sun: rename private pages to file */
79103620Sgrehan#define	MAP_TRYFIXED		0	/* attempt hint address, even within heap */
80160722Smarcel#endif
81160722Smarcel
82103620Sgrehan/*
83103620Sgrehan * Error return from mmap()
84160722Smarcel */
85103620Sgrehan#define MAP_FAILED	((void *)-1)
86103620Sgrehan
87160722Smarcel/*
88 * POSIX memory advisory values.
89 * Note: keep consistent with the original definitions below.
90 */
91#define	POSIX_MADV_NORMAL	0	/* no further special treatment */
92#define	POSIX_MADV_RANDOM	1	/* expect random page references */
93#define	POSIX_MADV_SEQUENTIAL	2	/* expect sequential page references */
94#define	POSIX_MADV_WILLNEED	3	/* will need these pages */
95#define	POSIX_MADV_DONTNEED	4	/* don't need these pages */
96
97#if __BSD_VISIBLE
98/*
99 * Original advice values, equivalent to POSIX definitions,
100 * and few implementation-specific ones.  For in-kernel and historic use.
101 */
102#define	MADV_NORMAL		POSIX_MADV_NORMAL
103#define	MADV_RANDOM		POSIX_MADV_RANDOM
104#define	MADV_SEQUENTIAL		POSIX_MADV_SEQUENTIAL
105#define	MADV_WILLNEED		POSIX_MADV_WILLNEED
106#define	MADV_DONTNEED		POSIX_MADV_DONTNEED
107#define	MADV_SPACEAVAIL		5	/* insure that resources are reserved */
108#define	MADV_FREE		6	/* pages are empty, free them */
109#endif
110
111/*
112 * Flags to minherit
113 */
114#define MAP_INHERIT_SHARE	0	/* share with child */
115#define MAP_INHERIT_COPY	1	/* copy into child */
116#define MAP_INHERIT_NONE	2	/* absent from child */
117#define MAP_INHERIT_ZERO	3	/* zero in child */
118
119/*
120 * Flags to msync
121 */
122#define	MS_ASYNC	0x01	/* perform asynchronous writes */
123#define	MS_SYNC		0x02	/* perform synchronous writes */
124#define	MS_INVALIDATE	0x04	/* invalidate cached data */
125
126/*
127 * Flags to mlockall
128 */
129#define	MCL_CURRENT	0x01	/* lock all pages currently mapped */
130#define	MCL_FUTURE	0x02	/* lock all pages mapped in the future */
131
132#ifndef _KERNEL
133#include <sys/_types.h>
134
135#ifndef _SIZE_T_DEFINED_
136#define _SIZE_T_DEFINED_
137typedef __size_t	size_t;
138#endif
139
140#ifndef _OFF_T_DEFINED_
141#define _OFF_T_DEFINED_
142typedef __off_t		off_t;
143#endif
144
145__BEGIN_DECLS
146void *	mmap(void *, size_t, int, int, int, off_t);
147int	mprotect(void *, size_t, int);
148int	munmap(void *, size_t);
149int	msync(void *, size_t, int);
150int	mlock(const void *, size_t);
151int	munlock(const void *, size_t);
152int	mlockall(int);
153int	munlockall(void);
154#if __BSD_VISIBLE
155int	madvise(void *, size_t, int);
156int	minherit(void *, size_t, int);
157int	mimmutable(void *, size_t);
158void *	mquery(void *, size_t, int, int, int, off_t);
159#endif
160int	posix_madvise(void *, size_t, int);
161int	shm_open(const char *, int, __mode_t);
162int	shm_unlink(const char *);
163int	shm_mkstemp(char *);
164__END_DECLS
165
166#endif /* !_KERNEL */
167