Skip to content

Commit 70e32e6

Browse files
vitalybukaDanielCChen
authored andcommitted
[sanitizer] Fix ThreadLister::IsAlive (llvm#111942)
'status_path_' must include `tid`. Regression from llvm#111909.
1 parent cdc8e27 commit 70e32e6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,6 @@ bool internal_sigismember(__sanitizer_sigset_t *set, int signum) {
10271027
// ThreadLister implementation.
10281028
ThreadLister::ThreadLister(pid_t pid) : buffer_(4096) {
10291029
task_path_.AppendF("/proc/%d/task", pid);
1030-
status_path_.AppendF("%s/status", task_path_.data());
10311030
}
10321031

10331032
ThreadLister::Result ThreadLister::ListThreads(
@@ -1087,6 +1086,8 @@ ThreadLister::Result ThreadLister::ListThreads(
10871086
}
10881087

10891088
const char *ThreadLister::LoadStatus(tid_t tid) {
1089+
status_path_.clear();
1090+
status_path_.AppendF("%s/%llu/status", task_path_.data(), tid);
10901091
auto cleanup = at_scope_exit([&] {
10911092
// Resize back to capacity if it is downsized by `ReadFileToVector`.
10921093
buffer_.resize(buffer_.capacity());

compiler-rt/lib/sanitizer_common/tests/sanitizer_linux_test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ TEST_F(ThreadListerTest, ThreadListerSeesAllSpawnedThreads) {
143143
std::vector<tid_t> listed_tids = ReadTidsToVector(&thread_lister);
144144
ASSERT_TRUE(HasElement(listed_tids, self_tid));
145145
ASSERT_TRUE(Includes(listed_tids, tids_));
146+
147+
ASSERT_NE(nullptr, thread_lister.LoadStatus(self_tid));
148+
for (auto tid : tids_) ASSERT_NE(nullptr, thread_lister.LoadStatus(tid));
146149
}
147150

148151
TEST_F(ThreadListerTest, DoNotForgetThreads) {

0 commit comments

Comments
 (0)