1/* Memory-mapping-related declarations/definitions, not architecture-specific.
2 Copyright (C) 2017-2018 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 <http://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 memfd_create. */
25# ifndef MFD_CLOEXEC
26# define MFD_CLOEXEC 1U
27# define MFD_ALLOW_SEALING 2U
28# define MFD_HUGETLB 4U
29# endif
30
31/* Flags for mlock2. */
32# ifndef MLOCK_ONFAULT
33# define MLOCK_ONFAULT 1U
34# endif
35
36/* Access rights for pkey_alloc. */
37# ifndef PKEY_DISABLE_ACCESS
38# define PKEY_DISABLE_ACCESS 0x1
39# define PKEY_DISABLE_WRITE 0x2
40# endif
41
42__BEGIN_DECLS
43
44/* Create a new memory file descriptor. NAME is a name for debugging.
45 FLAGS is a combination of the MFD_* constants. */
46int memfd_create (const char *__name, unsigned int __flags) __THROW;
47
48/* Lock pages from ADDR (inclusive) to ADDR + LENGTH (exclusive) into
49 memory. FLAGS is a combination of the MLOCK_* flags above. */
50int mlock2 (const void *__addr, size_t __length, unsigned int __flags) __THROW;
51
52/* Allocate a new protection key, with the PKEY_DISABLE_* bits
53 specified in ACCESS_RIGHTS. The protection key mask for the
54 current thread is updated to match the access privilege for the new
55 key. */
56int pkey_alloc (unsigned int __flags, unsigned int __access_rights) __THROW;
57
58/* Update the access rights for the current thread for KEY, which must
59 have been allocated using pkey_alloc. */
60int pkey_set (int __key, unsigned int __access_rights) __THROW;
61
62/* Return the access rights for the current thread for KEY, which must
63 have been allocated using pkey_alloc. */
64int pkey_get (int __key) __THROW;
65
66/* Free an allocated protection key, which must have been allocated
67 using pkey_alloc. */
68int pkey_free (int __key) __THROW;
69
70/* Apply memory protection flags for KEY to the specified address
71 range. */
72int pkey_mprotect (void *__addr, size_t __len, int __prot, int __pkey) __THROW;
73
74__END_DECLS
75
76#endif /* __USE_GNU */
77