X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmman%2Fmmap.c;h=eff88d82a8fcff843247a5436f42016690daac24;hb=1ef37aa00ea830dfda76e04e3d941cafa74d8b76;hp=fd2bb07e5d5fb53f180bf21e04145914d20e1aa1;hpb=60164570111873175111cf8a5b973375e492eee9;p=musl diff --git a/src/mman/mmap.c b/src/mman/mmap.c index fd2bb07e..eff88d82 100644 --- a/src/mman/mmap.c +++ b/src/mman/mmap.c @@ -1,31 +1,41 @@ #include #include #include +#include #include #include "syscall.h" -#include "libc.h" -static void dummy1(int x) { } -static void dummy0(void) { } -weak_alias(dummy1, __vm_lock); -weak_alias(dummy0, __vm_unlock); +static void dummy(void) { } +weak_alias(dummy, __vm_wait); + +#define UNIT SYSCALL_MMAP2_UNIT +#define OFF_MASK ((-0x2000ULL << (8*sizeof(syscall_arg_t)-1)) | (UNIT-1)) void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off) { - void *ret; - if (sizeof(off_t) > sizeof(long)) - if (((long)off & 0xfff) | ((long)((unsigned long long)off>>(12 + 8*(sizeof(off_t)-sizeof(long)))))) - start = (void *)-1; - if (flags & MAP_FIXED) __vm_lock(-1); + long ret; + if (off & OFF_MASK) { + errno = EINVAL; + return MAP_FAILED; + } + if (len >= PTRDIFF_MAX) { + errno = ENOMEM; + return MAP_FAILED; + } + if (flags & MAP_FIXED) { + __vm_wait(); + } #ifdef SYS_mmap2 - ret = (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off>>12); + ret = __syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT); #else - ret = (void *)syscall(SYS_mmap, start, len, prot, flags, fd, off); + ret = __syscall(SYS_mmap, start, len, prot, flags, fd, off); #endif - if (flags & MAP_FIXED) __vm_unlock(); - return ret; + /* Fixup incorrect EPERM from kernel. */ + if (ret == -EPERM && !start && (flags&MAP_ANON) && !(flags&MAP_FIXED)) + ret = -ENOMEM; + return (void *)__syscall_ret(ret); } weak_alias(__mmap, mmap); -LFS64(mmap); +weak_alias(mmap, mmap64);