the whole point of this locking is to prevent munmap, or mmap with
MAP_FIXED, from deallocating virtual addresses, or changing the
backing a given virtual address refers to, during certain race windows
involving self-synchronized unmapping or destruction of pthread
synchronization objects. there is no need for exclusion in the other
direction, so it suffices to take the lock momentarily and release it
before making the syscall, rather than holding it across the syscall.
void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
{
void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
{
if (off & OFF_MASK) {
errno = EINVAL;
return MAP_FAILED;
if (off & OFF_MASK) {
errno = EINVAL;
return MAP_FAILED;
errno = ENOMEM;
return MAP_FAILED;
}
errno = ENOMEM;
return MAP_FAILED;
}
- if (flags & MAP_FIXED) __vm_lock(-1);
+ if (flags & MAP_FIXED) {
+ __vm_lock(-1);
+ __vm_unlock();
+ }
- ret = (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT);
+ return (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT);
- ret = (void *)syscall(SYS_mmap, start, len, prot, flags, fd, off);
+ return (void *)syscall(SYS_mmap, start, len, prot, flags, fd, off);
- if (flags & MAP_FIXED) __vm_unlock();
- return ret;
}
weak_alias(__mmap, mmap);
}
weak_alias(__mmap, mmap);
{
int ret;
__vm_lock(-1);
{
int ret;
__vm_lock(-1);
- ret = syscall(SYS_munmap, start, len);
+ ret = syscall(SYS_munmap, start, len);