Skip to content

Commit e4eb32e

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.4
2 parents 07892aa + c71240f commit e4eb32e

File tree

9 files changed

+35
-22
lines changed

9 files changed

+35
-22
lines changed

compiler-rt/lib/asan/asan_posix.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ void PlatformTSDDtor(void *tsd) {
149149
# endif
150150

151151
static void BeforeFork() {
152+
VReport(2, "BeforeFork tid: %d\n", GetTid());
152153
if (CAN_SANITIZE_LEAKS) {
153154
__lsan::LockGlobal();
154155
}
@@ -168,6 +169,7 @@ static void AfterFork(bool fork_child) {
168169
if (CAN_SANITIZE_LEAKS) {
169170
__lsan::UnlockGlobal();
170171
}
172+
VReport(2, "AfterFork tid: %d\n", GetTid());
171173
}
172174

173175
void InstallAtForkHandler() {

compiler-rt/lib/dfsan/dfsan_custom.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,13 +2859,15 @@ WRAPPER_ALIAS(__isoc99_sscanf, sscanf)
28592859
WRAPPER_ALIAS(__isoc23_sscanf, sscanf)
28602860

28612861
static void BeforeFork() {
2862+
VReport(2, "BeforeFork tid: %d\n", GetTid());
28622863
StackDepotLockBeforeFork();
28632864
ChainedOriginDepotLockBeforeFork();
28642865
}
28652866

28662867
static void AfterFork(bool fork_child) {
28672868
ChainedOriginDepotUnlockAfterFork(fork_child);
28682869
StackDepotUnlockAfterFork(fork_child);
2870+
VReport(2, "AfterFork tid: %d\n", GetTid());
28692871
}
28702872

28712873
SANITIZER_INTERFACE_ATTRIBUTE

compiler-rt/lib/hwasan/hwasan_linux.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ uptr TagMemoryAligned(uptr p, uptr size, tag_t tag) {
528528
}
529529

530530
static void BeforeFork() {
531+
VReport(2, "BeforeFork tid: %d\n", GetTid());
531532
if (CAN_SANITIZE_LEAKS) {
532533
__lsan::LockGlobal();
533534
}
@@ -547,6 +548,7 @@ static void AfterFork(bool fork_child) {
547548
if (CAN_SANITIZE_LEAKS) {
548549
__lsan::UnlockGlobal();
549550
}
551+
VReport(2, "AfterFork tid: %d\n", GetTid());
550552
}
551553

552554
void HwasanInstallAtForkHandler() {

compiler-rt/lib/lsan/lsan_posix.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void InstallAtExitCheckLeaks() {
9797
}
9898

9999
static void BeforeFork() {
100+
VReport(2, "BeforeFork tid: %d\n", GetTid());
100101
LockGlobal();
101102
LockThreads();
102103
LockAllocator();
@@ -108,6 +109,7 @@ static void AfterFork(bool fork_child) {
108109
UnlockAllocator();
109110
UnlockThreads();
110111
UnlockGlobal();
112+
VReport(2, "AfterFork tid: %d\n", GetTid());
111113
}
112114

113115
void InstallAtForkHandler() {

compiler-rt/lib/msan/msan_linux.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ void MsanTSDDtor(void *tsd) {
302302
# endif
303303

304304
static void BeforeFork() {
305+
VReport(2, "BeforeFork tid: %d\n", GetTid());
305306
// Usually we lock ThreadRegistry, but msan does not have one.
306307
LockAllocator();
307308
StackDepotLockBeforeFork();
@@ -313,6 +314,7 @@ static void AfterFork(bool fork_child) {
313314
StackDepotUnlockAfterFork(fork_child);
314315
UnlockAllocator();
315316
// Usually we unlock ThreadRegistry, but msan does not have one.
317+
VReport(2, "AfterFork tid: %d\n", GetTid());
316318
}
317319

318320
void InstallAtForkHandler() {

compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,21 +1025,21 @@ bool internal_sigismember(__sanitizer_sigset_t *set, int signum) {
10251025

10261026
# if !SANITIZER_NETBSD
10271027
// ThreadLister implementation.
1028-
ThreadLister::ThreadLister(pid_t pid) : pid_(pid), buffer_(4096) {
1029-
char task_directory_path[80];
1030-
internal_snprintf(task_directory_path, sizeof(task_directory_path),
1031-
"/proc/%d/task/", pid);
1032-
descriptor_ = internal_open(task_directory_path, O_RDONLY | O_DIRECTORY);
1033-
if (internal_iserror(descriptor_)) {
1034-
Report("Can't open /proc/%d/task for reading.\n", pid);
1035-
}
1028+
ThreadLister::ThreadLister(pid_t pid) : buffer_(4096) {
1029+
task_path_.AppendF("/proc/%d/task", pid);
1030+
status_path_.AppendF("%s/status", task_path_.data());
10361031
}
10371032

10381033
ThreadLister::Result ThreadLister::ListThreads(
10391034
InternalMmapVector<tid_t> *threads) {
1040-
if (internal_iserror(descriptor_))
1035+
int descriptor = internal_open(task_path_.data(), O_RDONLY | O_DIRECTORY);
1036+
if (internal_iserror(descriptor)) {
1037+
Report("Can't open %s for reading.\n", task_path_.data());
10411038
return Error;
1042-
internal_lseek(descriptor_, 0, SEEK_SET);
1039+
}
1040+
auto acts_cleanup = at_scope_exit([&] {
1041+
internal_close(descriptor);
1042+
});
10431043
threads->clear();
10441044

10451045
Result result = Ok;
@@ -1048,11 +1048,11 @@ ThreadLister::Result ThreadLister::ListThreads(
10481048
buffer_.resize(buffer_.capacity());
10491049
CHECK_GE(buffer_.size(), 4096);
10501050
uptr read = internal_getdents(
1051-
descriptor_, (struct linux_dirent *)buffer_.data(), buffer_.size());
1051+
descriptor, (struct linux_dirent *)buffer_.data(), buffer_.size());
10521052
if (!read)
10531053
return result;
10541054
if (internal_iserror(read)) {
1055-
Report("Can't read directory entries from /proc/%d/task.\n", pid_);
1055+
Report("Can't read directory entries from %s.\n", task_path_.data());
10561056
return Error;
10571057
}
10581058

@@ -1093,9 +1093,7 @@ ThreadLister::Result ThreadLister::ListThreads(
10931093
bool ThreadLister::IsAlive(int tid) {
10941094
// /proc/%d/task/%d/status uses same call to detect alive threads as
10951095
// proc_task_readdir. See task_state implementation in Linux.
1096-
char path[80];
1097-
internal_snprintf(path, sizeof(path), "/proc/%d/task/%d/status", pid_, tid);
1098-
if (!ReadFileToVector(path, &buffer_) || buffer_.empty())
1096+
if (!ReadFileToVector(status_path_.data(), &buffer_) || buffer_.empty())
10991097
return false;
11001098
buffer_.push_back(0);
11011099
static const char kPrefix[] = "\nPPid:";
@@ -1106,10 +1104,6 @@ bool ThreadLister::IsAlive(int tid) {
11061104
return (int)internal_atoll(field) != 0;
11071105
}
11081106

1109-
ThreadLister::~ThreadLister() {
1110-
if (!internal_iserror(descriptor_))
1111-
internal_close(descriptor_);
1112-
}
11131107
# endif
11141108

11151109
# if SANITIZER_WORDSIZE == 32

compiler-rt/lib/sanitizer_common/sanitizer_linux.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg);
9797
class ThreadLister {
9898
public:
9999
explicit ThreadLister(pid_t pid);
100-
~ThreadLister();
101100
enum Result {
102101
Error,
103102
Incomplete,
@@ -108,8 +107,8 @@ class ThreadLister {
108107
private:
109108
bool IsAlive(int tid);
110109

111-
pid_t pid_;
112-
int descriptor_ = -1;
110+
InternalScopedString task_path_;
111+
InternalScopedString status_path_;
113112
InternalMmapVector<char> buffer_;
114113
};
115114

compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ bool ThreadSuspender::SuspendThread(tid_t tid) {
148148
// Log this event and move on.
149149
VReport(1, "Could not attach to thread %zu (errno %d).\n", (uptr)tid,
150150
pterrno);
151+
if (common_flags()->verbosity >= 2) {
152+
InternalScopedString path;
153+
path.AppendF("/proc/%d/task/%llu/status", pid_, tid);
154+
InternalMmapVector<char> buffer;
155+
ReadFileToVector(path.data(), &buffer);
156+
buffer.push_back(0);
157+
VReport(2, "%s: %s\n", path.data(), buffer.data());
158+
}
151159
return false;
152160
} else {
153161
VReport(2, "Attached to thread %zu.\n", (uptr)tid);

compiler-rt/lib/tsan/rtl/tsan_rtl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ int Finalize(ThreadState *thr) {
806806

807807
#if !SANITIZER_GO
808808
void ForkBefore(ThreadState* thr, uptr pc) SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
809+
VReport(2, "BeforeFork tid: %d\n", GetTid());
809810
GlobalProcessorLock();
810811
// Detaching from the slot makes OnUserFree skip writing to the shadow.
811812
// The slot will be locked so any attempts to use it will deadlock anyway.
@@ -847,6 +848,7 @@ static void ForkAfter(ThreadState* thr,
847848
SlotAttachAndLock(thr);
848849
SlotUnlock(thr);
849850
GlobalProcessorUnlock();
851+
VReport(2, "AfterFork tid: %d\n", GetTid());
850852
}
851853

852854
void ForkParentAfter(ThreadState* thr, uptr pc) { ForkAfter(thr, false); }

0 commit comments

Comments
 (0)