mman.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* Definitions for BSD-style memory management.
  2. Copyright (C) 1994-2000, 2003, 2004, 2005 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. <http://www.gnu.org/licenses/>. */
  15. #ifndef _SYS_MMAN_H
  16. #define _SYS_MMAN_H 1
  17. #include <features.h>
  18. #include <bits/types.h>
  19. #define __need_size_t
  20. #include <stddef.h>
  21. #ifndef __off_t_defined
  22. # ifndef __USE_FILE_OFFSET64
  23. typedef __off_t off_t;
  24. # else
  25. typedef __off64_t off_t;
  26. # endif
  27. # define __off_t_defined
  28. #endif
  29. #ifndef __mode_t_defined
  30. typedef __mode_t mode_t;
  31. # define __mode_t_defined
  32. #endif
  33. #include <bits/mman.h>
  34. /* Return value of `mmap' in case of an error. */
  35. #define MAP_FAILED ((void *) -1)
  36. __BEGIN_DECLS
  37. /* Map addresses starting near ADDR and extending for LEN bytes. from
  38. OFFSET into the file FD describes according to PROT and FLAGS. If ADDR
  39. is nonzero, it is the desired mapping address. If the MAP_FIXED bit is
  40. set in FLAGS, the mapping will be at ADDR exactly (which must be
  41. page-aligned); otherwise the system chooses a convenient nearby address.
  42. The return value is the actual mapping address chosen or MAP_FAILED
  43. for errors (in which case `errno' is set). A successful `mmap' call
  44. deallocates any previous mapping for the affected region. */
  45. #ifndef __USE_FILE_OFFSET64
  46. extern void *mmap (void *__addr, size_t __len, int __prot,
  47. int __flags, int __fd, __off_t __offset) __THROW;
  48. libc_hidden_proto(mmap)
  49. #else
  50. # ifdef __REDIRECT_NTH
  51. extern void * __REDIRECT_NTH (mmap,
  52. (void *__addr, size_t __len, int __prot,
  53. int __flags, int __fd, __off64_t __offset),
  54. mmap64);
  55. # else
  56. # define mmap mmap64
  57. # endif
  58. #endif
  59. #ifdef __USE_LARGEFILE64
  60. extern void *mmap64 (void *__addr, size_t __len, int __prot,
  61. int __flags, int __fd, __off64_t __offset) __THROW;
  62. #endif
  63. /* Deallocate any mapping for the region starting at ADDR and extending LEN
  64. bytes. Returns 0 if successful, -1 for errors (and sets errno). */
  65. extern int munmap (void *__addr, size_t __len) __THROW;
  66. libc_hidden_proto(munmap)
  67. /* Change the memory protection of the region starting at ADDR and
  68. extending LEN bytes to PROT. Returns 0 if successful, -1 for errors
  69. (and sets errno). */
  70. extern int mprotect (void *__addr, size_t __len, int __prot) __THROW;
  71. #ifdef __ARCH_USE_MMU__
  72. /* Synchronize the region starting at ADDR and extending LEN bytes with the
  73. file it maps. Filesystem operations on a file being mapped are
  74. unpredictable before this is done. Flags are from the MS_* set.
  75. This function is a cancellation point and therefore not marked with
  76. __THROW. */
  77. extern int msync (void *__addr, size_t __len, int __flags);
  78. #else
  79. /* On no-mmu systems you can't have real private mappings. */
  80. static __inline__ int msync (void *__addr, size_t __len, int __flags) { return 0; }
  81. #endif
  82. #if defined __USE_BSD && (defined __UCLIBC_LINUX_SPECIFIC__ || defined __UCLIBC_HAS_THREADS_NATIVE__)
  83. /* Advise the system about particular usage patterns the program follows
  84. for the region starting at ADDR and extending LEN bytes. */
  85. extern int madvise (void *__addr, size_t __len, int __advice) __THROW;
  86. #endif
  87. #if defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__
  88. /* This is the POSIX name for this function. */
  89. extern int posix_madvise (void *__addr, size_t __len, int __advice) __THROW;
  90. #endif
  91. #if defined __UCLIBC_HAS_REALTIME__
  92. # ifdef __ARCH_USE_MMU__
  93. /* Guarantee all whole pages mapped by the range [ADDR,ADDR+LEN) to
  94. be memory resident. */
  95. extern int mlock (const void *__addr, size_t __len) __THROW;
  96. /* Unlock whole pages previously mapped by the range [ADDR,ADDR+LEN). */
  97. extern int munlock (const void *__addr, size_t __len) __THROW;
  98. /* Cause all currently mapped pages of the process to be memory resident
  99. until unlocked by a call to the `munlockall', until the process exits,
  100. or until the process calls `execve'. */
  101. extern int mlockall (int __flags) __THROW;
  102. /* All currently mapped pages of the process' address space become
  103. unlocked. */
  104. extern int munlockall (void) __THROW;
  105. #else
  106. /* On no-mmu systems, memory cannot be swapped out, so
  107. * these functions will always succeed. */
  108. static __inline__ int mlock (const void *__addr, size_t __len) { return 0; }
  109. static __inline__ int munlock (const void *__addr, size_t __len) { return 0; }
  110. static __inline__ int mlockall (int __flags) { return 0; }
  111. static __inline__ int munlockall (void) { return 0; }
  112. #endif
  113. #endif /* __UCLIBC_HAS_REALTIME__ */
  114. #if defined __USE_MISC && defined __UCLIBC_BSD_SPECIFIC__
  115. /* mincore returns the memory residency status of the pages in the
  116. current process's address space specified by [start, start + len).
  117. The status is returned in a vector of bytes. The least significant
  118. bit of each byte is 1 if the referenced page is in memory, otherwise
  119. it is zero. */
  120. extern int mincore (void *__start, size_t __len, unsigned char *__vec)
  121. __THROW;
  122. #endif
  123. #ifdef __USE_GNU
  124. /* Remap pages mapped by the range [ADDR,ADDR+OLD_LEN) to new length
  125. NEW_LEN. If MREMAP_MAYMOVE is set in FLAGS the returned address
  126. may differ from ADDR. If MREMAP_FIXED is set in FLAGS the function
  127. takes another paramter which is a fixed address at which the block
  128. resides after a successful call. */
  129. extern void *mremap (void *__addr, size_t __old_len, size_t __new_len,
  130. int __flags, ...) __THROW;
  131. libc_hidden_proto(mremap)
  132. #ifdef __UCLIBC_LINUX_SPECIFIC__
  133. /* Remap arbitrary pages of a shared backing store within an existing
  134. VMA. */
  135. extern int remap_file_pages (void *__start, size_t __size, int __prot,
  136. size_t __pgoff, int __flags) __THROW;
  137. #endif
  138. #endif
  139. /* Open shared memory segment. */
  140. extern int shm_open (const char *__name, int __oflag, mode_t __mode);
  141. /* Remove shared memory segment. */
  142. extern int shm_unlink (const char *__name);
  143. __END_DECLS
  144. #endif /* sys/mman.h */