From 0b17a6561ecebd5d0bbc5a28074158ccf03775e9 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 5 Jan 2008 10:40:03 +0000 Subject: if an arch does not provide __NR_mmap, fall back to __NR_mmap2 (this just generalizes what Blackfin was already doing) --- libc/sysdeps/linux/common/mmap.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'libc/sysdeps/linux/common/mmap.c') diff --git a/libc/sysdeps/linux/common/mmap.c b/libc/sysdeps/linux/common/mmap.c index 91fc0beb1..f40554ebb 100644 --- a/libc/sysdeps/linux/common/mmap.c +++ b/libc/sysdeps/linux/common/mmap.c @@ -10,6 +10,7 @@ #include #include #include +#include #ifdef __NR_mmap @@ -41,4 +42,32 @@ __ptr_t mmap(__ptr_t addr, size_t len, int prot, #endif libc_hidden_def(mmap) + +#elif defined(__NR_mmap2) + +libc_hidden_proto(mmap) + +#define __NR___syscall_mmap2 __NR_mmap2 +static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, + size_t, len, int, prot, int, flags, int, fd, off_t, offset); + +/* Some architectures always use 12 as page shift for mmap2() eventhough the + * real PAGE_SHIFT != 12. Other architectures use the same value as + * PAGE_SHIFT... + */ +# ifndef MMAP2_PAGE_SHIFT +# define MMAP2_PAGE_SHIFT 12 +# endif + +__ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset) +{ + if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) { + __set_errno(EINVAL); + return MAP_FAILED; + } + return __syscall_mmap2(addr, len, prot, flags, fd, offset >> MMAP2_PAGE_SHIFT); +} + +libc_hidden_def(mmap) + #endif -- cgit v1.2.3