unwind-dw2-fde.h revision 96489
1/* Subroutines needed for unwinding stack frames for exception handling. */ 2/* Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 3 Free Software Foundation, Inc. 4 Contributed by Jason Merrill <jason@cygnus.com>. 5 6This file is part of GCC. 7 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 10Software Foundation; either version 2, or (at your option) any later 11version. 12 13In addition to the permissions in the GNU General Public License, the 14Free Software Foundation gives you unlimited permission to link the 15compiled version of this file into combinations with other programs, 16and to distribute those combinations without any restriction coming 17from the use of this file. (The General Public License restrictions 18do apply in other respects; for example, they cover modification of 19the file, and distribution when not linked into a combine 20executable.) 21 22GCC is distributed in the hope that it will be useful, but WITHOUT ANY 23WARRANTY; without even the implied warranty of MERCHANTABILITY or 24FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25for more details. 26 27You should have received a copy of the GNU General Public License 28along with GCC; see the file COPYING. If not, write to the Free 29Software Foundation, 59 Temple Place - Suite 330, Boston, MA 3002111-1307, USA. */ 31 32 33struct fde_vector 34{ 35 void *orig_data; 36 size_t count; 37 struct dwarf_fde *array[]; 38}; 39 40struct object 41{ 42 void *pc_begin; 43 void *tbase; 44 void *dbase; 45 union { 46 struct dwarf_fde *single; 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; 58 we've got 32 bits left to play with... */ 59 unsigned long count : 21; 60 } b; 61 size_t i; 62 } s; 63 64 struct object *next; 65}; 66 67/* This is the original definition of struct object. While the struct 68 itself was opaque to users, they did know how large it was, and 69 allocate one statically in crtbegin for each DSO. Keep this around 70 so that we're aware of the static size limitations for the new struct. */ 71struct old_object 72{ 73 void *pc_begin; 74 void *pc_end; 75 struct dwarf_fde *fde_begin; 76 struct dwarf_fde **fde_array; 77 size_t count; 78 struct old_object *next; 79}; 80 81struct dwarf_eh_bases 82{ 83 void *tbase; 84 void *dbase; 85 void *func; 86}; 87 88 89extern void __register_frame_info_bases (void *, struct object *, 90 void *, void *); 91extern void __register_frame_info (void *, struct object *); 92extern void __register_frame (void *); 93extern void __register_frame_info_table_bases (void *, struct object *, 94 void *, void *); 95extern void __register_frame_info_table (void *, struct object *); 96extern void __register_frame_table (void *); 97extern void *__deregister_frame_info (void *); 98extern void *__deregister_frame_info_bases (void *); 99extern void __deregister_frame (void *); 100 101 102typedef int sword __attribute__ ((mode (SI))); 103typedef unsigned int uword __attribute__ ((mode (SI))); 104typedef unsigned int uaddr __attribute__ ((mode (pointer))); 105typedef int saddr __attribute__ ((mode (pointer))); 106typedef unsigned char ubyte; 107 108/* Terminology: 109 CIE - Common Information Element 110 FDE - Frame Descriptor Element 111 112 There is one per function, and it describes where the function code 113 is located, and what the register lifetimes and stack layout are 114 within the function. 115 116 The data structures are defined in the DWARF specification, although 117 not in a very readable way (see LITERATURE). 118 119 Every time an exception is thrown, the code needs to locate the FDE 120 for the current function, and starts to look for exception regions 121 from that FDE. This works in a two-level search: 122 a) in a linear search, find the shared image (i.e. DLL) containing 123 the PC 124 b) using the FDE table for that shared object, locate the FDE using 125 binary search (which requires the sorting). */ 126 127/* The first few fields of a CIE. The CIE_id field is 0 for a CIE, 128 to distinguish it from a valid FDE. FDEs are aligned to an addressing 129 unit boundary, but the fields within are unaligned. */ 130struct dwarf_cie 131{ 132 uword length; 133 sword CIE_id; 134 ubyte version; 135 unsigned char augmentation[]; 136} __attribute__ ((packed, aligned (__alignof__ (void *)))); 137 138/* The first few fields of an FDE. */ 139struct dwarf_fde 140{ 141 uword length; 142 sword CIE_delta; 143 unsigned char pc_begin[]; 144} __attribute__ ((packed, aligned (__alignof__ (void *)))); 145 146typedef struct dwarf_fde fde; 147 148/* Locate the CIE for a given FDE. */ 149 150static inline struct dwarf_cie * 151get_cie (struct dwarf_fde *f) 152{ 153 return (void *)&f->CIE_delta - f->CIE_delta; 154} 155 156static inline fde * 157next_fde (fde *f) 158{ 159 return (fde *) ((char *) f + f->length + sizeof (f->length)); 160} 161 162extern fde * _Unwind_Find_FDE (void *, struct dwarf_eh_bases *); 163