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