• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_DEFINE_H
16 #define DFX_DEFINE_H
17 
18 #include <endian.h>
19 #include <inttypes.h>
20 #include <stdbool.h>
21 
22 #define SIGDUMP 35
23 #define SIGLOCAL_DUMP 36
24 #define PROCESSDUMP_TIMEOUT 30
25 #define NAME_LEN 128
26 #define PATH_LEN 1024
27 #define MAX_HANDLED_TID_NUMBER 256
28 #define MAX_FATAL_MSG_SIZE 1024
29 
30 static const int SOCKET_BUFFER_SIZE = 256;
31 static const char FAULTLOGGERD_SOCK_PATH[] = "/dev/unix/socket/faultloggerd.server";
32 static const char SERVER_SOCKET_NAME[] = "faultloggerd.server";
33 static const char PROC_SELF_STATUS_PATH[] = "/proc/self/status";
34 
35 #if defined(__arm__)
36 static const int USER_REG_NUM = 16;
37 static const int REG_PC_NUM = 15;
38 static const int REG_LR_NUM = 14;
39 static const int REG_SP_NUM = 13;
40 #elif defined(__aarch64__)
41 static const int USER_REG_NUM = 34;
42 static const int REG_PC_NUM = 32;
43 static const int REG_LR_NUM = 30;
44 static const int REG_SP_NUM = 31;
45 #elif defined(__x86_64__)
46 static const int USER_REG_NUM = 27;
47 static const int REG_PC_NUM = 16;
48 #endif
49 
50 static const int ARM_EXEC_STEP_NORMAL = 4;
51 static const int ARM_EXEC_STEP_THUMB = 3;
52 
53 static const char PID_STR_NAME[] = "Pid:";
54 static const char PPID_STR_NAME[] = "PPid:";
55 static const char NSPID_STR_NAME[] = "NSpid:";
56 
57 static const int STATUS_LINE_SIZE = 1024;
58 static const int CONF_LINE_SIZE = 1024;
59 static const int SYMBOL_BUF_SIZE = 1024;
60 
61 static const int DUMP_CATCHER_NUMBER_ONE = 1;
62 static const int DUMP_CATCHER_NUMBER_TWO = 2;
63 static const int DUMP_CATCHER_NUMBER_THREE = 3;
64 
65 static const int FAULTSTACK_ITEM_BUFFER_LENGTH = 2048;
66 static const int FAULTSTACK_SP_REVERSE = 3;
67 static const int FAULTSTACK_FIRST_FRAME_SEARCH_LENGTH = 64;
68 
69 
70 // max unwind 64 steps.
71 static const int BACK_STACK_MAX_STEPS = 64;
72 // 128K back trace stack size
73 static const int BACK_STACK_INFO_SIZE = 128 * 1024;
74 
75 static const int BACK_TRACE_RING_BUFFER_SIZE = 32 * 1024;
76 static const int BACK_TRACE_RING_BUFFER_PRINT_WAIT_TIME_MS = 10;
77 
78 static const int LOG_BUF_LEN = 1024;
79 static const int FILE_WRITE_BUF_LEN = 4096;
80 
81 static const int REGS_PRINT_LEN_ARM = 256;
82 static const int REGS_PRINT_LEN_ARM64 = 1024;
83 static const int REGS_PRINT_LEN_X86 = 512;
84 
85 #define OHOS_TEMP_FAILURE_RETRY(exp)            \
86     ({                                          \
87     long int _rc;                               \
88     do {                                        \
89         _rc = (long int)(exp);                  \
90     } while ((_rc == -1) && (errno == EINTR));  \
91     _rc;                                        \
92     })
93 
94 // keep sync with the definition in hitracec.h
95 typedef struct TraceInfo {
96 #if __BYTE_ORDER == __LITTLE_ENDIAN
97     uint64_t valid : 1;
98     uint64_t ver : 3;
99     uint64_t chainId : 60;
100 
101     uint64_t flags : 12;
102     uint64_t spanId : 26;
103     uint64_t parentSpanId : 26;
104 #elif __BYTE_ORDER == __BIG_ENDIAN
105     uint64_t chainId : 60;
106     uint64_t ver : 3;
107     uint64_t valid : 1;
108 
109     uint64_t parentSpanId : 26;
110     uint64_t spanId : 26;
111     uint64_t flags : 12;
112 #else
113 #error "ERROR: No BIG_LITTLE_ENDIAN defines."
114 #endif
115 } TraceInfo;
116 
117 typedef struct ProcInfo {
118     int tid;
119     int pid;
120     int ppid;
121     bool ns;
122 } ProcInfo;
123 
124 #endif // DFX_DEFINE_H
125