1800b99b8Sopenharmony_ci/* 2800b99b8Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3800b99b8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4800b99b8Sopenharmony_ci * you may not use this file except in compliance with the License. 5800b99b8Sopenharmony_ci * You may obtain a copy of the License at 6800b99b8Sopenharmony_ci * 7800b99b8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8800b99b8Sopenharmony_ci * 9800b99b8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10800b99b8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11800b99b8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12800b99b8Sopenharmony_ci * See the License for the specific language governing permissions and 13800b99b8Sopenharmony_ci * limitations under the License. 14800b99b8Sopenharmony_ci */ 15800b99b8Sopenharmony_ci#ifndef DFX_DEFINE_H 16800b99b8Sopenharmony_ci#define DFX_DEFINE_H 17800b99b8Sopenharmony_ci 18800b99b8Sopenharmony_ci#include <inttypes.h> 19800b99b8Sopenharmony_ci#include <stdbool.h> 20800b99b8Sopenharmony_ci 21800b99b8Sopenharmony_ci#define SIGDUMP 35 22800b99b8Sopenharmony_ci#define SIGLOCAL_DUMP 38 23800b99b8Sopenharmony_ci#define SIGLEAK_STACK 42 24800b99b8Sopenharmony_ci#define SIGLEAK_STACK_FDSAN 1 // When sig = 42, use si_code = 1 mark the event as fdsan 25800b99b8Sopenharmony_ci#define SIGLEAK_STACK_JEMALLOC 2 // When sig = 42, use si_code = 2 mark the event as jemalloc 26800b99b8Sopenharmony_ci#define SIGLEAK_STACK_BADFD 0xbadfd // When sig = 42, use si_code = 0xbadfd mark the event as badfd 27800b99b8Sopenharmony_ci#define PROCESSDUMP_TIMEOUT 8 28800b99b8Sopenharmony_ci#define DUMPCATCHER_TIMEOUT 15 29800b99b8Sopenharmony_ci 30800b99b8Sopenharmony_ci#ifndef NAME_MAX 31800b99b8Sopenharmony_ci#define NAME_MAX 255 32800b99b8Sopenharmony_ci#endif 33800b99b8Sopenharmony_ci#ifndef PATH_MAX 34800b99b8Sopenharmony_ci#define PATH_MAX 1024 35800b99b8Sopenharmony_ci#endif 36800b99b8Sopenharmony_ci#define NAME_BUF_LEN 128 37800b99b8Sopenharmony_ci#define PATH_LEN 512 38800b99b8Sopenharmony_ci#define LINE_BUF_SIZE 1024 39800b99b8Sopenharmony_ci#define MAX_FATAL_MSG_SIZE 1024 40800b99b8Sopenharmony_ci#define MAX_PIPE_SIZE (1024 * 1024) 41800b99b8Sopenharmony_ci#define MAX_FUNC_NAME_LEN 256 42800b99b8Sopenharmony_ci#define MAX_APP_RUNNING_UNIQUE_ID_LEN 64 43800b99b8Sopenharmony_cistatic const int NUMBER_ONE_THOUSAND = 1000; 44800b99b8Sopenharmony_cistatic const int NUMBER_ONE_MILLION = 1000000; 45800b99b8Sopenharmony_ci 46800b99b8Sopenharmony_cistatic const int PTRACE_ATTATCH_KEY_THREAD_TIMEOUT = 1000; 47800b99b8Sopenharmony_cistatic const int PTRACE_ATTATCH_OTHER_THREAD_TIMEOUT = 50; 48800b99b8Sopenharmony_ci 49800b99b8Sopenharmony_cistatic const int INVALID_FD = -1; 50800b99b8Sopenharmony_cistatic const int DUMP_TYPE_REMOTE = -1; 51800b99b8Sopenharmony_cistatic const int DUMP_TYPE_NATIVE = -1; 52800b99b8Sopenharmony_cistatic const int DUMP_TYPE_MIX = -2; 53800b99b8Sopenharmony_cistatic const int DUMP_TYPE_KERNEL = -3; 54800b99b8Sopenharmony_cistatic const int DUMP_TYPE_LOCAL = -4; 55800b99b8Sopenharmony_ci 56800b99b8Sopenharmony_cistatic const int DEFAULT_MAX_FRAME_NUM = 256; 57800b99b8Sopenharmony_cistatic const int DEFAULT_MAX_LOCAL_FRAME_NUM = 32; 58800b99b8Sopenharmony_cistatic const int PIPE_NUM_SZ = 2; 59800b99b8Sopenharmony_cistatic const int PIPE_READ = 0; 60800b99b8Sopenharmony_cistatic const int PIPE_WRITE = 1; 61800b99b8Sopenharmony_cistatic const int SOCKET_BUFFER_SIZE = 256; 62800b99b8Sopenharmony_cistatic const char FAULTLOGGER_DAEMON_RESP[] = "RESP:COMPLETE"; 63800b99b8Sopenharmony_cistatic const char FAULTLOGGERD_SOCK_BASE_PATH[] = "/dev/unix/socket/"; 64800b99b8Sopenharmony_cistatic const char SERVER_SOCKET_NAME[] = "faultloggerd.server"; 65800b99b8Sopenharmony_cistatic const char SERVER_CRASH_SOCKET_NAME[] = "faultloggerd.crash.server"; 66800b99b8Sopenharmony_cistatic const char SERVER_SDKDUMP_SOCKET_NAME[] = "faultloggerd.sdkdump.server"; 67800b99b8Sopenharmony_ci 68800b99b8Sopenharmony_cistatic const char PROC_SELF_STATUS_PATH[] = "/proc/self/status"; 69800b99b8Sopenharmony_cistatic const char PROC_SELF_TASK_PATH[] = "/proc/self/task"; 70800b99b8Sopenharmony_cistatic const char PROC_SELF_CMDLINE_PATH[] = "/proc/self/cmdline"; 71800b99b8Sopenharmony_cistatic const char PROC_SELF_COMM_PATH[] = "/proc/self/comm"; 72800b99b8Sopenharmony_cistatic const char PROC_SELF_MAPS_PATH[] = "/proc/self/maps"; 73800b99b8Sopenharmony_cistatic const char PROC_SELF_EXE_PATH[] = "/proc/self/exe"; 74800b99b8Sopenharmony_ci 75800b99b8Sopenharmony_ci#ifndef LIKELY 76800b99b8Sopenharmony_ci#define LIKELY(exp) (__builtin_expect(!!(exp), true)) 77800b99b8Sopenharmony_ci#endif 78800b99b8Sopenharmony_ci#ifndef UNLIKELY 79800b99b8Sopenharmony_ci#define UNLIKELY(exp) (__builtin_expect(!!(exp), false)) 80800b99b8Sopenharmony_ci#endif 81800b99b8Sopenharmony_ci 82800b99b8Sopenharmony_ci#define AT_SYMBOL_DEFAULT __attribute__ ((visibility("default"))) 83800b99b8Sopenharmony_ci#define AT_SYMBOL_HIDDEN __attribute__ ((visibility("hidden"))) 84800b99b8Sopenharmony_ci#define AT_ALWAYS_INLINE __attribute__((always_inline)) 85800b99b8Sopenharmony_ci#define AT_WARN_UNUSED __attribute__((warn_unused_result)) 86800b99b8Sopenharmony_ci#define AT_UNUSED __attribute__((unused)) 87800b99b8Sopenharmony_ci#define MAYBE_UNUSED [[maybe_unused]] 88800b99b8Sopenharmony_ci#define NO_SANITIZE __attribute__((no_sanitize("address"), no_sanitize("hwaddress"))) 89800b99b8Sopenharmony_ci 90800b99b8Sopenharmony_ci#ifndef FALLTHROUGH_INTENDED 91800b99b8Sopenharmony_ci#define FALLTHROUGH_INTENDED [[clang::fallthrough]] // NOLINT 92800b99b8Sopenharmony_ci#endif 93800b99b8Sopenharmony_ci 94800b99b8Sopenharmony_ci#define OHOS_TEMP_FAILURE_RETRY(exp) \ 95800b99b8Sopenharmony_ci ({ \ 96800b99b8Sopenharmony_ci long int _rc; \ 97800b99b8Sopenharmony_ci do { \ 98800b99b8Sopenharmony_ci _rc = (long int)(exp); \ 99800b99b8Sopenharmony_ci } while ((_rc == -1) && (errno == EINTR)); \ 100800b99b8Sopenharmony_ci _rc; \ 101800b99b8Sopenharmony_ci }) 102800b99b8Sopenharmony_ci 103800b99b8Sopenharmony_ci#if defined(__LP64__) 104800b99b8Sopenharmony_ci#define PRIX64_ADDR "#018" PRIx64 105800b99b8Sopenharmony_ci#else 106800b99b8Sopenharmony_ci#define PRIX64_ADDR "#010" PRIx64 107800b99b8Sopenharmony_ci#endif 108800b99b8Sopenharmony_ci 109800b99b8Sopenharmony_ci#endif 110