| 1 | /* Remap a virtual memory address. Linux specific syscall. |
| 2 | Copyright (C) 2021-2024 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, see |
| 17 | <https://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #include <sys/mman.h> |
| 20 | #include <sysdep.h> |
| 21 | #include <stdarg.h> |
| 22 | #include <stddef.h> |
| 23 | #include <errno.h> |
| 24 | |
| 25 | #define MREMAP_KNOWN_BITS \ |
| 26 | (MREMAP_MAYMOVE \ |
| 27 | | MREMAP_FIXED \ |
| 28 | | MREMAP_DONTUNMAP) |
| 29 | |
| 30 | void * |
| 31 | __mremap (void *addr, size_t old_len, size_t new_len, int flags, ...) |
| 32 | { |
| 33 | va_list va; |
| 34 | void *new_addr = NULL; |
| 35 | |
| 36 | if (flags & ~(MREMAP_KNOWN_BITS)) |
| 37 | { |
| 38 | __set_errno (EINVAL); |
| 39 | return MAP_FAILED; |
| 40 | } |
| 41 | |
| 42 | if (flags & (MREMAP_FIXED | MREMAP_DONTUNMAP)) |
| 43 | { |
| 44 | va_start (va, flags); |
| 45 | new_addr = va_arg (va, void *); |
| 46 | va_end (va); |
| 47 | } |
| 48 | |
| 49 | return (void *) INLINE_SYSCALL_CALL (mremap, addr, old_len, new_len, flags, |
| 50 | new_addr); |
| 51 | } |
| 52 | libc_hidden_def (__mremap) |
| 53 | weak_alias (__mremap, mremap) |
| 54 | |