powerpc64: Fix by using the configure value $libc_cv_cc_submachine [BZ #31629]
[glibc.git] / sysdeps / generic / unwind-dw2-fde.h
blobacfb5bbd2fedd338a98f48723d09dd45c31eb088
1 /* Subroutines needed for unwinding stack frames for exception handling. */
2 /* Copyright (C) 1997-2024 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
21 struct fde_vector
23 void *orig_data;
24 size_t count;
25 struct dwarf_fde *array __flexarr;
28 #ifdef _LIBC
29 #include <gccframe.h>
30 #else
31 struct object
33 void *pc_begin;
34 void *tbase;
35 void *dbase;
36 union {
37 struct dwarf_fde *single;
38 struct dwarf_fde **array;
39 struct fde_vector *sort;
40 } u;
42 union {
43 struct {
44 unsigned long sorted : 1;
45 unsigned long from_array : 1;
46 unsigned long mixed_encoding : 1;
47 unsigned long encoding : 8;
48 /* ??? Wish there was an easy way to detect a 64-bit host here;
49 we've got 32 bits left to play with... */
50 unsigned long count : 21;
51 } b;
52 size_t i;
53 } s;
55 #ifdef DWARF2_OBJECT_END_PTR_EXTENSION
56 char *fde_end;
57 #endif
59 struct object *next;
61 #endif
63 /* This is the original definition of struct object. While the struct
64 itself was opaque to users, they did know how large it was, and
65 allocate one statically in crtbegin for each DSO. Keep this around
66 so that we're aware of the static size limitations for the new struct. */
67 struct old_object
69 void *pc_begin;
70 void *pc_end;
71 struct dwarf_fde *fde_begin;
72 struct dwarf_fde **fde_array;
73 size_t count;
74 struct old_object *next;
77 struct dwarf_eh_bases
79 void *tbase;
80 void *dbase;
81 void *func;
85 extern void __register_frame_info_bases (void *, struct object *,
86 void *, void *);
87 extern void __register_frame_info (void *, struct object *);
88 extern void __register_frame (void *);
89 extern void __register_frame_info_table_bases (void *, struct object *,
90 void *, void *);
91 extern void __register_frame_info_table (void *, struct object *);
92 extern void __register_frame_table (void *);
93 extern void *__deregister_frame_info (void *);
94 extern void *__deregister_frame_info_bases (void *);
95 extern void __deregister_frame (void *);
98 typedef int sword __attribute__ ((mode (SI)));
99 typedef unsigned int uword __attribute__ ((mode (SI)));
100 typedef unsigned int uaddr __attribute__ ((mode (pointer)));
101 typedef int saddr __attribute__ ((mode (pointer)));
102 typedef unsigned char ubyte;
104 /* Terminology:
105 CIE - Common Information Element
106 FDE - Frame Descriptor Element
108 There is one per function, and it describes where the function code
109 is located, and what the register lifetimes and stack layout are
110 within the function.
112 The data structures are defined in the DWARF specification, although
113 not in a very readable way (see LITERATURE).
115 Every time an exception is thrown, the code needs to locate the FDE
116 for the current function, and starts to look for exception regions
117 from that FDE. This works in a two-level search:
118 a) in a linear search, find the shared image (i.e. DLL) containing
119 the PC
120 b) using the FDE table for that shared object, locate the FDE using
121 binary search (which requires the sorting). */
123 /* The first few fields of a CIE. The CIE_id field is 0 for a CIE,
124 to distinguish it from a valid FDE. FDEs are aligned to an addressing
125 unit boundary, but the fields within are unaligned. */
126 struct dwarf_cie
128 uword length;
129 sword CIE_id;
130 ubyte version;
131 unsigned char augmentation __flexarr;
132 } __attribute__ ((packed, aligned (__alignof__ (void *))));
134 /* The first few fields of an FDE. */
135 struct dwarf_fde
137 uword length;
138 sword CIE_delta;
139 unsigned char pc_begin __flexarr;
140 } __attribute__ ((packed, aligned (__alignof__ (void *))));
142 typedef struct dwarf_fde fde;
144 /* Locate the CIE for a given FDE. */
146 static inline struct dwarf_cie *
147 get_cie (struct dwarf_fde *f)
149 return (void *)&f->CIE_delta - f->CIE_delta;
152 static inline fde *
153 next_fde (fde *f)
155 return (fde *) ((char *) f + f->length + sizeof (f->length));
158 extern fde * _Unwind_Find_FDE (void *, struct dwarf_eh_bases *);
160 static inline int
161 last_fde (struct object *obj __attribute__ ((__unused__)), fde *f)
163 #ifdef DWARF2_OBJECT_END_PTR_EXTENSION
164 return (char *)f == obj->fde_end || f->length == 0;
165 #else
166 return f->length == 0;
167 #endif