Skip to content

[sanitizer] Fix ThreadLister::IsAlive #111942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

vitalybuka
Copy link
Collaborator

'status_path_' must include tid.
Regression from #111909.

@llvmbot
Copy link
Member

llvmbot commented Oct 11, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)

Changes

'status_path_' must include tid.
Regression from #111909.


Full diff: https://github.com/llvm/llvm-project/pull/111942.diff

2 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp (+2-1)
  • (modified) compiler-rt/lib/sanitizer_common/tests/sanitizer_linux_test.cpp (+3)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 31750cf65ab6eb..33107eb0b42993 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -1027,7 +1027,6 @@ bool internal_sigismember(__sanitizer_sigset_t *set, int signum) {
 // ThreadLister implementation.
 ThreadLister::ThreadLister(pid_t pid) : buffer_(4096) {
   task_path_.AppendF("/proc/%d/task", pid);
-  status_path_.AppendF("%s/status", task_path_.data());
 }
 
 ThreadLister::Result ThreadLister::ListThreads(
@@ -1087,6 +1086,8 @@ ThreadLister::Result ThreadLister::ListThreads(
 }
 
 const char *ThreadLister::LoadStatus(tid_t tid) {
+  status_path_.clear();
+  status_path_.AppendF("%s/%llu/status", task_path_.data(), tid);
   auto cleanup = at_scope_exit([&] {
     // Resize back to capacity if it is downsized by `ReadFileToVector`.
     buffer_.resize(buffer_.capacity());
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_linux_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_linux_test.cpp
index b286ab72a5c795..ce4a40444cd496 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_linux_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_linux_test.cpp
@@ -143,6 +143,9 @@ TEST_F(ThreadListerTest, ThreadListerSeesAllSpawnedThreads) {
   std::vector<tid_t> listed_tids = ReadTidsToVector(&thread_lister);
   ASSERT_TRUE(HasElement(listed_tids, self_tid));
   ASSERT_TRUE(Includes(listed_tids, tids_));
+
+  ASSERT_NE(nullptr, thread_lister.LoadStatus(self_tid));
+  for (auto tid : tids_) ASSERT_NE(nullptr, thread_lister.LoadStatus(tid));
 }
 
 TEST_F(ThreadListerTest, DoNotForgetThreads) {

Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@vitalybuka vitalybuka changed the base branch from users/vitalybuka/spr/main.sanitizer-fix-threadlisterisalive to main October 11, 2024 03:57
@vitalybuka vitalybuka merged commit 59b2945 into main Oct 11, 2024
7 of 9 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/sanitizer-fix-threadlisterisalive branch October 11, 2024 03:57
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
'status_path_' must include `tid`.
Regression from llvm#111909.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants