]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/mmap64.c
118624185e58da457afddf8a08a045044cb29ad6
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / mmap64.c
1 /* mmap - map files or devices into memory. Linux version.
2 Copyright (C) 1999-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 1999.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
19
20 #include <errno.h>
21 #include <unistd.h>
22 #include <sys/mman.h>
23 #include <sysdep.h>
24 #include <mmap_internal.h>
25
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
32 #define MMAP_OFF_MASK (MMAP_OFF_HIGH_MASK | MMAP_OFF_LOW_MASK)
33
34 /* An architecture may override this. */
35 #ifndef MMAP_PREPARE
36 # define MMAP_PREPARE(addr, len, prot, flags, fd, offset)
37 #endif
38
39 void *
40 __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
41 {
42 MMAP_CHECK_PAGE_UNIT ();
43
44 if (offset & MMAP_OFF_MASK)
45 return (void *) INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
46
47 MMAP_PREPARE (addr, len, prot, flags, fd, offset);
48 #ifdef __NR_mmap2
49 return (void *) MMAP_CALL (mmap2, addr, len, prot, flags, fd,
50 (off_t) (offset / MMAP2_PAGE_UNIT));
51 #else
52 return (void *) MMAP_CALL (mmap, addr, len, prot, flags, fd, offset);
53 #endif
54 }
55 weak_alias (__mmap64, mmap64)
56 libc_hidden_def (__mmap64)
57
58 #ifdef __OFF_T_MATCHES_OFF64_T
59 weak_alias (__mmap64, mmap)
60 weak_alias (__mmap64, __mmap)
61 libc_hidden_def (__mmap)
62 #endif