17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5a576ab5bSrab * Common Development and Distribution License (the "License"). 6a576ab5bSrab * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22a576ab5bSrab * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _MDB_GELF_H 277c478bd9Sstevel@tonic-gate #define _MDB_GELF_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <mdb/mdb_nv.h> 327c478bd9Sstevel@tonic-gate #include <mdb/mdb_io.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include <sys/types.h> 357c478bd9Sstevel@tonic-gate #include <gelf.h> 367c478bd9Sstevel@tonic-gate #include <sys/machelf.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 397c478bd9Sstevel@tonic-gate extern "C" { 407c478bd9Sstevel@tonic-gate #endif 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #ifdef _MDB 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #define GST_FUZZY 0 /* lookup_by_addr matches closest sym */ 457c478bd9Sstevel@tonic-gate #define GST_EXACT 1 /* lookup_by_addr must be exact */ 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #define GF_FILE 0 /* Open as ELF file image */ 487c478bd9Sstevel@tonic-gate #define GF_PROGRAM 1 /* Open as ELF program image */ 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate typedef struct mdb_gelf_sect { 517c478bd9Sstevel@tonic-gate GElf_Shdr gs_shdr; /* ELF section header */ 527c478bd9Sstevel@tonic-gate const char *gs_name; /* Section name */ 537c478bd9Sstevel@tonic-gate void *gs_data; /* Section data */ 547c478bd9Sstevel@tonic-gate } mdb_gelf_sect_t; 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate typedef struct mdb_gelf_file { 577c478bd9Sstevel@tonic-gate GElf_Ehdr gf_ehdr; /* ELF file header */ 587c478bd9Sstevel@tonic-gate GElf_Phdr *gf_phdrs; /* Array of program headers */ 597c478bd9Sstevel@tonic-gate size_t gf_npload; /* Number of sorted PT_LOAD phdrs */ 607c478bd9Sstevel@tonic-gate GElf_Phdr *gf_dynp; /* Pointer to PT_DYNAMIC phdr */ 617c478bd9Sstevel@tonic-gate GElf_Dyn *gf_dyns; /* Array of dynamic entries */ 627c478bd9Sstevel@tonic-gate size_t gf_ndyns; /* Number of dynamic entries */ 6330da1432Sahl size_t gf_shnum; /* Number of section headers */ 6430da1432Sahl size_t gf_shstrndx; /* Index of section string table */ 6530da1432Sahl size_t gf_phnum; /* Number of program headers */ 667c478bd9Sstevel@tonic-gate mdb_gelf_sect_t *gf_sects; /* Array of section structs */ 677c478bd9Sstevel@tonic-gate mdb_io_t *gf_io; /* I/o backend for ELF file */ 687c478bd9Sstevel@tonic-gate int gf_mode; /* Mode flag (see above) */ 697c478bd9Sstevel@tonic-gate } mdb_gelf_file_t; 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate typedef struct mdb_gelf_symtab { 727c478bd9Sstevel@tonic-gate mdb_nv_t gst_nv; /* Name/value hash for name lookups */ 737c478bd9Sstevel@tonic-gate void *gst_asmap; /* Sorted array of symbol pointers */ 747c478bd9Sstevel@tonic-gate size_t gst_aslen; /* Number of entries in gst_asmap */ 757c478bd9Sstevel@tonic-gate size_t gst_asrsv; /* Actual reserved size of gst_asmap */ 767c478bd9Sstevel@tonic-gate const GElf_Ehdr *gst_ehdr; /* Associated ELF file ehdr */ 777c478bd9Sstevel@tonic-gate mdb_gelf_file_t *gst_file; /* Associated ELF file */ 787c478bd9Sstevel@tonic-gate mdb_gelf_sect_t *gst_dsect; /* Associated ELF data section */ 797c478bd9Sstevel@tonic-gate mdb_gelf_sect_t *gst_ssect; /* Associated ELF string section */ 807c478bd9Sstevel@tonic-gate uint_t gst_id; /* Next symbol ID to use if mutable */ 817c478bd9Sstevel@tonic-gate uint_t gst_tabid; /* ID for symbol table */ 827c478bd9Sstevel@tonic-gate } mdb_gelf_symtab_t; 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate typedef struct mdb_gelf_dsym { 857c478bd9Sstevel@tonic-gate union { 867c478bd9Sstevel@tonic-gate Elf32_Sym ds_s32; /* 32-bit native symbol data */ 877c478bd9Sstevel@tonic-gate Elf64_Sym ds_s64; /* 64-bit native symbol data */ 887c478bd9Sstevel@tonic-gate } ds_u; 897c478bd9Sstevel@tonic-gate GElf_Sym ds_sym; /* Generic ELF symbol data */ 907c478bd9Sstevel@tonic-gate mdb_var_t *ds_var; /* Backpointer to nv element */ 917c478bd9Sstevel@tonic-gate uint_t ds_id; /* Symbol id number */ 927c478bd9Sstevel@tonic-gate } mdb_gelf_dsym_t; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate extern int mdb_gelf_check(mdb_io_t *, Elf32_Ehdr *, GElf_Half); 957c478bd9Sstevel@tonic-gate extern mdb_gelf_file_t *mdb_gelf_create(mdb_io_t *, GElf_Half, int); 967c478bd9Sstevel@tonic-gate extern void mdb_gelf_destroy(mdb_gelf_file_t *); 97*22872efbSedp extern void mdb_gelf_dyns_set(mdb_gelf_file_t *, void *, size_t); 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate extern void mdb_gelf_ehdr_to_gehdr(Ehdr *, GElf_Ehdr *); 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate typedef enum { GIO_READ, GIO_WRITE } mdb_gelf_rw_t; 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate extern ssize_t mdb_gelf_rw(mdb_gelf_file_t *, void *, size_t, uintptr_t, 1047c478bd9Sstevel@tonic-gate ssize_t (*)(mdb_io_t *, void *, size_t), mdb_gelf_rw_t); 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate extern mdb_gelf_symtab_t *mdb_gelf_symtab_create_file(mdb_gelf_file_t *, 1077c478bd9Sstevel@tonic-gate GElf_Word, uint_t); 1087c478bd9Sstevel@tonic-gate extern mdb_gelf_symtab_t *mdb_gelf_symtab_create_file_by_name(mdb_gelf_file_t *, 1097c478bd9Sstevel@tonic-gate const char *, const char *, uint_t); 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate extern mdb_gelf_symtab_t *mdb_gelf_symtab_create_raw(const GElf_Ehdr *, 1127c478bd9Sstevel@tonic-gate const void *, void *, const void *, void *, uint_t); 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate extern mdb_gelf_symtab_t *mdb_gelf_symtab_create_dynamic(mdb_gelf_file_t *, 1157c478bd9Sstevel@tonic-gate uint_t); 1167c478bd9Sstevel@tonic-gate extern mdb_gelf_symtab_t *mdb_gelf_symtab_create_mutable(void); 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate extern void mdb_gelf_symtab_destroy(mdb_gelf_symtab_t *); 1197c478bd9Sstevel@tonic-gate extern size_t mdb_gelf_symtab_size(mdb_gelf_symtab_t *); 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate extern const char *mdb_gelf_sym_name(mdb_gelf_symtab_t *, const GElf_Sym *); 1227c478bd9Sstevel@tonic-gate extern int mdb_gelf_sym_closer(const GElf_Sym *, const GElf_Sym *, uintptr_t); 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate extern int mdb_gelf_symtab_lookup_by_addr(mdb_gelf_symtab_t *, 1257c478bd9Sstevel@tonic-gate uintptr_t, uint_t, char *, size_t, GElf_Sym *, uint_t *); 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate extern int mdb_gelf_symtab_lookup_by_name(mdb_gelf_symtab_t *, 1287c478bd9Sstevel@tonic-gate const char *, GElf_Sym *, uint_t *); 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate extern int mdb_gelf_symtab_lookup_by_file(mdb_gelf_symtab_t *, 1317c478bd9Sstevel@tonic-gate const char *, const char *, GElf_Sym *, uint_t *); 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate extern void mdb_gelf_symtab_iter(mdb_gelf_symtab_t *, int (*)(void *, 1347c478bd9Sstevel@tonic-gate const GElf_Sym *, const char *, uint_t), void *); 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate extern void mdb_gelf_symtab_insert(mdb_gelf_symtab_t *, 1377c478bd9Sstevel@tonic-gate const char *, const GElf_Sym *); 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate extern void mdb_gelf_symtab_delete(mdb_gelf_symtab_t *, 1407c478bd9Sstevel@tonic-gate const char *, GElf_Sym *); 1417c478bd9Sstevel@tonic-gate 142a576ab5bSrab extern mdb_gelf_sect_t *mdb_gelf_sect_by_name(mdb_gelf_file_t *, 143a576ab5bSrab const char *); 144a576ab5bSrab 145a576ab5bSrab extern void *mdb_gelf_sect_load(mdb_gelf_file_t *, mdb_gelf_sect_t *); 146a576ab5bSrab 1477c478bd9Sstevel@tonic-gate #endif /* _MDB */ 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1507c478bd9Sstevel@tonic-gate } 1517c478bd9Sstevel@tonic-gate #endif 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate #endif /* _MDB_GELF_H */ 154