Update copyright notices with scripts/update-copyrights.
[glibc.git] / sysdeps / unix / sysv / linux / mmap64.c
blob7d94c1db9a2b94d177c7ef8e9e3ebc0d45e2a8c4
1 /* Copyright (C) 1999-2013 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, see
17 <http://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <unistd.h>
21 #include <sys/mman.h>
23 #include <sysdep.h>
24 #include <sys/syscall.h>
25 #include <bp-checks.h>
27 #include <kernel-features.h>
29 /* This is always 12, even on architectures where PAGE_SHIFT != 12. */
30 #if MMAP2_PAGE_SHIFT == -1
31 static int page_shift;
32 #else
33 # ifndef MMAP2_PAGE_SHIFT
34 # define MMAP2_PAGE_SHIFT 12
35 # endif
36 #define page_shift MMAP2_PAGE_SHIFT
37 #endif
40 void *
41 __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
43 #if MMAP2_PAGE_SHIFT == -1
44 if (page_shift == 0)
46 int page_size = getpagesize ();
47 while ((1 << ++page_shift) != page_size)
50 #endif
51 if (offset & ((1 << page_shift) - 1))
53 __set_errno (EINVAL);
54 return MAP_FAILED;
56 void *result;
57 __ptrvalue (result) = (void *__unbounded)
58 INLINE_SYSCALL (mmap2, 6, __ptrvalue (addr),
59 len, prot, flags, fd,
60 (off_t) (offset >> MMAP2_PAGE_SHIFT));
61 #if __BOUNDED_POINTERS__
62 __ptrlow (result) = __ptrvalue (result);
63 __ptrhigh (result) = __ptrvalue (result) + len;
64 #endif
65 return result;
67 weak_alias (__mmap64, mmap64)