Simplify accept4, recvmmsg, sendmmsg code.
[glibc.git] / sysdeps / unix / sysv / linux / mmap64.c
blobd3ea279afed07de04a60f079661dfaf76fb00e1d
1 /* mmap - map files or devices into memory. Linux version.
2 Copyright (C) 1999-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 1999.
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.
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.
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/>. */
20 #include <errno.h>
21 #include <unistd.h>
22 #include <sys/mman.h>
23 #include <sysdep.h>
24 #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 #define MMAP_OFF_MASK (MMAP_OFF_HIGH_MASK | MMAP_OFF_LOW_MASK)
34 /* An architecture may override this. */
35 #ifndef MMAP_PREPARE
36 # define MMAP_PREPARE(addr, len, prot, flags, fd, offset)
37 #endif
39 void *
40 __mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
42 MMAP_CHECK_PAGE_UNIT ();
44 if (offset & MMAP_OFF_MASK)
45 return (void *) INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
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
55 weak_alias (__mmap64, mmap64)
57 #ifdef __OFF_T_MATCHES_OFF64_T
58 weak_alias (__mmap64, mmap)
59 weak_alias (__mmap64, __mmap)
60 #endif