1 /* libunwind - a platform-independent unwind library 2 3 This file is part of libunwind. 4 5 Permission is hereby granted, free of charge, to any person obtaining 6 a copy of this software and associated documentation files (the 7 "Software"), to deal in the Software without restriction, including 8 without limitation the rights to use, copy, modify, merge, publish, 9 distribute, sublicense, and/or sell copies of the Software, and to 10 permit persons to whom the Software is furnished to do so, subject to 11 the following conditions: 12 13 The above copyright notice and this permission notice shall be 14 included in all copies or substantial portions of the Software. 15 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 23 24 #ifndef _UCD_internal_h 25 #define _UCD_internal_h 26 27 #ifdef HAVE_CONFIG_H 28 #include <config.h> 29 #endif 30 31 #ifdef HAVE_SYS_TYPES_H 32 #include <sys/types.h> 33 #endif 34 #ifdef HAVE_SYS_PROCFS_H 35 #include <sys/procfs.h> /* struct elf_prstatus */ 36 #endif 37 #include <errno.h> 38 #include <string.h> 39 #include <limits.h> 40 #include <stdio.h> 41 #include <stdlib.h> 42 43 #include <libunwind-coredump.h> 44 45 #include "libunwind_i.h" 46 47 48 #if SIZEOF_OFF_T == 4 49 typedef uint32_t uoff_t; 50 #elif SIZEOF_OFF_T == 8 51 typedef uint64_t uoff_t; 52 #else 53 # error Unknown size of off_t! 54 #endif 55 56 57 /* Similar to ELF phdrs. p_paddr element is absent, 58 * since it's always 0 in coredumps. 59 */ 60 struct coredump_phdr 61 { 62 uint32_t p_type; 63 uint32_t p_flags; 64 uoff_t p_offset; 65 uoff_t p_vaddr; 66 uoff_t p_filesz; 67 uoff_t p_memsz; 68 uoff_t p_align; 69 /* Data for backing file. If backing_fd < 0, there is no file */ 70 uoff_t backing_filesize; 71 char *backing_filename; /* for error meesages only */ 72 int backing_fd; 73 }; 74 75 typedef struct coredump_phdr coredump_phdr_t; 76 77 #if defined(HAVE_STRUCT_ELF_PRSTATUS) 78 #define PRSTATUS_STRUCT elf_prstatus 79 #elif defined(HAVE_STRUCT_PRSTATUS) 80 #define PRSTATUS_STRUCT prstatus 81 #else 82 #define PRSTATUS_STRUCT non_existent 83 #endif 84 85 struct UCD_info 86 { 87 int big_endian; /* bool */ 88 int coredump_fd; 89 char *coredump_filename; /* for error meesages only */ 90 coredump_phdr_t *phdrs; /* array, allocated */ 91 unsigned phdrs_count; 92 void *note_phdr; /* allocated or NULL */ 93 struct PRSTATUS_STRUCT *prstatus; /* points inside note_phdr */ 94 int n_threads; 95 struct PRSTATUS_STRUCT *threads; 96 struct elf_dyn_info edi; 97 }; 98 99 100 typedef int (*note_visitor_t)(uint32_t, uint32_t, uint32_t, char *, uint8_t *, void *); 101 102 103 coredump_phdr_t * _UCD_get_elf_image(struct UCD_info *ui, unw_word_t ip); 104 105 int _UCD_elf_read_segment(struct UCD_info *ui, coredump_phdr_t *phdr, uint8_t **segment, size_t *segment_size); 106 int _UCD_elf_visit_notes(uint8_t *segment, size_t segment_size, note_visitor_t visit, void *arg); 107 int _UCD_get_threadinfo(struct UCD_info *ui, coredump_phdr_t *phdrs, unsigned phdr_size); 108 int _UCD_get_mapinfo(struct UCD_info *ui, coredump_phdr_t *phdrs, unsigned phdr_size); 109 110 111 #endif 112