mman.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* $OpenBSD: mman.h,v 1.28 2014/12/17 06:58:10 guenther Exp $ */
  2. /* $NetBSD: mman.h,v 1.11 1995/03/26 20:24:23 jtc Exp $ */
  3. /*-
  4. * Copyright (c) 1982, 1986, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the University nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * @(#)mman.h 8.1 (Berkeley) 6/2/93
  32. */
  33. #ifndef _KERNEL
  34. #include <sys/cdefs.h>
  35. #endif
  36. /*
  37. * Protections are chosen from these bits, or-ed together
  38. */
  39. #define PROT_NONE 0x00 /* no permissions */
  40. #define PROT_READ 0x01 /* pages can be read */
  41. #define PROT_WRITE 0x02 /* pages can be written */
  42. #define PROT_EXEC 0x04 /* pages can be executed */
  43. /*
  44. * Flags contain sharing type and options.
  45. * Sharing types; choose one.
  46. */
  47. #define MAP_SHARED 0x0001 /* share changes */
  48. #define MAP_PRIVATE 0x0002 /* changes are private */
  49. /*
  50. * Other flags
  51. */
  52. #define MAP_FIXED 0x0010 /* map addr must be exactly as requested */
  53. #define __MAP_NOREPLACE 0x0800 /* fail if address not available */
  54. #define MAP_ANON 0x1000 /* allocated from memory, swap space */
  55. #define MAP_ANONYMOUS MAP_ANON /* alternate POSIX spelling */
  56. #define __MAP_NOFAULT 0x2000
  57. #define MAP_FLAGMASK 0x3ff7
  58. #ifdef _KERNEL
  59. /*
  60. * Backwards compat for OpenBSD 5.5.
  61. * TODO: Remove after OpenBSD 5.7 release.
  62. */
  63. #define MAP_OLDCOPY 0x0004 /* alias for MAP_PRIVATE */
  64. #define MAP_OLDRENAME 0x0020
  65. #define MAP_OLDNORESERVE 0x0040
  66. #define MAP_OLDINHERIT 0x0080
  67. #define MAP_OLDNOEXTEND 0x0100
  68. #define MAP_OLDHASSEMAPHORE 0x0200
  69. #define MAP_OLDTRYFIXED 0x0400
  70. #endif
  71. #ifndef _KERNEL
  72. /*
  73. * Legacy defines for userland source compatibility.
  74. * Can be removed once no longer needed in base and ports.
  75. */
  76. #define MAP_COPY MAP_PRIVATE /* "copy" region at mmap time */
  77. #define MAP_FILE 0 /* map from file (default) */
  78. #define MAP_HASSEMAPHORE 0 /* region may contain semaphores */
  79. #define MAP_INHERIT 0 /* region is retained after exec */
  80. #define MAP_NOEXTEND 0 /* for MAP_FILE, don't change file size */
  81. #define MAP_NORESERVE 0 /* Sun: don't reserve needed swap area */
  82. #define MAP_RENAME 0 /* Sun: rename private pages to file */
  83. #define MAP_TRYFIXED 0 /* attempt hint address, even within heap */
  84. #endif
  85. /*
  86. * Error return from mmap()
  87. */
  88. #define MAP_FAILED ((void *)-1)
  89. /*
  90. * POSIX memory advisory values.
  91. * Note: keep consistent with the original definitions below.
  92. */
  93. #define POSIX_MADV_NORMAL 0 /* no further special treatment */
  94. #define POSIX_MADV_RANDOM 1 /* expect random page references */
  95. #define POSIX_MADV_SEQUENTIAL 2 /* expect sequential page references */
  96. #define POSIX_MADV_WILLNEED 3 /* will need these pages */
  97. #define POSIX_MADV_DONTNEED 4 /* don't need these pages */
  98. #if __BSD_VISIBLE
  99. /*
  100. * Original advice values, equivalent to POSIX definitions,
  101. * and few implementation-specific ones. For in-kernel and historic use.
  102. */
  103. #define MADV_NORMAL POSIX_MADV_NORMAL
  104. #define MADV_RANDOM POSIX_MADV_RANDOM
  105. #define MADV_SEQUENTIAL POSIX_MADV_SEQUENTIAL
  106. #define MADV_WILLNEED POSIX_MADV_WILLNEED
  107. #define MADV_DONTNEED POSIX_MADV_DONTNEED
  108. #define MADV_SPACEAVAIL 5 /* insure that resources are reserved */
  109. #define MADV_FREE 6 /* pages are empty, free them */
  110. #endif
  111. /*
  112. * Flags to minherit
  113. */
  114. #define MAP_INHERIT_SHARE 0 /* share with child */
  115. #define MAP_INHERIT_COPY 1 /* copy into child */
  116. #define MAP_INHERIT_NONE 2 /* absent from child */
  117. #define MAP_INHERIT_ZERO 3 /* zero in child */
  118. /*
  119. * Flags to msync
  120. */
  121. #define MS_ASYNC 0x01 /* perform asynchronous writes */
  122. #define MS_SYNC 0x02 /* perform synchronous writes */
  123. #define MS_INVALIDATE 0x04 /* invalidate cached data */
  124. /*
  125. * Flags to mlockall
  126. */
  127. #define MCL_CURRENT 0x01 /* lock all pages currently mapped */
  128. #define MCL_FUTURE 0x02 /* lock all pages mapped in the future */
  129. #ifndef _KERNEL
  130. #include <sys/_types.h>
  131. #ifndef _SIZE_T_DEFINED_
  132. #define _SIZE_T_DEFINED_
  133. typedef __size_t size_t;
  134. #endif
  135. #ifndef _OFF_T_DEFINED_
  136. #define _OFF_T_DEFINED_
  137. typedef __off_t off_t;
  138. #endif
  139. __BEGIN_DECLS
  140. void * mmap(void *, size_t, int, int, int, off_t);
  141. int mprotect(void *, size_t, int);
  142. int munmap(void *, size_t);
  143. int msync(void *, size_t, int);
  144. int mlock(const void *, size_t);
  145. int munlock(const void *, size_t);
  146. int mlockall(int);
  147. int munlockall(void);
  148. #if __BSD_VISIBLE
  149. int madvise(void *, size_t, int);
  150. int mincore(void *, size_t, char *);
  151. int minherit(void *, size_t, int);
  152. void * mquery(void *, size_t, int, int, int, off_t);
  153. #endif
  154. int posix_madvise(void *, size_t, int);
  155. int shm_open(const char *, int, __mode_t);
  156. int shm_unlink(const char *);
  157. int shm_mkstemp(char *);
  158. __END_DECLS
  159. #endif /* !_KERNEL */