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_DEFINE_H
16 #define DFX_DEFINE_H
17 
18 #include <inttypes.h>
19 #include <stdbool.h>
20 
21 #define SIGDUMP 35
22 #define SIGLOCAL_DUMP 38
23 #define SIGLEAK_STACK 42
24 #define SIGLEAK_STACK_FDSAN 1 // When sig = 42, use si_code = 1 mark the event as fdsan
25 #define SIGLEAK_STACK_JEMALLOC 2 // When sig = 42, use si_code = 2 mark the event as jemalloc
26 #define SIGLEAK_STACK_BADFD 0xbadfd // When sig = 42, use si_code = 0xbadfd mark the event as badfd
27 #define PROCESSDUMP_TIMEOUT 8
28 #define DUMPCATCHER_TIMEOUT 15
29 
30 #ifndef NAME_MAX
31 #define NAME_MAX         255
32 #endif
33 #ifndef PATH_MAX
34 #define PATH_MAX        1024
35 #endif
36 #define NAME_BUF_LEN    128
37 #define PATH_LEN        512
38 #define LINE_BUF_SIZE   1024
39 #define MAX_FATAL_MSG_SIZE  1024
40 #define MAX_PIPE_SIZE (1024 * 1024)
41 #define MAX_FUNC_NAME_LEN  256
42 #define MAX_APP_RUNNING_UNIQUE_ID_LEN  64
43 static const int NUMBER_ONE_THOUSAND = 1000;
44 static const int NUMBER_ONE_MILLION = 1000000;
45 
46 static const int PTRACE_ATTATCH_KEY_THREAD_TIMEOUT = 1000;
47 static const int PTRACE_ATTATCH_OTHER_THREAD_TIMEOUT = 50;
48 
49 static const int INVALID_FD = -1;
50 static const int DUMP_TYPE_REMOTE = -1;
51 static const int DUMP_TYPE_NATIVE = -1;
52 static const int DUMP_TYPE_MIX = -2;
53 static const int DUMP_TYPE_KERNEL = -3;
54 static const int DUMP_TYPE_LOCAL = -4;
55 
56 static const int DEFAULT_MAX_FRAME_NUM = 256;
57 static const int DEFAULT_MAX_LOCAL_FRAME_NUM = 32;
58 static const int PIPE_NUM_SZ = 2;
59 static const int PIPE_READ = 0;
60 static const int PIPE_WRITE = 1;
61 static const int SOCKET_BUFFER_SIZE = 256;
62 static const char FAULTLOGGER_DAEMON_RESP[] =  "RESP:COMPLETE";
63 static const char FAULTLOGGERD_SOCK_BASE_PATH[] = "/dev/unix/socket/";
64 static const char SERVER_SOCKET_NAME[] = "faultloggerd.server";
65 static const char SERVER_CRASH_SOCKET_NAME[] = "faultloggerd.crash.server";
66 static const char SERVER_SDKDUMP_SOCKET_NAME[] = "faultloggerd.sdkdump.server";
67 
68 static const char PROC_SELF_STATUS_PATH[] = "/proc/self/status";
69 static const char PROC_SELF_TASK_PATH[] = "/proc/self/task";
70 static const char PROC_SELF_CMDLINE_PATH[] = "/proc/self/cmdline";
71 static const char PROC_SELF_COMM_PATH[] = "/proc/self/comm";
72 static const char PROC_SELF_MAPS_PATH[] = "/proc/self/maps";
73 static const char PROC_SELF_EXE_PATH[] = "/proc/self/exe";
74 
75 #ifndef LIKELY
76 #define LIKELY(exp)       (__builtin_expect(!!(exp), true))
77 #endif
78 #ifndef UNLIKELY
79 #define UNLIKELY(exp)     (__builtin_expect(!!(exp), false))
80 #endif
81 
82 #define AT_SYMBOL_DEFAULT       __attribute__ ((visibility("default")))
83 #define AT_SYMBOL_HIDDEN        __attribute__ ((visibility("hidden")))
84 #define AT_ALWAYS_INLINE        __attribute__((always_inline))
85 #define AT_WARN_UNUSED          __attribute__((warn_unused_result))
86 #define AT_UNUSED               __attribute__((unused))
87 #define MAYBE_UNUSED            [[maybe_unused]]
88 #define NO_SANITIZE __attribute__((no_sanitize("address"), no_sanitize("hwaddress")))
89 
90 #ifndef FALLTHROUGH_INTENDED
91 #define FALLTHROUGH_INTENDED [[clang::fallthrough]]  // NOLINT
92 #endif
93 
94 #define OHOS_TEMP_FAILURE_RETRY(exp)            \
95     ({                                          \
96     long int _rc;                               \
97     do {                                        \
98         _rc = (long int)(exp);                  \
99     } while ((_rc == -1) && (errno == EINTR));  \
100     _rc;                                        \
101     })
102 
103 #if defined(__LP64__)
104 #define PRIX64_ADDR "#018" PRIx64
105 #else
106 #define PRIX64_ADDR "#010" PRIx64
107 #endif
108 
109 #endif
110