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