OSDN Git Service

2cf200dc9db0ebcbf3d6283fe13daeb75fc69f1c
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / common / mmap64.c
1 /*
2  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
3  *
4  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
5  */
6 /* Massivly hacked up for uClibc by Erik Andersen */
7
8 #include <_lfs_64.h>
9
10 #ifdef __UCLIBC_HAS_LFS__
11
12 #include <errno.h>
13 #include <unistd.h>
14 #include <sys/mman.h>
15 #include <sys/syscall.h>
16 #include <bits/uClibc_page.h>
17
18 libc_hidden_proto(mmap)
19
20 # if !defined __NR_mmap2 || !defined _syscall6
21
22 /*
23  * This version is a stub that just chops off everything at the mmap 32 bit
24  * mmap() address space...  You will probably need to add in an arch specific
25  * implementation to override this as there is not a generic way for me to
26  * implement this particular syscall if your arch lacks _syscall6...
27  *
28  */
29
30 __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t offset)
31 {
32         if (offset != (off_t) offset ||
33             (offset + len) != (off_t) (offset + len)) {
34                 __set_errno(EINVAL);
35                 return MAP_FAILED;
36         }
37
38         return mmap(addr, len, prot, flags, fd, (off_t) offset);
39 }
40
41 # else
42
43 #  define __NR___syscall_mmap2      __NR_mmap2
44 static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
45                         int, prot, int, flags, int, fd, off_t, offset);
46
47 /* Some architectures always use 12 as page shift for mmap2() eventhough the
48  * real PAGE_SHIFT != 12.  Other architectures use the same value as
49  * PAGE_SHIFT...
50  */
51 #  ifndef MMAP2_PAGE_SHIFT
52 #   define MMAP2_PAGE_SHIFT 12
53 #  endif
54
55 __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t offset)
56 {
57         if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) {
58                 __set_errno(EINVAL);
59                 return MAP_FAILED;
60         }
61
62         return __syscall_mmap2(addr, len, prot, flags, fd, (off_t) (offset >> MMAP2_PAGE_SHIFT));
63 }
64
65 # endif
66 #endif /* __UCLIBC_HAS_LFS__ */