]> git.ipfire.org Git - thirdparty/systemd.git/blob - klibc/klibc/mmap.c
3d28cba601ed4dea3fbd70c970b3d81bbf1e535c
[thirdparty/systemd.git] / klibc / klibc / mmap.c
1 /*
2 * mmap.c
3 */
4
5 #include <stdint.h>
6 #include <errno.h>
7 #include <sys/syscall.h>
8 #include <sys/mman.h>
9 #include <asm/page.h> /* For PAGE_SHIFT */
10
11 #if defined(__sparc__)
12 # define MMAP2_SHIFT 12 /* Fixed by syscall definition */
13 #else
14 # define MMAP2_SHIFT PAGE_SHIFT
15 #endif
16 #define MMAP2_MASK ((1UL << MMAP2_SHIFT)-1)
17
18 /*
19 * Prefer mmap2() over mmap(), except on the architectures listed
20 */
21
22 #if defined(__NR_mmap2) && !defined(__sparc__) && !defined(__ia64__)
23
24 /* This architecture uses mmap2() */
25
26 static inline _syscall6(void *,mmap2,void *,start,size_t,length,int,prot,int,flags,int,fd,off_t,offset);
27
28 /* The Linux mmap2() system call takes a page offset as the offset argument.
29 We need to make sure we have the proper conversion in place. */
30
31 void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
32 {
33 if ( offset & MMAP2_MASK ) {
34 errno = EINVAL;
35 return MAP_FAILED;
36 }
37
38 return mmap2(start, length, prot, flags, fd, (size_t)offset >> MMAP2_SHIFT);
39 }
40
41 #else
42
43 /* This architecture uses a plain mmap() system call */
44 /* Only use this for architectures where mmap() is a real 6-argument system call! */
45
46 _syscall6(void *,mmap,void *,start,size_t,length,int,prot,int,flags,int,fd,off_t,offset)
47
48 #endif
49
50
51