Skip to content

Commit

Permalink
[sanitizer] Fix ThreadLister::IsAlive (#111942)
Browse files Browse the repository at this point in the history
'status_path_' must include `tid`.
Regression from #111909.
  • Loading branch information
vitalybuka authored Oct 11, 2024
1 parent e01ae39 commit 59b2945
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 59b2945

Please sign in to comment.