[compiler-rt] 029b410 - [HWASAN] Set os_id in Thread::Init to make sure that the thread can be found by GetThreadByOsIDLocked.
Kirill Stoimenov via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 1 17:43:00 PST 2023
Author: Kirill Stoimenov
Date: 2023-02-02T01:42:48Z
New Revision: 029b410df31afd6ea1aee9da6949c84b6db19112
URL: https://github.com/llvm/llvm-project/commit/029b410df31afd6ea1aee9da6949c84b6db19112
DIFF: https://github.com/llvm/llvm-project/commit/029b410df31afd6ea1aee9da6949c84b6db19112.diff
LOG: [HWASAN] Set os_id in Thread::Init to make sure that the thread can be found by GetThreadByOsIDLocked.
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D143125
Added:
Modified:
compiler-rt/lib/hwasan/hwasan_interceptors.cpp
compiler-rt/lib/hwasan/hwasan_thread.cpp
compiler-rt/lib/hwasan/hwasan_thread.h
compiler-rt/test/lsan/TestCases/Linux/cleanup_in_tsd_destructor.c
compiler-rt/test/lsan/TestCases/Linux/fork_threaded.cpp
compiler-rt/test/lsan/TestCases/Linux/guard-page.c
compiler-rt/test/lsan/TestCases/Linux/libdl_deadlock.cpp
compiler-rt/test/lsan/TestCases/many_tls_keys_pthread.cpp
compiler-rt/test/lsan/TestCases/many_tls_keys_thread.cpp
compiler-rt/test/lsan/TestCases/use_registers.cpp
compiler-rt/test/lsan/TestCases/use_registers_extra.cpp
compiler-rt/test/lsan/TestCases/use_stacks_threaded.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
index 05bf3f29eca30..c1ed2cd60580c 100644
--- a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
@@ -39,6 +39,7 @@ static void *HwasanThreadStartFunc(void *arg) {
INTERCEPTOR(int, pthread_create, void *th, void *attr, void *(*callback)(void*),
void * param) {
+ EnsureMainThreadIDIsCorrect();
ScopedTaggingDisabler disabler;
ThreadStartArg *A = reinterpret_cast<ThreadStartArg *> (MmapOrDie(
GetPageSizeCached(), "pthread_create"));
diff --git a/compiler-rt/lib/hwasan/hwasan_thread.cpp b/compiler-rt/lib/hwasan/hwasan_thread.cpp
index 4a78f60629032..3375782ef29b4 100644
--- a/compiler-rt/lib/hwasan/hwasan_thread.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_thread.cpp
@@ -44,6 +44,8 @@ void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size,
static atomic_uint64_t unique_id;
unique_id_ = atomic_fetch_add(&unique_id, 1, memory_order_relaxed);
+ if (!IsMainThread())
+ os_id_ = GetTid();
if (auto sz = flags()->heap_history_size)
heap_allocations_ = HeapAllocationsRingBuffer::New(sz);
@@ -149,6 +151,12 @@ tag_t Thread::GenerateRandomTag(uptr num_bits) {
return tag;
}
+void EnsureMainThreadIDIsCorrect() {
+ auto *t = __hwasan::GetCurrentThread();
+ if (t && (t->IsMainThread()))
+ t->set_os_id(GetTid());
+}
+
} // namespace __hwasan
// --- Implementation of LSan-specific functions --- {{{1
@@ -169,11 +177,7 @@ void LockThreadRegistry() { __hwasan::hwasanThreadList().Lock(); }
void UnlockThreadRegistry() { __hwasan::hwasanThreadList().Unlock(); }
-void EnsureMainThreadIDIsCorrect() {
- auto *t = __hwasan::GetCurrentThread();
- if (t && (t->IsMainThread()))
- t->set_os_id(GetTid());
-}
+void EnsureMainThreadIDIsCorrect() { __hwasan::EnsureMainThreadIDIsCorrect(); }
bool GetThreadRangesLocked(tid_t os_id, uptr *stack_begin, uptr *stack_end,
uptr *tls_begin, uptr *tls_end, uptr *cache_begin,
diff --git a/compiler-rt/lib/hwasan/hwasan_thread.h b/compiler-rt/lib/hwasan/hwasan_thread.h
index 9727585ef7544..9e1b438e48f77 100644
--- a/compiler-rt/lib/hwasan/hwasan_thread.h
+++ b/compiler-rt/lib/hwasan/hwasan_thread.h
@@ -110,6 +110,9 @@ class Thread {
Thread *GetCurrentThread();
uptr *GetCurrentThreadLongPtr();
+// Used to handle fork().
+void EnsureMainThreadIDIsCorrect();
+
struct ScopedTaggingDisabler {
ScopedTaggingDisabler() { GetCurrentThread()->DisableTagging(); }
~ScopedTaggingDisabler() { GetCurrentThread()->EnableTagging(); }
diff --git a/compiler-rt/test/lsan/TestCases/Linux/cleanup_in_tsd_destructor.c b/compiler-rt/test/lsan/TestCases/Linux/cleanup_in_tsd_destructor.c
index 29f6a483a7a1d..00a0ec3b9967f 100644
--- a/compiler-rt/test/lsan/TestCases/Linux/cleanup_in_tsd_destructor.c
+++ b/compiler-rt/test/lsan/TestCases/Linux/cleanup_in_tsd_destructor.c
@@ -7,9 +7,6 @@
// RUN: %env_lsan_opts="report_objects=1:use_registers=0:use_stacks=0:use_tls=1" %run %t
// RUN: %env_lsan_opts="report_objects=1:use_registers=0:use_stacks=0:use_tls=0" not %run %t 2>&1 | FileCheck %s
-// Fixme: remove once test passes with hwasan
-// UNSUPPORTED: hwasan
-
// Investigate why it does not fail with use_stack=0
// UNSUPPORTED: arm-linux || armhf-linux
diff --git a/compiler-rt/test/lsan/TestCases/Linux/fork_threaded.cpp b/compiler-rt/test/lsan/TestCases/Linux/fork_threaded.cpp
index b80cfeef4342f..62702b4dfe47b 100644
--- a/compiler-rt/test/lsan/TestCases/Linux/fork_threaded.cpp
+++ b/compiler-rt/test/lsan/TestCases/Linux/fork_threaded.cpp
@@ -3,9 +3,6 @@
// RUN: %clangxx_lsan %s -o %t
// RUN: %run %t 2>&1
-// Fixme: remove once test passes with hwasan
-// UNSUPPORTED: hwasan
-
#include <assert.h>
#include <pthread.h>
#include <stdio.h>
diff --git a/compiler-rt/test/lsan/TestCases/Linux/guard-page.c b/compiler-rt/test/lsan/TestCases/Linux/guard-page.c
index dd2a581586637..ba03c1ff3535b 100644
--- a/compiler-rt/test/lsan/TestCases/Linux/guard-page.c
+++ b/compiler-rt/test/lsan/TestCases/Linux/guard-page.c
@@ -1,9 +1,6 @@
// Check that if LSan finds that SP doesn't point into thread stack (e.g.
// if swapcontext is used), LSan will not hit the guard page.
// RUN: %clang_lsan %s -o %t && %run %t
-
-// Fixme: remove once test passes with hwasan
-// UNSUPPORTED: hwasan
// Missing 'getcontext' and 'makecontext' on Android.
// UNSUPPORTED: android
diff --git a/compiler-rt/test/lsan/TestCases/Linux/libdl_deadlock.cpp b/compiler-rt/test/lsan/TestCases/Linux/libdl_deadlock.cpp
index ddc9d888b68ad..ad7abe2d6478a 100644
--- a/compiler-rt/test/lsan/TestCases/Linux/libdl_deadlock.cpp
+++ b/compiler-rt/test/lsan/TestCases/Linux/libdl_deadlock.cpp
@@ -2,9 +2,6 @@
// where lsan would call dl_iterate_phdr while holding the allocator lock.
// RUN: %clangxx_lsan %s -o %t && %run %t
-// Fixme: remove once test passes with hwasan
-// UNSUPPORTED: hwasan
-
#include <link.h>
#include <mutex>
#include <stdlib.h>
diff --git a/compiler-rt/test/lsan/TestCases/many_tls_keys_pthread.cpp b/compiler-rt/test/lsan/TestCases/many_tls_keys_pthread.cpp
index 86a28396b9f41..b67550f51a704 100644
--- a/compiler-rt/test/lsan/TestCases/many_tls_keys_pthread.cpp
+++ b/compiler-rt/test/lsan/TestCases/many_tls_keys_pthread.cpp
@@ -4,9 +4,6 @@
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_tls=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1
-// Fixme: remove once test passes with hwasan
-// UNSUPPORTED: hwasan
-
// On glibc, this requires the range returned by GetTLS to include
// specific_1stblock and specific in `struct pthread`.
// UNSUPPORTED: arm-linux, armhf-linux
@@ -77,4 +74,4 @@ int main() {
}
// CHECK: LeakSanitizer: detected memory leaks
-// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:
+// CHECK: SUMMARY: {{.*}}Sanitizer:
diff --git a/compiler-rt/test/lsan/TestCases/many_tls_keys_thread.cpp b/compiler-rt/test/lsan/TestCases/many_tls_keys_thread.cpp
index dac13639b8db6..f0deb444c86d4 100644
--- a/compiler-rt/test/lsan/TestCases/many_tls_keys_thread.cpp
+++ b/compiler-rt/test/lsan/TestCases/many_tls_keys_thread.cpp
@@ -4,9 +4,6 @@
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_tls=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1
-// Fixme: remove once test passes with hwasan
-// UNSUPPORTED: hwasan
-
// Patch r303906 did not fix all the problems.
// UNSUPPORTED: arm-linux,armhf-linux
@@ -60,4 +57,4 @@ int main() {
}
// CHECK: LeakSanitizer: detected memory leaks
-// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:
+// CHECK: SUMMARY: {{.*}}Sanitizer:
diff --git a/compiler-rt/test/lsan/TestCases/use_registers.cpp b/compiler-rt/test/lsan/TestCases/use_registers.cpp
index 69ac4b1590b88..a4fbf27aefb6d 100644
--- a/compiler-rt/test/lsan/TestCases/use_registers.cpp
+++ b/compiler-rt/test/lsan/TestCases/use_registers.cpp
@@ -4,9 +4,6 @@
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1
-// Fixme: remove once test passes with hwasan
-// UNSUPPORTED: hwasan
-
#include "sanitizer_common/print_address.h"
#include <assert.h>
#include <pthread.h>
@@ -80,4 +77,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:0x[0-9,a-f]+]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: [[ADDR]] (1337 bytes)
-// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:
+// CHECK: SUMMARY: {{.*}}Sanitizer:
diff --git a/compiler-rt/test/lsan/TestCases/use_registers_extra.cpp b/compiler-rt/test/lsan/TestCases/use_registers_extra.cpp
index ffeffc459655d..0a423dfb65684 100644
--- a/compiler-rt/test/lsan/TestCases/use_registers_extra.cpp
+++ b/compiler-rt/test/lsan/TestCases/use_registers_extra.cpp
@@ -4,9 +4,6 @@
// RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1
-// Fixme: remove once test passes with hwasan
-// UNSUPPORTED: hwasan
-
// FIXME: Support more platforms.
// REQUIRES: x86-target-arch && linux
@@ -60,4 +57,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:0x[0-9,a-f]+]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: [[ADDR]] (1337 bytes)
-// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:
+// CHECK: SUMMARY: {{.*}}Sanitizer:
diff --git a/compiler-rt/test/lsan/TestCases/use_stacks_threaded.cpp b/compiler-rt/test/lsan/TestCases/use_stacks_threaded.cpp
index 015070f52fe9b..f1ad7a184289a 100644
--- a/compiler-rt/test/lsan/TestCases/use_stacks_threaded.cpp
+++ b/compiler-rt/test/lsan/TestCases/use_stacks_threaded.cpp
@@ -4,9 +4,6 @@
// RUN: %env_lsan_opts="report_objects=1:use_registers=0:use_stacks=1" %run %t 2>&1
// RUN: %env_lsan_opts="" %run %t 2>&1
-// Fixme: remove once test passes with hwasan
-// UNSUPPORTED: hwasan
-
#include <assert.h>
#include <pthread.h>
#include <sched.h>
@@ -37,4 +34,4 @@ int main() {
// CHECK: Test alloc: [[ADDR:0x[0-9,a-f]+]]
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: [[ADDR]] (1337 bytes)
-// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:
+// CHECK: SUMMARY: {{.*}}Sanitizer:
More information about the llvm-commits
mailing list