mirror of
https://github.com/intel/llvm.git
synced 2026-02-08 17:28:30 +08:00
[HWASAN] Init lsan and install at_exit hook
Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D141146
This commit is contained in:
@@ -388,10 +388,22 @@ __attribute__((constructor(0))) void __hwasan_init() {
|
||||
HwasanAllocatorInit();
|
||||
HwasanInstallAtForkHandler();
|
||||
|
||||
if (CAN_SANITIZE_LEAKS) {
|
||||
__lsan::InitCommonLsan();
|
||||
InstallAtExitCheckLeaks();
|
||||
}
|
||||
|
||||
#if HWASAN_CONTAINS_UBSAN
|
||||
__ubsan::InitAsPlugin();
|
||||
#endif
|
||||
|
||||
if (CAN_SANITIZE_LEAKS) {
|
||||
__lsan::ScopedInterceptorDisabler disabler;
|
||||
Symbolizer::LateInitialize();
|
||||
} else {
|
||||
Symbolizer::LateInitialize();
|
||||
}
|
||||
|
||||
VPrintf(1, "HWAddressSanitizer init done\n");
|
||||
|
||||
hwasan_init_is_running = 0;
|
||||
|
||||
@@ -144,6 +144,8 @@ void HwasanOnDeadlySignal(int signo, void *info, void *context);
|
||||
|
||||
void HwasanInstallAtForkHandler();
|
||||
|
||||
void InstallAtExitCheckLeaks();
|
||||
|
||||
void UpdateMemoryUsage();
|
||||
|
||||
void AppendToErrorMessageBuffer(const char *buffer);
|
||||
|
||||
@@ -185,6 +185,8 @@ void InstallAtExitHandler() {}
|
||||
|
||||
void HwasanInstallAtForkHandler() {}
|
||||
|
||||
void InstallAtExitCheckLeaks() {}
|
||||
|
||||
void InitializeOsSupport() {
|
||||
#ifdef __aarch64__
|
||||
uint32_t features = 0;
|
||||
|
||||
@@ -220,6 +220,10 @@ INTERCEPTOR(void, longjmp, __hw_jmp_buf env, int val) {
|
||||
namespace __hwasan {
|
||||
|
||||
int OnExit() {
|
||||
if (CAN_SANITIZE_LEAKS && common_flags()->detect_leaks &&
|
||||
__lsan::HasReportedLeaks()) {
|
||||
return common_flags()->exitcode;
|
||||
}
|
||||
// FIXME: ask frontend whether we need to return failure.
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -541,6 +541,17 @@ void HwasanInstallAtForkHandler() {
|
||||
pthread_atfork(before, after, after);
|
||||
}
|
||||
|
||||
void InstallAtExitCheckLeaks() {
|
||||
if (CAN_SANITIZE_LEAKS) {
|
||||
if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit) {
|
||||
if (flags()->halt_on_error)
|
||||
Atexit(__lsan::DoLeakCheck);
|
||||
else
|
||||
Atexit(__lsan::DoRecoverableLeakCheckVoid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace __hwasan
|
||||
|
||||
#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
|
||||
|
||||
Reference in New Issue
Block a user