Browse Source

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 <rep.dot.nop@gmail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Mike Frysinger 13 years ago
parent
commit
b713a0b26f
1 changed files with 13 additions and 2 deletions
  1. 13 2
      libc/sysdeps/linux/common/mmap64.c

+ 13 - 2
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