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 PROCESSDUMP_TIMEOUT 8 25 #define DUMPCATCHER_TIMEOUT 15 26 27 #ifndef NAME_MAX 28 #define NAME_MAX 255 29 #endif 30 #ifndef PATH_MAX 31 #define PATH_MAX 1024 32 #endif 33 #define NAME_BUF_LEN 128 34 #define PATH_LEN 512 35 #define LINE_BUF_SIZE 1024 36 #define MAX_FATAL_MSG_SIZE 1024 37 #define MAX_PIPE_SIZE (1024 * 1024) 38 #define MAX_FUNC_NAME_LEN 256 39 #define MAX_APP_RUNNING_UNIQUE_ID_LEN 64 40 static const int NUMBER_ONE_THOUSAND = 1000; 41 static const int NUMBER_ONE_MILLION = 1000000; 42 43 static const int PTRACE_ATTATCH_KEY_THREAD_TIMEOUT = 1000; 44 static const int PTRACE_ATTATCH_OTHER_THREAD_TIMEOUT = 10; 45 46 static const int INVALID_FD = -1; 47 static const int DUMP_TYPE_REMOTE = -1; 48 static const int DUMP_TYPE_NATIVE = -1; 49 static const int DUMP_TYPE_MIX = -2; 50 static const int DUMP_TYPE_KERNEL = -3; 51 static const int DUMP_TYPE_LOCAL = -4; 52 53 static const int DEFAULT_MAX_FRAME_NUM = 256; 54 static const int DEFAULT_MAX_LOCAL_FRAME_NUM = 32; 55 static const int PIPE_NUM_SZ = 2; 56 static const int PIPE_READ = 0; 57 static const int PIPE_WRITE = 1; 58 static const int SOCKET_BUFFER_SIZE = 256; 59 static const char FAULTLOGGER_DAEMON_RESP[] = "RESP:COMPLETE"; 60 static const char FAULTLOGGERD_SOCK_BASE_PATH[] = "/dev/unix/socket/"; 61 static const char SERVER_SOCKET_NAME[] = "faultloggerd.server"; 62 static const char SERVER_CRASH_SOCKET_NAME[] = "faultloggerd.crash.server"; 63 static const char SERVER_SDKDUMP_SOCKET_NAME[] = "faultloggerd.sdkdump.server"; 64 65 static const char PROC_SELF_STATUS_PATH[] = "/proc/self/status"; 66 static const char PROC_SELF_TASK_PATH[] = "/proc/self/task"; 67 static const char PROC_SELF_CMDLINE_PATH[] = "/proc/self/cmdline"; 68 static const char PROC_SELF_COMM_PATH[] = "/proc/self/comm"; 69 static const char PROC_SELF_MAPS_PATH[] = "/proc/self/maps"; 70 static const char PROC_SELF_EXE_PATH[] = "/proc/self/exe"; 71 72 #ifndef LIKELY 73 #define LIKELY(exp) (__builtin_expect(!!(exp), true)) 74 #endif 75 #ifndef UNLIKELY 76 #define UNLIKELY(exp) (__builtin_expect(!!(exp), false)) 77 #endif 78 79 #define AT_SYMBOL_DEFAULT __attribute__ ((visibility("default"))) 80 #define AT_SYMBOL_HIDDEN __attribute__ ((visibility("hidden"))) 81 #define AT_ALWAYS_INLINE __attribute__((always_inline)) 82 #define AT_WARN_UNUSED __attribute__((warn_unused_result)) 83 #define AT_UNUSED __attribute__((unused)) 84 #define MAYBE_UNUSED [[maybe_unused]] 85 86 #ifndef FALLTHROUGH_INTENDED 87 #define FALLTHROUGH_INTENDED [[clang::fallthrough]] // NOLINT 88 #endif 89 90 #define OHOS_TEMP_FAILURE_RETRY(exp) \ 91 ({ \ 92 long int _rc; \ 93 do { \ 94 _rc = (long int)(exp); \ 95 } while ((_rc == -1) && (errno == EINTR)); \ 96 _rc; \ 97 }) 98 99 #endif 100