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.
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/>. */
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. */
36 # define MMAP_PREPARE(addr, len, prot, flags, fd, offset)
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
);
49 return (void *) MMAP_CALL (mmap2
, addr
, len
, prot
, flags
, fd
,
50 (off_t
) (offset
/ MMAP2_PAGE_UNIT
));
52 return (void *) MMAP_CALL (mmap
, addr
, len
, prot
, flags
, fd
, offset
);
55 weak_alias (__mmap64
, mmap64
)
56 libc_hidden_def (__mmap64
)
58 #ifdef __OFF_T_MATCHES_OFF64_T
59 weak_alias (__mmap64
, mmap
)
60 weak_alias (__mmap64
, __mmap
)
61 libc_hidden_def (__mmap
)