1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. 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 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 #ifndef EBPF_STD_TYPE_H 15 #define EBPF_STD_TYPE_H 16 17 namespace OHOS { 18 namespace EBPF_TOOLS { 19 struct HeaderDataItem { 20 uint32_t headSize = 0; 21 uint32_t version = 0; 22 uint32_t clock = 0; 23 uint32_t cmdLineLen = 0; 24 }__attribute__((packed)); 25 26 struct EventMaps { 27 uint32_t type = 0; 28 uint32_t len = 0; 29 uint64_t start = 0; 30 uint64_t end = 0; 31 uint32_t offset = 0; 32 uint32_t pid = 0; 33 uint32_t fileNameLen = 0; 34 std::string fileName; 35 } __attribute__((packed)); 36 37 struct SymbolInfo { 38 uint32_t type = 0; 39 uint32_t len = 0; 40 uint64_t textVaddr = 0; 41 uint32_t textOffset = 0; 42 uint32_t strTabLen = 0; 43 uint32_t symTabLen = 0; 44 uint32_t fileNameSize = 0; 45 uint32_t symEntlen = 0; 46 char *strTab = nullptr; 47 char *symTab = nullptr; 48 std::string fileName; 49 }__attribute__((packed)); 50 51 struct EventFs { 52 static constexpr uint8_t MAX_TRACER_NAME_LEN = 8; 53 static constexpr uint8_t MAX_TYPE_NAME_LEN = 16; 54 static constexpr uint8_t MAX_COMM_LEN = 16; 55 uint32_t tag = 0; 56 uint32_t len = 0; 57 uint32_t pid = 0; 58 uint32_t tid = 0; 59 char tracerName[MAX_TRACER_NAME_LEN]; 60 uint64_t start = 0; 61 uint64_t end = 0; 62 char typeName[MAX_TYPE_NAME_LEN]; 63 int32_t ret = 0; 64 uint16_t nrUserIPs = 0; 65 uint16_t type = 0; 66 std::vector<uint64_t> args; 67 char comm[MAX_COMM_LEN]; 68 std::vector<uint64_t> userIPs; 69 }__attribute__((packed)); 70 71 struct EventMem { 72 static constexpr uint8_t MAX_TRACER_NAME_LEN = 8; 73 static constexpr uint8_t MAX_TYPE_NAME_LEN = 16; 74 static constexpr uint8_t MAX_COMM_LEN = 16; 75 uint32_t tag = 0; 76 uint32_t len = 0; 77 uint32_t pid = 0; 78 uint32_t tid = 0; 79 char tagName[MAX_TRACER_NAME_LEN]; 80 uint64_t start = 0; 81 uint64_t end = 0; 82 char typeName[MAX_TYPE_NAME_LEN]; 83 uint64_t addr = 0; 84 uint32_t size = 0; 85 uint16_t nips = 0; 86 uint16_t type = 0; 87 char comm[MAX_COMM_LEN]; 88 std::vector<uint64_t> userIPs; 89 }__attribute__((packed)); 90 91 struct EventStr { 92 static constexpr uint8_t MAX_STR_TRACE_NAME_LEN = 8; 93 static constexpr uint8_t MAX_STR_TYPE_NAME_LEN = 16; 94 uint32_t tag = 0; 95 uint32_t len = 0; 96 uint32_t pid = 0; 97 uint32_t tid = 0; 98 uint64_t start = 0; 99 uint32_t srcTracer = 0; 100 uint32_t srcType = 0; 101 uint32_t strLen = 0; 102 uint32_t padding = 0; 103 std::string fileName; 104 }__attribute__((packed)); 105 106 struct EventBIO { 107 static constexpr uint8_t MAX_TYPE_NAME_LEN = 16; 108 static constexpr uint8_t MAX_COMM_LEN = 16; 109 uint32_t tag = 0; 110 uint32_t len = 0; 111 uint32_t pid = 0; 112 uint32_t tid = 0; 113 char comm[MAX_COMM_LEN]; 114 uint64_t start = 0; 115 uint64_t end = 0; 116 uint32_t prio = 0; 117 uint32_t size = 0; 118 uint64_t blkcnt = 0; 119 uint32_t nips = 0; 120 uint32_t type = 0; 121 char typeName[MAX_TYPE_NAME_LEN]; 122 std::vector<uint64_t> userIPs; 123 }__attribute__((packed)); 124 125 struct Record { 126 Record() = default; 127 ~Record() = default; RecordRecord128 Record(std::string name, uint64_t sym, uint64_t str) 129 { 130 fileName = name; 131 symTabAddr = sym; 132 strTabAddr = str; 133 } 134 std::string fileName; 135 uint64_t symTabAddr = 0; 136 uint64_t strTabAddr = 0; 137 }; 138 139 struct Elf32_Sym { 140 uint32_t st_name; 141 uint32_t st_value; 142 uint32_t st_size; 143 unsigned char st_info; 144 unsigned char st_other; 145 uint16_t st_shndx; 146 }__attribute__((packed)); 147 148 struct Elf64_Sym { 149 uint32_t st_name; 150 unsigned char st_info; 151 unsigned char st_other; 152 uint16_t st_shndx; 153 uint64_t st_value; 154 uint64_t st_size; 155 }__attribute__((packed)); 156 157 enum TracerType:int { 158 MAPSTRACE = 0, 159 SYMBOLTRACE, 160 FSTRACE, 161 PFTRACE, 162 BIOTRACE, 163 STRTRACE, 164 DLOPEN_TRACE, 165 KERNEL_SYM = 0x10001, 166 BADTRACE, 167 }; 168 } // EBPF_TOOLS 169 } // OHOS 170 171 #endif // EBPF_STD_TYPE_H