blob: bfd0fbbe25d3d4970dc019961440a6d380293f40 [file] [log] [blame]
Josh Gaocbe70cb2016-10-18 18:17:52 -07001/*
2 * Copyright 2016, 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#pragma once
18
Josh Gao2b2ae0c2017-08-21 14:31:17 -070019#include <signal.h>
Josh Gaocbe70cb2016-10-18 18:17:52 -070020#include <stdint.h>
Josh Gao2b2ae0c2017-08-21 14:31:17 -070021#include <sys/ucontext.h>
22#include <unistd.h>
Josh Gaocbe70cb2016-10-18 18:17:52 -070023
Narayan Kamatha73df602017-05-24 15:07:25 +010024#include "dump_type.h"
25
Josh Gaocbe70cb2016-10-18 18:17:52 -070026// Sockets in the ANDROID_SOCKET_NAMESPACE_RESERVED namespace.
27// Both sockets are SOCK_SEQPACKET sockets, so no explicit length field is needed.
28constexpr char kTombstonedCrashSocketName[] = "tombstoned_crash";
Narayan Kamath922f6b22017-05-15 15:59:30 +010029constexpr char kTombstonedJavaTraceSocketName[] = "tombstoned_java_trace";
Josh Gaocbe70cb2016-10-18 18:17:52 -070030constexpr char kTombstonedInterceptSocketName[] = "tombstoned_intercept";
31
32enum class CrashPacketType : uint8_t {
33 // Initial request from crash_dump.
34 kDumpRequest = 0,
35
36 // Notification of a completed crash dump.
37 // Sent after a dump is completed and the process has been untraced, but
38 // before it has been resumed with SIGCONT.
39 kCompletedDump,
40
41 // Responses to kRequest.
42 // kPerformDump sends along an output fd via cmsg(3).
43 kPerformDump = 128,
44 kAbortDump,
45};
46
47struct DumpRequest {
Narayan Kamatha73df602017-05-24 15:07:25 +010048 DebuggerdDumpType dump_type;
Josh Gaocbe70cb2016-10-18 18:17:52 -070049 int32_t pid;
50};
51
52// The full packet must always be written, regardless of whether the union is used.
53struct TombstonedCrashPacket {
54 CrashPacketType packet_type;
55 union {
56 DumpRequest dump_request;
57 } packet;
58};
59
60// Comes with a file descriptor via SCM_RIGHTS.
61// This packet should be sent before an actual dump happens.
62struct InterceptRequest {
Narayan Kamatha73df602017-05-24 15:07:25 +010063 DebuggerdDumpType dump_type;
Josh Gaocbe70cb2016-10-18 18:17:52 -070064 int32_t pid;
65};
66
Josh Gao460b3362017-03-30 16:40:47 -070067enum class InterceptStatus : uint8_t {
Narayan Kamatha73df602017-05-24 15:07:25 +010068 // Returned when an intercept of a different type has already been
69 // registered (and is active) for a given PID.
70 kFailedAlreadyRegistered,
71 // Returned in all other failure cases.
Josh Gao460b3362017-03-30 16:40:47 -070072 kFailed,
73 kStarted,
74 kRegistered,
75};
76
Josh Gaocbe70cb2016-10-18 18:17:52 -070077// Sent either immediately upon failure, or when the intercept has been used.
78struct InterceptResponse {
Josh Gao460b3362017-03-30 16:40:47 -070079 InterceptStatus status;
Josh Gaocbe70cb2016-10-18 18:17:52 -070080 char error_message[127]; // always null-terminated
81};
Josh Gao2b2ae0c2017-08-21 14:31:17 -070082
83// Sent from handler to crash_dump via pipe.
Josh Gao9da1f512018-08-06 15:38:29 -070084struct __attribute__((__packed__)) CrashInfoHeader {
85 uint32_t version;
86};
87
88struct __attribute__((__packed__)) CrashInfoDataV1 {
Josh Gao2b2ae0c2017-08-21 14:31:17 -070089 siginfo_t siginfo;
90 ucontext_t ucontext;
91 uintptr_t abort_msg_address;
92};
Josh Gao9da1f512018-08-06 15:38:29 -070093
94struct __attribute__((__packed__)) CrashInfoDataV2 : public CrashInfoDataV1 {
95 uintptr_t fdsan_table_address;
96};
97
98struct __attribute__((__packed__)) CrashInfo {
99 CrashInfoHeader header;
100 union {
101 CrashInfoDataV1 v1;
102 CrashInfoDataV2 v2;
103 } data;
104};