• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <stdio.h>
21 #include <sys/types.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /**
28  * @brief  type of request
29  *
30 */
31 typedef enum FaultLoggerType : int32_t {
32     /** C/C++ crash at runtime */
33     CPP_CRASH = 2,
34     /** js crash at runtime */
35     JS_CRASH,
36     /** application freeze */
37     APP_FREEZE,
38     /** trace native stack */
39     CPP_STACKTRACE = 101,
40     /** trace js stack */
41     JS_STACKTRACE,
42     /** js heap */
43     JS_HEAP_SNAPSHOT,
44     /** js raw heap */
45     JS_RAW_SNAPSHOT,
46     /** js heap leak list */
47     JS_HEAP_LEAK_LIST,
48     /** leak stacktrace */
49     LEAK_STACKTRACE,
50     /** ffrt crash log */
51     FFRT_CRASH_LOG,
52     /** jit code log */
53     JIT_CODE_LOG,
54     /** address sanitizer log*/
55     ADDR_SANITIZER,
56     /** cj heap */
57     CJ_HEAP_SNAPSHOT = 110
58 } FaultLoggerType;
59 
60 /**
61  * @brief  type of faultlogger client
62  *
63 */
64 typedef enum FaultLoggerClientType : int8_t {
65     /** For request a debug file to record nornal unwind and process dump logs */
66     LOG_FILE_DES_CLIENT,
67     /** For request to dump stack */
68     SDK_DUMP_CLIENT,
69     /** For request file descriptor of pipe */
70     PIPE_FD_CLIENT,
71     /** For report crash dump exception */
72     REPORT_EXCEPTION_CLIENT,
73     /** For report dump stats */
74     DUMP_STATS_CLIENT,
75     /** For request to coredump */
76     COREDUMP_CLIENT,
77     /** For request to report coredump status */
78     COREDUMP_PROCESS_DUMP_CLIENT,
79     /** For request liteperf file descriptor of pipe */
80     PIPE_FD_LITEPERF_CLIENT,
81 } FaultLoggerClientType;
82 
83 typedef struct RequestDataHead {
84     /** type of faultlogger client */
85     int8_t clientType;
86     /** target process id outside sandbox */
87     int32_t clientPid;
88 } __attribute__((packed)) RequestDataHead;
89 
90 typedef struct CoreDumpRequestData {
91     /** request data head **/
92     RequestDataHead head;
93     /** target id */
94     int32_t pid;
95     /** endtime ms */
96     uint64_t endTime;
97     /** do or cancel coredump */
98     int32_t coredumpAction;
99 } __attribute__((packed)) CoreDumpRequestData;
100 
101 /**
102  * @brief  type of coredump Action
103  *
104 */
105 typedef enum CoreDumpAction : int32_t {
106     /** do coredump */
107     DO_CORE_DUMP,
108     /** cancel coredump */
109     CANCEL_CORE_DUMP,
110 } CoreDumpAction;
111 
112 /**
113  * @brief  type of coredump Status
114  *
115 */
116 typedef enum CoreDumpStatus : int32_t {
117     /** core dump start */
118     CORE_DUMP_START = 1,
119     /** core dump end */
120     CORE_DUMP_END,
121     /** core dump error */
122     CORE_DUMP_ERROR,
123 } CoreDumpStatus;
124 
125 typedef struct CoreDumpStatusData {
126     /** request data head **/
127     RequestDataHead head;
128     /** target id */
129     int32_t pid;
130     /** process id */
131     int32_t processDumpPid;
132     /** coredump status */
133     // 1 start  2 end  3 error
134     int32_t coredumpStatus;
135     /** coredump file name */
136     char fileName[256];
137     /** coredump result */
138     int32_t retCode;
139 } __attribute__((packed)) CoreDumpStatusData;
140 
141 typedef struct CoreDumpResult {
142     /** coredump file name **/
143     char fileName[256];
144     /** coredump result */
145     int32_t retCode;
146 } __attribute__((packed)) CoreDumpResult;
147 
148 typedef struct SdkDumpRequestData {
149     /** request data head **/
150     RequestDataHead head;
151     /** process id */
152     int32_t pid;
153     /** signal code */
154     int32_t sigCode;
155     /** thread id */
156     int32_t tid;
157     /** thread id of calling sdk dump ,only for sdk dump client */
158     int32_t callerTid;
159     /** time of current request */
160     uint64_t time;
161     /** dumpcatcher remote unwind endtime ms */
162     uint64_t endTime;
163 } __attribute__((packed)) SdkDumpRequestData;
164 
165 /**
166  * @brief  type of request about pipe
167 */
168 typedef enum FaultLoggerPipeType : int8_t {
169     /** For request file descriptor of pipe to read buffer  */
170     PIPE_FD_READ = 0,
171     /** For request file descriptor of pipe to write buffer  */
172     PIPE_FD_WRITE,
173     /** For request to delete file descriptor of pipe */
174     PIPE_FD_DELETE,
175 } FaultLoggerPipeType;
176 
177 typedef struct PipFdRequestData {
178     /** request data head **/
179     RequestDataHead head;
180     /** process id */
181     int32_t pid;
182     /** type of pipe */
183     int8_t pipeType;
184 } __attribute__((packed)) PipFdRequestData;
185 
186 typedef struct LitePerfFdRequestData {
187     /** request data head **/
188     RequestDataHead head;
189     /** process id */
190     int32_t pid;
191     /** user id */
192     uid_t uid;
193     /** type of pipe */
194     int8_t pipeType;
195     /** timeout of request */
196     int32_t timeout;
197 } __attribute__((packed)) LitePerfFdRequestData;
198 
199 /**
200  * @brief  request information
201 */
202 typedef struct FaultLoggerdRequest {
203     /** request data head **/
204     RequestDataHead head;
205     /** process id */
206     int32_t pid;
207     /** type of resquest */
208     int32_t type;
209     /** thread id */
210     int32_t tid;
211     /** time of current request */
212     uint64_t time;
213 } __attribute__((packed)) FaultLoggerdRequest;
214 
215 /**
216  * @brief  type of faultloggerd stats request
217 */
218 typedef enum FaultLoggerdStatType : int32_t {
219     /** dump catcher stats */
220     DUMP_CATCHER = 0,
221     /** processdump stats */
222     PROCESS_DUMP
223 } FaultLoggerdStatType;
224 
225 /**
226  * @brief  struct of faultloggerd stats request
227 */
228 typedef struct FaultLoggerdStatsRequest {
229     /** request data head **/
230     RequestDataHead head;
231     /** type of resquest */
232     int32_t type;
233     /** target process id outside sandbox */
234     int32_t pid;
235     /** the time call dumpcatcher interface */
236     uint64_t requestTime;
237     /** the time signal arrive in targe process */
238     uint64_t signalTime;
239     /** the time enter processdump main */
240     uint64_t processdumpStartTime;
241     /** the time finish processdump */
242     uint64_t processdumpFinishTime;
243     /** the time return from dumpcatcher interface */
244     uint64_t dumpCatcherFinishTime;
245     /** dumpcatcher result */
246     int32_t result;
247     /** count of thread in target process */
248     uint32_t targetProcessThreadCount;
249     /** write dump info cost time */
250     uint32_t writeDumpInfoCost;
251     /** caller elf offset */
252     uintptr_t offset;
253     char summary[128]; // 128 : max summary size
254     /** the caller elf of dumpcatcher interface */
255     char callerElf[128]; // 128 : max function name size
256     /** the caller processName */
257     char callerProcess[128]; // 128 : max function name size
258     /** the target processName */
259     char targetProcess[128]; // 128 : max function name size
260 } __attribute__((packed)) FaultLoggerdStatsRequest;
261 
262 typedef enum ResponseCode : int32_t {
263     /** failed receive msg form server */
264     RECEIVE_DATA_FAILED = -4,
265     /** failed send msg to server */
266     SEND_DATA_FAILED = -3,
267     /** failed connect to server */
268     CONNECT_FAILED = -2,
269     /** default code **/
270     DEFAULT_ERROR_CODE = -1,
271     /** request success */
272     REQUEST_SUCCESS = 0,
273     /** unknown client type */
274     UNKNOWN_CLIENT_TYPE = 1,
275     /** the data size is not matched to client type */
276     INVALID_REQUEST_DATA = 2,
277     /** reject to resolve the request */
278     REQUEST_REJECT = 3,
279     /** abnormal service */
280     ABNORMAL_SERVICE = 4,
281     /** repeat dump */
282     SDK_DUMP_REPEAT,
283     /** the process to dump not exist */
284     SDK_DUMP_NOPROC,
285     /** the process to dump has crashed */
286     SDK_PROCESS_CRASHED,
287     /** repeat coredump */
288     CORE_DUMP_REPEAT,
289     /** the process to coredump has crashed */
290     CORE_PROCESS_CRASHED,
291     /** the process to coredump not exist */
292     CORE_DUMP_NOPROC,
293     /** cancel coredump */
294     CORE_DUMP_CANCEL,
295     /** coredump generate fail */
296     CORE_DUMP_GENERATE_FAIL,
297 } ResponseCode;
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 #endif