• 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_DUMP_REQUEST_H
16 #define DFX_DUMP_REQUEST_H
17 
18 #include <inttypes.h>
19 #include <signal.h>
20 #include <ucontext.h>
21 #include "dfx_define.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /**
28  * @brief ProcessDump type
29  */
30 enum ProcessDumpType : int32_t {
31     DUMP_TYPE_CPP_CRASH,
32     DUMP_TYPE_DUMP_CATCH,
33     DUMP_TYPE_MEM_LEAK,
34     DUMP_TYPE_FDSAN,
35     DUMP_TYPE_JEMALLOC,
36     DUMP_TYPE_BADFD,
37     DUMP_TYPE_COREDUMP,
38     DUMP_TYPE_LITEPERF,
39 };
40 
41 /**
42  * @brief Process trace information
43  */
44 enum OperateResult : int32_t {
45     OPE_FAIL = 0,
46     OPE_SUCCESS = 1,
47     OPE_CONTINUE = 2,
48 };
49 
50 typedef enum {
51     MESSAGE_NONE = 0,
52     MESSAGE_FATAL, // Need to write LastFatalMessage
53     MESSAGE_CALLBACK, // call back memssage
54 } MessageType;
55 
56 typedef struct {
57     MessageType type;
58     char body[MAX_FATAL_MSG_SIZE];
59 } Message;
60 
61 #ifndef is_ohos_lite
62 typedef struct DumpHiTraceIdStruct {
63 #if __BYTE_ORDER == __LITTLE_ENDIAN
64     uint64_t valid : 1;
65     uint64_t ver : 3;
66     uint64_t chainId : 60;
67 
68     uint64_t flags : 12;
69     uint64_t spanId : 26;
70     uint64_t parentSpanId : 26;
71 #elif __BYTE_ORDER == __BIG_ENDIAN
72     uint64_t chainId : 60;
73     uint64_t ver : 3;
74     uint64_t valid : 1;
75 
76     uint64_t parentSpanId : 26;
77     uint64_t spanId : 26;
78     uint64_t flags : 12;
79 #else
80 #error "ERROR: No BIG_LITTLE_ENDIAN defines."
81 #endif
82 } DumpHiTraceIdStruct;
83 #endif
84 
85 /**
86  * @brief ProcessDump request information
87  * It is used to save and transfer the current process context from signalhandler to processdump,
88  * and also contains some other information of the process.
89  */
90 struct ProcessDumpRequest {
91     /** processdump type */
92     enum ProcessDumpType type;
93     /** thread id */
94     int32_t tid;
95     /** asynchronous thread id */
96     /** process id */
97     int32_t pid;
98     /** namespace process id */
99     int32_t nsPid;
100     /** process user id */
101     uint32_t uid;
102     /** reserved field */
103     uint64_t reserved;
104     /** timestamp */
105     uint64_t timeStamp;
106     /** current process signal context */
107     siginfo_t siginfo;
108     /** current process context */
109     ucontext_t context;
110     /** thread name */
111     char threadName[NAME_BUF_LEN];
112     /** process name */
113     char processName[NAME_BUF_LEN];
114     /** Storing different types of messages */
115     Message msg;
116     /** current porcess fd table address*/
117     uint64_t fdTableAddr;
118     /** stackId for async-stack */
119     uint64_t stackId;
120     /** application runing unique Id */
121     char appRunningId[MAX_APP_RUNNING_UNIQUE_ID_LEN];
122     /** source child process with processdump pipe */
123     int childPipeFd[2];
124     /** vm process pid addr */
125     intptr_t vmProcRealPidAddr;
126     /** whether block source process pid */
127     intptr_t blockCrashExitAddr;
128     /** whether processdump unwind crash success */
129     intptr_t unwindResultAddr;
130     uintptr_t crashObj;
131     uint64_t crashLogConfig;
132 #ifndef is_ohos_lite
133     DumpHiTraceIdStruct hitraceId;
134 #endif
135 };
136 
137 static const int CRASH_BLOCK_EXIT_FLAG  = 0x13579BDF;
138 static const int CRASH_UNWIND_SUCCESS_FLAG = 0x2468ACEF;
139 #ifdef __cplusplus
140 }
141 #endif
142 #endif
143