Skip to content

Commit

Permalink
Merge "Add a host config for Scudo." into main
Browse files Browse the repository at this point in the history
  • Loading branch information
cferris1000 authored and Gerrit Code Review committed May 23, 2024
2 parents 603ceda + eefb73d commit 7fc8017
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 31 deletions.
63 changes: 33 additions & 30 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,6 @@ cc_defaults {
"-Werror=thread-safety",
"-Werror=type-limits",
"-Werror",

// Always force alignment to 16 bytes even on 32 bit.
// Android assumes that allocations of multiples of 16 bytes
// will be aligned to at least 16 bytes.
"-DSCUDO_MIN_ALIGNMENT_LOG=4",

// Allow scudo to use android_unsafe_frame_pointer_chase(), which is
// normally a private function.
"-DHAVE_ANDROID_UNSAFE_FRAME_POINTER_CHASE",
],
cppflags: [
"-nostdinc++",
Expand All @@ -147,7 +138,6 @@ cc_defaults {
"standalone/report_linux.cpp",
"standalone/string_utils.cpp",
"standalone/timing.cpp",
"standalone/wrappers_c_bionic.cpp"
],
arch: {
arm: {
Expand Down Expand Up @@ -180,25 +170,53 @@ cc_defaults {
"libc_headers",
"bionic_libc_platform_headers",
],
srcs: ["standalone/wrappers_c_bionic.cpp"],
cflags: [
"-D_BIONIC=1",

// Indicate that bionic has reserved a TLS for Scudo.
"-DSCUDO_HAS_PLATFORM_TLS_SLOT",

// Always force alignment to 16 bytes even on 32 bit.
// Android assumes that allocations of multiples of 16 bytes
// will be aligned to at least 16 bytes.
"-DSCUDO_MIN_ALIGNMENT_LOG=4",

// Allow scudo to use android_unsafe_frame_pointer_chase(),
// which is normally a private function.
"-DHAVE_ANDROID_UNSAFE_FRAME_POINTER_CHASE",
],
},
native_bridge: {
cflags: ["-DSCUDO_DISABLE_TBI"],
},
host: {
srcs: ["standalone/wrappers_c.cpp"],
},
},
}

cc_library_static {
cc_library {
name: "libscudo",
defaults: ["libscudo_defaults"],
cflags: [
"-D_BIONIC=1",
"-DSCUDO_HAS_PLATFORM_TLS_SLOT",
],
visibility: [
"//bionic:__subpackages__",
"//build/kati:__subpackages__",
"//frameworks/libs/native_bridge_support/android_api/libc:__subpackages__",
"//external/ninja:__subpackages__",
"//external/stg:__subpackages__",
"//system/core/debuggerd:__subpackages__",
],
shared: {
enabled: false,
},
target: {
host: {
shared: {
enabled: true,
},
},
},
apex_available: [
"com.android.runtime",
],
Expand Down Expand Up @@ -321,7 +339,6 @@ cc_test {
srcs: [
"android/tests/size_map_verify_unit_tests.cpp",
],

}

cc_binary {
Expand Down Expand Up @@ -355,20 +372,6 @@ cc_defaults {
},
}

cc_library {
name: "libscudo_verify_config",
stl: "libc++",
defaults: [
"scudo_verify_defaults",
"libscudo_defaults",
],
target: {
bionic: {
system_shared_libs: ["libc"],
},
},
}

cc_test {
name: "scudo_verify_config",
defaults: [
Expand Down
9 changes: 8 additions & 1 deletion config/config_build_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@

#include "allocator_config.h"

#if defined(__ANDROID__)

#if defined(SCUDO_LOW_MEMORY_CHECK)
static_assert(
std::is_same<scudo::Config, scudo::AndroidLowMemoryConfig>() == true,
"Low Memory is enabled, but AndroidLowMemoryConfig is not the default");
#else
static_assert(std::is_same<scudo::Config, scudo::AndroidNormalConfig>() == true,
"Not using AndrodNormalConfig as the default");
"Not using AndrodNormalConfig as the Android default");
#endif

#else
static_assert(std::is_same<scudo::Config, scudo::HostConfig>() == true,
"Not using HostConfig as the default");
#endif

static_assert(std::is_same<scudo::Config, scudo::DefaultConfig>() == true,
Expand Down
53 changes: 53 additions & 0 deletions config/custom_scudo_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,51 @@ typedef TableSizeClassMap<AndroidNormalSizeClassConfig>
static_assert(AndroidNormalSizeClassMap::usesCompressedLSBFormat(), "");
#endif

struct HostConfig {
static const bool MaySupportMemoryTagging = false;

template <class A> using TSDRegistryT = TSDRegistryExT<A>; // Exclusive TSD

struct Primary {
using SizeClassMap = AndroidNormalSizeClassMap;
#if SCUDO_CAN_USE_PRIMARY64
static const uptr RegionSizeLog = 30U;
typedef u32 CompactPtrT;
static const uptr CompactPtrScale = SCUDO_MIN_ALIGNMENT_LOG;
static const uptr GroupSizeLog = 26U;
static const bool EnableRandomOffset = false;
static const uptr MapSizeIncrement = 1UL << 18;
#else
static const uptr RegionSizeLog = 18U;
static const uptr GroupSizeLog = 18U;
typedef uptr CompactPtrT;
#endif
static const s32 MinReleaseToOsIntervalMs = -1;
static const s32 MaxReleaseToOsIntervalMs = 10000;
static const s32 DefaultReleaseToOsIntervalMs = 10000;
};
#if SCUDO_CAN_USE_PRIMARY64
template <typename Config> using PrimaryT = SizeClassAllocator64<Config>;
#else
template <typename Config> using PrimaryT = SizeClassAllocator32<Config>;
#endif

struct Secondary {
struct Cache {
static const u32 EntriesArraySize = 1024U;
static const u32 QuarantineSize = 32U;
static const u32 DefaultMaxEntriesCount = 1024U;
static const uptr DefaultMaxEntrySize = 1UL << 30;
static const s32 MinReleaseToOsIntervalMs = -1;
static const s32 MaxReleaseToOsIntervalMs = 10000;
static const s32 DefaultReleaseToOsIntervalMs = 10000;
};
template <typename Config> using CacheT = MapAllocatorCache<Config>;
};

template <typename Config> using SecondaryT = MapAllocator<Config>;
};

struct AndroidNormalConfig {
#if defined(__aarch64__)
static const bool MaySupportMemoryTagging = true;
Expand Down Expand Up @@ -173,12 +218,20 @@ struct AndroidLowMemoryConfig {
template <typename Config> using SecondaryT = MapAllocator<Config>;
};

#if defined(__ANDROID__)

#if defined(SCUDO_LOW_MEMORY)
typedef AndroidLowMemoryConfig Config;
#else
typedef AndroidNormalConfig Config;
#endif

#else

typedef HostConfig Config;

#endif

typedef Config DefaultConfig;

} // namespace scudo

0 comments on commit 7fc8017

Please sign in to comment.