summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libc/sysdeps/linux/common/mmap64.c15
1 files changed, 13 insertions, 2 deletions
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