1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _MDB_GELF_H 28 #define _MDB_GELF_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #include <mdb/mdb_nv.h> 33 #include <mdb/mdb_io.h> 34 35 #include <sys/types.h> 36 #include <gelf.h> 37 #include <sys/machelf.h> 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 #ifdef _MDB 44 45 #define GST_FUZZY 0 /* lookup_by_addr matches closest sym */ 46 #define GST_EXACT 1 /* lookup_by_addr must be exact */ 47 48 #define GF_FILE 0 /* Open as ELF file image */ 49 #define GF_PROGRAM 1 /* Open as ELF program image */ 50 51 typedef struct mdb_gelf_sect { 52 GElf_Shdr gs_shdr; /* ELF section header */ 53 const char *gs_name; /* Section name */ 54 void *gs_data; /* Section data */ 55 } mdb_gelf_sect_t; 56 57 typedef struct mdb_gelf_file { 58 GElf_Ehdr gf_ehdr; /* ELF file header */ 59 GElf_Phdr *gf_phdrs; /* Array of program headers */ 60 size_t gf_npload; /* Number of sorted PT_LOAD phdrs */ 61 GElf_Phdr *gf_dynp; /* Pointer to PT_DYNAMIC phdr */ 62 GElf_Dyn *gf_dyns; /* Array of dynamic entries */ 63 size_t gf_ndyns; /* Number of dynamic entries */ 64 mdb_gelf_sect_t *gf_sects; /* Array of section structs */ 65 mdb_io_t *gf_io; /* I/o backend for ELF file */ 66 int gf_mode; /* Mode flag (see above) */ 67 } mdb_gelf_file_t; 68 69 typedef struct mdb_gelf_symtab { 70 mdb_nv_t gst_nv; /* Name/value hash for name lookups */ 71 void *gst_asmap; /* Sorted array of symbol pointers */ 72 size_t gst_aslen; /* Number of entries in gst_asmap */ 73 size_t gst_asrsv; /* Actual reserved size of gst_asmap */ 74 const GElf_Ehdr *gst_ehdr; /* Associated ELF file ehdr */ 75 mdb_gelf_file_t *gst_file; /* Associated ELF file */ 76 mdb_gelf_sect_t *gst_dsect; /* Associated ELF data section */ 77 mdb_gelf_sect_t *gst_ssect; /* Associated ELF string section */ 78 uint_t gst_id; /* Next symbol ID to use if mutable */ 79 uint_t gst_tabid; /* ID for symbol table */ 80 } mdb_gelf_symtab_t; 81 82 typedef struct mdb_gelf_dsym { 83 union { 84 Elf32_Sym ds_s32; /* 32-bit native symbol data */ 85 Elf64_Sym ds_s64; /* 64-bit native symbol data */ 86 } ds_u; 87 GElf_Sym ds_sym; /* Generic ELF symbol data */ 88 mdb_var_t *ds_var; /* Backpointer to nv element */ 89 uint_t ds_id; /* Symbol id number */ 90 } mdb_gelf_dsym_t; 91 92 extern int mdb_gelf_check(mdb_io_t *, Elf32_Ehdr *, GElf_Half); 93 extern mdb_gelf_file_t *mdb_gelf_create(mdb_io_t *, GElf_Half, int); 94 extern void mdb_gelf_destroy(mdb_gelf_file_t *); 95 96 extern void mdb_gelf_ehdr_to_gehdr(Ehdr *, GElf_Ehdr *); 97 98 typedef enum { GIO_READ, GIO_WRITE } mdb_gelf_rw_t; 99 100 extern ssize_t mdb_gelf_rw(mdb_gelf_file_t *, void *, size_t, uintptr_t, 101 ssize_t (*)(mdb_io_t *, void *, size_t), mdb_gelf_rw_t); 102 103 extern mdb_gelf_symtab_t *mdb_gelf_symtab_create_file(mdb_gelf_file_t *, 104 GElf_Word, uint_t); 105 extern mdb_gelf_symtab_t *mdb_gelf_symtab_create_file_by_name(mdb_gelf_file_t *, 106 const char *, const char *, uint_t); 107 108 extern mdb_gelf_symtab_t *mdb_gelf_symtab_create_raw(const GElf_Ehdr *, 109 const void *, void *, const void *, void *, uint_t); 110 111 extern mdb_gelf_symtab_t *mdb_gelf_symtab_create_dynamic(mdb_gelf_file_t *, 112 uint_t); 113 extern mdb_gelf_symtab_t *mdb_gelf_symtab_create_mutable(void); 114 115 extern void mdb_gelf_symtab_destroy(mdb_gelf_symtab_t *); 116 extern size_t mdb_gelf_symtab_size(mdb_gelf_symtab_t *); 117 118 extern const char *mdb_gelf_sym_name(mdb_gelf_symtab_t *, const GElf_Sym *); 119 extern int mdb_gelf_sym_closer(const GElf_Sym *, const GElf_Sym *, uintptr_t); 120 121 extern int mdb_gelf_symtab_lookup_by_addr(mdb_gelf_symtab_t *, 122 uintptr_t, uint_t, char *, size_t, GElf_Sym *, uint_t *); 123 124 extern int mdb_gelf_symtab_lookup_by_name(mdb_gelf_symtab_t *, 125 const char *, GElf_Sym *, uint_t *); 126 127 extern int mdb_gelf_symtab_lookup_by_file(mdb_gelf_symtab_t *, 128 const char *, const char *, GElf_Sym *, uint_t *); 129 130 extern void mdb_gelf_symtab_iter(mdb_gelf_symtab_t *, int (*)(void *, 131 const GElf_Sym *, const char *, uint_t), void *); 132 133 extern void mdb_gelf_symtab_insert(mdb_gelf_symtab_t *, 134 const char *, const GElf_Sym *); 135 136 extern void mdb_gelf_symtab_delete(mdb_gelf_symtab_t *, 137 const char *, GElf_Sym *); 138 139 #endif /* _MDB */ 140 141 #ifdef __cplusplus 142 } 143 #endif 144 145 #endif /* _MDB_GELF_H */ 146