00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "tconfig.h"
00030 #include <string.h>
00031 #include <stdlib.h>
00032 #include "dwarf2.h"
00033 #include "unwind.h"
00034 #define NO_BASE_OF_ENCODED_VALUE
00035 #define DWARF2_OBJECT_END_PTR_EXTENSION
00036 #include "unwind-pe.h"
00037 #include "unwind-dw2-fde.h"
00038
00039
00040 typedef int __gthread_mutex_t;
00041 #define __gthread_mutex_lock(x) (void)(x)
00042 #define __gthread_mutex_unlock(x) (void)(x)
00043
00044 static const fde * _Unwind_Find_registered_FDE (void *pc,
00045 struct dwarf_eh_bases *bases);
00046
00047 #define _Unwind_Find_FDE _Unwind_Find_registered_FDE
00048 #include "unwind-dw2-fde.c"
00049 #undef _Unwind_Find_FDE
00050
00051
00052 #define KEYMGR_GCC3_LIVE_IMAGE_LIST 301
00053 #define KEYMGR_GCC3_DW2_OBJ_LIST 302
00054
00055 extern void *_keymgr_get_and_lock_processwide_ptr (int);
00056 extern void _keymgr_set_and_unlock_processwide_ptr (int, void *);
00057 extern void _keymgr_unlock_processwide_ptr (int);
00058
00059 struct mach_header;
00060 struct mach_header_64;
00061 extern char *getsectdatafromheader (struct mach_header*, const char*,
00062 const char *, unsigned long *);
00063 extern char *getsectdatafromheader_64 (struct mach_header*, const char*,
00064 const char *, unsigned long *);
00065
00066
00067 struct km_object_info {
00068 struct object *seen_objects;
00069 struct object *unseen_objects;
00070 unsigned spare[2];
00071 };
00072
00073
00074 struct live_images {
00075 unsigned long this_size;
00076 struct mach_header *mh;
00077 unsigned long vm_slide;
00078 void (*destructor)(struct live_images *);
00079 struct live_images *next;
00080 unsigned int examined_p;
00081 void *fde;
00082 void *object_info;
00083 unsigned long info[2];
00084 };
00085
00086
00087 enum {
00088 EXAMINED_IMAGE_MASK = 1,
00089 ALLOCED_IMAGE_MASK = 2,
00090
00091
00092 IMAGE_IS_TEXT_MASK = 4,
00093 DESTRUCTOR_MAY_BE_CALLED_LIVE = 8
00094
00095
00096 };
00097
00098
00099
00100
00101
00102
00103
00104
00105 static void
00106 live_image_destructor (struct live_images *image)
00107 {
00108 if (image->object_info)
00109 {
00110 struct km_object_info *the_obj_info;
00111
00112 the_obj_info =
00113 _keymgr_get_and_lock_processwide_ptr (KEYMGR_GCC3_DW2_OBJ_LIST);
00114 if (the_obj_info)
00115 {
00116 seen_objects = the_obj_info->seen_objects;
00117 unseen_objects = the_obj_info->unseen_objects;
00118
00119
00120 __deregister_frame_info_bases (image->fde);
00121
00122 the_obj_info->seen_objects = seen_objects;
00123 the_obj_info->unseen_objects = unseen_objects;
00124 }
00125 _keymgr_set_and_unlock_processwide_ptr (KEYMGR_GCC3_DW2_OBJ_LIST,
00126 the_obj_info);
00127
00128 free (image->object_info);
00129 image->object_info = NULL;
00130 if (image->examined_p & ALLOCED_IMAGE_MASK)
00131 free (image->fde);
00132 image->fde = NULL;
00133 }
00134 image->examined_p = 0;
00135 image->destructor = NULL;
00136 }
00137
00138
00139
00140
00141
00142
00143 static inline const fde *
00144 examine_objects (void *pc, struct dwarf_eh_bases *bases, int dont_alloc)
00145 {
00146 const fde *result = NULL;
00147 struct live_images *image;
00148
00149 image = _keymgr_get_and_lock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST);
00150
00151 for (; image != NULL; image = image->next)
00152 if ((image->examined_p & EXAMINED_IMAGE_MASK) == 0)
00153 {
00154 char *fde;
00155 unsigned long sz;
00156
00157 #ifdef __ppc64__
00158 fde = getsectdatafromheader_64 ((struct mach_header_64 *) image->mh,
00159 "__DATA", "__eh_frame", &sz);
00160 #else
00161 fde = getsectdatafromheader (image->mh, "__DATA", "__eh_frame", &sz);
00162 #endif
00163 if (fde == NULL)
00164 {
00165 #ifdef __ppc64__
00166 fde = getsectdatafromheader_64 ((struct mach_header_64 *) image->mh,
00167 "__TEXT", "__eh_frame", &sz);
00168 #else
00169 fde = getsectdatafromheader (image->mh, "__TEXT",
00170 "__eh_frame", &sz);
00171 #endif
00172 if (fde != NULL)
00173 image->examined_p |= IMAGE_IS_TEXT_MASK;
00174 }
00175
00176
00177 if (fde != NULL && sz > 0)
00178 {
00179 char *real_fde = (fde + image->vm_slide);
00180 struct object *ob = NULL;
00181 struct object panicob;
00182
00183 if (! dont_alloc)
00184 ob = calloc (1, sizeof (struct object));
00185 dont_alloc |= ob == NULL;
00186 if (dont_alloc)
00187 ob = &panicob;
00188
00189 ob->pc_begin = (void *)-1;
00190 ob->tbase = 0;
00191 ob->dbase = 0;
00192 ob->u.single = (struct dwarf_fde *)real_fde;
00193 ob->s.i = 0;
00194 ob->s.b.encoding = DW_EH_PE_omit;
00195 ob->fde_end = real_fde + sz;
00196
00197 image->fde = real_fde;
00198
00199 result = search_object (ob, pc);
00200
00201 if (! dont_alloc)
00202 {
00203 struct object **p;
00204
00205 image->destructor = live_image_destructor;
00206 image->object_info = ob;
00207
00208 image->examined_p |= (EXAMINED_IMAGE_MASK
00209 | DESTRUCTOR_MAY_BE_CALLED_LIVE);
00210
00211
00212 for (p = &seen_objects; *p ; p = &(*p)->next)
00213 if ((*p)->pc_begin < ob->pc_begin)
00214 break;
00215 ob->next = *p;
00216 *p = ob;
00217 }
00218
00219 if (result)
00220 {
00221 int encoding;
00222
00223 bases->tbase = ob->tbase;
00224 bases->dbase = ob->dbase;
00225
00226 encoding = ob->s.b.encoding;
00227 if (ob->s.b.mixed_encoding)
00228 encoding = get_fde_encoding (result);
00229 read_encoded_value_with_base (encoding,
00230 base_from_object (encoding, ob),
00231 result->pc_begin,
00232 (_Unwind_Ptr *)&bases->func);
00233 break;
00234 }
00235 }
00236 else
00237 image->examined_p |= EXAMINED_IMAGE_MASK;
00238 }
00239
00240 _keymgr_unlock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST);
00241
00242 return result;
00243 }
00244
00245 const fde *
00246 _Unwind_Find_FDE (void *pc, struct dwarf_eh_bases *bases)
00247 {
00248 struct km_object_info *the_obj_info;
00249 const fde *ret = NULL;
00250
00251 the_obj_info =
00252 _keymgr_get_and_lock_processwide_ptr (KEYMGR_GCC3_DW2_OBJ_LIST);
00253 if (! the_obj_info)
00254 the_obj_info = calloc (1, sizeof (*the_obj_info));
00255
00256 if (the_obj_info != NULL)
00257 {
00258 seen_objects = the_obj_info->seen_objects;
00259 unseen_objects = the_obj_info->unseen_objects;
00260
00261 ret = _Unwind_Find_registered_FDE (pc, bases);
00262 }
00263
00264
00265
00266 if (ret == NULL)
00267 ret = examine_objects (pc, bases, the_obj_info == NULL);
00268
00269 if (the_obj_info != NULL)
00270 {
00271 the_obj_info->seen_objects = seen_objects;
00272 the_obj_info->unseen_objects = unseen_objects;
00273 }
00274 _keymgr_set_and_unlock_processwide_ptr (KEYMGR_GCC3_DW2_OBJ_LIST,
00275 the_obj_info);
00276 return ret;
00277 }