diff options
author | Rich Felker <dalias@aerifal.cx> | 2015-11-02 16:37:51 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2015-11-02 16:37:51 -0500 |
commit | fda365a53074f97f3213caefe70ea13297acecb2 (patch) | |
tree | 2506ac8bfc363f5671a2be0c16a0a69c23167fdf /src/mman/mremap.c | |
parent | f9ecb6bfa1dc9f93a10dad97a158e6b8334c586c (diff) | |
download | musl-fda365a53074f97f3213caefe70ea13297acecb2.tar.gz musl-fda365a53074f97f3213caefe70ea13297acecb2.tar.xz musl-fda365a53074f97f3213caefe70ea13297acecb2.zip |
fix mremap memory synchronization and use of variadic argument
since mremap with the MREMAP_FIXED flag is an operation that unmaps existing mappings, it needs to use the vm lock mechanism to ensure that any in-progress synchronization operations using vm identities from before the call have finished. also, the variadic argument was erroneously being read even if the MREMAP_FIXED flag was not passed. in practice this didn't break anything, but it's UB and in theory LTO could turn it into a hard error.
Diffstat (limited to 'src/mman/mremap.c')
-rw-r--r-- | src/mman/mremap.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/mman/mremap.c b/src/mman/mremap.c index 1096ace1..ce4e8ea1 100644 --- a/src/mman/mremap.c +++ b/src/mman/mremap.c @@ -1,3 +1,4 @@ +#define _GNU_SOURCE #include <unistd.h> #include <sys/mman.h> #include <errno.h> @@ -6,19 +7,25 @@ #include "syscall.h" #include "libc.h" +static void dummy(void) { } +weak_alias(dummy, __vm_wait); + void *__mremap(void *old_addr, size_t old_len, size_t new_len, int flags, ...) { va_list ap; - void *new_addr; + void *new_addr = 0; if (new_len >= PTRDIFF_MAX) { errno = ENOMEM; return MAP_FAILED; } - va_start(ap, flags); - new_addr = va_arg(ap, void *); - va_end(ap); + if (flags & MREMAP_FIXED) { + __vm_wait(); + va_start(ap, flags); + new_addr = va_arg(ap, void *); + va_end(ap); + } return (void *)syscall(SYS_mremap, old_addr, old_len, new_len, flags, new_addr); } |