riscv: Fix alignment-ignorant memcpy implementation
[glibc.git] / sysdeps / unix / sysv / linux / mmap.c
blobc7f8a6f4133c8d7ca60f06ee072670015773f877
1 /* mmap - map files or devices into memory. Linux version.
2 Copyright (C) 2017-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 <stdint.h>
25 #ifndef __OFF_T_MATCHES_OFF64_T
26 # include <mmap_internal.h>
28 /* An architecture may override this. */
29 # ifndef MMAP_ADJUST_OFFSET
30 # define MMAP_ADJUST_OFFSET(offset) offset
31 # endif
33 void *
34 __mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
36 MMAP_CHECK_PAGE_UNIT ();
38 if (offset & MMAP_OFF_LOW_MASK)
39 return (void *) INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
41 #ifdef __NR_mmap2
42 return (void *) MMAP_CALL (mmap2, addr, len, prot, flags, fd,
43 offset / (uint32_t) MMAP2_PAGE_UNIT);
44 #else
45 return (void *) MMAP_CALL (mmap, addr, len, prot, flags, fd,
46 MMAP_ADJUST_OFFSET (offset));
47 #endif
49 weak_alias (__mmap, mmap)
50 libc_hidden_def (__mmap)
52 #endif /* __OFF_T_MATCHES_OFF64_T */