1 /* 2 * Copyright (c) 2021-2023 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 #ifndef DFX_FAULTLOGGERD_CLIENT_H 16 #define DFX_FAULTLOGGERD_CLIENT_H 17 18 #include <inttypes.h> 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 /** 25 * @brief type of request 26 * 27 */ 28 enum FaultLoggerType { 29 JAVA_CRASH = 1, 30 /** C/C++ crash at runtime */ 31 CPP_CRASH, 32 /** js crash at runtime */ 33 JS_CRASH, 34 /** application freeze */ 35 APP_FREEZE, 36 /** trace java stack*/ 37 JAVA_STACKTRACE = 100, // unsupported yet 38 /** trace native stack */ 39 CPP_STACKTRACE, 40 /** trace js stack */ 41 JS_STACKTRACE, 42 /** js heap */ 43 JS_HEAP_SNAPSHOT, 44 }; 45 46 /** 47 * @brief type of faultlogger client 48 * 49 */ 50 enum FaultLoggerClientType { 51 /** For original request crash info temp file */ 52 DEFAULT_CLIENT = 0, 53 /** For request a debug file to record nornal unwind and process dump logs */ 54 LOG_FILE_DES_CLIENT, 55 /** For request to record nornal unwind and process dump to hilog */ 56 PRINT_T_HILOG_CLIENT, 57 /** For request to check permission */ 58 PERMISSION_CLIENT, 59 /** For request to dump stack */ 60 SDK_DUMP_CLIENT, 61 /** For request file descriptor of pipe */ 62 PIPE_FD_CLIENT, 63 }; 64 /** 65 * @brief type of request about pipe 66 */ 67 enum FaultLoggerPipeType { 68 /** For request file descriptor of pipe to read buffer */ 69 PIPE_FD_READ_BUF = 0, 70 /** For request file descriptor of pipe to write buffer */ 71 PIPE_FD_WRITE_BUF, 72 /** For request file descriptor of pipe to read result */ 73 PIPE_FD_READ_RES, 74 /** For request file descriptor of pipe to write result */ 75 PIPE_FD_WRITE_RES, 76 /** For request to delete file descriptor of pipe */ 77 PIPE_FD_DELETE, 78 }; 79 /** 80 * @brief type of responding check permission request 81 */ 82 enum FaultLoggerCheckPermissionResp { 83 /** pass */ 84 CHECK_PERMISSION_PASS = 1, 85 /** reject */ 86 CHECK_PERMISSION_REJECT, 87 }; 88 /** 89 * @brief type of responding sdk dump request 90 */ 91 enum FaultLoggerSdkDumpResp { 92 /** pass */ 93 SDK_DUMP_PASS = 1, 94 /** reject */ 95 SDK_DUMP_REJECT, 96 /** repeat request */ 97 SDK_DUMP_REPEAT, 98 /** process not exist */ 99 SDK_DUMP_NOPROC, 100 }; 101 /** 102 * @brief request information 103 */ 104 struct FaultLoggerdRequest { 105 /** type of resquest */ 106 int32_t type; 107 /** type of faultlogger client */ 108 int32_t clientType; 109 /** type of pipe */ 110 int32_t pipeType; 111 /** signal code */ 112 int32_t sigCode; 113 /** process id */ 114 int32_t pid; 115 /** thread id */ 116 int32_t tid; 117 /** user id */ 118 uint32_t uid; 119 /** process id of calling sdk dump ,only for sdk dump client */ 120 int32_t callerPid; 121 /** thread id of calling sdk dump ,only for sdk dump client */ 122 int32_t callerTid; 123 /** time of current request */ 124 uint64_t time; 125 } __attribute__((packed)); 126 /** 127 * @brief Check connection status of client 128 * 129 * @return if available return true, otherwise return false 130 */ 131 bool CheckConnectStatus(); 132 /** 133 * @brief request file descriptor 134 * @param type type of resqust 135 * @return if succeed return file descriptor, otherwise return -1 136 */ 137 int32_t RequestFileDescriptor(int32_t type); 138 139 /** 140 * @brief request log file descriptor 141 * @param request struct of request information 142 * @return if succeed return file descriptor, otherwise return -1 143 */ 144 int32_t RequestLogFileDescriptor(struct FaultLoggerdRequest *request); 145 146 /** 147 * @brief request pipe file descriptor 148 * @param pid process id of request pipe 149 * @param pipeType type of request about pipe 150 * @return if succeed return file descriptor, otherwise return -1 151 */ 152 int32_t RequestPipeFd(int32_t pid, int32_t pipeType); 153 154 /** 155 * @brief request delete file descriptor 156 * @param pid process id of request pipe 157 * @return if succeed return 0, otherwise return -1 158 */ 159 int32_t RequestDelPipeFd(int32_t pid); 160 161 /** 162 * @brief request file descriptor 163 * @param request struct of request information 164 * @return if succeed return file descriptor, otherwise return -1 165 */ 166 int RequestFileDescriptorEx(const struct FaultLoggerdRequest *request); 167 168 /** 169 * @brief request checking permission of process 170 * @param pid process id 171 * @return if pass return true , otherwise return false 172 */ 173 bool RequestCheckPermission(int32_t pid); 174 /** 175 * @brief request printing message to hilog 176 * @param msg message 177 * @param length length of message 178 * @return if succeed return 0 , otherwise return -1 179 */ 180 int RequestPrintTHilog(const char *msg, int length); 181 182 /** 183 * @brief request dump stack about process 184 * @param pid process id 185 * @param tid thread id, if equal 0 means dump all the threads in a process. 186 * @return if succeed return 0 , otherwise return -1 187 */ 188 int RequestSdkDump(int32_t type, int32_t pid, int32_t tid); 189 190 #ifdef __cplusplus 191 } 192 #endif 193 #endif 194