]>
Commit | Line | Data |
---|---|---|
158d5fa0 | 1 | /* mmap - map files or devices into memory. Linux version. |
581c785b | 2 | Copyright (C) 1999-2022 Free Software Foundation, Inc. |
3eb515a6 | 3 | This file is part of the GNU C Library. |
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 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
3eb515a6 UD |
18 | |
19 | #include <errno.h> | |
20 | #include <unistd.h> | |
9372c958 | 21 | #include <sys/mman.h> |
3eb515a6 | 22 | #include <sysdep.h> |
158d5fa0 | 23 | #include <mmap_internal.h> |
3eb515a6 | 24 | |
a008c76b | 25 | #ifdef __NR_mmap2 |
158d5fa0 AZ |
26 | /* To avoid silent truncation of offset when using mmap2, do not accept |
27 | offset larger than 1 << (page_shift + off_t bits). For archictures with | |
28 | 32 bits off_t and page size of 4096 it would be 1^44. */ | |
a008c76b | 29 | # define MMAP_OFF_HIGH_MASK \ |
158d5fa0 | 30 | ((-(MMAP2_PAGE_UNIT << 1) << (8 * sizeof (off_t) - 1))) |
a008c76b AZ |
31 | #else |
32 | /* Some ABIs might use __NR_mmap while having sizeof (off_t) smaller than | |
33 | sizeof (off64_t) (currently only MIPS64n32). For this case just set | |
34 | zero the higher bits so mmap with large offset does not fail. */ | |
35 | # define MMAP_OFF_HIGH_MASK 0x0 | |
36 | #endif | |
9372c958 | 37 | |
158d5fa0 AZ |
38 | #define MMAP_OFF_MASK (MMAP_OFF_HIGH_MASK | MMAP_OFF_LOW_MASK) |
39 | ||
40 | /* An architecture may override this. */ | |
41 | #ifndef MMAP_PREPARE | |
42 | # define MMAP_PREPARE(addr, len, prot, flags, fd, offset) | |
43 | #endif | |
9372c958 RM |
44 | |
45 | void * | |
46 | __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset) | |
3eb515a6 | 47 | { |
158d5fa0 AZ |
48 | MMAP_CHECK_PAGE_UNIT (); |
49 | ||
50 | if (offset & MMAP_OFF_MASK) | |
2caca60d | 51 | return (void *) INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); |
158d5fa0 AZ |
52 | |
53 | MMAP_PREPARE (addr, len, prot, flags, fd, offset); | |
54 | #ifdef __NR_mmap2 | |
55 | return (void *) MMAP_CALL (mmap2, addr, len, prot, flags, fd, | |
56 | (off_t) (offset / MMAP2_PAGE_UNIT)); | |
57 | #else | |
58 | return (void *) MMAP_CALL (mmap, addr, len, prot, flags, fd, offset); | |
59 | #endif | |
3eb515a6 | 60 | } |
3eb515a6 | 61 | weak_alias (__mmap64, mmap64) |
fa872e1b | 62 | libc_hidden_def (__mmap64) |
158d5fa0 AZ |
63 | |
64 | #ifdef __OFF_T_MATCHES_OFF64_T | |
65 | weak_alias (__mmap64, mmap) | |
66 | weak_alias (__mmap64, __mmap) | |
fa872e1b | 67 | libc_hidden_def (__mmap) |
158d5fa0 | 68 | #endif |