]> git.ipfire.org Git - thirdparty/glibc.git/blame - misc/sys/mman.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / misc / sys / mman.h
CommitLineData
3d42e04d 1/* Definitions for BSD-style memory management.
2b778ceb 2 Copyright (C) 1994-2021 Free Software Foundation, Inc.
54d79e99 3 This file is part of the GNU C Library.
d2f5be2a 4
54d79e99 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
d2f5be2a 9
54d79e99
UD
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
d2f5be2a 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
d2f5be2a 18
d2f5be2a 19#ifndef _SYS_MMAN_H
d2f5be2a 20#define _SYS_MMAN_H 1
d2f5be2a 21
f4017d20 22#include <features.h>
5107cf1d 23#include <bits/types.h>
a5a0310d
UD
24#define __need_size_t
25#include <stddef.h>
d2f5be2a 26
bba09d23
UD
27#ifndef __off_t_defined
28# ifndef __USE_FILE_OFFSET64
29typedef __off_t off_t;
30# else
31typedef __off64_t off_t;
32# endif
33# define __off_t_defined
34#endif
35
36#ifndef __mode_t_defined
37typedef __mode_t mode_t;
38# define __mode_t_defined
39#endif
40
0413b54c 41#include <bits/mman.h>
787e4db9 42
0413b54c 43/* Return value of `mmap' in case of an error. */
c1422e5b 44#define MAP_FAILED ((void *) -1)
01f3e03b 45
d2f5be2a
UD
46__BEGIN_DECLS
47/* Map addresses starting near ADDR and extending for LEN bytes. from
48 OFFSET into the file FD describes according to PROT and FLAGS. If ADDR
49 is nonzero, it is the desired mapping address. If the MAP_FIXED bit is
50 set in FLAGS, the mapping will be at ADDR exactly (which must be
51 page-aligned); otherwise the system chooses a convenient nearby address.
0413b54c 52 The return value is the actual mapping address chosen or MAP_FAILED
d2f5be2a
UD
53 for errors (in which case `errno' is set). A successful `mmap' call
54 deallocates any previous mapping for the affected region. */
55
dfd2257a 56#ifndef __USE_FILE_OFFSET64
c1422e5b
UD
57extern void *mmap (void *__addr, size_t __len, int __prot,
58 int __flags, int __fd, __off_t __offset) __THROW;
dfd2257a 59#else
f377d022
UD
60# ifdef __REDIRECT_NTH
61extern void * __REDIRECT_NTH (mmap,
62 (void *__addr, size_t __len, int __prot,
63 int __flags, int __fd, __off64_t __offset),
64 mmap64);
c559a3ca
UD
65# else
66# define mmap mmap64
67# endif
dfd2257a
UD
68#endif
69#ifdef __USE_LARGEFILE64
c1422e5b
UD
70extern void *mmap64 (void *__addr, size_t __len, int __prot,
71 int __flags, int __fd, __off64_t __offset) __THROW;
dfd2257a 72#endif
d2f5be2a
UD
73
74/* Deallocate any mapping for the region starting at ADDR and extending LEN
75 bytes. Returns 0 if successful, -1 for errors (and sets errno). */
c1422e5b 76extern int munmap (void *__addr, size_t __len) __THROW;
d2f5be2a
UD
77
78/* Change the memory protection of the region starting at ADDR and
79 extending LEN bytes to PROT. Returns 0 if successful, -1 for errors
80 (and sets errno). */
c1422e5b 81extern int mprotect (void *__addr, size_t __len, int __prot) __THROW;
d2f5be2a
UD
82
83/* Synchronize the region starting at ADDR and extending LEN bytes with the
84 file it maps. Filesystem operations on a file being mapped are
2c008571
UD
85 unpredictable before this is done. Flags are from the MS_* set.
86
87 This function is a cancellation point and therefore not marked with
88 __THROW. */
89extern int msync (void *__addr, size_t __len, int __flags);
d2f5be2a 90
498afc54 91#ifdef __USE_MISC
d2f5be2a
UD
92/* Advise the system about particular usage patterns the program follows
93 for the region starting at ADDR and extending LEN bytes. */
c1422e5b 94extern int madvise (void *__addr, size_t __len, int __advice) __THROW;
0413b54c 95#endif
8f6f7a31
UD
96#ifdef __USE_XOPEN2K
97/* This is the POSIX name for this function. */
98extern int posix_madvise (void *__addr, size_t __len, int __advice) __THROW;
99#endif
d2f5be2a 100
3d42e04d
UD
101/* Guarantee all whole pages mapped by the range [ADDR,ADDR+LEN) to
102 be memory resident. */
a784e502 103extern int mlock (const void *__addr, size_t __len) __THROW;
3d42e04d
UD
104
105/* Unlock whole pages previously mapped by the range [ADDR,ADDR+LEN). */
a784e502 106extern int munlock (const void *__addr, size_t __len) __THROW;
3d42e04d 107
fbaad149
RM
108/* Cause all currently mapped pages of the process to be memory resident
109 until unlocked by a call to the `munlockall', until the process exits,
110 or until the process calls `execve'. */
c1422e5b 111extern int mlockall (int __flags) __THROW;
fbaad149
RM
112
113/* All currently mapped pages of the process' address space become
114 unlocked. */
c1422e5b 115extern int munlockall (void) __THROW;
fbaad149 116
0413b54c 117#ifdef __USE_MISC
4ede8b06
UD
118/* mincore returns the memory residency status of the pages in the
119 current process's address space specified by [start, start + len).
120 The status is returned in a vector of bytes. The least significant
121 bit of each byte is 1 if the referenced page is in memory, otherwise
122 it is zero. */
0ddc17ba
UD
123extern int mincore (void *__start, size_t __len, unsigned char *__vec)
124 __THROW;
d26d01d1 125#endif
0ddc17ba 126
d26d01d1 127#ifdef __USE_GNU
eaa51b47
UD
128/* Remap pages mapped by the range [ADDR,ADDR+OLD_LEN) to new length
129 NEW_LEN. If MREMAP_MAYMOVE is set in FLAGS the returned address
130 may differ from ADDR. If MREMAP_FIXED is set in FLAGS the function
3a09b620 131 takes another parameter which is a fixed address at which the block
eaa51b47
UD
132 resides after a successful call. */
133extern void *mremap (void *__addr, size_t __old_len, size_t __new_len,
134 int __flags, ...) __THROW;
135
0ddc17ba
UD
136/* Remap arbitrary pages of a shared backing store within an existing
137 VMA. */
138extern int remap_file_pages (void *__start, size_t __size, int __prot,
139 size_t __pgoff, int __flags) __THROW;
0413b54c 140#endif
75cd5204 141
967866f4
UD
142
143/* Open shared memory segment. */
a784e502 144extern int shm_open (const char *__name, int __oflag, mode_t __mode);
967866f4
UD
145
146/* Remove shared memory segment. */
a784e502 147extern int shm_unlink (const char *__name);
967866f4 148
d2f5be2a
UD
149__END_DECLS
150
3d42e04d 151#endif /* sys/mman.h */