• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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 
28 #include <sys/utsname.h>
29 #include <ucontext.h>
30 
31 #include <iomanip>
32 
33 #include "base/dumpable.h"
34 #include "base/macros.h"
35 #include "base/utils.h"
36 #include "native_stack_dump.h"
37 
38 namespace art HIDDEN {
39 
40 struct Backtrace {
41  public:
BacktraceBacktrace42   explicit Backtrace(void* raw_context) : raw_context_(raw_context) {}
DumpBacktrace43   void Dump(std::ostream& os) const {
44     // This is a backtrace from a crash, do not skip any frames in case the
45     // crash is in the unwinder itself.
46     DumpNativeStack(os, GetTid(), "\t", nullptr, raw_context_, false);
47   }
48  private:
49   // Stores the context of the signal that was unexpected and will terminate the runtime. The
50   // DumpNativeStack code will take care of casting it to the expected type. This is required
51   // as our signal handler runs on an alternate stack.
52   void* raw_context_;
53 };
54 
55 struct OsInfo {
DumpOsInfo56   void Dump(std::ostream& os) const {
57     utsname info;
58     uname(&info);
59     // Linux 2.6.38.8-gg784 (x86_64)
60     // Darwin 11.4.0 (x86_64)
61     os << info.sysname << " " << info.release << " (" << info.machine << ")";
62   }
63 };
64 
65 const char* GetSignalName(int signal_number);
66 const char* GetSignalCodeName(int signal_number, int signal_code);
67 
68 // Return the signal number we recognize as timeout. -1 means not active/supported.
69 int GetTimeoutSignal();
70 
71 void HandleUnexpectedSignalCommon(int signal_number,
72                                   siginfo_t* info,
73                                   void* raw_context,
74                                   bool handle_timeout_signal,
75                                   bool dump_on_stderr);
76 
77 void InitPlatformSignalHandlersCommon(void (*newact)(int, siginfo_t*, void*),
78                                       struct sigaction* oldact,
79                                       bool handle_timeout_signal);
80 
81 void FlagRuntimeAbort();
82 
83 }  // namespace art
84 
85 #endif  // ART_RUNTIME_RUNTIME_COMMON_H_
86