提交 fda365a5 编写于 作者: R Rich Felker

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.
上级 f9ecb6bf
#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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册