blob: 7e1961e75aff38ad87eab9639ea7ef67894e0875 [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
19#include <stdint.h>
20
Narayan Kamatha73df602017-05-24 15:07:25 +010021#include "dump_type.h"
22
Josh Gaocbe70cb2016-10-18 18:17:52 -070023// Sockets in the ANDROID_SOCKET_NAMESPACE_RESERVED namespace.
24// Both sockets are SOCK_SEQPACKET sockets, so no explicit length field is needed.
25constexpr char kTombstonedCrashSocketName[] = "tombstoned_crash";
Narayan Kamath922f6b22017-05-15 15:59:30 +010026constexpr char kTombstonedJavaTraceSocketName[] = "tombstoned_java_trace";
Josh Gaocbe70cb2016-10-18 18:17:52 -070027constexpr char kTombstonedInterceptSocketName[] = "tombstoned_intercept";
28
29enum class CrashPacketType : uint8_t {
30 // Initial request from crash_dump.
31 kDumpRequest = 0,
32
33 // Notification of a completed crash dump.
34 // Sent after a dump is completed and the process has been untraced, but
35 // before it has been resumed with SIGCONT.
36 kCompletedDump,
37
38 // Responses to kRequest.
39 // kPerformDump sends along an output fd via cmsg(3).
40 kPerformDump = 128,
41 kAbortDump,
42};
43
44struct DumpRequest {
Narayan Kamatha73df602017-05-24 15:07:25 +010045 DebuggerdDumpType dump_type;
Josh Gaocbe70cb2016-10-18 18:17:52 -070046 int32_t pid;
47};
48
49// The full packet must always be written, regardless of whether the union is used.
50struct TombstonedCrashPacket {
51 CrashPacketType packet_type;
52 union {
53 DumpRequest dump_request;
54 } packet;
55};
56
57// Comes with a file descriptor via SCM_RIGHTS.
58// This packet should be sent before an actual dump happens.
59struct InterceptRequest {
Narayan Kamatha73df602017-05-24 15:07:25 +010060 DebuggerdDumpType dump_type;
Josh Gaocbe70cb2016-10-18 18:17:52 -070061 int32_t pid;
62};
63
Josh Gao460b3362017-03-30 16:40:47 -070064enum class InterceptStatus : uint8_t {
Narayan Kamatha73df602017-05-24 15:07:25 +010065 // Returned when an intercept of a different type has already been
66 // registered (and is active) for a given PID.
67 kFailedAlreadyRegistered,
68 // Returned in all other failure cases.
Josh Gao460b3362017-03-30 16:40:47 -070069 kFailed,
70 kStarted,
71 kRegistered,
72};
73
Josh Gaocbe70cb2016-10-18 18:17:52 -070074// Sent either immediately upon failure, or when the intercept has been used.
75struct InterceptResponse {
Josh Gao460b3362017-03-30 16:40:47 -070076 InterceptStatus status;
Josh Gaocbe70cb2016-10-18 18:17:52 -070077 char error_message[127]; // always null-terminated
78};