Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/mmap.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 946 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 946 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
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 <unistd.h> |
10 | #include <bitsize.h> |
11 | #include <klibc/sysconfig.h> |
12 | |
13 | /* |
14 | * Set in SYSCALLS whether or not we should use an unadorned mmap() system |
15 | * call (typical on 64-bit architectures). |
16 | */ |
17 | #if !_KLIBC_NO_MMU && _KLIBC_USE_MMAP2 |
18 | |
19 | /* This architecture uses mmap2(). The Linux mmap2() system call takes |
20 | a page offset as the offset argument. We need to make sure we have |
21 | the proper conversion in place. */ |
22 | |
23 | extern void *__mmap2(void *, size_t, int, int, int, size_t); |
24 | |
25 | void *mmap(void *start, size_t length, int prot, int flags, int fd, |
26 | off_t offset) |
27 | { |
28 | const int mmap2_shift = _KLIBC_MMAP2_SHIFT; |
29 | const off_t mmap2_mask = ((off_t) 1 << mmap2_shift) - 1; |
30 | |
31 | if (offset & mmap2_mask) { |
32 | errno = EINVAL; |
33 | return MAP_FAILED; |
34 | } |
35 | |
36 | return __mmap2(start, length, prot, flags, fd, |
37 | (size_t) offset >> mmap2_shift); |
38 | } |
39 | |
40 | #endif |