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 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 extern char *getsectdatafromheader (struct mach_header*, const char*,
00061 const char *, unsigned long *);
00062
00063
00064 struct km_object_info {
00065 struct object *seen_objects;
00066 struct object *unseen_objects;
00067 unsigned spare[2];
00068 };
00069
00070
00071 struct live_images {
00072 unsigned long this_size;
00073 struct mach_header *mh;
00074 unsigned long vm_slide;
00075 void (*destructor)(struct live_images *);
00076 struct live_images *next;
00077 unsigned int examined_p;
00078 void *fde;
00079 void *object_info;
00080 unsigned long info[2];
00081 };
00082
00083
00084 enum {
00085 EXAMINED_IMAGE_MASK = 1,
00086 ALLOCED_IMAGE_MASK = 2,
00087
00088
00089 IMAGE_IS_TEXT_MASK = 4,
00090 DESTRUCTOR_MAY_BE_CALLED_LIVE = 8
00091
00092
00093 };
00094
00095
00096
00097
00098
00099
00100
00101
00102 static void
00103 live_image_destructor (struct live_images *image)
00104 {
00105 if (image->object_info)
00106 {
00107
00108 __deregister_frame_info_bases (image->fde);
00109
00110 free (image->object_info);
00111 image->object_info = NULL;
00112 if (image->examined_p & ALLOCED_IMAGE_MASK)
00113 free (image->fde);
00114 image->fde = NULL;
00115 }
00116 image->examined_p = 0;
00117 image->destructor = NULL;
00118 }
00119
00120
00121
00122
00123
00124
00125 static inline fde *
00126 examine_objects (void *pc, struct dwarf_eh_bases *bases, int dont_alloc)
00127 {
00128 fde *result = NULL;
00129 struct live_images *image;
00130
00131 image = _keymgr_get_and_lock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST);
00132
00133 for (; image != NULL; image = image->next)
00134 if ((image->examined_p & EXAMINED_IMAGE_MASK) == 0)
00135 {
00136 char *fde;
00137 unsigned long sz;
00138
00139 fde = getsectdatafromheader (image->mh, "__DATA", "__eh_frame", &sz);
00140 if (fde == NULL)
00141 {
00142 fde = getsectdatafromheader (image->mh, "__TEXT",
00143 "__eh_frame", &sz);
00144 if (fde != NULL)
00145 image->examined_p |= IMAGE_IS_TEXT_MASK;
00146 }
00147
00148
00149 if (fde != NULL && sz > 0)
00150 {
00151 char *real_fde = (fde + image->vm_slide);
00152 struct object *ob = NULL;
00153 struct object panicob;
00154
00155 if (! dont_alloc)
00156 ob = calloc (1, sizeof (struct object));
00157 dont_alloc |= ob == NULL;
00158 if (dont_alloc)
00159 ob = &panicob;
00160
00161 ob->pc_begin = (void *)-1;
00162 ob->tbase = 0;
00163 ob->dbase = 0;
00164 ob->u.single = (struct dwarf_fde *)real_fde;
00165 ob->s.i = 0;
00166 ob->s.b.encoding = DW_EH_PE_omit;
00167 ob->fde_end = real_fde + sz;
00168
00169 if (! dont_alloc)
00170 {
00171 ob->next = unseen_objects;
00172 unseen_objects = ob;
00173
00174 image->destructor = live_image_destructor;
00175 image->object_info = ob;
00176
00177 image->examined_p |= (EXAMINED_IMAGE_MASK
00178 | DESTRUCTOR_MAY_BE_CALLED_LIVE);
00179 }
00180 image->fde = real_fde;
00181
00182 result = search_object (ob, pc);
00183 if (result)
00184 {
00185 int encoding;
00186
00187 bases->tbase = ob->tbase;
00188 bases->dbase = ob->dbase;
00189
00190 encoding = ob->s.b.encoding;
00191 if (ob->s.b.mixed_encoding)
00192 encoding = get_fde_encoding (result);
00193 read_encoded_value_with_base (encoding,
00194 base_from_object (encoding, ob),
00195 result->pc_begin,
00196 (_Unwind_Ptr *)&bases->func);
00197 break;
00198 }
00199 }
00200 else
00201 image->examined_p |= EXAMINED_IMAGE_MASK;
00202 }
00203
00204 _keymgr_unlock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST);
00205
00206 return result;
00207 }
00208
00209 fde *
00210 _Unwind_Find_FDE (void *pc, struct dwarf_eh_bases *bases)
00211 {
00212 struct km_object_info *the_obj_info;
00213 fde *ret = NULL;
00214
00215 the_obj_info =
00216 _keymgr_get_and_lock_processwide_ptr (KEYMGR_GCC3_DW2_OBJ_LIST);
00217 if (! the_obj_info)
00218 the_obj_info = calloc (1, sizeof (*the_obj_info));
00219
00220 if (the_obj_info != NULL)
00221 {
00222 seen_objects = the_obj_info->seen_objects;
00223 unseen_objects = the_obj_info->unseen_objects;
00224
00225 ret = _Unwind_Find_registered_FDE (pc, bases);
00226 }
00227
00228
00229
00230 if (ret == NULL)
00231 ret = examine_objects (pc, bases, the_obj_info == NULL);
00232
00233 if (the_obj_info != NULL)
00234 {
00235 the_obj_info->seen_objects = seen_objects;
00236 the_obj_info->unseen_objects = unseen_objects;
00237 _keymgr_set_and_unlock_processwide_ptr (KEYMGR_GCC3_DW2_OBJ_LIST,
00238 the_obj_info);
00239 }
00240 return ret;
00241 }