X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fmman%2Fmmap.c;h=b56cff86b6da4b9265b3a1350fb4ea54c0f46015;hp=5be6e12de13abaaae2f3af473d6c559216e4821f;hb=3cd6f5229f079f892411e82fce3fe15c78eef4d8;hpb=2cdfb7ca26f46f151afbc23d5d94fc68597137f5 diff --git a/src/mman/mmap.c b/src/mman/mmap.c index 5be6e12d..b56cff86 100644 --- a/src/mman/mmap.c +++ b/src/mman/mmap.c @@ -1,20 +1,38 @@ #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); + +#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 *)syscall6(__NR_mmap2, (long)start, len, prot, flags, fd, off>>12); + void *ret; + + if (off & OFF_MASK) { + errno = EINVAL; + return MAP_FAILED; + } + if (len >= PTRDIFF_MAX) { + errno = ENOMEM; + 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 *)syscall6(__NR_mmap, (long)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);