summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlemmard <flemmard@gmail.com>2014-11-13 00:12:22 +0100
committerArne Coucheron <arco68@gmail.com>2015-10-19 23:53:50 +0200
commitc82102f470244762cf108a6fedd8538f37a510d3 (patch)
treeae004aced5b96ce9dd3cfeb4c8499e3cec08226d
parent4b5256a4395495f7de3224483605e169599bc5a3 (diff)
downloadbionic-c82102f470244762cf108a6fedd8538f37a510d3.zip
bionic-c82102f470244762cf108a6fedd8538f37a510d3.tar.gz
bionic-c82102f470244762cf108a6fedd8538f37a510d3.tar.bz2
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
-rw-r--r--libc/Android.mk4
-rw-r--r--libc/bionic/mmap.cpp7
2 files changed, 10 insertions, 1 deletions
diff --git a/libc/Android.mk b/libc/Android.mk
index b50717d..d184250 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -610,6 +610,10 @@ ifneq ($(BOARD_MALLOC_ALIGNMENT),)
libc_common_cflags += -DMALLOC_ALIGNMENT=$(BOARD_MALLOC_ALIGNMENT)
endif
+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 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<off64_t>(offset));
+ return mmap64(addr, size, prot, flags, fd, TO_64(static_cast<off64_t>(offset)));
}