remove LFS64 symbol aliases; replace with dynamic linker remapping
[musl.git] / src / mman / mmap.c
blob43e5e02941dc7205df6f8932a052e2d318400ea4
1 #include <unistd.h>
2 #include <sys/mman.h>
3 #include <errno.h>
4 #include <stdint.h>
5 #include <limits.h>
6 #include "syscall.h"
8 static void dummy(void) { }
9 weak_alias(dummy, __vm_wait);
11 #define UNIT SYSCALL_MMAP2_UNIT
12 #define OFF_MASK ((-0x2000ULL << (8*sizeof(syscall_arg_t)-1)) | (UNIT-1))
14 void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
16 long ret;
17 if (off & OFF_MASK) {
18 errno = EINVAL;
19 return MAP_FAILED;
21 if (len >= PTRDIFF_MAX) {
22 errno = ENOMEM;
23 return MAP_FAILED;
25 if (flags & MAP_FIXED) {
26 __vm_wait();
28 #ifdef SYS_mmap2
29 ret = __syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT);
30 #else
31 ret = __syscall(SYS_mmap, start, len, prot, flags, fd, off);
32 #endif
33 /* Fixup incorrect EPERM from kernel. */
34 if (ret == -EPERM && !start && (flags&MAP_ANON) && !(flags&MAP_FIXED))
35 ret = -ENOMEM;
36 return (void *)__syscall_ret(ret);
39 weak_alias(__mmap, mmap);