Use sigwaitinfo instead of sigwait when waiting for signals sigwaitinfo also returns the siginfo_t that allows us to pass additional information along with the signal number. Currently the additional information is unused. This will be used when strting long running method traces for ANR reports. Bug: 352518093 Test: art/test.py Change-Id: I19fc84b273a17a9b573ee41c545b4d4679ea9b39
diff --git a/runtime/signal_catcher.cc b/runtime/signal_catcher.cc index c7e297f..655c063 100644 --- a/runtime/signal_catcher.cc +++ b/runtime/signal_catcher.cc
@@ -165,14 +165,14 @@ ProfileSaver::ForceProcessProfiles(); } -int SignalCatcher::WaitForSignal(Thread* self, SignalSet& signals) { +int SignalCatcher::WaitForSignal(Thread* self, SignalSet& signals, siginfo_t* info) { ScopedThreadStateChange tsc(self, ThreadState::kWaitingInMainSignalCatcherLoop); // Signals for sigwait() must be blocked but not ignored. We // block signals like SIGQUIT for all threads, so the condition // is met. When the signal hits, we wake up, without any signal // handlers being invoked. - int signal_number = signals.Wait(); + int signal_number = signals.Wait(info); if (!ShouldHalt()) { // Let the user know we got the signal, just in case the system's too screwed for us to // actually do what they want us to do... @@ -207,7 +207,8 @@ signals.Add(SIGUSR1); while (true) { - int signal_number = signal_catcher->WaitForSignal(self, signals); + siginfo_t info; + int signal_number = signal_catcher->WaitForSignal(self, signals, &info); if (signal_catcher->ShouldHalt()) { runtime->DetachCurrentThread(); return nullptr;
diff --git a/runtime/signal_catcher.h b/runtime/signal_catcher.h index 4d5d71e..ba518c3 100644 --- a/runtime/signal_catcher.h +++ b/runtime/signal_catcher.h
@@ -17,11 +17,12 @@ #ifndef ART_RUNTIME_SIGNAL_CATCHER_H_ #define ART_RUNTIME_SIGNAL_CATCHER_H_ +#include <csignal> #include <optional> #include "android-base/unique_fd.h" -#include "base/mutex.h" #include "base/macros.h" +#include "base/mutex.h" namespace art HIDDEN { @@ -52,7 +53,7 @@ void Output(const std::string& s); void SetHaltFlag(bool new_value) REQUIRES(!lock_); bool ShouldHalt() REQUIRES(!lock_); - int WaitForSignal(Thread* self, SignalSet& signals) REQUIRES(!lock_); + int WaitForSignal(Thread* self, SignalSet& signals, siginfo_t* info) REQUIRES(!lock_); mutable Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; ConditionVariable cond_ GUARDED_BY(lock_);
diff --git a/runtime/signal_set.h b/runtime/signal_set.h index 470319c..ceda92d 100644 --- a/runtime/signal_set.h +++ b/runtime/signal_set.h
@@ -29,6 +29,7 @@ #define sigaddset64 sigaddset #define pthread_sigmask64 pthread_sigmask #define sigwait64 sigwait +#define sigwaitinfo64 sigwaitinfo #endif namespace art HIDDEN { @@ -53,14 +54,15 @@ } } - int Wait() { + int Wait(siginfo_t* info) { // Sleep in sigwait() until a signal arrives. gdb causes EINTR failures. - int signal_number; - int rc = TEMP_FAILURE_RETRY(sigwait64(&set_, &signal_number)); - if (rc != 0) { - PLOG(FATAL) << "sigwait failed"; + while (true) { + int signal_number = TEMP_FAILURE_RETRY(sigwaitinfo64(&set_, info)); + if (signal_number > 0) { + return signal_number; + } + PLOG(FATAL) << "sigwaitinfo failed"; } - return signal_number; } private: