1/* $OpenBSD: mman.h,v 1.36 2026/03/26 21:46:24 daniel Exp $ */
2/* $NetBSD: mman.h,v 1.11 1995/03/26 20:24:23 jtc Exp $ */
3
4/*-
5 * Copyright (c) 1982, 1986, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)mman.h 8.1 (Berkeley) 6/2/93
33 */
34
35#ifndef _KERNEL
36#include <sys/cdefs.h>
37#endif
38
39/*
40 * Protections are chosen from these bits, or-ed together
41 */
42#define PROT_NONE 0x00 /* no permissions */
43#define PROT_READ 0x01 /* pages can be read */
44#define PROT_WRITE 0x02 /* pages can be written */
45#define PROT_EXEC 0x04 /* pages can be executed */
46
47/*
48 * Flags contain sharing type and options.
49 * Sharing types; choose one.
50 */
51#define MAP_SHARED 0x0001 /* share changes */
52#define MAP_PRIVATE 0x0002 /* changes are private */
53
54/*
55 * Other flags
56 */
57#define MAP_FIXED 0x0010 /* map addr must be exactly as requested */
58#define __MAP_NOREPLACE 0x0800 /* fail if address not available */
59#define MAP_ANON 0x1000 /* allocated from memory, swap space */
60#define MAP_ANONYMOUS MAP_ANON /* alternate POSIX spelling */
61#define __MAP_NOFAULT 0x2000
62#define MAP_STACK 0x4000 /* mapping is used for a stack */
63#define MAP_CONCEAL 0x8000 /* omit from dumps */
64
65#define MAP_FLAGMASK 0xfff7
66
67#ifndef _KERNEL
68/*
69 * Legacy defines for userland source compatibility.
70 * Can be removed once no longer needed in base and ports.
71 */
72#define MAP_COPY MAP_PRIVATE /* "copy" region at mmap time */
73#define MAP_FILE 0 /* map from file (default) */
74#define MAP_HASSEMAPHORE 0 /* region may contain semaphores */
75#define MAP_INHERIT 0 /* region is retained after exec */
76#define MAP_NOEXTEND 0 /* for MAP_FILE, don't change file size */
77#define MAP_NORESERVE 0 /* Sun: don't reserve needed swap area */
78#define MAP_RENAME 0 /* Sun: rename private pages to file */
79#define MAP_TRYFIXED 0 /* attempt hint address, even within heap */
80#endif
81
82/*
83 * Error return from mmap()
84 */
85#define MAP_FAILED ((void *)-1)
86
87/*
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#ifndef _MODE_T_DEFINED_
146#define _MODE_T_DEFINED_
147typedef __mode_t mode_t;
148#endif
149
150__BEGIN_DECLS
151void * mmap(void *, size_t, int, int, int, off_t);
152int mprotect(void *, size_t, int);
153int munmap(void *, size_t);
154int msync(void *, size_t, int);
155int mlock(const void *, size_t);
156int munlock(const void *, size_t);
157int mlockall(int);
158int munlockall(void);
159#if __BSD_VISIBLE
160int madvise(void *, size_t, int);
161int minherit(void *, size_t, int);
162int mimmutable(void *, size_t);
163void * mquery(void *, size_t, int, int, int, off_t);
164#endif
165int posix_madvise(void *, size_t, int);
166int shm_open(const char *, int, mode_t);
167int shm_unlink(const char *);
168int shm_mkstemp(char *);
169__END_DECLS
170
171#endif /* !_KERNEL */