Revert "Add aborts to catch frees of bad pointers."

bug:21873627

This reverts commit ad86b0533fd6bfc78ffebb8a8be275ed0ac93776.

Change-Id: I68c23b39ec4e0a746d3a92c51c9c7cd470cb4cde
diff --git a/Android.mk b/Android.mk
index 80a2ff2..c496631 100644
--- a/Android.mk
+++ b/Android.mk
@@ -16,7 +16,7 @@
 
 LOCAL_PATH := $(call my-dir)
 
-jemalloc_common_cflags := \
+common_cflags := \
 	-std=gnu99 \
 	-D_REENTRANT \
 	-fvisibility=hidden \
@@ -39,18 +39,18 @@
 #     then large allocations will take longer to complete.
 #   ANDROID_LG_TCACHE_MAXCLASS_DEFAULT=XX
 #     1 << XX is the maximum sized allocation that will be in the tcache.
-jemalloc_common_cflags += \
+common_cflags += \
 	-DANDROID_ALWAYS_PURGE \
 	-DANDROID_MAX_ARENAS=2 \
 	-DANDROID_TCACHE_NSLOTS_SMALL_MAX=8 \
 	-DANDROID_TCACHE_NSLOTS_LARGE=16 \
 	-DANDROID_LG_TCACHE_MAXCLASS_DEFAULT=16 \
 
-jemalloc_common_c_includes := \
+common_c_includes := \
 	$(LOCAL_PATH)/src \
 	$(LOCAL_PATH)/include \
 
-jemalloc_lib_src_files := \
+lib_src_files := \
 	src/arena.c \
 	src/atomic.c \
 	src/base.c \
@@ -86,14 +86,13 @@
 	$(LOCAL_PATH)/Android.mk \
 
 LOCAL_CFLAGS := \
-	$(jemalloc_common_cflags) \
-	-include bionic/libc/private/libc_logging.h \
+	$(common_cflags) \
 
 LOCAL_C_INCLUDES := \
-	$(jemalloc_common_c_includes) \
+	$(common_c_includes) \
 
 LOCAL_SRC_FILES := \
-	$(jemalloc_lib_src_files) \
+	$(lib_src_files) \
 
 # This is linked into libc, which asan runtime library depends on.
 LOCAL_SANITIZE := never
@@ -112,15 +111,14 @@
 	$(LOCAL_PATH)/Android.mk \
 
 LOCAL_CFLAGS := \
-	$(jemalloc_common_cflags) \
+	$(common_cflags) \
 	-DJEMALLOC_JET \
-	-include $(LOCAL_PATH)/android/include/libc_logging.h \
 
 LOCAL_C_INCLUDES := \
-	$(jemalloc_common_c_includes) \
+	$(common_c_includes) \
 
 LOCAL_SRC_FILES := \
-	$(jemalloc_lib_src_files) \
+	$(lib_src_files) \
 
 include $(BUILD_STATIC_LIBRARY)
 
@@ -147,12 +145,11 @@
 	$(LOCAL_PATH)/Android.mk \
 
 LOCAL_CFLAGS := \
-	$(jemalloc_common_cflags) \
+	$(common_cflags) \
 	-DJEMALLOC_UNIT_TEST \
-	-include $(LOCAL_PATH)/android/include/libc_logging.h \
 
 LOCAL_C_INCLUDES := \
-	$(jemalloc_common_c_includes) \
+	$(common_c_includes) \
 	$(LOCAL_PATH)/test/src \
 	$(LOCAL_PATH)/test/include \
 
@@ -165,7 +162,7 @@
 #-----------------------------------------------------------------------
 # jemalloc unit tests
 #-----------------------------------------------------------------------
-jemalloc_unit_tests := \
+unit_tests := \
 	test/unit/atomic.c \
 	test/unit/bitmap.c \
 	test/unit/ckh.c \
@@ -194,7 +191,7 @@
 	test/unit/util.c \
 	test/unit/zero.c \
 
