• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     /** leak stacktrace */
45     LEAK_STACKTRACE,
46 };
47 
48 /**
49  * @brief  type of faultlogger client
50  *
51 */
52 enum FaultLoggerClientType {
53     /** For original request crash info temp file  */
54     DEFAULT_CLIENT = 0,
55     /** For request a debug file to record nornal unwind and process dump logs */
56     LOG_FILE_DES_CLIENT,
57     /** For request to record nornal unwind and process dump to hilog */
58     PRINT_T_HILOG_CLIENT,
59     /** For request to check permission */
60     PERMISSION_CLIENT,
61     /** For request to dump stack  */
62     SDK_DUMP_CLIENT,
63     /** For request file descriptor of pipe  */
64     PIPE_FD_CLIENT,
65 };
66 /**
67  * @brief  type of request about pipe
68 */
69 enum FaultLoggerPipeType {
70     /** For request file descriptor of pipe to read buffer  */
71     PIPE_FD_READ_BUF = 0,
72     /** For request file descriptor of pipe to write buffer  */
73     PIPE_FD_WRITE_BUF,
74     /** For request file descriptor of pipe to read result  */
75     PIPE_FD_READ_RES,
76     /** For request file descriptor of pipe to write result  */
77     PIPE_FD_WRITE_RES,
78     /** For request file descriptor of pipe to json read buffer  */
79     PIPE_FD_JSON_READ_BUF,
80     /** For request file descriptor of pipe to json write buffer  */
81     PIPE_FD_JSON_WRITE_BUF,
82     /** For request file descriptor of pipe to json read result  */
83     PIPE_FD_JSON_READ_RES,
84     /** For request file descriptor of pipe to json write result  */
85     PIPE_FD_JSON_WRITE_RES,
86     /** For request to delete file descriptor of pipe */
87     PIPE_FD_DELETE,
88 };
89 /**
90  * @brief  type of responding check permission request
91 */
92 enum FaultLoggerCheckPermissionResp {
93     /** pass */
94     CHECK_PERMISSION_PASS = 1,
95     /** reject */
96     CHECK_PERMISSION_REJECT,
97 };
98 /**
99  * @brief  type of responding sdk dump request
100 */
101 enum FaultLoggerSdkDumpResp {
102     /** pass */
103     SDK_DUMP_PASS = 1,
104     /** reject */
105     SDK_DUMP_REJECT,
106     /** repeat request */
107     SDK_DUMP_REPEAT,
108     /** process not exist */
109     SDK_DUMP_NOPROC,
110 };
111 /**
112  * @brief  request information
113 */
114 struct FaultLoggerdRequest {
115     /** type of resquest */
116     int32_t type;
117     /** type of faultlogger client */
118     int32_t clientType;
119     /** type of pipe */
120     int32_t pipeType;
121     /** signal code */
122     int32_t sigCode;
123     /** process id */
124     int32_t pid;
125     /** thread id */
126     int32_t tid;
127     /** user id */
128     uint32_t uid;
129     /** process id of calling sdk dump ,only for sdk dump client */
130     int32_t callerPid;
131     /** thread id of calling sdk dump ,only for sdk dump client */
132     int32_t callerTid;
133     /** time of current request */
134     uint64_t time;
135     /** ture output json string, false output default string */
136     bool isJson;
137 } __attribute__((packed));
138 /**
139  * @brief Check connection status of client
140  *
141  * @return if available return true, otherwise return false
142 */
143 bool CheckConnectStatus();
144 /**
145  * @brief request file descriptor
146  * @param type type of resqust
147  * @return if succeed return file descriptor, otherwise return -1
148 */
149 int32_t RequestFileDescriptor(int32_t type);
150 
151 /**
152  * @brief request log file descriptor
153  * @param request struct of request information
154  * @return if succeed return file descriptor, otherwise return -1
155 */
156 int32_t RequestLogFileDescriptor(struct FaultLoggerdRequest *request);
157 
158 /**
159  * @brief request pipe file descriptor
160  * @param pid process id of request pipe
161  * @param pipeType type of request about pipe
162  * @return if succeed return file descriptor, otherwise return -1
163 */
164 int32_t RequestPipeFd(int32_t pid, int32_t pipeType);
165 
166 /**
167  * @brief request delete file descriptor
168  * @param pid process id of request pipe
169  * @return if succeed return 0, otherwise return -1
170 */
171 int32_t RequestDelPipeFd(int32_t pid);
172 
173 /**
174  * @brief request file descriptor
175  * @param request struct of request information
176  * @return if succeed return file descriptor, otherwise return -1
177 */
178 int RequestFileDescriptorEx(const struct FaultLoggerdRequest *request);
179 
180 /**
181  * @brief request checking permission of process
182  * @param pid process id
183  * @return if pass return true , otherwise return false
184 */
185 bool RequestCheckPermission(int32_t pid);
186 /**
187  * @brief request printing message to hilog
188  * @param msg message
189  * @param length length of message
190  * @return if succeed return 0 , otherwise return -1
191 */
192 int RequestPrintTHilog(const char *msg, int length);
193 
194 /**
195  * @brief request dump stack about process
196  * @param pid process id
197  * @param tid thread id, if equal 0 means dump all the threads in a process.
198  * @return if succeed return 0 , otherwise return -1
199 */
200 int RequestSdkDump(int32_t type, int32_t pid, int32_t tid);
201 
202 /**
203  * @brief request dump stack about process
204  * @param pid process id
205  * @param tid thread id, if equal 0 means dump all the threads in a process.
206  * @return if succeed return 0 , otherwise return -1
207 */
208 int RequestSdkDumpJson(int32_t type, int32_t pid, int32_t tid, bool isJson);
209 
210 #ifdef __cplusplus
211 }
212 #endif
213 #endif
214