blob: 52817fd34f381702c0fd147e8d3d8db651763dda [file] [log] [blame]
Roland Levillain21482ad2017-01-19 20:04:27 +00001/*
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#include <sys/utsname.h>
23#include <ucontext.h>
24
25#include <iomanip>
26
27#include "base/dumpable.h"
28#include "native_stack_dump.h"
29#include "utils.h"
30
31namespace art {
32
33struct Backtrace {
34 public:
35 explicit Backtrace(void* raw_context) : raw_context_(raw_context) {}
36 void Dump(std::ostream& os) const {
37 DumpNativeStack(os, GetTid(), nullptr, "\t", nullptr, raw_context_);
38 }
39 private:
40 // Stores the context of the signal that was unexpected and will terminate the runtime. The
41 // DumpNativeStack code will take care of casting it to the expected type. This is required
42 // as our signal handler runs on an alternate stack.
43 void* raw_context_;
44};
45
46struct OsInfo {
47 void Dump(std::ostream& os) const {
48 utsname info;
49 uname(&info);
50 // Linux 2.6.38.8-gg784 (x86_64)
51 // Darwin 11.4.0 (x86_64)
52 os << info.sysname << " " << info.release << " (" << info.machine << ")";
53 }
54};
55
56const char* GetSignalName(int signal_number);
57const char* GetSignalCodeName(int signal_number, int signal_code);
58
59struct UContext {
60 explicit UContext(void* raw_context)
61 : context(reinterpret_cast<ucontext_t*>(raw_context)->uc_mcontext) {}
62
63 void Dump(std::ostream& os) const;
64
65 void DumpRegister32(std::ostream& os, const char* name, uint32_t value) const;
66 void DumpRegister64(std::ostream& os, const char* name, uint64_t value) const;
67
68 void DumpX86Flags(std::ostream& os, uint32_t flags) const;
69
70 mcontext_t& context;
71};
72
73// Return the signal number we recognize as timeout. -1 means not active/supported.
74int GetTimeoutSignal();
75
76void HandleUnexpectedSignalCommon(int signal_number,
77 siginfo_t* info,
78 void* raw_context,
79 bool running_on_linux);
80
81void InitPlatformSignalHandlersCommon(void (*newact)(int, siginfo_t*, void*),
82 struct sigaction* oldact,
83 bool handle_timeout_signal);
84
85} // namespace art
86
87#endif // ART_RUNTIME_RUNTIME_COMMON_H_