2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / mmap64.c
blobd3c68cd106c9d4d4e8fc2b9b3cf7a3715da86a82
1 /* Copyright (C) 1999,2000,2001,2002,2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 1999.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <unistd.h>
22 #include <sys/mman.h>
24 #include <sysdep.h>
25 #include <sys/syscall.h>
26 #include <bp-checks.h>
28 #include <kernel-features.h>
30 #ifdef __NR_mmap2
32 /* This is always 12, even on architectures where PAGE_SHIFT != 12. */
33 # ifndef MMAP2_PAGE_SHIFT
34 # define MMAP2_PAGE_SHIFT 12
35 # endif
37 # ifndef __ASSUME_MMAP2_SYSCALL
38 static int have_no_mmap2;
39 # endif
40 #endif
43 void *
44 __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
46 #ifdef __NR_mmap2
47 if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1))
49 __set_errno (EINVAL);
50 return MAP_FAILED;
52 # ifndef __ASSUME_MMAP2_SYSCALL
53 if (! have_no_mmap2)
54 # endif
56 # ifndef __ASSUME_MMAP2_SYSCALL
57 int saved_errno = errno;
58 # endif
59 void *result;
60 __ptrvalue (result) = (void *__unbounded)
61 INLINE_SYSCALL (mmap2, 6, __ptrvalue (addr),
62 len, prot, flags, fd,
63 (off_t) (offset >> MMAP2_PAGE_SHIFT));
64 # if __BOUNDED_POINTERS__
65 __ptrlow (result) = __ptrvalue (result);
66 __ptrhigh (result) = __ptrvalue (result) + len;
67 # endif
68 # ifndef __ASSUME_MMAP2_SYSCALL
69 if (result != MAP_FAILED || errno != ENOSYS)
70 # endif
71 return result;
73 # ifndef __ASSUME_MMAP2_SYSCALL
74 __set_errno (saved_errno);
75 have_no_mmap2 = 1;
76 # endif
78 #endif
79 #ifndef __ASSUME_MMAP2_SYSCALL
80 if (offset != (off_t) offset || (offset + len) != (off_t) (offset + len))
82 __set_errno (EINVAL);
83 return MAP_FAILED;
86 return __mmap (addr, len, prot, flags, fd, (off_t) offset);
87 #endif
89 weak_alias (__mmap64, mmap64)