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/>. */
23 #include <mmap_internal.h>
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)))
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
38 #define MMAP_OFF_MASK (MMAP_OFF_HIGH_MASK | MMAP_OFF_LOW_MASK)
40 /* An architecture may override this. */
42 # define MMAP_PREPARE(addr, len, prot, flags, fd, offset)
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
);
55 return (void *) MMAP_CALL (mmap2
, addr
, len
, prot
, flags
, fd
,
56 (off_t
) (offset
/ MMAP2_PAGE_UNIT
));
58 return (void *) MMAP_CALL (mmap
, addr
, len
, prot
, flags
, fd
, offset
);
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
)