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