[git commit] mmap64: Use correct type for offset parameter

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Thu Apr 26 07:24:38 UTC 2012


commit: http://git.uclibc.org/uClibc/commit/?id=b713a0b26f59e059ba2c73ab802fb03a4e785c03
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/master

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 <rep.dot.nop at gmail.com>
Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
 libc/sysdeps/linux/common/mmap64.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/libc/sysdeps/linux/common/mmap64.c b/libc/sysdeps/linux/common/mmap64.c
index 1c8854a..b6eb2b3 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


More information about the uClibc-cvs mailing list