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
diff --git a/libc/Android.mk b/libc/Android.mk
index 1ca84c1..8c6903c 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -639,6 +639,10 @@
libc_malloc_src := bionic/jemalloc_wrapper.cpp
libc_common_c_includes += external/jemalloc/include
+ifeq ($(BOARD_USES_LEGACY_MMAP),true)
+ libc_common_cflags += -DLEGACY_MMAP
+endif
+
# Define some common conlyflags
libc_common_conlyflags := \
-std=gnu99
diff --git a/libc/bionic/mmap.cpp b/libc/bionic/mmap.cpp
index 57a8cdf..9919f40 100644
--- a/libc/bionic/mmap.cpp
+++ b/libc/bionic/mmap.cpp
@@ -38,6 +38,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;
@@ -73,5 +78,5 @@
}
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<off64_t>(offset));
+ return mmap64(addr, size, prot, flags, fd, TO_64(static_cast<off64_t>(offset)));
}