// Copyright 2017 The Crashpad Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "util/posix/signals.h" #include <unistd.h> #include <iterator> #include <vector> #include "base/check_op.h" #include "base/logging.h" #include "build/build_config.h" #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS) #include <sys/syscall.h> #endif namespace crashpad { namespace { // These are the core-generating signals. // // On macOS, these come from 10.12.3 xnu-3789.41.3/bsd/sys/signalvar.h sigprop: // entries with SA_CORE are in the set. // // For Linux, see linux-4.4.52/kernel/signal.c get_signal() and // linux-4.4.52/include/linux/signal.h sig_kernel_coredump(): signals in // SIG_KERNEL_COREDUMP_MASK are in the set. constexpr int kCrashSignals[] = …; // These are the non-core-generating but terminating signals. // // On macOS, these come from 10.12.3 xnu-3789.41.3/bsd/sys/signalvar.h sigprop: // entries with SA_KILL but not SA_CORE are in the set. SIGKILL is excluded // because it is uncatchable. // // For Linux, see linux-4.4.52/kernel/signal.c get_signal() and // linux-4.4.52/include/linux/signal.h sig_kernel_coredump(), // sig_kernel_ignore(), and sig_kernel_stop(): signals not in // SIG_KERNEL_COREDUMP_MASK, SIG_KERNEL_IGNORE_MASK, or SIG_KERNEL_STOP_MASK are // in the set. SIGKILL is excluded because it is uncatchable (it’s in // SIG_KERNEL_ONLY_MASK and qualifies for sig_kernel_only()). Real-time signals // in the range [SIGRTMIN, SIGRTMAX) also have termination as the default // action, although they are not listed here. constexpr int kTerminateSignals[] = …; bool InstallHandlers(const std::vector<int>& signals, Signals::Handler handler, int flags, Signals::OldActions* old_actions, const std::set<int>* unhandled_signals) { … } bool IsSignalInSet(int sig, const int* set, size_t set_size) { … } } // namespace struct sigaction* Signals::OldActions::ActionForSignal(int sig) { … } // static bool Signals::InstallHandler(int sig, Handler handler, int flags, struct sigaction* old_action) { … } // static bool Signals::InstallDefaultHandler(int sig) { … } // static bool Signals::InstallCrashHandlers(Handler handler, int flags, OldActions* old_actions, const std::set<int>* unhandled_signals) { … } // static bool Signals::InstallTerminateHandlers(Handler handler, int flags, OldActions* old_actions) { … } // static bool Signals::WillSignalReraiseAutonomously(const siginfo_t* siginfo) { … } // static void Signals::RestoreHandlerAndReraiseSignalOnReturn( const siginfo_t* siginfo, const struct sigaction* old_action) { … } // static bool Signals::IsCrashSignal(int sig) { … } // static bool Signals::IsTerminateSignal(int sig) { … } } // namespace crashpad