1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DFX_SOCKET_REQUEST_H 17 #define DFX_SOCKET_REQUEST_H 18 19 #include <inttypes.h> 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 /** 26 * @brief type of request 27 * 28 */ 29 typedef enum FaultLoggerType : int32_t { 30 /** C/C++ crash at runtime */ 31 CPP_CRASH = 2, 32 /** js crash at runtime */ 33 JS_CRASH, 34 /** application freeze */ 35 APP_FREEZE, 36 /** trace native stack */ 37 CPP_STACKTRACE = 101, 38 /** trace js stack */ 39 JS_STACKTRACE, 40 /** js heap */ 41 JS_HEAP_SNAPSHOT, 42 /** js raw heap */ 43 JS_RAW_SNAPSHOT, 44 /** js heap leak list */ 45 JS_HEAP_LEAK_LIST, 46 /** leak stacktrace */ 47 LEAK_STACKTRACE, 48 /** ffrt crash log */ 49 FFRT_CRASH_LOG, 50 /** jit code log */ 51 JIT_CODE_LOG, 52 /** address sanitizer log*/ 53 ADDR_SANITIZER 54 } FaultLoggerType; 55 56 /** 57 * @brief type of faultlogger client 58 * 59 */ 60 typedef enum FaultLoggerClientType : int8_t { 61 /** For request a debug file to record nornal unwind and process dump logs */ 62 LOG_FILE_DES_CLIENT, 63 /** For request to dump stack */ 64 SDK_DUMP_CLIENT, 65 /** For request file descriptor of pipe */ 66 PIPE_FD_CLIENT, 67 /** For report crash dump exception */ 68 REPORT_EXCEPTION_CLIENT, 69 /** For report dump stats */ 70 DUMP_STATS_CLIENT, 71 } FaultLoggerClientType; 72 73 typedef struct RequestDataHead { 74 /** type of faultlogger client */ 75 int8_t clientType; 76 /** target process id outside sandbox */ 77 int32_t clientPid; 78 } __attribute__((packed)) RequestDataHead; 79 80 typedef struct SdkDumpRequestData { 81 /** request data head **/ 82 RequestDataHead head; 83 /** process id */ 84 int32_t pid; 85 /** signal code */ 86 int32_t sigCode; 87 /** thread id */ 88 int32_t tid; 89 /** thread id of calling sdk dump ,only for sdk dump client */ 90 int32_t callerTid; 91 /** time of current request */ 92 uint64_t time; 93 /** dumpcatcher remote unwind endtime ms */ 94 uint64_t endTime; 95 } __attribute__((packed)) SdkDumpRequestData; 96 97 /** 98 * @brief type of request about pipe 99 */ 100 typedef enum FaultLoggerPipeType : int8_t { 101 /** For request file descriptor of pipe to read buffer */ 102 PIPE_FD_READ = 0, 103 /** For request file descriptor of pipe to write buffer */ 104 PIPE_FD_WRITE, 105 /** For request to delete file descriptor of pipe */ 106 PIPE_FD_DELETE, 107 } FaultLoggerPipeType; 108 109 typedef struct PipFdRequestData { 110 /** request data head **/ 111 RequestDataHead head; 112 /** process id */ 113 int32_t pid; 114 /** type of pipe */ 115 int8_t pipeType; 116 } __attribute__((packed)) PipFdRequestData; 117 118 /** 119 * @brief request information 120 */ 121 typedef struct FaultLoggerdRequest { 122 /** request data head **/ 123 RequestDataHead head; 124 /** process id */ 125 int32_t pid; 126 /** type of resquest */ 127 int32_t type; 128 /** thread id */ 129 int32_t tid; 130 /** time of current request */ 131 uint64_t time; 132 } __attribute__((packed)) FaultLoggerdRequest; 133 134 /** 135 * @brief type of faultloggerd stats request 136 */ 137 typedef enum FaultLoggerdStatType : int32_t { 138 /** dump catcher stats */ 139 DUMP_CATCHER = 0, 140 /** processdump stats */ 141 PROCESS_DUMP 142 } FaultLoggerdStatType; 143 144 /** 145 * @brief struct of faultloggerd stats request 146 */ 147 typedef struct FaultLoggerdStatsRequest { 148 /** request data head **/ 149 RequestDataHead head; 150 /** type of resquest */ 151 int32_t type; 152 /** target process id outside sandbox */ 153 int32_t pid; 154 /** the time call dumpcatcher interface */ 155 uint64_t requestTime; 156 /** the time signal arrive in targe process */ 157 uint64_t signalTime; 158 /** the time enter processdump main */ 159 uint64_t processdumpStartTime; 160 /** the time finish processdump */ 161 uint64_t processdumpFinishTime; 162 /** the time return from dumpcatcher interface */ 163 uint64_t dumpCatcherFinishTime; 164 /** dumpcatcher result */ 165 int32_t result; 166 /** caller elf offset */ 167 uintptr_t offset; 168 char summary[128]; // 128 : max summary size 169 /** the caller elf of dumpcatcher interface */ 170 char callerElf[128]; // 128 : max function name size 171 /** the caller processName */ 172 char callerProcess[128]; // 128 : max function name size 173 /** the target processName */ 174 char targetProcess[128]; // 128 : max function name size 175 } __attribute__((packed)) FaultLoggerdStatsRequest; 176 177 typedef enum ResponseCode : int32_t { 178 /** failed receive msg form server */ 179 RECEIVE_DATA_FAILED = -4, 180 /** failed send msg to server */ 181 SEND_DATA_FAILED = -3, 182 /** failed connect to server */ 183 CONNECT_FAILED = -2, 184 /** default code **/ 185 DEFAULT_ERROR_CODE = -1, 186 /** request success */ 187 REQUEST_SUCCESS = 0, 188 /** unknown client type */ 189 UNKNOWN_CLIENT_TYPE = 1, 190 /** the data size is not matched to client type */ 191 INVALID_REQUEST_DATA = 2, 192 /** reject to resolve the request */ 193 REQUEST_REJECT = 3, 194 /** abnormal service */ 195 ABNORMAL_SERVICE = 4, 196 /** repeat dump */ 197 SDK_DUMP_REPEAT, 198 /** the process to dump not exist */ 199 SDK_DUMP_NOPROC, 200 /** the process to dump has crashed */ 201 SDK_PROCESS_CRASHED, 202 } ResponseCode; 203 204 #ifdef __cplusplus 205 } 206 #endif 207 #endif