1*387f9dfdSAndroid Build Coastguard Worker /* 2*387f9dfdSAndroid Build Coastguard Worker * Copyright (c) 2016 GitHub, Inc. 3*387f9dfdSAndroid Build Coastguard Worker * 4*387f9dfdSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*387f9dfdSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*387f9dfdSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*387f9dfdSAndroid Build Coastguard Worker * 8*387f9dfdSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*387f9dfdSAndroid Build Coastguard Worker * 10*387f9dfdSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*387f9dfdSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*387f9dfdSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*387f9dfdSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*387f9dfdSAndroid Build Coastguard Worker * limitations under the License. 15*387f9dfdSAndroid Build Coastguard Worker */ 16*387f9dfdSAndroid Build Coastguard Worker #ifndef LIBBCC_ELF_H 17*387f9dfdSAndroid Build Coastguard Worker #define LIBBCC_ELF_H 18*387f9dfdSAndroid Build Coastguard Worker 19*387f9dfdSAndroid Build Coastguard Worker #ifdef __cplusplus 20*387f9dfdSAndroid Build Coastguard Worker extern "C" { 21*387f9dfdSAndroid Build Coastguard Worker #endif 22*387f9dfdSAndroid Build Coastguard Worker 23*387f9dfdSAndroid Build Coastguard Worker #include <stddef.h> 24*387f9dfdSAndroid Build Coastguard Worker #include <stdint.h> 25*387f9dfdSAndroid Build Coastguard Worker 26*387f9dfdSAndroid Build Coastguard Worker struct bcc_elf_usdt { 27*387f9dfdSAndroid Build Coastguard Worker uint64_t pc; 28*387f9dfdSAndroid Build Coastguard Worker uint64_t base_addr; 29*387f9dfdSAndroid Build Coastguard Worker // Virtual address semaphore is found at 30*387f9dfdSAndroid Build Coastguard Worker uint64_t semaphore; 31*387f9dfdSAndroid Build Coastguard Worker 32*387f9dfdSAndroid Build Coastguard Worker const char *provider; 33*387f9dfdSAndroid Build Coastguard Worker const char *name; 34*387f9dfdSAndroid Build Coastguard Worker const char *arg_fmt; 35*387f9dfdSAndroid Build Coastguard Worker 36*387f9dfdSAndroid Build Coastguard Worker // Offset from start of file where the semaphore is at 37*387f9dfdSAndroid Build Coastguard Worker uint64_t semaphore_offset; 38*387f9dfdSAndroid Build Coastguard Worker }; 39*387f9dfdSAndroid Build Coastguard Worker 40*387f9dfdSAndroid Build Coastguard Worker // Binary module path, bcc_elf_usdt struct, payload 41*387f9dfdSAndroid Build Coastguard Worker typedef void (*bcc_elf_probecb)(const char *, const struct bcc_elf_usdt *, 42*387f9dfdSAndroid Build Coastguard Worker void *); 43*387f9dfdSAndroid Build Coastguard Worker // Symbol name, start address, length, payload 44*387f9dfdSAndroid Build Coastguard Worker // Callback returning a negative value indicates to stop the iteration 45*387f9dfdSAndroid Build Coastguard Worker typedef int (*bcc_elf_symcb)(const char *, uint64_t, uint64_t, void *); 46*387f9dfdSAndroid Build Coastguard Worker // Section idx, str table idx, str length, start address, length, payload 47*387f9dfdSAndroid Build Coastguard Worker typedef int (*bcc_elf_symcb_lazy)(size_t, size_t, size_t, uint64_t, uint64_t, 48*387f9dfdSAndroid Build Coastguard Worker int, void *); 49*387f9dfdSAndroid Build Coastguard Worker // Segment virtual address, memory size, file offset, payload 50*387f9dfdSAndroid Build Coastguard Worker // Callback returning a negative value indicates to stop the iteration 51*387f9dfdSAndroid Build Coastguard Worker typedef int (*bcc_elf_load_sectioncb)(uint64_t, uint64_t, uint64_t, void *); 52*387f9dfdSAndroid Build Coastguard Worker 53*387f9dfdSAndroid Build Coastguard Worker // Iterate over all USDT probes noted in a binary module 54*387f9dfdSAndroid Build Coastguard Worker // Returns -1 on error, and 0 on success 55*387f9dfdSAndroid Build Coastguard Worker int bcc_elf_foreach_usdt(const char *path, bcc_elf_probecb callback, 56*387f9dfdSAndroid Build Coastguard Worker void *payload); 57*387f9dfdSAndroid Build Coastguard Worker // Iterate over all executable load sections of an ELF 58*387f9dfdSAndroid Build Coastguard Worker // Returns -1 on error, 1 if stopped by callback, and 0 on success 59*387f9dfdSAndroid Build Coastguard Worker int bcc_elf_foreach_load_section(const char *path, 60*387f9dfdSAndroid Build Coastguard Worker bcc_elf_load_sectioncb callback, 61*387f9dfdSAndroid Build Coastguard Worker void *payload); 62*387f9dfdSAndroid Build Coastguard Worker // Iterate over symbol table of a binary module 63*387f9dfdSAndroid Build Coastguard Worker // Parameter "option" points to a bcc_symbol_option struct to indicate whether 64*387f9dfdSAndroid Build Coastguard Worker // and how to use debuginfo file, and what types of symbols to load. 65*387f9dfdSAndroid Build Coastguard Worker // Returns -1 on error, and 0 on success or stopped by callback 66*387f9dfdSAndroid Build Coastguard Worker int bcc_elf_foreach_sym(const char *path, bcc_elf_symcb callback, void *option, 67*387f9dfdSAndroid Build Coastguard Worker void *payload); 68*387f9dfdSAndroid Build Coastguard Worker // Similar to bcc_elf_foreach_sym, but pass reference to symbolized string along 69*387f9dfdSAndroid Build Coastguard Worker // with symbolized string length 70*387f9dfdSAndroid Build Coastguard Worker int bcc_elf_foreach_sym_lazy(const char *path, bcc_elf_symcb_lazy callback, 71*387f9dfdSAndroid Build Coastguard Worker void *option, void *payload); 72*387f9dfdSAndroid Build Coastguard Worker // Iterate over all symbols from current system's vDSO 73*387f9dfdSAndroid Build Coastguard Worker // Returns -1 on error, and 0 on success or stopped by callback 74*387f9dfdSAndroid Build Coastguard Worker int bcc_elf_foreach_vdso_sym(bcc_elf_symcb callback, void *payload); 75*387f9dfdSAndroid Build Coastguard Worker 76*387f9dfdSAndroid Build Coastguard Worker int bcc_elf_get_text_scn_info(const char *path, uint64_t *addr, 77*387f9dfdSAndroid Build Coastguard Worker uint64_t *offset); 78*387f9dfdSAndroid Build Coastguard Worker 79*387f9dfdSAndroid Build Coastguard Worker int bcc_elf_get_type(const char *path); 80*387f9dfdSAndroid Build Coastguard Worker int bcc_elf_is_shared_obj(const char *path); 81*387f9dfdSAndroid Build Coastguard Worker int bcc_elf_is_exe(const char *path); 82*387f9dfdSAndroid Build Coastguard Worker int bcc_elf_is_vdso(const char *name); 83*387f9dfdSAndroid Build Coastguard Worker int bcc_free_memory(); 84*387f9dfdSAndroid Build Coastguard Worker int bcc_elf_get_buildid(const char *path, char *buildid); 85*387f9dfdSAndroid Build Coastguard Worker int bcc_elf_symbol_str(const char *path, size_t section_idx, 86*387f9dfdSAndroid Build Coastguard Worker size_t str_table_idx, char *out, size_t len, 87*387f9dfdSAndroid Build Coastguard Worker int debugfile); 88*387f9dfdSAndroid Build Coastguard Worker 89*387f9dfdSAndroid Build Coastguard Worker #ifdef __cplusplus 90*387f9dfdSAndroid Build Coastguard Worker } 91*387f9dfdSAndroid Build Coastguard Worker #endif 92*387f9dfdSAndroid Build Coastguard Worker #endif 93