X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmman%2Fmmap.c;h=e99271f7e5dd7092cf5b84201906527425151ed9;hb=4d98280388a21db6913911ff647b2e56338d46cf;hp=0b092ae24747b8f7c89cbc4816470a3e8dc1d5d1;hpb=aa398f56fa398f2202b04e82c67f822f3233786f;p=musl diff --git a/src/mman/mmap.c b/src/mman/mmap.c index 0b092ae2..e99271f7 100644 --- a/src/mman/mmap.c +++ b/src/mman/mmap.c @@ -5,16 +5,29 @@ #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); + +#define OFF_MASK ((-0x2000ULL << (8*sizeof(long)-1)) | 0xfff) + void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off) { - 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; -#ifdef __NR_mmap2 - return (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off>>12); + void *ret; + + if (off & OFF_MASK) { + errno = EINVAL; + return MAP_FAILED; + } + if (flags & MAP_FIXED) __vm_lock(-1); +#ifdef SYS_mmap2 + ret = (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off>>12); #else - return (void *)syscall(SYS_mmap, start, len, prot, flags, fd, off); + ret = (void *)syscall(SYS_mmap, start, len, prot, flags, fd, off); #endif + if (flags & MAP_FIXED) __vm_unlock(); + return ret; } weak_alias(__mmap, mmap);