1/* Memory-mapping-related declarations/definitions, not architecture-specific.
2 Copyright (C) 2017-2026 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
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.
9
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
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_MMAN_H
20# error "Never use <bits/mman-shared.h> directly; include <sys/mman.h> instead."
21#endif
22
23#ifdef __USE_GNU
24/* Flags for mremap. */
25# define MREMAP_MAYMOVE 1
26# define MREMAP_FIXED 2
27# define MREMAP_DONTUNMAP 4
28
29/* Flags for memfd_create. */
30# ifndef MFD_CLOEXEC
31# define MFD_CLOEXEC 1U
32# define MFD_ALLOW_SEALING 2U
33# define MFD_HUGETLB 4U
34# endif
35# ifndef MFD_NOEXEC_SEAL
36# define MFD_NOEXEC_SEAL 8U
37# define MFD_EXEC 0x10U
38# endif
39
40/* Flags for mlock2. */
41# ifndef MLOCK_ONFAULT
42# define MLOCK_ONFAULT 1U
43# endif
44
45/* Access restrictions for pkey_alloc. */
46# define PKEY_UNRESTRICTED 0x0
47# define PKEY_DISABLE_ACCESS 0x1
48# define PKEY_DISABLE_WRITE 0x2
49
50__BEGIN_DECLS
51
52/* Create a new memory file descriptor. NAME is a name for debugging.
53 FLAGS is a combination of the MFD_* constants. */
54int memfd_create (const char *__name, unsigned int __flags) __THROW;
55
56/* Lock pages from ADDR (inclusive) to ADDR + LENGTH (exclusive) into
57 memory. FLAGS is a combination of the MLOCK_* flags above. */
58int mlock2 (const void *__addr, size_t __length, unsigned int __flags) __THROW
59 __attr_access_none (1);
60
61/* Allocate a new protection key, with the PKEY_DISABLE_* bits
62 specified in ACCESS_RESTRICTIONS. The protection key mask for the
63 current thread is updated to match the access privilege for the new
64 key. */
65int pkey_alloc (unsigned int __flags, unsigned int __access_restrictions) __THROW;
66
67/* Update the access restrictions for the current thread for KEY, which must
68 have been allocated using pkey_alloc. */
69int pkey_set (int __key, unsigned int __access_restrictions) __THROW;
70
71/* Return the access restrictions for the current thread for KEY, which must
72 have been allocated using pkey_alloc. */
73int pkey_get (int __key) __THROW;
74
75/* Free an allocated protection key, which must have been allocated
76 using pkey_alloc. */
77int pkey_free (int __key) __THROW;
78
79/* Apply memory protection flags for KEY to the specified address
80 range. */
81int pkey_mprotect (void *__addr, size_t __len, int __prot, int __pkey) __THROW;
82
83/* Seal the address range to avoid further modifications, such as remapping to
84 shrink or expand the VMA, changing protection permission with mprotect,
85 unmap with munmap, or destructive semantics such as madvise with
86 MADV_DONTNEED.
87
88 The address range must be a valid VMA, without any gaps (unallocated
89 memory) between the start and end, and ADDR must be page-aligned (LEN will
90 be page-aligned implicitly). */
91int mseal (void *__addr, size_t __len, unsigned long flags) __THROW;
92
93__END_DECLS
94
95#endif /* __USE_GNU */
96