-$(foreach test,$(jemalloc_unit_tests), \
+$(foreach test,$(unit_tests), \
   $(eval test_name := $(basename $(notdir $(test)))); \
   $(eval test_src := $(test)); \
   $(eval test_cflags := -DJEMALLOC_UNIT_TEST); \
@@ -215,25 +212,24 @@
 	$(LOCAL_PATH)/Android.mk \
 
 LOCAL_CFLAGS := \
-	$(jemalloc_common_cflags) \
+	$(common_cflags) \
 	-DJEMALLOC_INTEGRATION_TEST \
-	-include $(LOCAL_PATH)/android/include/libc_logging.h \
 
 LOCAL_C_INCLUDES := \
-	$(jemalloc_common_c_includes) \
+	$(common_c_includes) \
 	$(LOCAL_PATH)/test/src \
 	$(LOCAL_PATH)/test/include \
 
-LOCAL_SRC_FILES := \
-	$(jemalloc_testlib_srcs) \
-	$(jemalloc_lib_src_files) \
+LOCAL_SRC_FILES := $(jemalloc_testlib_srcs)
+
+LOCAL_WHOLE_STATIC_LIBRARIES := libjemalloc
 
 include $(BUILD_STATIC_LIBRARY)
 
 #-----------------------------------------------------------------------
 # jemalloc integration tests
 #-----------------------------------------------------------------------
-jemalloc_integration_tests := \
+integration_tests := \
 	test/integration/aligned_alloc.c \
 	test/integration/allocated.c \
 	test/integration/sdallocx.c \
@@ -246,7 +242,7 @@
 	test/integration/xallocx.c \
 	test/integration/chunk.c \
 
-$(foreach test,$(jemalloc_integration_tests), \
+$(foreach test,$(integration_tests), \
   $(eval test_name := $(basename $(notdir $(test)))); \
   $(eval test_src := $(test)); \
   $(eval test_cflags := -DJEMALLOC_INTEGRATION_TEST); \
diff --git a/Android.test.mk b/Android.test.mk
index 1c40478..0278677 100644
--- a/Android.test.mk
+++ b/Android.test.mk
@@ -21,15 +21,14 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_NATIVE_TESTS)/$(test_path)
 
 LOCAL_ADDITIONAL_DEPENDENCIES := \
-	$(LOCAL_PATH)/Android.test.mk \
+	$(LOCAL_PATH)/Android.mk \
 
 LOCAL_CFLAGS := \
-	$(jemalloc_common_cflags) \
+	$(common_cflags) \
 	$(test_cflags) \
-	-include $(LOCAL_PATH)/android/include/libc_logging.h \
 
 LOCAL_C_INCLUDES := \
-	$(jemalloc_common_c_includes) \
+	$(common_c_includes) \
 	$(LOCAL_PATH)/test/src \
 	$(LOCAL_PATH)/test/include \
 
diff --git a/android/include/libc_logging.h b/android/include/libc_logging.h
deleted file mode 100644
index 19c2cfe..0000000
--- a/android/include/libc_logging.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *  * Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *  * Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _JEMALLOC_LIBC_LOGGING_H
-#define _JEMALLOC_LIBC_LOGGING_H
-
-/* Convert this to an abort for jemalloc tests. */
-#define __libc_fatal(format, ...) abort()
-
-#endif  /* _JEMALLOC_LIBC_LOGGING_H */
diff --git a/include/jemalloc/internal/arena.h b/include/jemalloc/internal/arena.h
index 0209e61..6f3c77c 100644
--- a/include/jemalloc/internal/arena.h
+++ b/include/jemalloc/internal/arena.h
@@ -1162,20 +1162,8 @@
 	chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
 	if (likely(chunk != ptr)) {
 		pageind = ((uintptr_t)ptr - (uintptr_t)chunk) >> LG_PAGE;
-#if defined(__ANDROID__)
-		/* Verify the ptr is actually in the chunk. */
-		if (unlikely(pageind < map_bias || pageind >= chunk_npages)) {
-			__libc_fatal("Invalid address %p passed to free: invalid page index", ptr);
-		}
-#endif
 		mapbits = arena_mapbits_get(chunk, pageind);
 		assert(arena_mapbits_allocated_get(chunk, pageind) != 0);
-#if defined(__ANDROID__)
-		/* Verify the ptr has been allocated. */
-		if (unlikely((mapbits & CHUNK_MAP_ALLOCATED) == 0)) {
-			__libc_fatal("Invalid address %p passed to free: value not allocated", ptr);
-		}
-#endif
 		if (likely((mapbits & CHUNK_MAP_LARGE) == 0)) {
 			/* Small allocation. */
 			if (likely(tcache != NULL)) {