Skip to content

Commit

Permalink
add hardened_malloc library
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed May 6, 2019
1 parent f857501 commit 20160b8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
44 changes: 35 additions & 9 deletions libc/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ libc_common_flags = [
// Clang's exit-time destructor registration hides __dso_handle, but
// __dso_handle needs to have default visibility on ARM32. See b/73485611.
"-Wexit-time-destructors",

"-DH_MALLOC_PREFIX",
]

// Define some common cflags
Expand All @@ -64,9 +66,17 @@ cc_defaults {
cppflags: [],
include_dirs: [
"bionic/libc/async_safe/include",
"external/jemalloc/include",
],

multilib: {
lib32: {
include_dirs: ["external/jemalloc/include"],
},
lib64: {
include_dirs: ["external/hardened_malloc/"],
},
},

stl: "none",
system_shared_libs: [],
sanitize: {
Expand Down Expand Up @@ -1577,11 +1587,6 @@ cc_library_static {
name: "libc_ndk",
defaults: ["libc_defaults"],
srcs: libc_common_src_files + ["bionic/malloc_common.cpp"],
multilib: {
lib32: {
srcs: libc_common_src_files_32,
},
},
arch: {
arm: {
srcs: [
Expand Down Expand Up @@ -1613,9 +1618,18 @@ cc_library_static {
"libc_syscalls",
"libc_tzcode",
"libm",
"libjemalloc",
"libstdc++",
],

multilib: {
lib32: {
srcs: libc_common_src_files_32,
whole_static_libs: ["libjemalloc"],
},
lib64: {
whole_static_libs: ["libhardened_malloc"],
},
},
}

// ========================================================
Expand Down Expand Up @@ -1705,7 +1719,11 @@ cc_library_static {
// ========================================================
cc_library_static {
defaults: ["libc_defaults"],
srcs: ["bionic/jemalloc_wrapper.cpp"],
multilib: {
lib32: {
srcs: ["bionic/jemalloc_wrapper.cpp"],
},
},
cflags: ["-fvisibility=hidden"],

name: "libc_malloc",
Expand Down Expand Up @@ -1768,9 +1786,17 @@ cc_library {
],
whole_static_libs: [
"libc_common",
"libjemalloc",
],

multilib: {
lib32: {
whole_static_libs: ["libjemalloc"],
},
lib64: {
whole_static_libs: ["libhardened_malloc"],
},
},

nocrt: true,

arch: {
Expand Down
5 changes: 5 additions & 0 deletions libc/bionic/malloc_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@
#include <private/bionic_globals.h>
#include <private/bionic_malloc_dispatch.h>

#ifdef __LP64__
#include "h_malloc.h"
#define Malloc(function) h_ ## function
#else
#include "jemalloc.h"
#define Malloc(function) je_ ## function
#endif

static constexpr MallocDispatch __libc_malloc_default_dispatch
__attribute__((unused)) = {
Expand Down

0 comments on commit 20160b8

Please sign in to comment.