blob: f33b2f0c91518cd5bce5542f1ed93e1eeac83ec9 [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
Peter Collingbournef3d542f2020-03-05 16:46:15 -080088struct __attribute__((__packed__)) CrashInfoDataStatic {
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
Peter Collingbournef3d542f2020-03-05 16:46:15 -080094struct __attribute__((__packed__)) CrashInfoDataDynamic : public CrashInfoDataStatic {
Josh Gao9da1f512018-08-06 15:38:29 -070095 uintptr_t fdsan_table_address;
Mitch Phillipse0b4bb12020-02-14 14:54:31 -080096 uintptr_t gwp_asan_state;
97 uintptr_t gwp_asan_metadata;
Peter Collingbournef8622522020-04-07 14:07:32 -070098 uintptr_t scudo_stack_depot;
99 uintptr_t scudo_region_info;
Peter Collingbournebb4b49c2021-01-06 21:02:19 -0800100 uintptr_t scudo_ring_buffer;
Mitch Phillipse0b4bb12020-02-14 14:54:31 -0800101};
102
Josh Gao9da1f512018-08-06 15:38:29 -0700103struct __attribute__((__packed__)) CrashInfo {
104 CrashInfoHeader header;
105 union {
Peter Collingbournef3d542f2020-03-05 16:46:15 -0800106 CrashInfoDataStatic s;
107 CrashInfoDataDynamic d;
Josh Gao9da1f512018-08-06 15:38:29 -0700108 } data;
109};