X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=klibc%2Fklibc%2Fmmap.c;h=11c540aed60c97c73120d641ff98e83b4b395ca1;hp=aedf4dceb562916eac2f65a4b366a712d6a522de;hb=e5f053b5312a0f8d62a2bcff8ddb095052d228bc;hpb=3555a14bae9f372385e4bc01368027cdbc29384c diff --git a/klibc/klibc/mmap.c b/klibc/klibc/mmap.c index aedf4dceb..11c540aed 100644 --- a/klibc/klibc/mmap.c +++ b/klibc/klibc/mmap.c @@ -6,46 +6,44 @@ #include #include #include +#include #include /* For PAGE_SHIFT */ +#include -#if defined(__sparc__) +/* + * MMAP2_SHIFT is definitely *NOT* equal to getpageshift() for + * many 32-bit architectures. Supposedly this is fixed to 12 + * for all 32-bit architectures. CHECK THIS!!! + */ # define MMAP2_SHIFT 12 /* Fixed by syscall definition */ -#else -# define MMAP2_SHIFT PAGE_SHIFT -#endif -#define MMAP2_MASK ((1UL << MMAP2_SHIFT)-1) /* - * Prefer mmap2() over mmap(), except on the architectures listed + * Set in SYSCALLS whether or not we should use an unadorned mmap() system + * call (typical on 64-bit architectures). */ +#if (_BITSIZE == 32 && defined(__NR_mmap2)) || (_BITSIZE == 64 && !defined(__NR_mmap)) -#if defined(__NR_mmap2) && !defined(__sparc__) && !defined(__ia64__) && !defined(__powerpc64__) - -/* This architecture uses mmap2() */ - -static inline _syscall6(void *,mmap2,void *,start,size_t,length,int,prot,int,flags,int,fd,off_t,offset); +/* This architecture uses mmap2(). The Linux mmap2() system call takes + a page offset as the offset argument. We need to make sure we have + the proper conversion in place. */ -/* The Linux mmap2() system call takes a page offset as the offset argument. - We need to make sure we have the proper conversion in place. */ +extern void *__mmap2(void *, size_t, int, int, int, size_t); void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) { - if ( offset & MMAP2_MASK ) { + const int mmap2_shift = MMAP2_SHIFT; + const unsigned long mmap2_mask = (1UL << mmap2_shift) - 1; + + if ( offset & mmap2_mask ) { errno = EINVAL; return MAP_FAILED; } - return mmap2(start, length, prot, flags, fd, (size_t)offset >> MMAP2_SHIFT); + return __mmap2(start, length, prot, flags, fd, (size_t)offset >> mmap2_shift); } -#else - -/* This architecture uses a plain mmap() system call */ -/* Only use this for architectures where mmap() is a real 6-argument system call! */ - -_syscall6(void *,mmap,void *,start,size_t,length,int,prot,int,flags,int,fd,off_t,offset) - #endif +