diff --git a/compiler-rt/lib/asan/asan_rtl.cpp b/compiler-rt/lib/asan/asan_rtl.cpp index 2bbf0ac5240a703e3e48ce6d8e960e7905dd7edb..68683406314987b8520093a2c501a7b91f1e80fd 100644 --- a/compiler-rt/lib/asan/asan_rtl.cpp +++ b/compiler-rt/lib/asan/asan_rtl.cpp @@ -433,6 +433,8 @@ static void AsanInitInternal() { // AsanInitInternal -> android_log_write -> __interceptor_strcmp AndroidLogInit(); + OhosLogInit(); // OHOS_LOCAL + ReplaceSystemMalloc(); DisableCoreDumperIfNecessary(); diff --git a/compiler-rt/lib/hwasan/hwasan.cpp b/compiler-rt/lib/hwasan/hwasan.cpp index 235aa73740af811a8d25785f087179835fb08100..41c0c8b51fdfbbccd7664ec55cf4f006fc1beff5 100644 --- a/compiler-rt/lib/hwasan/hwasan.cpp +++ b/compiler-rt/lib/hwasan/hwasan.cpp @@ -351,6 +351,7 @@ __attribute__((constructor(0))) void __hwasan_init() { SetPrintfAndReportCallback(AppendToErrorMessageBuffer); // This may call libc -> needs initialized shadow. AndroidLogInit(); + OhosLogInit(); // OHOS_LOCAL InitializeInterceptors(); InstallDeadlySignalHandlers(HwasanOnDeadlySignal); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 08c6062ba067856502ace04bada1ac516fce46f2..c4153201a1a04632b1d23e23f89d646642e66003 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -925,9 +925,11 @@ inline void LogMessageOnPrintf(const char *str) {} #if SANITIZER_LINUX || SANITIZER_WIN_TRACE // Initialize Android logging. Any writes before this are silently lost. void AndroidLogInit(); +void OhosLogInit(); // OHOS_LOCAL void SetAbortMessage(const char *); #else inline void AndroidLogInit() {} +inline void OhosLogInit() {} // OHOS_LOCAL // FIXME: MacOS implementation could use CRSetCrashLogMessage. inline void SetAbortMessage(const char *) {} #endif diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp index 182155687d08c08bc8bd681489ad11e02061e848..785c399d02384e18d68e315ac1bad499742bccf6 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp @@ -896,7 +896,34 @@ void SetAbortMessage(const char *str) { if (&android_set_abort_message) android_set_abort_message(str); } +// OHOS_LOCAL begin +#elif SANITIZER_OHOS + +void AndroidLogInit() {} + +static atomic_uint8_t ohos_log_initialized; + +void OhosLogInit() { + atomic_store(&ohos_log_initialized, 1, memory_order_release); +} + +static bool ShouldLogAfterPrintf() { + return atomic_load(&ohos_log_initialized, memory_order_acquire); +} + +extern "C" SANITIZER_WEAK_ATTRIBUTE int musl_log(const char *fmt, ...); +void WriteOneLineToSyslog(const char *s) { + if (&musl_log) { + musl_log(s); + } else { + syslog(LOG_INFO, "%s", s); + } +} +void SetAbortMessage(const char *str) {} + #else +void OhosLogInit() {} + void AndroidLogInit() {} static bool ShouldLogAfterPrintf() { return true; } @@ -910,6 +937,7 @@ void LogMessageOnPrintf(const char *str) { if (common_flags()->log_to_syslog && ShouldLogAfterPrintf()) WriteToSyslog(str); } +// OHOS_LOCAL end #endif // SANITIZER_LINUX diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp index e0568c9b62d5ee6c838e2d5d4bf6d3da776416e3..e7b7d6f31f0f0dc2b3f34bd270a928da295aa4c3 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp @@ -1182,6 +1182,8 @@ void LogFullErrorReport(const char *buffer) { TraceLoggingValue(buffer, "AsanReportContents")); } } + +void OhosLogInit(void) {} // OHOS_LOCAL #endif // SANITIZER_WIN_TRACE void InitializePlatformCommonFlags(CommonFlags *cf) {} diff --git a/compiler-rt/lib/ubsan/ubsan_init.cpp b/compiler-rt/lib/ubsan/ubsan_init.cpp index 5802d58896f0fe8066bd707b3e760d3dbd7a4e82..01080567331ed894bf855f01b0b3a69720c63fd6 100644 --- a/compiler-rt/lib/ubsan/ubsan_init.cpp +++ b/compiler-rt/lib/ubsan/ubsan_init.cpp @@ -46,6 +46,7 @@ static void CommonStandaloneInit() { __sanitizer::InitializePlatformEarly(); __sanitizer_set_report_path(common_flags()->log_path); AndroidLogInit(); + OhosLogInit(); // OHOS_LOCAL InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir); CommonInit();