mman.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* Definitions for BSD-style memory management.
  2. Copyright (C) 1994-1999, 2000 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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #ifndef _SYS_MMAN_H
  17. #define _SYS_MMAN_H 1
  18. #include <features.h>
  19. #include <bits/types.h>
  20. #define __need_size_t
  21. #include <stddef.h>
  22. #ifndef __off_t_defined
  23. # ifndef __USE_FILE_OFFSET64
  24. typedef __off_t off_t;
  25. # else
  26. typedef __off64_t off_t;
  27. # endif
  28. # define __off_t_defined
  29. #endif
  30. #ifndef __mode_t_defined
  31. typedef __mode_t mode_t;
  32. # define __mode_t_defined
  33. #endif
  34. #include <bits/mman.h>
  35. /* Return value of `mmap' in case of an error. */
  36. #define MAP_FAILED ((void *) -1)
  37. __BEGIN_DECLS
  38. /* Map addresses starting near ADDR and extending for LEN bytes. from
  39. OFFSET into the file FD describes according to PROT and FLAGS. If ADDR
  40. is nonzero, it is the desired mapping address. If the MAP_FIXED bit is
  41. set in FLAGS, the mapping will be at ADDR exactly (which must be
  42. page-aligned); otherwise the system chooses a convenient nearby address.
  43. The return value is the actual mapping address chosen or MAP_FAILED
  44. for errors (in which case `errno' is set). A successful `mmap' call
  45. deallocates any previous mapping for the affected region. */
  46. #ifndef __USE_FILE_OFFSET64
  47. extern void *mmap (void *__addr, size_t __len, int __prot,
  48. int __flags, int __fd, __off_t __offset) __THROW;
  49. #else
  50. # ifdef __REDIRECT
  51. extern void * __REDIRECT (mmap,
  52. (void *__addr, size_t __len, int __prot,
  53. int __flags, int __fd, __off64_t __offset) __THROW,
  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. /* Change the memory protection of the region starting at ADDR and
  67. extending LEN bytes to PROT. Returns 0 if successful, -1 for errors
  68. (and sets errno). */
  69. extern int mprotect (void *__addr, size_t __len, int __prot) __THROW;
  70. /* Synchronize the region starting at ADDR and extending LEN bytes with the
  71. file it maps. Filesystem operations on a file being mapped are
  72. unpredictable before this is done. Flags are from the MS_* set. */
  73. extern int msync (void *__addr, size_t __len, int __flags) __THROW;
  74. #ifdef __USE_BSD
  75. /* Advise the system about particular usage patterns the program follows
  76. for the region starting at ADDR and extending LEN bytes. */
  77. extern int madvise (void *__addr, size_t __len, int __advice) __THROW;
  78. #endif
  79. #ifdef __USE_XOPEN2K
  80. /* This is the POSIX name for this function. */
  81. extern int posix_madvise (void *__addr, size_t __len, int __advice) __THROW;
  82. #endif
  83. /* Guarantee all whole pages mapped by the range [ADDR,ADDR+LEN) to
  84. be memory resident. */
  85. extern int mlock (__const void *__addr, size_t __len) __THROW;
  86. /* Unlock whole pages previously mapped by the range [ADDR,ADDR+LEN). */
  87. extern int munlock (__const void *__addr, size_t __len) __THROW;
  88. /* Cause all currently mapped pages of the process to be memory resident
  89. until unlocked by a call to the `munlockall', until the process exits,
  90. or until the process calls `execve'. */
  91. extern int mlockall (int __flags) __THROW;
  92. /* All currently mapped pages of the process' address space become
  93. unlocked. */
  94. extern int munlockall (void) __THROW;
  95. #ifdef __USE_MISC
  96. /* Remap pages mapped by the range [ADDR,ADDR+OLD_LEN) to new length
  97. NEW_LEN. If MAY_MOVE is MREMAP_MAYMOVE the returned address may
  98. differ from ADDR. */
  99. extern void *mremap (void *__addr, size_t __old_len, size_t __new_len,
  100. int __may_move) __THROW;
  101. /* mincore returns the memory residency status of the pages in the
  102. current process's address space specified by [start, start + len).
  103. The status is returned in a vector of bytes. The least significant
  104. bit of each byte is 1 if the referenced page is in memory, otherwise
  105. it is zero. */
  106. extern int mincore (void *__start, size_t __len, unsigned char *__vec);
  107. #endif
  108. /* Open shared memory segment. */
  109. extern int shm_open (__const char *__name, int __oflag, mode_t __mode);
  110. /* Remove shared memory segment. */
  111. extern int shm_unlink (__const char *__name);
  112. __END_DECLS
  113. #endif /* sys/mman.h */