diff --git a/compiler-rt/lib/gwp_asan/optional/backtrace_ohos.cpp b/compiler-rt/lib/gwp_asan/optional/backtrace_ohos.cpp index 4ac52449b7d7384019312dbd8ff844b3bd4e2098..ad9ceddbb1b317a8b363139a7e9393b561c1db6e 100644 --- a/compiler-rt/lib/gwp_asan/optional/backtrace_ohos.cpp +++ b/compiler-rt/lib/gwp_asan/optional/backtrace_ohos.cpp @@ -17,9 +17,12 @@ extern "C" char **backtrace_symbols(void *const *trace, size_t len); #include "print_backtrace_linux_libc.inc" +// Consistent with musl extern "C" GWP_ASAN_WEAK size_t -libc_gwp_asan_unwind_fast(size_t *frame_buf, size_t max_record_stack, - __attribute__((unused)) void *signal_context); +libc_gwp_asan_unwind_fast(size_t *frame_buf, size_t max_record_stack); + +extern "C" GWP_ASAN_WEAK size_t +libc_gwp_asan_unwind_segv(size_t *frame_buf, size_t max_record_stack, void *signal_context); namespace gwp_asan { namespace backtrace { @@ -30,14 +33,14 @@ options::Backtrace_t getBacktraceFunction() { assert(&libc_gwp_asan_unwind_fast && "libc_gwp_asan_unwind_fast wasn't provided from musl."); return [](size_t *frame_buf, size_t max_record_stack) { - return libc_gwp_asan_unwind_fast(frame_buf, max_record_stack, nullptr); + return libc_gwp_asan_unwind_fast(frame_buf, max_record_stack); }; } PrintBacktrace_t getPrintBacktraceFunction() { return PrintBacktrace; } SegvBacktrace_t getSegvBacktraceFunction() { - assert(&libc_gwp_asan_unwind_fast && - "libc_gwp_asan_unwind_fast wasn't provided from musl."); - return libc_gwp_asan_unwind_fast; + assert(&libc_gwp_asan_unwind_segv && + "libc_gwp_asan_unwind_segv wasn't provided from musl."); + return libc_gwp_asan_unwind_segv; } } // namespace backtrace diff --git a/compiler-rt/test/gwp_asan/backtrace.c b/compiler-rt/test/gwp_asan/backtrace.c index f4be7305bfb7ef226734de7eacc2e4c09e93a843..1f8d781d94372bfbd062e0ff95bc00488d25e6d1 100644 --- a/compiler-rt/test/gwp_asan/backtrace.c +++ b/compiler-rt/test/gwp_asan/backtrace.c @@ -28,10 +28,20 @@ __attribute__((noinline)) void touch_mem(void *ptr) { // CHECK: allocate_mem int main() { +// OHOS_LOCAL begin +#ifdef __OHOS__ + // Tested in OHOS, it can be detected with just one execution, without the need for multiple loops. + // If the number of loops is too high, it may cause all slots to be occupied + void *ptr = allocate_mem(); + free_mem(ptr); + touch_mem(ptr); +#else for (unsigned i = 0; i < 0x10000; ++i) { void *ptr = allocate_mem(); free_mem(ptr); touch_mem(ptr); } +#endif +// OHOS_LOCAL end return 0; } diff --git a/compiler-rt/test/gwp_asan/lit.cfg.py b/compiler-rt/test/gwp_asan/lit.cfg.py index 58658a4551dc45f8186b74213b8acf4e47c5daf5..8140916128cf8922201c837a92210a9e164230cb 100644 --- a/compiler-rt/test/gwp_asan/lit.cfg.py +++ b/compiler-rt/test/gwp_asan/lit.cfg.py @@ -44,7 +44,12 @@ config.substitutions.append(( # Platform-specific default GWP_ASAN for lit tests. Ensure that GWP-ASan is # enabled and that it samples every allocation. -default_gwp_asan_options = 'GWP_ASAN_Enabled=1:GWP_ASAN_SampleRate=1' +if config.host_os == 'OHOS': # OHOS_LOCAL + # The default value for GWP_ASAN_MaxSimulataneousAllocations is 16, which is not sufficient for gwp-asan testing + # in OHOS, resulting in many test cases being unable to trigger gwp-asan detection. + default_gwp_asan_options = 'GWP_ASAN_Enabled=1:GWP_ASAN_SampleRate=1:GWP_ASAN_MaxSimultaneousAllocations=500' +else: + default_gwp_asan_options = 'GWP_ASAN_Enabled=1:GWP_ASAN_SampleRate=1' config.environment['SCUDO_OPTIONS'] = default_gwp_asan_options default_gwp_asan_options += ':'