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