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 <endian.h> 19 #include <inttypes.h> 20 #include <stdbool.h> 21 22 #define SIGDUMP 35 23 #define SIGLOCAL_DUMP 36 24 #define PROCESSDUMP_TIMEOUT 8 25 #define DUMPCATCHER_TIMEOUT 15 26 #define NAME_LEN 128 27 #define PATH_LEN 1024 28 #define MAX_FATAL_MSG_SIZE 1024 29 30 static const int INVALID_FD = -1; 31 32 static const int SOCKET_BUFFER_SIZE = 256; 33 static const char FAULTLOGGERD_SOCK_BASE_PATH[] = "/dev/unix/socket/"; 34 static const char SERVER_SOCKET_NAME[] = "faultloggerd.server"; 35 static const char SERVER_CRASH_SOCKET_NAME[] = "faultloggerd.crash.server"; 36 static const char PROC_SELF_STATUS_PATH[] = "/proc/self/status"; 37 static const char PROC_SELF_TASK_PATH[] = "/proc/self/task"; 38 static const char PROC_SELF_CMDLINE_PATH[] = "/proc/self/cmdline"; 39 static const char PROC_SELF_COMM_PATH[] = "/proc/self/comm"; 40 41 static const int DUMP_CATCHER_NUMBER_ONE = 1; 42 static const int DUMP_CATCHER_NUMBER_TWO = 2; 43 static const int DUMP_CATCHER_NUMBER_THREE = 3; 44 static const int NUMBER_ONE_THOUSAND = 1000; 45 static const int NUMBER_ONE_MILLION = 1000000; 46 47 static const int FAULTSTACK_ITEM_BUFFER_LENGTH = 2048; 48 static const int FAULTSTACK_SP_REVERSE = 3; 49 static const int FAULTSTACK_FIRST_FRAME_SEARCH_LENGTH = 64; 50 51 static const int SYMBOL_BUF_SIZE = 1024; 52 static const int LOG_BUF_LEN = 1024; 53 static const int FILE_WRITE_BUF_LEN = 4096; 54 55 static const char TEST_BUNDLE_NAME[] = "com.example.myapplication"; 56 static const char TRUNCATE_TEST_BUNDLE_NAME[] = "e.myapplication"; 57 58 static const int DUMP_TYPE_NATIVE = -1; 59 static const int DUMP_TYPE_MIX = -2; 60 static const int DUMP_TYPE_KERNEL = -3; 61 62 #define LIKELY(exp) (__builtin_expect(!!(exp), true)) 63 #define UNLIKELY(exp) (__builtin_expect(!!(exp), false)) 64 65 #define AT_SYMBOL_DEFAULT __attribute__ ((visibility("default"))) 66 #define AT_SYMBOL_HIDDEN __attribute__ ((visibility("hidden"))) 67 #define AT_ALWAYS_INLINE __attribute__((always_inline)) 68 #define AT_WARN_UNUSED __attribute__((warn_unused_result)) 69 #define AT_UNUSED __attribute__((unused)) 70 #define MAYBE_UNUSED [[maybe_unused]] 71 72 #define OHOS_TEMP_FAILURE_RETRY(exp) \ 73 ({ \ 74 long int _rc; \ 75 do { \ 76 _rc = (long int)(exp); \ 77 } while ((_rc == -1) && (errno == EINTR)); \ 78 _rc; \ 79 }) 80 81 #define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c" 82 #define BYTE_TO_BINARY(byte) \ 83 ((byte) & 0x80 ? '1' : '0'), \ 84 ((byte) & 0x40 ? '1' : '0'), \ 85 ((byte) & 0x20 ? '1' : '0'), \ 86 ((byte) & 0x10 ? '1' : '0'), \ 87 ((byte) & 0x08 ? '1' : '0'), \ 88 ((byte) & 0x04 ? '1' : '0'), \ 89 ((byte) & 0x02 ? '1' : '0'), \ 90 ((byte) & 0x01 ? '1' : '0') 91 #endif // DFX_DEFINE_H 92