]>
Commit | Line | Data |
---|---|---|
b168057a | 1 | /* Copyright (C) 1999-2015 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 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
3eb515a6 UD |
18 | |
19 | #include <errno.h> | |
20 | #include <unistd.h> | |
9372c958 | 21 | #include <sys/mman.h> |
0716c4fc | 22 | #include <string.h> |
3eb515a6 UD |
23 | |
24 | #include <sysdep.h> | |
25 | #include <sys/syscall.h> | |
26 | ||
9372c958 | 27 | /* This is always 12, even on architectures where PAGE_SHIFT != 12. */ |
348363b2 | 28 | #if MMAP2_PAGE_SHIFT == -1 |
085f930b | 29 | static int page_shift; |
348363b2 JM |
30 | #else |
31 | # ifndef MMAP2_PAGE_SHIFT | |
32 | # define MMAP2_PAGE_SHIFT 12 | |
9372c958 | 33 | # endif |
348363b2 | 34 | #define page_shift MMAP2_PAGE_SHIFT |
9372c958 RM |
35 | #endif |
36 | ||
37 | ||
38 | void * | |
39 | __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset) | |
3eb515a6 | 40 | { |
348363b2 | 41 | #if MMAP2_PAGE_SHIFT == -1 |
085f930b UD |
42 | if (page_shift == 0) |
43 | { | |
42c8fdd8 JM |
44 | int page_size = __getpagesize (); |
45 | page_shift = __ffs (page_size) - 1; | |
085f930b | 46 | } |
9372c958 | 47 | #endif |
348363b2 | 48 | if (offset & ((1 << page_shift) - 1)) |
3eb515a6 UD |
49 | { |
50 | __set_errno (EINVAL); | |
51 | return MAP_FAILED; | |
52 | } | |
348363b2 | 53 | void *result; |
70d9946a JM |
54 | result = (void *) |
55 | INLINE_SYSCALL (mmap2, 6, addr, | |
348363b2 | 56 | len, prot, flags, fd, |
8fbec010 | 57 | (off_t) (offset >> page_shift)); |
348363b2 | 58 | return result; |
3eb515a6 | 59 | } |
3eb515a6 | 60 | weak_alias (__mmap64, mmap64) |