From c82102f470244762cf108a6fedd8538f37a510d3 Mon Sep 17 00:00:00 2001 From: Flemmard Date: Thu, 13 Nov 2014 00:12:22 +0100 Subject: bionic: Add flag to restore legacy mmap behavior * Pre-lollipop mmap would not care whether offset was signed or unsigned. * Lollipop adds 64-bit support which results in sign extension of offset, causing a negative offset when a positive offset > 2^31 is given. Change-Id: I5d19d898fc131cf848217974915d1b466a474f99 --- libc/bionic/mmap.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'libc/bionic') diff --git a/libc/bionic/mmap.cpp b/libc/bionic/mmap.cpp index 8f25a89..53e8b46 100644 --- a/libc/bionic/mmap.cpp +++ b/libc/bionic/mmap.cpp @@ -36,6 +36,11 @@ extern "C" void* __mmap2(void*, size_t, int, int, int, size_t); #define MMAP2_SHIFT 12 // 2**12 == 4096 +#ifdef LEGACY_MMAP +#define TO_64(a) ((a) & 0x00000000ffffffff) +#else +#define TO_64(a) (a) +#endif static bool kernel_has_MADV_MERGEABLE = true; @@ -60,5 +65,5 @@ void* mmap64(void* addr, size_t size, int prot, int flags, int fd, off64_t offse } void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset) { - return mmap64(addr, size, prot, flags, fd, static_cast(offset)); + return mmap64(addr, size, prot, flags, fd, TO_64(static_cast(offset))); } -- cgit v1.1