From 9523df14d56314fb810849b481694eba0c40f32a Mon Sep 17 00:00:00 2001 From: Elfgo Date: Tue, 22 Apr 2025 09:04:35 +0000 Subject: [PATCH] [Compiler-RT][GWP_ASan] Put GWP_ASan Check Log To FaultLogger Offering: BiSheng Mobile CPU Change-Id: Idab3f9751eb454072a019fb933fe101477a20a66 Signed-off-by: Elfgo --- compiler-rt/lib/gwp_asan/gwp_asan_c_interface.cpp | 8 ++++++++ compiler-rt/lib/gwp_asan/optional/printf.h | 5 +++++ .../lib/gwp_asan/platform_specific/utilities_posix.cpp | 10 ++++++++++ 3 files changed, 23 insertions(+) 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 e0bbfde90950..5fff53b1e2cc 100644 --- a/compiler-rt/lib/gwp_asan/gwp_asan_c_interface.cpp +++ b/compiler-rt/lib/gwp_asan/gwp_asan_c_interface.cpp @@ -7,6 +7,9 @@ //===----------------------------------------------------------------------===// #include "gwp_asan/guarded_pool_allocator.h" +// OHOS_LOCAL begin +#include "gwp_asan/optional/printf.h" +// OHOS_LOCAL end #include "gwp_asan/optional/segv_handler.h" #include @@ -35,6 +38,11 @@ void init_gwp_asan(void *init_options) { gwp_asan::options::Options opts; gwp_asan_option *input_opts = reinterpret_cast(init_options); +// OHOS_LOCAL begin + #if defined(__OHOS__) + gwp_asan::Printf = input_opts->gwp_asan_printf; + #endif +// OHOS_LOCAL end opts.help = input_opts->help; opts.Enabled = input_opts->enable; opts.MaxSimultaneousAllocations = input_opts->max_simultaneous_allocations; diff --git a/compiler-rt/lib/gwp_asan/optional/printf.h b/compiler-rt/lib/gwp_asan/optional/printf.h index 1004a2c24989..6b603ce97af9 100644 --- a/compiler-rt/lib/gwp_asan/optional/printf.h +++ b/compiler-rt/lib/gwp_asan/optional/printf.h @@ -29,5 +29,10 @@ namespace gwp_asan { // library's printf(). Notably, it returns 'void' rather than 'int'. typedef void (*Printf_t)(const char *Format, ...); +// OHOS_LOCAL begin +#if defined(__OHOS__) +inline Printf_t Printf = nullptr; +#endif +// OHOS_LOCAL end } // namespace gwp_asan #endif // GWP_ASAN_OPTIONAL_PRINTF_H_ diff --git a/compiler-rt/lib/gwp_asan/platform_specific/utilities_posix.cpp b/compiler-rt/lib/gwp_asan/platform_specific/utilities_posix.cpp index 735796305509..8b196563115c 100644 --- a/compiler-rt/lib/gwp_asan/platform_specific/utilities_posix.cpp +++ b/compiler-rt/lib/gwp_asan/platform_specific/utilities_posix.cpp @@ -6,6 +6,9 @@ // //===----------------------------------------------------------------------===// +// OHOS_LOCAL begin +#include "gwp_asan/optional/printf.h" +// OHOS_LOCAL end #include // IWYU pragma: keep (for __BIONIC__ macro) #ifdef __BIONIC__ @@ -23,6 +26,13 @@ void die(const char *Message) { android_set_abort_message(Message); abort(); #else // __BIONIC__ +// OHOS_LOCAL begin +#if defined(__OHOS__) + Printf("GWP-ASan has a check error\n"); + Printf("%s\n", Message); + Printf("*** End GWP-ASan report ***\n"); + #endif +// OHOS_LOCAL end fprintf(stderr, "%s", Message); __builtin_trap(); #endif // __BIONIC__ -- Gitee