1 /*
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 
21 // Sockets in the ANDROID_SOCKET_NAMESPACE_RESERVED namespace.
22 // Both sockets are SOCK_SEQPACKET sockets, so no explicit length field is needed.
23 constexpr char kTombstonedCrashSocketName[] = "tombstoned_crash";
24 constexpr char kTombstonedInterceptSocketName[] = "tombstoned_intercept";
25 
26 enum class CrashPacketType : uint8_t {
27   // Initial request from crash_dump.
28   kDumpRequest = 0,
29 
30   // Notification of a completed crash dump.
31   // Sent after a dump is completed and the process has been untraced, but
32   // before it has been resumed with SIGCONT.
33   kCompletedDump,
34 
35   // Responses to kRequest.
36   // kPerformDump sends along an output fd via cmsg(3).
37   kPerformDump = 128,
38   kAbortDump,
39 };
40 
41 struct DumpRequest {
42   int32_t pid;
43 };
44 
45 // The full packet must always be written, regardless of whether the union is used.
46 struct TombstonedCrashPacket {
47   CrashPacketType packet_type;
48   union {
49     DumpRequest dump_request;
50   } packet;
51 };
52 
53 // Comes with a file descriptor via SCM_RIGHTS.
54 // This packet should be sent before an actual dump happens.
55 struct InterceptRequest {
56   int32_t pid;
57 };
58 
59 enum class InterceptStatus : uint8_t {
60   kFailed,
61   kStarted,
62   kRegistered,
63 };
64 
65 // Sent either immediately upon failure, or when the intercept has been used.
66 struct InterceptResponse {
67   InterceptStatus status;
68   char error_message[127];  // always null-terminated
69 };
70