1800b99b8Sopenharmony_ci/*
2800b99b8Sopenharmony_ci * Copyright (c) 2021-2023 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#ifndef DFX_DUMP_REQUEST_H
16800b99b8Sopenharmony_ci#define DFX_DUMP_REQUEST_H
17800b99b8Sopenharmony_ci
18800b99b8Sopenharmony_ci#include <inttypes.h>
19800b99b8Sopenharmony_ci#include <signal.h>
20800b99b8Sopenharmony_ci#include <ucontext.h>
21800b99b8Sopenharmony_ci#include "dfx_define.h"
22800b99b8Sopenharmony_ci
23800b99b8Sopenharmony_ci#ifdef __cplusplus
24800b99b8Sopenharmony_ciextern "C" {
25800b99b8Sopenharmony_ci#endif
26800b99b8Sopenharmony_ci
27800b99b8Sopenharmony_ci/**
28800b99b8Sopenharmony_ci * @brief ProcessDump type
29800b99b8Sopenharmony_ci */
30800b99b8Sopenharmony_cienum ProcessDumpType : int32_t {
31800b99b8Sopenharmony_ci    /** dump process stack */
32800b99b8Sopenharmony_ci    DUMP_TYPE_PROCESS,
33800b99b8Sopenharmony_ci    /** dump thread stack */
34800b99b8Sopenharmony_ci    DUMP_TYPE_THREAD,
35800b99b8Sopenharmony_ci};
36800b99b8Sopenharmony_ci
37800b99b8Sopenharmony_ci/**
38800b99b8Sopenharmony_ci * @brief Process trace information
39800b99b8Sopenharmony_ci */
40800b99b8Sopenharmony_cienum OperateResult : int32_t {
41800b99b8Sopenharmony_ci    OPE_FAIL = 0,
42800b99b8Sopenharmony_ci    OPE_SUCCESS = 1,
43800b99b8Sopenharmony_ci    OPE_CONTINUE = 2,
44800b99b8Sopenharmony_ci};
45800b99b8Sopenharmony_ci
46800b99b8Sopenharmony_cienum ProcessFlowMode : int32_t {
47800b99b8Sopenharmony_ci    SPLIT_MODE,
48800b99b8Sopenharmony_ci    FUSION_MODE,
49800b99b8Sopenharmony_ci};
50800b99b8Sopenharmony_ci
51800b99b8Sopenharmony_cienum RemoteProcessType : int32_t {
52800b99b8Sopenharmony_ci    MAIN_PROCESS,
53800b99b8Sopenharmony_ci    VIRTUAL_PROCESS
54800b99b8Sopenharmony_ci};
55800b99b8Sopenharmony_ci
56800b99b8Sopenharmony_cienum PidType : int32_t {
57800b99b8Sopenharmony_ci    REAL_PROCESS_PID,
58800b99b8Sopenharmony_ci    VIRTUAL_PROCESS_PID,
59800b99b8Sopenharmony_ci    PID_MAX,
60800b99b8Sopenharmony_ci};
61800b99b8Sopenharmony_ci
62800b99b8Sopenharmony_ci/**
63800b99b8Sopenharmony_ci * @brief Process trace information
64800b99b8Sopenharmony_ci * keep sync with the definition in hitracec.h
65800b99b8Sopenharmony_ci */
66800b99b8Sopenharmony_citypedef struct TraceInfo {
67800b99b8Sopenharmony_ci#if __BYTE_ORDER == __LITTLE_ENDIAN
68800b99b8Sopenharmony_ci    uint64_t valid : 1;
69800b99b8Sopenharmony_ci    uint64_t ver : 3;
70800b99b8Sopenharmony_ci    uint64_t chainId : 60;
71800b99b8Sopenharmony_ci
72800b99b8Sopenharmony_ci    uint64_t flags : 12;
73800b99b8Sopenharmony_ci    uint64_t spanId : 26;
74800b99b8Sopenharmony_ci    uint64_t parentSpanId : 26;
75800b99b8Sopenharmony_ci#elif __BYTE_ORDER == __BIG_ENDIAN
76800b99b8Sopenharmony_ci    uint64_t chainId : 60;
77800b99b8Sopenharmony_ci    uint64_t ver : 3;
78800b99b8Sopenharmony_ci    uint64_t valid : 1;
79800b99b8Sopenharmony_ci
80800b99b8Sopenharmony_ci    uint64_t parentSpanId : 26;
81800b99b8Sopenharmony_ci    uint64_t spanId : 26;
82800b99b8Sopenharmony_ci    uint64_t flags : 12;
83800b99b8Sopenharmony_ci#else
84800b99b8Sopenharmony_ci#error "ERROR: No BIG_LITTLE_ENDIAN defines."
85800b99b8Sopenharmony_ci#endif
86800b99b8Sopenharmony_ci} TraceInfo;
87800b99b8Sopenharmony_ci
88800b99b8Sopenharmony_citypedef enum {
89800b99b8Sopenharmony_ci    NONE = 0,
90800b99b8Sopenharmony_ci    MESSAGE_FATAL, // hilog last fatal log message
91800b99b8Sopenharmony_ci    MESSAGE_FDSAN_DEBUG, // fdsan debug message
92800b99b8Sopenharmony_ci    MESSAGE_JEMALLOC, // jemalloc message
93800b99b8Sopenharmony_ci    MESSAGE_BADFD, // badfd message
94800b99b8Sopenharmony_ci} MessageType;
95800b99b8Sopenharmony_ci
96800b99b8Sopenharmony_citypedef struct {
97800b99b8Sopenharmony_ci    MessageType type;
98800b99b8Sopenharmony_ci    char body[MAX_FATAL_MSG_SIZE];
99800b99b8Sopenharmony_ci} Message;
100800b99b8Sopenharmony_ci
101800b99b8Sopenharmony_ci/**
102800b99b8Sopenharmony_ci * @brief ProcessDump request information
103800b99b8Sopenharmony_ci * It is used to save and transfer the current process context from signalhandler to processdump,
104800b99b8Sopenharmony_ci * and also contains some other information of the process.
105800b99b8Sopenharmony_ci */
106800b99b8Sopenharmony_cistruct ProcessDumpRequest {
107800b99b8Sopenharmony_ci    /** processdump type */
108800b99b8Sopenharmony_ci    enum ProcessDumpType type;
109800b99b8Sopenharmony_ci    /** thread id */
110800b99b8Sopenharmony_ci    int32_t tid;
111800b99b8Sopenharmony_ci    /** asynchronous thread id */
112800b99b8Sopenharmony_ci    int32_t recycleTid;
113800b99b8Sopenharmony_ci    /** process id */
114800b99b8Sopenharmony_ci    int32_t pid;
115800b99b8Sopenharmony_ci    /** namespace process id */
116800b99b8Sopenharmony_ci    int32_t nsPid;
117800b99b8Sopenharmony_ci    /** virtual process id */
118800b99b8Sopenharmony_ci    int32_t vmPid;
119800b99b8Sopenharmony_ci    /** virtual namespace process id */
120800b99b8Sopenharmony_ci    int32_t vmNsPid;
121800b99b8Sopenharmony_ci    /** process user id */
122800b99b8Sopenharmony_ci    uint32_t uid;
123800b99b8Sopenharmony_ci    /** reserved field */
124800b99b8Sopenharmony_ci    uint64_t reserved;
125800b99b8Sopenharmony_ci    /** timestamp */
126800b99b8Sopenharmony_ci    uint64_t timeStamp;
127800b99b8Sopenharmony_ci    /** current process signal context */
128800b99b8Sopenharmony_ci    siginfo_t siginfo;
129800b99b8Sopenharmony_ci    /** current process context */
130800b99b8Sopenharmony_ci    ucontext_t context;
131800b99b8Sopenharmony_ci    /** thread name */
132800b99b8Sopenharmony_ci    char threadName[NAME_BUF_LEN];
133800b99b8Sopenharmony_ci    /** process name */
134800b99b8Sopenharmony_ci    char processName[NAME_BUF_LEN];
135800b99b8Sopenharmony_ci    /** Storing different types of messages */
136800b99b8Sopenharmony_ci    Message msg;
137800b99b8Sopenharmony_ci    /** process trace info */
138800b99b8Sopenharmony_ci    TraceInfo traceInfo;
139800b99b8Sopenharmony_ci    /** current porcess fd table address*/
140800b99b8Sopenharmony_ci    uint64_t fdTableAddr;
141800b99b8Sopenharmony_ci    /** stackId for async-stack */
142800b99b8Sopenharmony_ci    uint64_t stackId;
143800b99b8Sopenharmony_ci    /** application runing unique Id */
144800b99b8Sopenharmony_ci    char appRunningId[MAX_APP_RUNNING_UNIQUE_ID_LEN];
145800b99b8Sopenharmony_ci    /** source process with processdump pipe */
146800b99b8Sopenharmony_ci    int pmPipeFd[2];
147800b99b8Sopenharmony_ci    /** vm process with proceeesump pipe */
148800b99b8Sopenharmony_ci    int vmPipeFd[2];
149800b99b8Sopenharmony_ci    /** is integrate crash dump flow 0:false 1:true */
150800b99b8Sopenharmony_ci    int32_t dumpMode;
151800b99b8Sopenharmony_ci    uintptr_t crashObj;
152800b99b8Sopenharmony_ci};
153800b99b8Sopenharmony_ci#ifdef __cplusplus
154800b99b8Sopenharmony_ci}
155800b99b8Sopenharmony_ci#endif
156800b99b8Sopenharmony_ci#endif
157