diff --git a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp index 5bf1284e1f896f81a5b7164408294cf457da1df4..6c06f10ab34ead7e5c1fae705a6432b2cc562d6e 100644 --- a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp +++ b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp @@ -58,6 +58,10 @@ void GuardedPoolAllocator::init(const options::Options &Opts) { SingletonPtr = this; Backtrace = Opts.Backtrace; + // OHOS_LOCAL begin + MinSampleSize = Opts.MinSampleSize; + WhiteListPath = Opts.WhiteListPath; + // OHOS_LOCAL end State.VersionMagic = {{AllocatorVersionMagic::kAllocatorVersionMagic[0], AllocatorVersionMagic::kAllocatorVersionMagic[1], @@ -220,9 +224,11 @@ void *GuardedPoolAllocator::allocate(size_t Size, size_t Alignment) { if (Alignment == 0) Alignment = alignof(max_align_t); + // OHOS_LOCAL begin if (!isPowerOfTwo(Alignment) || Alignment > State.maximumAllocationSize() || - Size > State.maximumAllocationSize()) + Size > State.maximumAllocationSize() || Size < MinSampleSize) return nullptr; + // OHOS_LOCAL end size_t BackingSize = getRequiredBackingSize(Size, Alignment, State.PageSize); if (BackingSize > State.maximumAllocationSize()) diff --git a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h index 152028acd822c28c96b9d8ebc6192f57aa469e30..59686070ab069d47d415b836fbeb81c3851dcd4d 100644 --- a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h +++ b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.h @@ -197,6 +197,11 @@ private: gwp_asan::AllocatorState State; + // OHOS_LOCAL begin + uint32_t MinSampleSize{0}; + const char *WhiteListPath = ""; + // OHOS_LOCAL end + // A mutex to protect the guarded slot and metadata pool for this class. Mutex PoolMutex; // Some unwinders can grab the libdl lock. In order to provide atfork diff --git a/compiler-rt/lib/gwp_asan/gwp_asan_c_interface.cpp b/compiler-rt/lib/gwp_asan/gwp_asan_c_interface.cpp index 5fff53b1e2ccd57802a939b9f8c258419cf2372c..a46b33d939d42e451b249af76a761746fd020b3f 100644 --- a/compiler-rt/lib/gwp_asan/gwp_asan_c_interface.cpp +++ b/compiler-rt/lib/gwp_asan/gwp_asan_c_interface.cpp @@ -32,6 +32,10 @@ typedef struct gwp_asan_option { gwp_asan::Printf_t gwp_asan_printf; gwp_asan::backtrace::PrintBacktrace_t printf_backtrace; gwp_asan::backtrace::SegvBacktrace_t segv_backtrace; + // OHOS_LOCAL begin + int min_sample_size; + const char *white_list_path; + // OHOS_LOCAL end } gwp_asan_option; void init_gwp_asan(void *init_options) @@ -50,6 +54,10 @@ void init_gwp_asan(void *init_options) opts.InstallSignalHandlers = input_opts->install_signal_handlers; opts.InstallForkHandlers = input_opts->install_fork_handlers; opts.Backtrace = input_opts->backtrace; + // OHOS_LOCAL begin + opts.MinSampleSize = input_opts->min_sample_size; + opts.WhiteListPath = input_opts->white_list_path; + // OHOS_LOCAL end guarded_poll_alloctor.init(opts); if (input_opts->install_signal_handlers) { gwp_asan::segv_handler::installSignalHandlersOhos(&guarded_poll_alloctor, input_opts->gwp_asan_printf, diff --git a/compiler-rt/lib/gwp_asan/options.h b/compiler-rt/lib/gwp_asan/options.h index 6fb43108b5deb226d60e346f89d6637b3b69aabd..06fd374e531055af6d777048223062155ff44770 100644 --- a/compiler-rt/lib/gwp_asan/options.h +++ b/compiler-rt/lib/gwp_asan/options.h @@ -35,6 +35,9 @@ typedef size_t (*Backtrace_t)(uintptr_t *TraceBuffer, size_t Size); struct Options { Backtrace_t Backtrace = nullptr; + // OHOS_LOCAL begin + const char *WhiteListPath = ""; + // OHOS_LOCAL end // Read the options from the included definitions file. #define GWP_ASAN_OPTION(Type, Name, DefaultValue, Description) \ @@ -49,6 +52,9 @@ struct Options { #undef GWP_ASAN_OPTION Backtrace = nullptr; + // OHOS_LOCAL begin + WhiteListPath = ""; + // OHOS_LOCAL end } }; } // namespace options diff --git a/compiler-rt/lib/gwp_asan/options.inc b/compiler-rt/lib/gwp_asan/options.inc index 9900a2ac40df100279bb303c0b7e39afff7aece9..2cbb058a9e20f7a2b2df9051a8d6ef01c858e22b 100644 --- a/compiler-rt/lib/gwp_asan/options.inc +++ b/compiler-rt/lib/gwp_asan/options.inc @@ -32,6 +32,12 @@ GWP_ASAN_OPTION(int, SampleRate, 5000, "selected for GWP-ASan sampling. Default is 5000. Sample rates " "up to (2^30 - 1) are supported.") +// OHOS_LOCAL begin +GWP_ASAN_OPTION(int, MinSampleSize, 0, + "Sampling is decided by whether the allocation size exceeds" + "the minimum threshold") +// OHOS_LOCAL end + // Developer note - This option is not actually processed by GWP-ASan itself. It // is included here so that a user can specify whether they want signal handlers // or not. The supporting allocator should inspect this value to see whether