]>
Commit | Line | Data |
---|---|---|
a334319f | 1 | /* Copyright (C) 1999,2000,01,02 Free Software Foundation, Inc. |
3eb515a6 | 2 | This file is part of the GNU C Library. |
9372c958 | 3 | Contributed by Jakub Jelinek <jakub@redhat.com>, 1999. |
3eb515a6 UD |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
3eb515a6 UD |
9 | |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
3eb515a6 | 14 | |
41bdb6e2 AJ |
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. */ | |
3eb515a6 UD |
19 | |
20 | #include <errno.h> | |
21 | #include <unistd.h> | |
9372c958 | 22 | #include <sys/mman.h> |
3eb515a6 UD |
23 | |
24 | #include <sysdep.h> | |
25 | #include <sys/syscall.h> | |
9372c958 | 26 | #include <bp-checks.h> |
3eb515a6 | 27 | |
a334319f | 28 | #include "kernel-features.h" |
9372c958 RM |
29 | |
30 | #ifdef __NR_mmap2 | |
9372c958 RM |
31 | |
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 | |
3eb515a6 | 36 | |
9372c958 RM |
37 | # ifndef __ASSUME_MMAP2_SYSCALL |
38 | static int have_no_mmap2; | |
39 | # endif | |
40 | #endif | |
41 | ||
42 | ||
43 | void * | |
44 | __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset) | |
3eb515a6 | 45 | { |
9372c958 RM |
46 | #ifdef __NR_mmap2 |
47 | if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) | |
48 | { | |
49 | __set_errno (EINVAL); | |
50 | return MAP_FAILED; | |
51 | } | |
52 | # ifndef __ASSUME_MMAP2_SYSCALL | |
53 | if (! have_no_mmap2) | |
54 | # endif | |
55 | { | |
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; | |
72 | ||
73 | # ifndef __ASSUME_MMAP2_SYSCALL | |
74 | __set_errno (saved_errno); | |
75 | have_no_mmap2 = 1; | |
76 | # endif | |
77 | } | |
78 | #endif | |
79 | #ifndef __ASSUME_MMAP2_SYSCALL | |
3eb515a6 UD |
80 | if (offset != (off_t) offset || (offset + len) != (off_t) (offset + len)) |
81 | { | |
82 | __set_errno (EINVAL); | |
83 | return MAP_FAILED; | |
84 | } | |
85 | ||
86 | return __mmap (addr, len, prot, flags, fd, (off_t) offset); | |
9372c958 | 87 | #endif |
3eb515a6 | 88 | } |
3eb515a6 | 89 | weak_alias (__mmap64, mmap64) |