Implement malloc hooks.
Use the malloc debug framework to implement the malloc debug hooks
since it can introduce a performance issue.
Also, modify the bionic/tests/utils.h slightly to dump an error message
when the exe failed.
Bug: 30561479
Test: Ran malloc hook unit tests.
Test: Ran malloc debug unit tests.
Test: Enabled malloc hooks and ran bionic unit tests and verified no
Test: unexpected failures.
Test: Enabled malloc debug and malloc hooks and verified malloc debug wins.
Test: Enabled malloc debug using env, property, and property with name
Test: still works.
Change-Id: Ib50046a0493c5c2050cf831befb812310bdcc249
(cherry picked from commit d6a1dc23796696f73f483943534d4c5c4b312d39)
diff --git a/libc/malloc_hooks/Android.bp b/libc/malloc_hooks/Android.bp
new file mode 100644
index 0000000..d4b5a2a
--- /dev/null
+++ b/libc/malloc_hooks/Android.bp
@@ -0,0 +1,66 @@
+// ==============================================================
+// libc_malloc_hooks.so
+// ==============================================================
+cc_library {
+ name: "libc_malloc_hooks",
+
+ srcs: [
+ "malloc_hooks.cpp",
+ ],
+
+ static_libs: [
+ "libasync_safe",
+ ],
+
+ multilib: {
+ lib32: {
+ version_script: "exported32.map",
+ },
+ lib64: {
+ version_script: "exported64.map",
+ },
+ },
+ include_dirs: ["bionic/libc"],
+
+ sanitize: {
+ never: true,
+ },
+ native_coverage: false,
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ "-fno-stack-protector",
+ ],
+}
+
+// ==============================================================
+// Unit Tests
+// ==============================================================
+cc_test {
+ name: "malloc_hooks_unit_tests",
+ multilib: {
+ lib32: {
+ suffix: "32",
+ },
+ lib64: {
+ suffix: "64",
+ },
+ },
+
+ srcs: [
+ "tests/malloc_hooks_tests.cpp",
+ ],
+
+ whole_static_libs: ["libc_malloc_hooks"],
+
+ shared_libs: ["libbase"],
+
+ local_include_dirs: ["tests"],
+ include_dirs: ["bionic/libc", "bionic"],
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+}