Skip to content

Commit 20160b8

Browse files
committed
add hardened_malloc library
1 parent f857501 commit 20160b8

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

libc/Android.bp

+35-9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ libc_common_flags = [
5151
// Clang's exit-time destructor registration hides __dso_handle, but
5252
// __dso_handle needs to have default visibility on ARM32. See b/73485611.
5353
"-Wexit-time-destructors",
54+
55+
"-DH_MALLOC_PREFIX",
5456
]
5557

5658
// Define some common cflags
@@ -64,9 +66,17 @@ cc_defaults {
6466
cppflags: [],
6567
include_dirs: [
6668
"bionic/libc/async_safe/include",
67-
"external/jemalloc/include",
6869
],
6970

71+
multilib: {
72+
lib32: {
73+
include_dirs: ["external/jemalloc/include"],
74+
},
75+
lib64: {
76+
include_dirs: ["external/hardened_malloc/"],
77+
},
78+
},
79+
7080
stl: "none",
7181
system_shared_libs: [],
7282
sanitize: {
@@ -1577,11 +1587,6 @@ cc_library_static {
15771587
name: "libc_ndk",
15781588
defaults: ["libc_defaults"],
15791589
srcs: libc_common_src_files + ["bionic/malloc_common.cpp"],
1580-
multilib: {
1581-
lib32: {
1582-
srcs: libc_common_src_files_32,
1583-
},
1584-
},
15851590
arch: {
15861591
arm: {
15871592
srcs: [
@@ -1613,9 +1618,18 @@ cc_library_static {
16131618
"libc_syscalls",
16141619
"libc_tzcode",
16151620
"libm",
1616-
"libjemalloc",
16171621
"libstdc++",
16181622
],
1623+
1624+
multilib: {
1625+
lib32: {
1626+
srcs: libc_common_src_files_32,
1627+
whole_static_libs: ["libjemalloc"],
1628+
},
1629+
lib64: {
1630+
whole_static_libs: ["libhardened_malloc"],
1631+
},
1632+
},
16191633
}
16201634

16211635
// ========================================================
@@ -1705,7 +1719,11 @@ cc_library_static {
17051719
// ========================================================
17061720
cc_library_static {
17071721
defaults: ["libc_defaults"],
1708-
srcs: ["bionic/jemalloc_wrapper.cpp"],
1722+
multilib: {
1723+
lib32: {
1724+
srcs: ["bionic/jemalloc_wrapper.cpp"],
1725+
},
1726+
},
17091727
cflags: ["-fvisibility=hidden"],
17101728

17111729
name: "libc_malloc",
@@ -1768,9 +1786,17 @@ cc_library {
17681786
],
17691787
whole_static_libs: [
17701788
"libc_common",
1771-
"libjemalloc",
17721789
],
17731790

1791+
multilib: {
1792+
lib32: {
1793+
whole_static_libs: ["libjemalloc"],
1794+
},
1795+
lib64: {
1796+
whole_static_libs: ["libhardened_malloc"],
1797+
},
1798+
},
1799+
17741800
nocrt: true,
17751801

17761802
arch: {

libc/bionic/malloc_common.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@
4646
#include <private/bionic_globals.h>
4747
#include <private/bionic_malloc_dispatch.h>
4848

49+
#ifdef __LP64__
50+
#include "h_malloc.h"
51+
#define Malloc(function) h_ ## function
52+
#else
4953
#include "jemalloc.h"
5054
#define Malloc(function) je_ ## function
55+
#endif
5156

5257
static constexpr MallocDispatch __libc_malloc_default_dispatch
5358
__attribute__((unused)) = {

0 commit comments

Comments
 (0)