summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-06-03 18:47:17 -0700
committerElliott Hughes <enh@google.com>2014-06-03 18:47:17 -0700
commit9b5235d74e794d29fa912fe95ca3d5ec488dd371 (patch)
tree1cc132c801f60ba36a48af810bae05fefd4e1b02
parent3dbc2fe33e7a1c0e545f7762d3c7a98429c5a82b (diff)
downloadbionic-9b5235d74e794d29fa912fe95ca3d5ec488dd371.zip
bionic-9b5235d74e794d29fa912fe95ca3d5ec488dd371.tar.gz
bionic-9b5235d74e794d29fa912fe95ca3d5ec488dd371.tar.bz2
Hide dlmalloc symbols.
We need to leave dlmalloc_trim and dlmalloc_inspect_all exposed for the VM, but if we're seriously looking at other malloc implementations, that's something we're going to have to fix. Bug: 11156955 Change-Id: If85156c280044f1616c09a3c50ba674aaf0e8d3a
-rw-r--r--libc/Android.mk26
-rw-r--r--libc/bionic/dlmalloc.c17
-rw-r--r--libc/bionic/dlmalloc.h9
3 files changed, 36 insertions, 16 deletions
diff --git a/libc/Android.mk b/libc/Android.mk
index c0e1d32..526551e 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -500,11 +500,9 @@ endif
ifeq ($(MALLOC_IMPL),jemalloc)
libc_common_cflags += -DUSE_JEMALLOC
-
libc_malloc_src := bionic/jemalloc.cpp
else
libc_common_cflags += -DUSE_DLMALLOC
-
libc_malloc_src := bionic/dlmalloc.c
endif
@@ -821,6 +819,7 @@ LOCAL_WHOLE_STATIC_LIBRARIES := \
libc_dns \
libc_freebsd \
libc_gdtoa \
+ libc_malloc \
libc_netbsd \
libc_openbsd \
libc_stack_protector \
@@ -828,8 +827,7 @@ LOCAL_WHOLE_STATIC_LIBRARIES := \
libc_tzcode \
ifeq ($(MALLOC_IMPL),jemalloc)
-LOCAL_WHOLE_STATIC_LIBRARIES += \
- libjemalloc
+LOCAL_WHOLE_STATIC_LIBRARIES += libjemalloc
endif
LOCAL_SYSTEM_SHARED_LIBRARIES :=
@@ -879,6 +877,24 @@ include $(BUILD_STATIC_LIBRARY)
# ========================================================
+# libc_malloc.a: the _prefixed_ malloc functions (like dlcalloc).
+# ========================================================
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := $(libc_malloc_src)
+LOCAL_CFLAGS := $(libc_common_cflags) \
+ -Werror \
+ -fvisibility=hidden \
+
+LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
+LOCAL_CPPFLAGS := $(libc_common_cppflags)
+LOCAL_C_INCLUDES := $(libc_common_c_includes)
+LOCAL_MODULE := libc_malloc
+LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
+include $(BUILD_STATIC_LIBRARY)
+
+
+# ========================================================
# libc.a
# ========================================================
include $(CLEAR_VARS)
@@ -886,7 +902,6 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
$(libc_arch_static_src_files) \
$(libc_static_common_src_files) \
- $(libc_malloc_src) \
bionic/malloc_debug_common.cpp \
bionic/libc_init_static.cpp \
@@ -919,7 +934,6 @@ LOCAL_C_INCLUDES := $(libc_common_c_includes)
LOCAL_SRC_FILES := \
$(libc_arch_dynamic_src_files) \
$(libc_static_common_src_files) \
- $(libc_malloc_src) \
bionic/malloc_debug_common.cpp \
bionic/debug_mapinfo.cpp \
bionic/debug_stacktrace.cpp \
diff --git a/libc/bionic/dlmalloc.c b/libc/bionic/dlmalloc.c
index 3a615d2..2d67392 100644
--- a/libc/bionic/dlmalloc.c
+++ b/libc/bionic/dlmalloc.c
@@ -46,14 +46,11 @@ static void __bionic_heap_usage_error(const char* function, void* address) {
*((int**) 0xdeadbaad) = (int*) address;
}
-static void* named_anonymous_mmap(size_t length)
-{
- void* ret;
- ret = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
- if (ret == MAP_FAILED)
- return ret;
-
- __bionic_name_mem(ret, length, "libc_malloc");
-
- return ret;
+static void* named_anonymous_mmap(size_t length) {
+ void* map = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+ if (map == MAP_FAILED) {
+ return map;
+ }
+ __bionic_name_mem(map, length, "libc_malloc");
+ return map;
}
diff --git a/libc/bionic/dlmalloc.h b/libc/bionic/dlmalloc.h
index 71b3be8..e065687 100644
--- a/libc/bionic/dlmalloc.h
+++ b/libc/bionic/dlmalloc.h
@@ -17,6 +17,9 @@
#ifndef LIBC_BIONIC_DLMALLOC_H_
#define LIBC_BIONIC_DLMALLOC_H_
+#include <sys/cdefs.h>
+#include <stddef.h>
+
/* Configure dlmalloc. */
#define HAVE_GETPAGESIZE 1
#define MALLOC_INSPECT_ALL 1
@@ -29,6 +32,12 @@
#define USE_SPIN_LOCKS 0
#define DEFAULT_MMAP_THRESHOLD (64U * 1024U)
+/* Export two symbols used by the VM. */
+__BEGIN_DECLS
+int dlmalloc_trim(size_t) __LIBC_ABI_PUBLIC__;
+void dlmalloc_inspect_all(void (*handler)(void*, void*, size_t, void*), void*) __LIBC_ABI_PUBLIC__;
+__END_DECLS
+
/* Include the proper definitions. */
#include "../upstream-dlmalloc/malloc.h"