Maintain stack alignment in ____longjmp_chk on x86_64
[glibc.git] / sysdeps / unix / sysv / linux / mmap64.c
blobb24b3f0c8bebabab28d578340442ebf15dd2bb2f
1 /* Copyright (C) 1999,2000,2001,2002,2006,2010 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 # if MMAP2_PAGE_SHIFT == -1
34 static int page_shift;
35 # else
36 # ifndef MMAP2_PAGE_SHIFT
37 # define MMAP2_PAGE_SHIFT 12
38 # endif
39 # define page_shift MMAP2_PAGE_SHIFT
40 # endif
42 # ifndef __ASSUME_MMAP2_SYSCALL
43 static int have_no_mmap2;
44 # endif
45 #endif
48 void *
49 __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
51 #ifdef __NR_mmap2
52 # if MMAP2_PAGE_SHIFT == -1
53 if (page_shift == 0)
55 int page_size = getpagesize ();
56 while ((1 << ++page_shift) != page_size)
59 # endif
60 if (offset & ((1 << page_shift) - 1))
62 __set_errno (EINVAL);
63 return MAP_FAILED;
65 # ifndef __ASSUME_MMAP2_SYSCALL
66 if (! have_no_mmap2)
67 # endif
69 # ifndef __ASSUME_MMAP2_SYSCALL
70 int saved_errno = errno;
71 # endif
72 void *result;
73 __ptrvalue (result) = (void *__unbounded)
74 INLINE_SYSCALL (mmap2, 6, __ptrvalue (addr),
75 len, prot, flags, fd,
76 (off_t) (offset >> MMAP2_PAGE_SHIFT));
77 # if __BOUNDED_POINTERS__
78 __ptrlow (result) = __ptrvalue (result);
79 __ptrhigh (result) = __ptrvalue (result) + len;
80 # endif
81 # ifndef __ASSUME_MMAP2_SYSCALL
82 if (result != MAP_FAILED || errno != ENOSYS)
83 # endif
84 return result;
86 # ifndef __ASSUME_MMAP2_SYSCALL
87 __set_errno (saved_errno);
88 have_no_mmap2 = 1;
89 # endif
91 #endif
92 #ifndef __ASSUME_MMAP2_SYSCALL
93 if (offset != (off_t) offset || (offset + len) != (off_t) (offset + len))
95 __set_errno (EINVAL);
96 return MAP_FAILED;
99 return __mmap (addr, len, prot, flags, fd, (off_t) offset);
100 #endif
102 weak_alias (__mmap64, mmap64)