| 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 |  | 
| Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 19 | #include <signal.h> | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 20 | #include <stdint.h> | 
| Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 21 | #include <sys/ucontext.h> | 
 | 22 | #include <unistd.h> | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 23 |  | 
| Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 24 | #include "dump_type.h" | 
 | 25 |  | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 26 | // Sockets in the ANDROID_SOCKET_NAMESPACE_RESERVED namespace. | 
 | 27 | // Both sockets are SOCK_SEQPACKET sockets, so no explicit length field is needed. | 
 | 28 | constexpr char kTombstonedCrashSocketName[] = "tombstoned_crash"; | 
| Narayan Kamath | 922f6b2 | 2017-05-15 15:59:30 +0100 | [diff] [blame] | 29 | constexpr char kTombstonedJavaTraceSocketName[] = "tombstoned_java_trace"; | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 30 | constexpr char kTombstonedInterceptSocketName[] = "tombstoned_intercept"; | 
 | 31 |  | 
 | 32 | enum 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 |  | 
 | 47 | struct DumpRequest { | 
| Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 48 |   DebuggerdDumpType dump_type; | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 49 |   int32_t pid; | 
 | 50 | }; | 
 | 51 |  | 
 | 52 | // The full packet must always be written, regardless of whether the union is used. | 
 | 53 | struct 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. | 
 | 62 | struct InterceptRequest { | 
| Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 63 |   DebuggerdDumpType dump_type; | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 64 |   int32_t pid; | 
 | 65 | }; | 
 | 66 |  | 
| Josh Gao | 460b336 | 2017-03-30 16:40:47 -0700 | [diff] [blame] | 67 | enum class InterceptStatus : uint8_t { | 
| Narayan Kamath | a73df60 | 2017-05-24 15:07:25 +0100 | [diff] [blame] | 68 |   // 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 Gao | 460b336 | 2017-03-30 16:40:47 -0700 | [diff] [blame] | 72 |   kFailed, | 
 | 73 |   kStarted, | 
 | 74 |   kRegistered, | 
 | 75 | }; | 
 | 76 |  | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 77 | // Sent either immediately upon failure, or when the intercept has been used. | 
 | 78 | struct InterceptResponse { | 
| Josh Gao | 460b336 | 2017-03-30 16:40:47 -0700 | [diff] [blame] | 79 |   InterceptStatus status; | 
| Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 80 |   char error_message[127];  // always null-terminated | 
 | 81 | }; | 
| Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 82 |  | 
 | 83 | // Sent from handler to crash_dump via pipe. | 
| Josh Gao | 9da1f51 | 2018-08-06 15:38:29 -0700 | [diff] [blame] | 84 | struct __attribute__((__packed__)) CrashInfoHeader { | 
 | 85 |   uint32_t version; | 
 | 86 | }; | 
 | 87 |  | 
 | 88 | struct __attribute__((__packed__)) CrashInfoDataV1 { | 
| Josh Gao | 2b2ae0c | 2017-08-21 14:31:17 -0700 | [diff] [blame] | 89 |   siginfo_t siginfo; | 
 | 90 |   ucontext_t ucontext; | 
 | 91 |   uintptr_t abort_msg_address; | 
 | 92 | }; | 
| Josh Gao | 9da1f51 | 2018-08-06 15:38:29 -0700 | [diff] [blame] | 93 |  | 
 | 94 | struct __attribute__((__packed__)) CrashInfoDataV2 : public CrashInfoDataV1 { | 
 | 95 |   uintptr_t fdsan_table_address; | 
 | 96 | }; | 
 | 97 |  | 
 | 98 | struct __attribute__((__packed__)) CrashInfo { | 
 | 99 |   CrashInfoHeader header; | 
 | 100 |   union { | 
 | 101 |     CrashInfoDataV1 v1; | 
 | 102 |     CrashInfoDataV2 v2; | 
 | 103 |   } data; | 
 | 104 | }; |