Roland Levillain | 21482ad | 2017-01-19 20:04:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_RUNTIME_RUNTIME_COMMON_H_ |
| 18 | #define ART_RUNTIME_RUNTIME_COMMON_H_ |
| 19 | |
| 20 | // Code shared by runtime/runtime_android.cc and runtime/runtime_linux.cc. |
| 21 | |
Roland Levillain | 32a5bb2 | 2017-01-31 14:33:16 +0000 | [diff] [blame] | 22 | #if defined(__APPLE__) |
| 23 | // On macOS, _XOPEN_SOURCE must be defined to access ucontext |
| 24 | // routines, as they are considered deprecated on that platform. |
| 25 | #define _XOPEN_SOURCE |
| 26 | #endif |
| 27 | |
Roland Levillain | 21482ad | 2017-01-19 20:04:27 +0000 | [diff] [blame] | 28 | #include <sys/utsname.h> |
| 29 | #include <ucontext.h> |
| 30 | |
| 31 | #include <iomanip> |
| 32 | |
| 33 | #include "base/dumpable.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 34 | #include "base/utils.h" |
Roland Levillain | 21482ad | 2017-01-19 20:04:27 +0000 | [diff] [blame] | 35 | #include "native_stack_dump.h" |
Roland Levillain | 21482ad | 2017-01-19 20:04:27 +0000 | [diff] [blame] | 36 | |
| 37 | namespace art { |
| 38 | |
| 39 | struct Backtrace { |
| 40 | public: |
| 41 | explicit Backtrace(void* raw_context) : raw_context_(raw_context) {} |
| 42 | void Dump(std::ostream& os) const { |
Christopher Ferris | b274931 | 2018-03-23 13:03:45 -0700 | [diff] [blame] | 43 | // This is a backtrace from a crash, do not skip any frames in case the |
| 44 | // crash is in the unwinder itself. |
| 45 | DumpNativeStack(os, GetTid(), nullptr, "\t", nullptr, raw_context_, false); |
Roland Levillain | 21482ad | 2017-01-19 20:04:27 +0000 | [diff] [blame] | 46 | } |
| 47 | private: |
| 48 | // Stores the context of the signal that was unexpected and will terminate the runtime. The |
| 49 | // DumpNativeStack code will take care of casting it to the expected type. This is required |
| 50 | // as our signal handler runs on an alternate stack. |
| 51 | void* raw_context_; |
| 52 | }; |
| 53 | |
| 54 | struct OsInfo { |
| 55 | void Dump(std::ostream& os) const { |
| 56 | utsname info; |
| 57 | uname(&info); |
| 58 | // Linux 2.6.38.8-gg784 (x86_64) |
| 59 | // Darwin 11.4.0 (x86_64) |
| 60 | os << info.sysname << " " << info.release << " (" << info.machine << ")"; |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | const char* GetSignalName(int signal_number); |
| 65 | const char* GetSignalCodeName(int signal_number, int signal_code); |
| 66 | |
Roland Levillain | 21482ad | 2017-01-19 20:04:27 +0000 | [diff] [blame] | 67 | // Return the signal number we recognize as timeout. -1 means not active/supported. |
| 68 | int GetTimeoutSignal(); |
| 69 | |
| 70 | void HandleUnexpectedSignalCommon(int signal_number, |
| 71 | siginfo_t* info, |
| 72 | void* raw_context, |
Andreas Gampe | c6fe427 | 2017-06-01 20:14:58 -0700 | [diff] [blame] | 73 | bool handle_timeout_signal, |
| 74 | bool dump_on_stderr); |
Roland Levillain | 21482ad | 2017-01-19 20:04:27 +0000 | [diff] [blame] | 75 | |
| 76 | void InitPlatformSignalHandlersCommon(void (*newact)(int, siginfo_t*, void*), |
| 77 | struct sigaction* oldact, |
| 78 | bool handle_timeout_signal); |
| 79 | |
Andreas Gampe | 8764860 | 2019-06-12 12:34:26 -0700 | [diff] [blame^] | 80 | void FlagRuntimeAbort(); |
| 81 | |
Roland Levillain | 21482ad | 2017-01-19 20:04:27 +0000 | [diff] [blame] | 82 | } // namespace art |
| 83 | |
| 84 | #endif // ART_RUNTIME_RUNTIME_COMMON_H_ |