1 /*
2 * Copyright (C) 2004-2007 Atmel Corporation
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser General
5 * Public License. See the file "COPYING.LIB" in the main directory of this
6 * archive for more details.
7 */
8
9 #include <errno.h>
10 #include <unistd.h>
11 #include <sys/mman.h>
12 #include <sys/syscall.h>
13
14
_syscall6(void *,mmap2,void *,addr,size_t,len,int,prot,int,flags,int,fd,__off_t,pgoff)15 static __inline__ _syscall6(void *, mmap2, void *, addr, size_t, len, int, prot,
16 int, flags, int, fd, __off_t, pgoff)
17
18 void *mmap(void *addr, size_t len, int prot, int flags, int fd, __off_t offset)
19 {
20 unsigned long page_size = sysconf(_SC_PAGESIZE);
21 unsigned long pgoff;
22
23 if (offset & (page_size - 1)) {
24 __set_errno(EINVAL);
25 return MAP_FAILED;
26 }
27
28 pgoff = (unsigned long)offset >> (31 - __builtin_clz(page_size));
29
30 return mmap2(addr, len, prot, flags, fd, pgoff);
31 }
32 libc_hidden_def(mmap)
33