lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 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 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, write to the Free |
| 17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 18 | 02111-1307 USA. */ |
| 19 | |
| 20 | #ifndef _SYS_MMAN_H |
| 21 | #define _SYS_MMAN_H 1 |
| 22 | |
| 23 | #include <features.h> |
| 24 | #include <bits/types.h> |
| 25 | #define __need_size_t |
| 26 | #include <stddef.h> |
| 27 | |
| 28 | #ifndef __off_t_defined |
| 29 | # ifndef __USE_FILE_OFFSET64 |
| 30 | typedef __off_t off_t; |
| 31 | # else |
| 32 | typedef __off64_t off_t; |
| 33 | # endif |
| 34 | # define __off_t_defined |
| 35 | #endif |
| 36 | |
| 37 | #ifndef __mode_t_defined |
| 38 | typedef __mode_t mode_t; |
| 39 | # define __mode_t_defined |
| 40 | #endif |
| 41 | |
| 42 | #include <bits/mman.h> |
| 43 | |
| 44 | /* Return value of `mmap' in case of an error. */ |
| 45 | #define MAP_FAILED ((void *) -1) |
| 46 | |
| 47 | __BEGIN_DECLS |
| 48 | /* Map addresses starting near ADDR and extending for LEN bytes. from |
| 49 | OFFSET into the file FD describes according to PROT and FLAGS. If ADDR |
| 50 | is nonzero, it is the desired mapping address. If the MAP_FIXED bit is |
| 51 | set in FLAGS, the mapping will be at ADDR exactly (which must be |
| 52 | page-aligned); otherwise the system chooses a convenient nearby address. |
| 53 | The return value is the actual mapping address chosen or MAP_FAILED |
| 54 | for errors (in which case `errno' is set). A successful `mmap' call |
| 55 | deallocates any previous mapping for the affected region. */ |
| 56 | |
| 57 | #ifndef __USE_FILE_OFFSET64 |
| 58 | extern void *mmap (void *__addr, size_t __len, int __prot, |
| 59 | int __flags, int __fd, __off_t __offset) __THROW; |
| 60 | libc_hidden_proto(mmap) |
| 61 | #else |
| 62 | # ifdef __REDIRECT_NTH |
| 63 | extern void * __REDIRECT_NTH (mmap, |
| 64 | (void *__addr, size_t __len, int __prot, |
| 65 | int __flags, int __fd, __off64_t __offset), |
| 66 | mmap64); |
| 67 | # else |
| 68 | # define mmap mmap64 |
| 69 | # endif |
| 70 | #endif |
| 71 | #ifdef __USE_LARGEFILE64 |
| 72 | extern void *mmap64 (void *__addr, size_t __len, int __prot, |
| 73 | int __flags, int __fd, __off64_t __offset) __THROW; |
| 74 | #endif |
| 75 | |
| 76 | /* Deallocate any mapping for the region starting at ADDR and extending LEN |
| 77 | bytes. Returns 0 if successful, -1 for errors (and sets errno). */ |
| 78 | extern int munmap (void *__addr, size_t __len) __THROW; |
| 79 | libc_hidden_proto(munmap) |
| 80 | |
| 81 | /* Change the memory protection of the region starting at ADDR and |
| 82 | extending LEN bytes to PROT. Returns 0 if successful, -1 for errors |
| 83 | (and sets errno). */ |
| 84 | extern int mprotect (void *__addr, size_t __len, int __prot) __THROW; |
| 85 | |
| 86 | #ifdef __ARCH_USE_MMU__ |
| 87 | |
| 88 | /* Synchronize the region starting at ADDR and extending LEN bytes with the |
| 89 | file it maps. Filesystem operations on a file being mapped are |
| 90 | unpredictable before this is done. Flags are from the MS_* set. |
| 91 | |
| 92 | This function is a cancellation point and therefore not marked with |
| 93 | __THROW. */ |
| 94 | extern int msync (void *__addr, size_t __len, int __flags); |
| 95 | |
| 96 | #else |
| 97 | |
| 98 | /* On no-mmu systems you can't have real private mappings. */ |
| 99 | static __inline__ int msync (void *__addr, size_t __len, int __flags) { return 0; } |
| 100 | |
| 101 | #endif |
| 102 | |
| 103 | #if defined __USE_BSD && (defined __UCLIBC_LINUX_SPECIFIC__ || defined __UCLIBC_HAS_THREADS_NATIVE__) |
| 104 | /* Advise the system about particular usage patterns the program follows |
| 105 | for the region starting at ADDR and extending LEN bytes. */ |
| 106 | extern int madvise (void *__addr, size_t __len, int __advice) __THROW; |
| 107 | #endif |
| 108 | #if defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__ |
| 109 | /* This is the POSIX name for this function. */ |
| 110 | extern int posix_madvise (void *__addr, size_t __len, int __advice) __THROW; |
| 111 | #endif |
| 112 | |
| 113 | #if defined __UCLIBC_HAS_REALTIME__ |
| 114 | # ifdef __ARCH_USE_MMU__ |
| 115 | |
| 116 | /* Guarantee all whole pages mapped by the range [ADDR,ADDR+LEN) to |
| 117 | be memory resident. */ |
| 118 | extern int mlock (__const void *__addr, size_t __len) __THROW; |
| 119 | |
| 120 | /* Unlock whole pages previously mapped by the range [ADDR,ADDR+LEN). */ |
| 121 | extern int munlock (__const void *__addr, size_t __len) __THROW; |
| 122 | |
| 123 | /* Cause all currently mapped pages of the process to be memory resident |
| 124 | until unlocked by a call to the `munlockall', until the process exits, |
| 125 | or until the process calls `execve'. */ |
| 126 | extern int mlockall (int __flags) __THROW; |
| 127 | |
| 128 | /* All currently mapped pages of the process' address space become |
| 129 | unlocked. */ |
| 130 | extern int munlockall (void) __THROW; |
| 131 | |
| 132 | #else |
| 133 | |
| 134 | /* On no-mmu systems, memory cannot be swapped out, so |
| 135 | * these functions will always succeed. */ |
| 136 | static __inline__ int mlock (__const void *__addr, size_t __len) { return 0; } |
| 137 | static __inline__ int munlock (__const void *__addr, size_t __len) { return 0; } |
| 138 | static __inline__ int mlockall (int __flags) { return 0; } |
| 139 | static __inline__ int munlockall (void) { return 0; } |
| 140 | #endif |
| 141 | #endif /* __UCLIBC_HAS_REALTIME__ */ |
| 142 | |
| 143 | #if defined __USE_MISC && defined __UCLIBC_BSD_SPECIFIC__ |
| 144 | /* mincore returns the memory residency status of the pages in the |
| 145 | current process's address space specified by [start, start + len). |
| 146 | The status is returned in a vector of bytes. The least significant |
| 147 | bit of each byte is 1 if the referenced page is in memory, otherwise |
| 148 | it is zero. */ |
| 149 | extern int mincore (void *__start, size_t __len, unsigned char *__vec) |
| 150 | __THROW; |
| 151 | #endif |
| 152 | |
| 153 | #ifdef __USE_GNU |
| 154 | /* Remap pages mapped by the range [ADDR,ADDR+OLD_LEN) to new length |
| 155 | NEW_LEN. If MREMAP_MAYMOVE is set in FLAGS the returned address |
| 156 | may differ from ADDR. If MREMAP_FIXED is set in FLAGS the function |
| 157 | takes another paramter which is a fixed address at which the block |
| 158 | resides after a successful call. */ |
| 159 | extern void *mremap (void *__addr, size_t __old_len, size_t __new_len, |
| 160 | int __flags, ...) __THROW; |
| 161 | libc_hidden_proto(mremap) |
| 162 | |
| 163 | #ifdef __UCLIBC_LINUX_SPECIFIC__ |
| 164 | /* Remap arbitrary pages of a shared backing store within an existing |
| 165 | VMA. */ |
| 166 | extern int remap_file_pages (void *__start, size_t __size, int __prot, |
| 167 | size_t __pgoff, int __flags) __THROW; |
| 168 | #endif |
| 169 | #endif |
| 170 | |
| 171 | |
| 172 | /* Open shared memory segment. */ |
| 173 | extern int shm_open (__const char *__name, int __oflag, mode_t __mode); |
| 174 | |
| 175 | /* Remove shared memory segment. */ |
| 176 | extern int shm_unlink (__const char *__name); |
| 177 | |
| 178 | __END_DECLS |
| 179 | |
| 180 | #endif /* sys/mman.h */ |