unwind-dw2-fde.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* Subroutines needed for unwinding stack frames for exception handling. */
  2. /* Copyright (C) 1997-2022 Free Software Foundation, Inc.
  3. Contributed by Jason Merrill <jason@cygnus.com>.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #ifndef GCC_UNWIND_DW2_FDE_H
  21. #define GCC_UNWIND_DW2_FDE_H
  22. #ifndef HIDE_EXPORTS
  23. #pragma GCC visibility push(default)
  24. #endif
  25. struct fde_vector
  26. {
  27. const void *orig_data;
  28. size_t count;
  29. const struct dwarf_fde *array[];
  30. };
  31. struct object
  32. {
  33. void *pc_begin;
  34. void *tbase;
  35. void *dbase;
  36. union {
  37. const struct dwarf_fde *single;
  38. struct dwarf_fde **array;
  39. struct fde_vector *sort;
  40. } u;
  41. union {
  42. struct {
  43. unsigned long sorted : 1;
  44. unsigned long from_array : 1;
  45. unsigned long mixed_encoding : 1;
  46. unsigned long encoding : 8;
  47. /* ??? Wish there was an easy way to detect a 64-bit host here;
  48. we've got 32 bits left to play with... */
  49. unsigned long count : 21;
  50. } b;
  51. size_t i;
  52. } s;
  53. #ifdef DWARF2_OBJECT_END_PTR_EXTENSION
  54. char *fde_end;
  55. #endif
  56. struct object *next;
  57. };
  58. /* This is the original definition of struct object. While the struct
  59. itself was opaque to users, they did know how large it was, and
  60. allocate one statically in crtbegin for each DSO. Keep this around
  61. so that we're aware of the static size limitations for the new struct. */
  62. struct old_object
  63. {
  64. void *pc_begin;
  65. void *pc_end;
  66. struct dwarf_fde *fde_begin;
  67. struct dwarf_fde **fde_array;
  68. size_t count;
  69. struct old_object *next;
  70. };
  71. struct dwarf_eh_bases
  72. {
  73. void *tbase;
  74. void *dbase;
  75. void *func;
  76. };
  77. extern void __register_frame_info_bases (const void *, struct object *,
  78. void *, void *);
  79. extern void __register_frame_info (const void *, struct object *);
  80. extern void __register_frame (void *);
  81. extern void __register_frame_info_table_bases (void *, struct object *,
  82. void *, void *);
  83. extern void __register_frame_info_table (void *, struct object *);
  84. extern void __register_frame_table (void *);
  85. extern void *__deregister_frame_info (const void *);
  86. extern void *__deregister_frame_info_bases (const void *);
  87. extern void __deregister_frame (void *);
  88. typedef int sword __attribute__ ((mode (SI)));
  89. typedef unsigned int uword __attribute__ ((mode (SI)));
  90. typedef unsigned int uaddr __attribute__ ((mode (pointer)));
  91. typedef int saddr __attribute__ ((mode (pointer)));
  92. typedef unsigned char ubyte;
  93. /* Terminology:
  94. CIE - Common Information Element
  95. FDE - Frame Descriptor Element
  96. There is one per function, and it describes where the function code
  97. is located, and what the register lifetimes and stack layout are
  98. within the function.
  99. The data structures are defined in the DWARF specification, although
  100. not in a very readable way (see LITERATURE).
  101. Every time an exception is thrown, the code needs to locate the FDE
  102. for the current function, and starts to look for exception regions
  103. from that FDE. This works in a two-level search:
  104. a) in a linear search, find the shared image (i.e. DLL) containing
  105. the PC
  106. b) using the FDE table for that shared object, locate the FDE using
  107. binary search (which requires the sorting). */
  108. /* The first few fields of a CIE. The CIE_id field is 0 for a CIE,
  109. to distinguish it from a valid FDE. FDEs are aligned to an addressing
  110. unit boundary, but the fields within are unaligned. */
  111. struct dwarf_cie
  112. {
  113. uword length;
  114. sword CIE_id;
  115. ubyte version;
  116. unsigned char augmentation[];
  117. } __attribute__ ((packed, aligned (__alignof__ (void *))));
  118. /* The first few fields of an FDE. */
  119. struct dwarf_fde
  120. {
  121. uword length;
  122. sword CIE_delta;
  123. unsigned char pc_begin[];
  124. } __attribute__ ((packed, aligned (__alignof__ (void *))));
  125. typedef struct dwarf_fde fde;
  126. /* Locate the CIE for a given FDE. */
  127. static inline const struct dwarf_cie *
  128. get_cie (const struct dwarf_fde *f)
  129. {
  130. return (const void *)&f->CIE_delta - f->CIE_delta;
  131. }
  132. static inline const fde *
  133. next_fde (const fde *f)
  134. {
  135. return (const fde *) ((const char *) f + f->length + sizeof (f->length));
  136. }
  137. extern const fde * _Unwind_Find_FDE (void *, struct dwarf_eh_bases *);
  138. static inline int
  139. last_fde (struct object *obj __attribute__ ((__unused__)), const fde *f)
  140. {
  141. #ifdef DWARF2_OBJECT_END_PTR_EXTENSION
  142. return f == (const fde *) obj->fde_end || f->length == 0;
  143. #else
  144. return f->length == 0;
  145. #endif
  146. }
  147. #ifndef HIDE_EXPORTS
  148. #pragma GCC visibility pop
  149. #endif
  150. #endif /* unwind-dw2-fde.h */