| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 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 |  | 
| Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 21 | #include "dump_type.h" | 
|  | 22 |  | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 23 | // Sockets in the ANDROID_SOCKET_NAMESPACE_RESERVED namespace. | 
|  | 24 | // Both sockets are SOCK_SEQPACKET sockets, so no explicit length field is needed. | 
|  | 25 | constexpr char kTombstonedCrashSocketName[] = "tombstoned_crash"; | 
| Narayan Kamath | 922f6b2 | 2017-05-15 15:59:30 +0100 | [diff] [blame] | 26 | constexpr char kTombstonedJavaTraceSocketName[] = "tombstoned_java_trace"; | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 27 | constexpr char kTombstonedInterceptSocketName[] = "tombstoned_intercept"; | 
|  | 28 |  | 
|  | 29 | enum 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 |  | 
|  | 44 | struct DumpRequest { | 
| Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 45 | DebuggerdDumpType dump_type; | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 46 | int32_t pid; | 
|  | 47 | }; | 
|  | 48 |  | 
|  | 49 | // The full packet must always be written, regardless of whether the union is used. | 
|  | 50 | struct 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. | 
|  | 59 | struct InterceptRequest { | 
| Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 60 | DebuggerdDumpType dump_type; | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 61 | int32_t pid; | 
|  | 62 | }; | 
|  | 63 |  | 
| Josh Gao | 460b336 | 2017-03-30 16:40:47 -0700 | [diff] [blame] | 64 | enum class InterceptStatus : uint8_t { | 
| Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 65 | // 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 Gao | 460b336 | 2017-03-30 16:40:47 -0700 | [diff] [blame] | 69 | kFailed, | 
|  | 70 | kStarted, | 
|  | 71 | kRegistered, | 
|  | 72 | }; | 
|  | 73 |  | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 74 | // Sent either immediately upon failure, or when the intercept has been used. | 
|  | 75 | struct InterceptResponse { | 
| Josh Gao | 460b336 | 2017-03-30 16:40:47 -0700 | [diff] [blame] | 76 | InterceptStatus status; | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 77 | char error_message[127];  // always null-terminated | 
|  | 78 | }; |