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_COREDUMP 3 // When sig = 42, use si_code = 3 mark the event as coredump 27 #define SIGLEAK_STACK_BADFD 0xbadfd // When sig = 42, use si_code = 0xbadfd mark the event as badfd 28 #define PROCESSDUMP_TIMEOUT 8 29 #define DUMPCATCHER_TIMEOUT 15 30 31 #ifndef NAME_MAX 32 #define NAME_MAX 255 33 #endif 34 #ifndef PATH_MAX 35 #define PATH_MAX 1024 36 #endif 37 #define NAME_BUF_LEN 128 38 #define PATH_LEN 512 39 #define LINE_BUF_SIZE 1024 40 #define MAX_FATAL_MSG_SIZE 1024 41 #define MAX_PIPE_SIZE (1024 * 1024) 42 #define MAX_FUNC_NAME_LEN 256 43 #define MAX_APP_RUNNING_UNIQUE_ID_LEN 64 44 static const int NUMBER_ONE_THOUSAND = 1000; 45 static const int NUMBER_ONE_MILLION = 1000000; 46 47 static const int PTRACE_ATTATCH_KEY_THREAD_TIMEOUT = 1000; 48 static const int PTRACE_ATTATCH_OTHER_THREAD_TIMEOUT = 50; 49 50 static const int INVALID_FD = -1; 51 static const int DUMP_TYPE_REMOTE = -1; 52 static const int DUMP_TYPE_REMOTE_JSON = -2; 53 static const int DUMP_TYPE_LOCAL = -3; 54 static const int DUMP_TYPE_LOCAL_MIX = -5; 55 static const int PIPE_BUF_INDEX = 0; 56 static const int PIPE_RES_INDEX = 1; 57 58 static const int DEFAULT_MAX_FRAME_NUM = 256; 59 static const int DEFAULT_MAX_LOCAL_FRAME_NUM = 32; 60 static const int PIPE_NUM_SZ = 2; 61 static const int PIPE_READ = 0; 62 static const int PIPE_WRITE = 1; 63 64 static const char* const PROC_SELF_STATUS_PATH = "/proc/self/status"; 65 static const char* const PROC_SELF_TASK_PATH = "/proc/self/task"; 66 static const char* const PROC_SELF_CMDLINE_PATH = "/proc/self/cmdline"; 67 static const char* const PROC_SELF_COMM_PATH = "/proc/self/comm"; 68 static const char* const PROC_SELF_MAPS_PATH = "/proc/self/maps"; 69 static const char* const PROC_SELF_EXE_PATH = "/proc/self/exe"; 70 #ifdef DFX_LOG_HILOG_BASE 71 static const char* const PROCESSDUMP_PATH = "/system/bin/processdump"; 72 #else 73 static const char* const PROCESSDUMP_PATH = "/bin/processdump"; 74 #endif 75 76 #ifndef LIKELY 77 #define LIKELY(exp) (__builtin_expect(!!(exp), true)) 78 #endif 79 #ifndef UNLIKELY 80 #define UNLIKELY(exp) (__builtin_expect(!!(exp), false)) 81 #endif 82 83 #define AT_SYMBOL_DEFAULT __attribute__ ((visibility("default"))) 84 #define AT_SYMBOL_HIDDEN __attribute__ ((visibility("hidden"))) 85 #define AT_ALWAYS_INLINE __attribute__((always_inline)) 86 #define AT_NOINLINE __attribute__((noinline)) 87 #define AT_OPT_NONE __attribute__((optnone)) 88 #define AT_WARN_UNUSED __attribute__((warn_unused_result)) 89 #define AT_UNUSED __attribute__((unused)) 90 #define AT_FALLTHROUGH __attribute__((fallthrough)) 91 #define MAYBE_UNUSED [[maybe_unused]] 92 #define NO_SANITIZE __attribute__((no_sanitize("address"), no_sanitize("hwaddress"))) 93 94 #ifndef FALLTHROUGH_INTENDED 95 #define FALLTHROUGH_INTENDED [[clang::fallthrough]] // NOLINT 96 #endif 97 98 #define OHOS_TEMP_FAILURE_RETRY(exp) \ 99 ({ \ 100 long int _rc; \ 101 do { \ 102 _rc = (long int)(exp); \ 103 } while ((_rc == -1) && (errno == EINTR)); \ 104 _rc; \ 105 }) 106 107 #if defined(__LP64__) 108 #define PRIX64_ADDR "#018" PRIx64 109 #else 110 #define PRIX64_ADDR "#010" PRIx64 111 #endif 112 113 #endif 114