mirror of
git://git.musl-libc.org/musl
synced 2024-12-24 07:32:49 +00:00
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.
This commit is contained in:
parent
f9ecb6bfa1
commit
fda365a530
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user