x86: In ld.so, diagnose missing APX support in APX-only builds
[glibc.git] / sysdeps / unix / sysv / linux / mmap64.c
blobf1869fac0ce917043fa6222c6c3c6cb09b15ab26
1 /* mmap - map files or devices into memory. Linux version.
2 Copyright (C) 1999-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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 <https://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <unistd.h>
21 #include <sys/mman.h>
22 #include <sysdep.h>
23 #include <mmap_internal.h>
25 #ifdef __NR_mmap2
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. */
29 # define MMAP_OFF_HIGH_MASK \
30 ((-(MMAP2_PAGE_UNIT << 1) << (8 * sizeof (off_t) - 1)))
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
38 #define MMAP_OFF_MASK (MMAP_OFF_HIGH_MASK | MMAP_OFF_LOW_MASK)
40 /* An architecture may override this. */
41 #ifndef MMAP_PREPARE
42 # define MMAP_PREPARE(addr, len, prot, flags, fd, offset)
43 #endif
45 void *
46 __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
48 MMAP_CHECK_PAGE_UNIT ();
50 if (offset & MMAP_OFF_MASK)
51 return (void *) INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
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
61 weak_alias (__mmap64, mmap64)
62 libc_hidden_def (__mmap64)
64 #ifdef __OFF_T_MATCHES_OFF64_T
65 weak_alias (__mmap64, mmap)
66 weak_alias (__mmap64, __mmap)
67 libc_hidden_def (__mmap)
68 #endif