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..5fff53b1e2ccd57802a939b9f8c258419cf2372c 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 1004a2c24989b60f227362193c71dce16e4b73a5..6b603ce97af97526f540cdb75f505e5d78dc2063 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 7357963055095627ddb286a80552acc120adc5ba..8b196563115c8cdfec1e07335d82dae5bb510a12 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__