diff --git a/Android.bp b/Android.bp index 88435b917bc..7dd3eca03ca 100644 --- a/Android.bp +++ b/Android.bp @@ -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++", @@ -147,7 +138,6 @@ cc_defaults { "standalone/report_linux.cpp", "standalone/string_utils.cpp", "standalone/timing.cpp", - "standalone/wrappers_c_bionic.cpp" ], arch: { arm: { @@ -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", ], @@ -321,7 +339,6 @@ cc_test { srcs: [ "android/tests/size_map_verify_unit_tests.cpp", ], - } cc_binary { @@ -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: [ diff --git a/config/config_build_check.cpp b/config/config_build_check.cpp index 3f97fc7514e..37cb3ec7fd8 100644 --- a/config/config_build_check.cpp +++ b/config/config_build_check.cpp @@ -33,13 +33,20 @@ #include "allocator_config.h" +#if defined(__ANDROID__) + #if defined(SCUDO_LOW_MEMORY_CHECK) static_assert( std::is_same() == true, "Low Memory is enabled, but AndroidLowMemoryConfig is not the default"); #else static_assert(std::is_same() == true, - "Not using AndrodNormalConfig as the default"); + "Not using AndrodNormalConfig as the Android default"); +#endif + +#else +static_assert(std::is_same() == true, + "Not using HostConfig as the default"); #endif static_assert(std::is_same() == true, diff --git a/config/custom_scudo_config.h b/config/custom_scudo_config.h index a0fa59230ce..8fe8cbc68ca 100644 --- a/config/custom_scudo_config.h +++ b/config/custom_scudo_config.h @@ -84,6 +84,51 @@ typedef TableSizeClassMap static_assert(AndroidNormalSizeClassMap::usesCompressedLSBFormat(), ""); #endif +struct HostConfig { + static const bool MaySupportMemoryTagging = false; + + template using TSDRegistryT = TSDRegistryExT; // 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 using PrimaryT = SizeClassAllocator64; +#else + template using PrimaryT = SizeClassAllocator32; +#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 using CacheT = MapAllocatorCache; + }; + + template using SecondaryT = MapAllocator; +}; + struct AndroidNormalConfig { #if defined(__aarch64__) static const bool MaySupportMemoryTagging = true; @@ -173,12 +218,20 @@ struct AndroidLowMemoryConfig { template using SecondaryT = MapAllocator; }; +#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