diff --git a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp index 5bf1284e1f896f81a5b7164408294cf457da1df4..3582b092e9aaecb23c2dfa6fcd387fdb1aae40c4 100644 --- a/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp +++ b/compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp @@ -8,6 +8,9 @@ #include "gwp_asan/guarded_pool_allocator.h" +// OHOS_LOCAL begin +#include "gwp_asan/optional/options_parser.h" +// OHOS_LOCAL end #include "gwp_asan/options.h" #include "gwp_asan/utilities.h" @@ -220,9 +223,12 @@ 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 < options::getOptions().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/gwp_asan_c_interface.cpp b/compiler-rt/lib/gwp_asan/gwp_asan_c_interface.cpp index e0bbfde90950965b4c8316c95caeac256ad456c5..7a63d3dffbcf33f2a16848aa81223b1fd850683f 100644 --- a/compiler-rt/lib/gwp_asan/gwp_asan_c_interface.cpp +++ b/compiler-rt/lib/gwp_asan/gwp_asan_c_interface.cpp @@ -29,6 +29,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) @@ -42,6 +46,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..e10fd2acebb6c768e82b85f994bc9392e92da2d8 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, 1024, + "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