1
0

mman.h 6.1 KB

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