From b713a0b26f59e059ba2c73ab802fb03a4e785c03 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 26 Apr 2012 09:24:38 +0200 Subject: mmap64: Use correct type for offset parameter Some arches check the size in INLINE_SYSCALL() and barf if it's too big (i.e. a 64bit value getting truncated to 32bit). Satisfy error-check on ppc32. Signed-off-by: Bernhard Reutner-Fischer Signed-off-by: Mike Frysinger --- libc/sysdeps/linux/common/mmap64.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'libc/sysdeps/linux') diff --git a/libc/sysdeps/linux/common/mmap64.c b/libc/sysdeps/linux/common/mmap64.c index 1c8854a4d..b6eb2b3d0 100644 --- a/libc/sysdeps/linux/common/mmap64.c +++ b/libc/sysdeps/linux/common/mmap64.c @@ -50,6 +50,16 @@ __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t offset) { + /* + * Some arches check the size in INLINE_SYSCALL() and barf if it's + * too big (i.e. a 64bit value getting truncated to 32bit). + */ +# if __WORDSIZE == 32 + uint32_t sysoff; +# else + uint64_t sysoff; +# endif + if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) { __set_errno(EINVAL); return MAP_FAILED; @@ -61,8 +71,9 @@ __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t * sign extend things and pass in the wrong value. So cast it to * an unsigned 64-bit value before doing the shift. */ - return (__ptr_t) INLINE_SYSCALL(mmap2, 6, addr, len, prot, flags, fd, - ((uint64_t)offset >> MMAP2_PAGE_SHIFT)); + sysoff = (uint64_t)offset >> MMAP2_PAGE_SHIFT; + + return (__ptr_t) INLINE_SYSCALL(mmap2, 6, addr, len, prot, flags, fd, sysoff); } # endif -- cgit v1.2.3