mman-shared.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _SYS_MMAN_H
  16. # error "Never use <bits/mman-shared.h> directly; include <sys/mman.h> instead."
  17. #endif
  18. #ifdef __USE_GNU
  19. /* Flags for mremap. */
  20. # define MREMAP_MAYMOVE 1
  21. # define MREMAP_FIXED 2
  22. # define MREMAP_DONTUNMAP 4
  23. /* Flags for memfd_create. */
  24. # ifndef MFD_CLOEXEC
  25. # define MFD_CLOEXEC 1U
  26. # define MFD_ALLOW_SEALING 2U
  27. # define MFD_HUGETLB 4U
  28. # endif
  29. # ifndef MFD_NOEXEC_SEAL
  30. # define MFD_NOEXEC_SEAL 8U
  31. # define MFD_EXEC 0x10U
  32. # endif
  33. /* Flags for mlock2. */
  34. # ifndef MLOCK_ONFAULT
  35. # define MLOCK_ONFAULT 1U
  36. # endif
  37. /* Access restrictions for pkey_alloc. */
  38. # define PKEY_UNRESTRICTED 0x0
  39. # define PKEY_DISABLE_ACCESS 0x1
  40. # define PKEY_DISABLE_WRITE 0x2
  41. __BEGIN_DECLS
  42. /* Create a new memory file descriptor. NAME is a name for debugging.
  43. FLAGS is a combination of the MFD_* constants. */
  44. int memfd_create (const char *__name, unsigned int __flags) __THROW;
  45. /* Lock pages from ADDR (inclusive) to ADDR + LENGTH (exclusive) into
  46. memory. FLAGS is a combination of the MLOCK_* flags above. */
  47. int mlock2 (const void *__addr, size_t __length, unsigned int __flags) __THROW
  48. __attr_access_none (1);
  49. /* Allocate a new protection key, with the PKEY_DISABLE_* bits
  50. specified in ACCESS_RESTRICTIONS. The protection key mask for the
  51. current thread is updated to match the access privilege for the new
  52. key. */
  53. int pkey_alloc (unsigned int __flags, unsigned int __access_restrictions) __THROW;
  54. /* Update the access restrictions for the current thread for KEY, which must
  55. have been allocated using pkey_alloc. */
  56. int pkey_set (int __key, unsigned int __access_restrictions) __THROW;
  57. /* Return the access restrictions for the current thread for KEY, which must
  58. have been allocated using pkey_alloc. */
  59. int pkey_get (int __key) __THROW;
  60. /* Free an allocated protection key, which must have been allocated
  61. using pkey_alloc. */
  62. int pkey_free (int __key) __THROW;
  63. /* Apply memory protection flags for KEY to the specified address
  64. range. */
  65. int pkey_mprotect (void *__addr, size_t __len, int __prot, int __pkey) __THROW;
  66. /* Seal the address range to avoid further modifications, such as remapping to
  67. shrink or expand the VMA, changing protection permission with mprotect,
  68. unmap with munmap, or destructive semantics such as madvise with
  69. MADV_DONTNEED.
  70. The address range must be a valid VMA, without any gaps (unallocated
  71. memory) between the start and end, and ADDR must be page-aligned (LEN will
  72. be page-aligned implicitly). */
  73. int mseal (void *__addr, size_t __len, unsigned long flags) __THROW;
  74. __END_DECLS
  75. #endif /* __USE_GNU */