mman-shared.h 2.8 KB

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