diff options
Diffstat (limited to 'libc')
-rw-r--r-- | libc/sysdeps/linux/common/mmap64.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/libc/sysdeps/linux/common/mmap64.c b/libc/sysdeps/linux/common/mmap64.c index 4ef039710..3c97c846a 100644 --- a/libc/sysdeps/linux/common/mmap64.c +++ b/libc/sysdeps/linux/common/mmap64.c @@ -59,13 +59,14 @@ __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t return MAP_FAILED; } -# ifdef __USE_FILE_OFFSET64 - return __syscall_mmap2(addr, len, prot, flags, - fd, ((__u_quad_t) offset >> MMAP2_PAGE_SHIFT)); -# else - return __syscall_mmap2(addr, len, prot, flags, - fd, ((__u_long) offset >> MMAP2_PAGE_SHIFT)); -# endif + /* + * We know __off64_t is always a signed 64-bit type, but need things + * to be unsigned before doing the shift. If it isn't, we might + * sign extend things and pass in the wrong value. So cast it to + * an unsigned 64-bit value before doing the shift. + */ + return __syscall_mmap2(addr, len, prot, flags, fd, + ((uint64_t)offset >> MMAP2_PAGE_SHIFT)); } # endif |