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_REMOTE_JSON = -2; 52 static const int DUMP_TYPE_LOCAL = -3; 53 static const int DUMP_TYPE_LOCAL_MIX = -5; 54 static const int PIPE_BUF_INDEX = 0; 55 static const int PIPE_RES_INDEX = 1; 56 57 static const int DEFAULT_MAX_FRAME_NUM = 256; 58 static const int DEFAULT_MAX_LOCAL_FRAME_NUM = 32; 59 static const int PIPE_NUM_SZ = 2; 60 static const int PIPE_READ = 0; 61 static const int PIPE_WRITE = 1; 62 63 static const char* const PROC_SELF_STATUS_PATH = "/proc/self/status"; 64 static const char* const PROC_SELF_TASK_PATH = "/proc/self/task"; 65 static const char* const PROC_SELF_CMDLINE_PATH = "/proc/self/cmdline"; 66 static const char* const PROC_SELF_COMM_PATH = "/proc/self/comm"; 67 static const char* const PROC_SELF_MAPS_PATH = "/proc/self/maps"; 68 static const char* const PROC_SELF_EXE_PATH = "/proc/self/exe"; 69 70 #ifndef LIKELY 71 #define LIKELY(exp) (__builtin_expect(!!(exp), true)) 72 #endif 73 #ifndef UNLIKELY 74 #define UNLIKELY(exp) (__builtin_expect(!!(exp), false)) 75 #endif 76 77 #define AT_SYMBOL_DEFAULT __attribute__ ((visibility("default"))) 78 #define AT_SYMBOL_HIDDEN __attribute__ ((visibility("hidden"))) 79 #define AT_ALWAYS_INLINE __attribute__((always_inline)) 80 #define AT_WARN_UNUSED __attribute__((warn_unused_result)) 81 #define AT_UNUSED __attribute__((unused)) 82 #define MAYBE_UNUSED [[maybe_unused]] 83 #define NO_SANITIZE __attribute__((no_sanitize("address"), no_sanitize("hwaddress"))) 84 85 #ifndef FALLTHROUGH_INTENDED 86 #define FALLTHROUGH_INTENDED [[clang::fallthrough]] // NOLINT 87 #endif 88 89 #define OHOS_TEMP_FAILURE_RETRY(exp) \ 90 ({ \ 91 long int _rc; \ 92 do { \ 93 _rc = (long int)(exp); \ 94 } while ((_rc == -1) && (errno == EINTR)); \ 95 _rc; \ 96 }) 97 98 #if defined(__LP64__) 99 #define PRIX64_ADDR "#018" PRIx64 100 #else 101 #define PRIX64_ADDR "#010" PRIx64 102 #endif 103 104 #endif 105