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
24extern "C" {
25#endif
26
27/**
28 * @brief ProcessDump type
29 */
30enum ProcessDumpType : int32_t {
31    /** dump process stack */
32    DUMP_TYPE_PROCESS,
33    /** dump thread stack */
34    DUMP_TYPE_THREAD,
35};
36
37/**
38 * @brief Process trace information
39 */
40enum OperateResult : int32_t {
41    OPE_FAIL = 0,
42    OPE_SUCCESS = 1,
43    OPE_CONTINUE = 2,
44};
45
46enum ProcessFlowMode : int32_t {
47    SPLIT_MODE,
48    FUSION_MODE,
49};
50
51enum RemoteProcessType : int32_t {
52    MAIN_PROCESS,
53    VIRTUAL_PROCESS
54};
55
56enum PidType : int32_t {
57    REAL_PROCESS_PID,
58    VIRTUAL_PROCESS_PID,
59    PID_MAX,
60};
61
62/**
63 * @brief Process trace information
64 * keep sync with the definition in hitracec.h
65 */
66typedef struct TraceInfo {
67#if __BYTE_ORDER == __LITTLE_ENDIAN
68    uint64_t valid : 1;
69    uint64_t ver : 3;
70    uint64_t chainId : 60;
71
72    uint64_t flags : 12;
73    uint64_t spanId : 26;
74    uint64_t parentSpanId : 26;
75#elif __BYTE_ORDER == __BIG_ENDIAN
76    uint64_t chainId : 60;
77    uint64_t ver : 3;
78    uint64_t valid : 1;
79
80    uint64_t parentSpanId : 26;
81    uint64_t spanId : 26;
82    uint64_t flags : 12;
83#else
84#error "ERROR: No BIG_LITTLE_ENDIAN defines."
85#endif
86} TraceInfo;
87
88typedef enum {
89    NONE = 0,
90    MESSAGE_FATAL, // hilog last fatal log message
91    MESSAGE_FDSAN_DEBUG, // fdsan debug message
92    MESSAGE_JEMALLOC, // jemalloc message
93    MESSAGE_BADFD, // badfd message
94} MessageType;
95
96typedef struct {
97    MessageType type;
98    char body[MAX_FATAL_MSG_SIZE];
99} Message;
100
101/**
102 * @brief ProcessDump request information
103 * It is used to save and transfer the current process context from signalhandler to processdump,
104 * and also contains some other information of the process.
105 */
106struct ProcessDumpRequest {
107    /** processdump type */
108    enum ProcessDumpType type;
109    /** thread id */
110    int32_t tid;
111    /** asynchronous thread id */
112    int32_t recycleTid;
113    /** process id */
114    int32_t pid;
115    /** namespace process id */
116    int32_t nsPid;
117    /** virtual process id */
118    int32_t vmPid;
119    /** virtual namespace process id */
120    int32_t vmNsPid;
121    /** process user id */
122    uint32_t uid;
123    /** reserved field */
124    uint64_t reserved;
125    /** timestamp */
126    uint64_t timeStamp;
127    /** current process signal context */
128    siginfo_t siginfo;
129    /** current process context */
130    ucontext_t context;
131    /** thread name */
132    char threadName[NAME_BUF_LEN];
133    /** process name */
134    char processName[NAME_BUF_LEN];
135    /** Storing different types of messages */
136    Message msg;
137    /** process trace info */
138    TraceInfo traceInfo;
139    /** current porcess fd table address*/
140    uint64_t fdTableAddr;
141    /** stackId for async-stack */
142    uint64_t stackId;
143    /** application runing unique Id */
144    char appRunningId[MAX_APP_RUNNING_UNIQUE_ID_LEN];
145    /** source process with processdump pipe */
146    int pmPipeFd[2];
147    /** vm process with proceeesump pipe */
148    int vmPipeFd[2];
149    /** is integrate crash dump flow 0:false 1:true */
150    int32_t dumpMode;
151    uintptr_t crashObj;
152};
153#ifdef __cplusplus
154}
155#endif
156#endif
157