1800b99b8Sopenharmony_ci/*
2800b99b8Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3800b99b8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4800b99b8Sopenharmony_ci * you may not use this file except in compliance with the License.
5800b99b8Sopenharmony_ci * You may obtain a copy of the License at
6800b99b8Sopenharmony_ci *
7800b99b8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8800b99b8Sopenharmony_ci *
9800b99b8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10800b99b8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11800b99b8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12800b99b8Sopenharmony_ci * See the License for the specific language governing permissions and
13800b99b8Sopenharmony_ci * limitations under the License.
14800b99b8Sopenharmony_ci */
15800b99b8Sopenharmony_ci
16800b99b8Sopenharmony_ci#ifndef DFX_SOCKET_REQUEST_H
17800b99b8Sopenharmony_ci#define DFX_SOCKET_REQUEST_H
18800b99b8Sopenharmony_ci
19800b99b8Sopenharmony_ci#include <inttypes.h>
20800b99b8Sopenharmony_ci
21800b99b8Sopenharmony_ci#ifdef __cplusplus
22800b99b8Sopenharmony_ciextern "C" {
23800b99b8Sopenharmony_ci#endif
24800b99b8Sopenharmony_ci
25800b99b8Sopenharmony_ci/**
26800b99b8Sopenharmony_ci * @brief  type of request
27800b99b8Sopenharmony_ci *
28800b99b8Sopenharmony_ci*/
29800b99b8Sopenharmony_cienum FaultLoggerType {
30800b99b8Sopenharmony_ci    /** C/C++ crash at runtime */
31800b99b8Sopenharmony_ci    CPP_CRASH = 2,
32800b99b8Sopenharmony_ci    /** js crash at runtime */
33800b99b8Sopenharmony_ci    JS_CRASH,
34800b99b8Sopenharmony_ci    /** application freeze */
35800b99b8Sopenharmony_ci    APP_FREEZE,
36800b99b8Sopenharmony_ci    /** trace native stack */
37800b99b8Sopenharmony_ci    CPP_STACKTRACE = 101,
38800b99b8Sopenharmony_ci    /** trace js stack */
39800b99b8Sopenharmony_ci    JS_STACKTRACE,
40800b99b8Sopenharmony_ci    /** js heap */
41800b99b8Sopenharmony_ci    JS_HEAP_SNAPSHOT,
42800b99b8Sopenharmony_ci    /** js raw heap */
43800b99b8Sopenharmony_ci    JS_RAW_SNAPSHOT,
44800b99b8Sopenharmony_ci    /** js heap leak list */
45800b99b8Sopenharmony_ci    JS_HEAP_LEAK_LIST,
46800b99b8Sopenharmony_ci    /** leak stacktrace */
47800b99b8Sopenharmony_ci    LEAK_STACKTRACE,
48800b99b8Sopenharmony_ci    /** ffrt crash log */
49800b99b8Sopenharmony_ci    FFRT_CRASH_LOG,
50800b99b8Sopenharmony_ci    /** jit code log */
51800b99b8Sopenharmony_ci    JIT_CODE_LOG,
52800b99b8Sopenharmony_ci};
53800b99b8Sopenharmony_ci
54800b99b8Sopenharmony_ci/**
55800b99b8Sopenharmony_ci * @brief  type of faultlogger client
56800b99b8Sopenharmony_ci *
57800b99b8Sopenharmony_ci*/
58800b99b8Sopenharmony_cienum FaultLoggerClientType {
59800b99b8Sopenharmony_ci    /** For original request crash info temp file */
60800b99b8Sopenharmony_ci    DEFAULT_CLIENT = 0,
61800b99b8Sopenharmony_ci    /** For request a debug file to record nornal unwind and process dump logs */
62800b99b8Sopenharmony_ci    LOG_FILE_DES_CLIENT,
63800b99b8Sopenharmony_ci    /** For request to record nornal unwind and process dump to hilog */
64800b99b8Sopenharmony_ci    PRINT_T_HILOG_CLIENT,
65800b99b8Sopenharmony_ci    /** For request to check permission */
66800b99b8Sopenharmony_ci    PERMISSION_CLIENT,
67800b99b8Sopenharmony_ci    /** For request to dump stack */
68800b99b8Sopenharmony_ci    SDK_DUMP_CLIENT,
69800b99b8Sopenharmony_ci    /** For request file descriptor of pipe */
70800b99b8Sopenharmony_ci    PIPE_FD_CLIENT,
71800b99b8Sopenharmony_ci    /** For report crash dump exception */
72800b99b8Sopenharmony_ci    REPORT_EXCEPTION_CLIENT,
73800b99b8Sopenharmony_ci};
74800b99b8Sopenharmony_ci
75800b99b8Sopenharmony_ci/**
76800b99b8Sopenharmony_ci * @brief  type of request about pipe
77800b99b8Sopenharmony_ci*/
78800b99b8Sopenharmony_cienum FaultLoggerPipeType {
79800b99b8Sopenharmony_ci    /** For request file descriptor of pipe to read buffer  */
80800b99b8Sopenharmony_ci    PIPE_FD_READ_BUF = 0,
81800b99b8Sopenharmony_ci    /** For request file descriptor of pipe to write buffer  */
82800b99b8Sopenharmony_ci    PIPE_FD_WRITE_BUF,
83800b99b8Sopenharmony_ci    /** For request file descriptor of pipe to read result  */
84800b99b8Sopenharmony_ci    PIPE_FD_READ_RES,
85800b99b8Sopenharmony_ci    /** For request file descriptor of pipe to write result  */
86800b99b8Sopenharmony_ci    PIPE_FD_WRITE_RES,
87800b99b8Sopenharmony_ci    /** For request file descriptor of pipe to json read buffer  */
88800b99b8Sopenharmony_ci    PIPE_FD_JSON_READ_BUF,
89800b99b8Sopenharmony_ci    /** For request file descriptor of pipe to json write buffer  */
90800b99b8Sopenharmony_ci    PIPE_FD_JSON_WRITE_BUF,
91800b99b8Sopenharmony_ci    /** For request file descriptor of pipe to json read result  */
92800b99b8Sopenharmony_ci    PIPE_FD_JSON_READ_RES,
93800b99b8Sopenharmony_ci    /** For request file descriptor of pipe to json write result  */
94800b99b8Sopenharmony_ci    PIPE_FD_JSON_WRITE_RES,
95800b99b8Sopenharmony_ci    /** For request to delete file descriptor of pipe */
96800b99b8Sopenharmony_ci    PIPE_FD_DELETE,
97800b99b8Sopenharmony_ci};
98800b99b8Sopenharmony_ci/**
99800b99b8Sopenharmony_ci * @brief  type of responding check permission request
100800b99b8Sopenharmony_ci*/
101800b99b8Sopenharmony_cienum FaultLoggerCheckPermissionResp {
102800b99b8Sopenharmony_ci    /** pass */
103800b99b8Sopenharmony_ci    CHECK_PERMISSION_PASS = 1,
104800b99b8Sopenharmony_ci    /** reject */
105800b99b8Sopenharmony_ci    CHECK_PERMISSION_REJECT,
106800b99b8Sopenharmony_ci};
107800b99b8Sopenharmony_ci/**
108800b99b8Sopenharmony_ci * @brief  type of responding sdk dump request
109800b99b8Sopenharmony_ci*/
110800b99b8Sopenharmony_cienum FaultLoggerSdkDumpResp {
111800b99b8Sopenharmony_ci    /** pass */
112800b99b8Sopenharmony_ci    SDK_DUMP_PASS = 1,
113800b99b8Sopenharmony_ci    /** reject */
114800b99b8Sopenharmony_ci    SDK_DUMP_REJECT,
115800b99b8Sopenharmony_ci    /** repeat request */
116800b99b8Sopenharmony_ci    SDK_DUMP_REPEAT,
117800b99b8Sopenharmony_ci    /** process not exist */
118800b99b8Sopenharmony_ci    SDK_DUMP_NOPROC,
119800b99b8Sopenharmony_ci    /** process has crashed */
120800b99b8Sopenharmony_ci    SDK_PROCESS_CRASHED,
121800b99b8Sopenharmony_ci};
122800b99b8Sopenharmony_ci/**
123800b99b8Sopenharmony_ci * @brief  request information
124800b99b8Sopenharmony_ci*/
125800b99b8Sopenharmony_cistruct FaultLoggerdRequest {
126800b99b8Sopenharmony_ci    /** type of resquest */
127800b99b8Sopenharmony_ci    int32_t type;
128800b99b8Sopenharmony_ci    /** type of faultlogger client */
129800b99b8Sopenharmony_ci    int32_t clientType;
130800b99b8Sopenharmony_ci    /** type of pipe */
131800b99b8Sopenharmony_ci    int32_t pipeType;
132800b99b8Sopenharmony_ci    /** signal code */
133800b99b8Sopenharmony_ci    int32_t sigCode;
134800b99b8Sopenharmony_ci    /** process id */
135800b99b8Sopenharmony_ci    int32_t pid;
136800b99b8Sopenharmony_ci    /** thread id */
137800b99b8Sopenharmony_ci    int32_t tid;
138800b99b8Sopenharmony_ci    /** user id */
139800b99b8Sopenharmony_ci    uint32_t uid;
140800b99b8Sopenharmony_ci    /** process id of calling sdk dump ,only for sdk dump client */
141800b99b8Sopenharmony_ci    int32_t callerPid;
142800b99b8Sopenharmony_ci    /** thread id of calling sdk dump ,only for sdk dump client */
143800b99b8Sopenharmony_ci    int32_t callerTid;
144800b99b8Sopenharmony_ci    /** time of current request */
145800b99b8Sopenharmony_ci    uint64_t time;
146800b99b8Sopenharmony_ci    /** ture output json string, false output default string */
147800b99b8Sopenharmony_ci    bool isJson;
148800b99b8Sopenharmony_ci    /** dumpcatcher remote unwind endtime ms */
149800b99b8Sopenharmony_ci    uint64_t endTime;
150800b99b8Sopenharmony_ci} __attribute__((packed));
151800b99b8Sopenharmony_ci
152800b99b8Sopenharmony_ci/**
153800b99b8Sopenharmony_ci * @brief  type of faultloggerd stats request
154800b99b8Sopenharmony_ci*/
155800b99b8Sopenharmony_cienum FaultLoggerdStatType {
156800b99b8Sopenharmony_ci    /** dump catcher stats */
157800b99b8Sopenharmony_ci    DUMP_CATCHER = 0,
158800b99b8Sopenharmony_ci    /** processdump stats */
159800b99b8Sopenharmony_ci    PROCESS_DUMP
160800b99b8Sopenharmony_ci};
161800b99b8Sopenharmony_ci
162800b99b8Sopenharmony_ci/**
163800b99b8Sopenharmony_ci * @brief  struct of faultloggerd stats request
164800b99b8Sopenharmony_ci*/
165800b99b8Sopenharmony_cistruct FaultLoggerdStatsRequest {
166800b99b8Sopenharmony_ci    /** type of resquest */
167800b99b8Sopenharmony_ci    int32_t type;
168800b99b8Sopenharmony_ci    /** target process id outside sandbox */
169800b99b8Sopenharmony_ci    int32_t pid;
170800b99b8Sopenharmony_ci    /** the time call dumpcatcher interface */
171800b99b8Sopenharmony_ci    uint64_t requestTime;
172800b99b8Sopenharmony_ci    /** the time signal arrive in targe process */
173800b99b8Sopenharmony_ci    uint64_t signalTime;
174800b99b8Sopenharmony_ci    /** the time enter processdump main */
175800b99b8Sopenharmony_ci    uint64_t processdumpStartTime;
176800b99b8Sopenharmony_ci    /** the time finish processdump */
177800b99b8Sopenharmony_ci    uint64_t processdumpFinishTime;
178800b99b8Sopenharmony_ci    /** the time return from dumpcatcher interface */
179800b99b8Sopenharmony_ci    uint64_t dumpCatcherFinishTime;
180800b99b8Sopenharmony_ci    /** dumpcatcher result */
181800b99b8Sopenharmony_ci    int32_t result;
182800b99b8Sopenharmony_ci    /** caller elf offset */
183800b99b8Sopenharmony_ci    uintptr_t offset;
184800b99b8Sopenharmony_ci    char summary[128]; // 128 : max summary size
185800b99b8Sopenharmony_ci    /** the caller elf of dumpcatcher interface */
186800b99b8Sopenharmony_ci    char callerElf[128]; // 128 : max function name size
187800b99b8Sopenharmony_ci    /** the caller processName */
188800b99b8Sopenharmony_ci    char callerProcess[128]; // 128 : max function name size
189800b99b8Sopenharmony_ci    /** the target processName */
190800b99b8Sopenharmony_ci    char targetProcess[128]; // 128 : max function name size
191800b99b8Sopenharmony_ci} __attribute__((packed));
192800b99b8Sopenharmony_ci#ifdef __cplusplus
193800b99b8Sopenharmony_ci}
194800b99b8Sopenharmony_ci#endif
195800b99b8Sopenharmony_ci#endif