_UCD_internal.h 3.1 KB

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