Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler-rt/lib/asan/asan_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void PlatformTSDDtor(void *tsd) {
# endif

static void BeforeFork() {
VReport(2, "BeforeFork tid: %d\n", GetTid());
if (CAN_SANITIZE_LEAKS) {
__lsan::LockGlobal();
}
Expand All @@ -168,6 +169,7 @@ static void AfterFork(bool fork_child) {
if (CAN_SANITIZE_LEAKS) {
__lsan::UnlockGlobal();
}
VReport(2, "AfterFork tid: %d\n", GetTid());
}

void InstallAtForkHandler() {
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/dfsan/dfsan_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2859,13 +2859,15 @@ WRAPPER_ALIAS(__isoc99_sscanf, sscanf)
WRAPPER_ALIAS(__isoc23_sscanf, sscanf)

static void BeforeFork() {
VReport(2, "BeforeFork tid: %d\n", GetTid());
StackDepotLockBeforeFork();
ChainedOriginDepotLockBeforeFork();
}

static void AfterFork(bool fork_child) {
ChainedOriginDepotUnlockAfterFork(fork_child);
StackDepotUnlockAfterFork(fork_child);
VReport(2, "AfterFork tid: %d\n", GetTid());
}

SANITIZER_INTERFACE_ATTRIBUTE
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/hwasan/hwasan_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ uptr TagMemoryAligned(uptr p, uptr size, tag_t tag) {
}

static void BeforeFork() {
VReport(2, "BeforeFork tid: %d\n", GetTid());
if (CAN_SANITIZE_LEAKS) {
__lsan::LockGlobal();
}
Expand All @@ -547,6 +548,7 @@ static void AfterFork(bool fork_child) {
if (CAN_SANITIZE_LEAKS) {
__lsan::UnlockGlobal();
}
VReport(2, "AfterFork tid: %d\n", GetTid());
}

void HwasanInstallAtForkHandler() {
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/lsan/lsan_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void InstallAtExitCheckLeaks() {
}

static void BeforeFork() {
VReport(2, "BeforeFork tid: %d\n", GetTid());
LockGlobal();
LockThreads();
LockAllocator();
Expand All @@ -108,6 +109,7 @@ static void AfterFork(bool fork_child) {
UnlockAllocator();
UnlockThreads();
UnlockGlobal();
VReport(2, "AfterFork tid: %d\n", GetTid());
}

void InstallAtForkHandler() {
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/msan/msan_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ void MsanTSDDtor(void *tsd) {
# endif

static void BeforeFork() {
VReport(2, "BeforeFork tid: %d\n", GetTid());
// Usually we lock ThreadRegistry, but msan does not have one.
LockAllocator();
StackDepotLockBeforeFork();
Expand All @@ -313,6 +314,7 @@ static void AfterFork(bool fork_child) {
StackDepotUnlockAfterFork(fork_child);
UnlockAllocator();
// Usually we unlock ThreadRegistry, but msan does not have one.
VReport(2, "AfterFork tid: %d\n", GetTid());
}

void InstallAtForkHandler() {
Expand Down
32 changes: 13 additions & 19 deletions compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,21 +1025,21 @@ bool internal_sigismember(__sanitizer_sigset_t *set, int signum) {

# if !SANITIZER_NETBSD
// ThreadLister implementation.
ThreadLister::ThreadLister(pid_t pid) : pid_(pid), buffer_(4096) {
char task_directory_path[80];
internal_snprintf(task_directory_path, sizeof(task_directory_path),
"/proc/%d/task/", pid);
descriptor_ = internal_open(task_directory_path, O_RDONLY | O_DIRECTORY);
if (internal_iserror(descriptor_)) {
Report("Can't open /proc/%d/task for reading.\n", pid);
}
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(
InternalMmapVector<tid_t> *threads) {
if (internal_iserror(descriptor_))
int descriptor = internal_open(task_path_.data(), O_RDONLY | O_DIRECTORY);
if (internal_iserror(descriptor)) {
Report("Can't open %s for reading.\n", task_path_.data());
return Error;
internal_lseek(descriptor_, 0, SEEK_SET);
}
auto acts_cleanup = at_scope_exit([&] {
internal_close(descriptor);
});
threads->clear();

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

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

ThreadLister::~ThreadLister() {
if (!internal_iserror(descriptor_))
internal_close(descriptor_);
}
# endif

# if SANITIZER_WORDSIZE == 32
Expand Down
5 changes: 2 additions & 3 deletions compiler-rt/lib/sanitizer_common/sanitizer_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg);
class ThreadLister {
public:
explicit ThreadLister(pid_t pid);
~ThreadLister();
enum Result {
Error,
Incomplete,
Expand All @@ -108,8 +107,8 @@ class ThreadLister {
private:
bool IsAlive(int tid);

pid_t pid_;
int descriptor_ = -1;
InternalScopedString task_path_;
InternalScopedString status_path_;
InternalMmapVector<char> buffer_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ bool ThreadSuspender::SuspendThread(tid_t tid) {
// Log this event and move on.
VReport(1, "Could not attach to thread %zu (errno %d).\n", (uptr)tid,
pterrno);
if (common_flags()->verbosity >= 2) {
InternalScopedString path;
path.AppendF("/proc/%d/task/%llu/status", pid_, tid);
InternalMmapVector<char> buffer;
ReadFileToVector(path.data(), &buffer);
buffer.push_back(0);
VReport(2, "%s: %s\n", path.data(), buffer.data());
}
return false;
} else {
VReport(2, "Attached to thread %zu.\n", (uptr)tid);
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ int Finalize(ThreadState *thr) {

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

void ForkParentAfter(ThreadState* thr, uptr pc) { ForkAfter(thr, false); }
Expand Down
Loading