1 /* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 GCC is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GCC; see the file COPYING. If not, write to
17 the Free Software Foundation, 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 /* As a special exception, if you link this library with other files,
21 some of which are compiled with GCC, to produce an executable,
22 this library does not by itself cause the resulting executable
23 to be covered by the GNU General Public License.
24 This exception does not however invalidate any other reasons why
25 the executable file might be covered by the GNU General Public License. */
27 /* Locate the FDE entry for a given address, using Darwin's keymgr support. */
34 #define NO_BASE_OF_ENCODED_VALUE
35 #define DWARF2_OBJECT_END_PTR_EXTENSION
36 #include "unwind-pe.h"
37 #include "unwind-dw2-fde.h"
38 /* Carefully don't include gthr.h. */
40 typedef int __gthread_mutex_t
;
41 #define __gthread_mutex_lock(x) (void)(x)
42 #define __gthread_mutex_unlock(x) (void)(x)
44 static fde
* _Unwind_Find_registered_FDE (void *pc
,
45 struct dwarf_eh_bases
*bases
);
47 #define _Unwind_Find_FDE _Unwind_Find_registered_FDE
48 #include "unwind-dw2-fde.c"
49 #undef _Unwind_Find_FDE
52 #define KEYMGR_GCC3_LIVE_IMAGE_LIST 301 /* loaded images */
53 #define KEYMGR_GCC3_DW2_OBJ_LIST 302 /* Dwarf2 object list */
55 extern void *_keymgr_get_and_lock_processwide_ptr (int);
56 extern void _keymgr_set_and_unlock_processwide_ptr (int, void *);
57 extern void _keymgr_unlock_processwide_ptr (int);
60 extern char *getsectdatafromheader (struct mach_header
*, const char*,
61 const char *, unsigned long *);
63 /* This is referenced from KEYMGR_GCC3_DW2_OBJ_LIST. */
64 struct km_object_info
{
65 struct object
*seen_objects
;
66 struct object
*unseen_objects
;
70 /* Node of KEYMGR_GCC3_LIVE_IMAGE_LIST. Info about each resident image. */
72 unsigned long this_size
; /* sizeof (live_images) */
73 struct mach_header
*mh
; /* the image info */
74 unsigned long vm_slide
;
75 void (*destructor
)(struct live_images
*); /* destructor for this */
76 struct live_images
*next
;
77 unsigned int examined_p
;
80 unsigned long info
[2]; /* Future use. */
83 /* Bits in the examined_p field of struct live_images. */
85 EXAMINED_IMAGE_MASK
= 1, /* We've seen this one. */
86 ALLOCED_IMAGE_MASK
= 2, /* The FDE entries were allocated by
87 malloc, and must be freed. This isn't
88 used by newer libgcc versions. */
89 IMAGE_IS_TEXT_MASK
= 4 /* This image is in the TEXT segment. */
92 /* Delete any data we allocated on a live_images structure.
93 IMAGE has already been removed from the KEYMGR_GCC3_LIVE_IMAGE_LIST.
94 Called by KeyMgr (which will delete the struct after we return.) */
97 live_image_destructor (struct live_images
*image
)
99 if (image
->object_info
)
101 /* Free any sorted arrays. */
102 __deregister_frame_info_bases (image
->fde
);
104 free (image
->object_info
);
105 image
->object_info
= NULL
;
106 if (image
->examined_p
& ALLOCED_IMAGE_MASK
)
111 /* Run through the list of live images. If we can allocate memory,
112 give each unseen image a new `struct object'. Even if we can't,
113 check whether the PC is inside the FDE of each unseen image.
117 examine_objects (void *pc
, struct dwarf_eh_bases
*bases
, int dont_alloc
)
120 struct live_images
*image
;
122 image
= _keymgr_get_and_lock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST
);
124 for (; image
!= NULL
; image
= image
->next
)
125 if ((image
->examined_p
& EXAMINED_IMAGE_MASK
) == 0)
130 fde
= getsectdatafromheader (image
->mh
, "__DATA", "__eh_frame", &sz
);
133 fde
= getsectdatafromheader (image
->mh
, "__TEXT",
136 image
->examined_p
|= IMAGE_IS_TEXT_MASK
;
139 /* If .eh_frame is empty, don't register at all. */
140 if (fde
!= NULL
&& sz
> 0)
142 char *real_fde
= (fde
+ image
->vm_slide
);
143 struct object
*ob
= NULL
;
144 struct object panicob
;
147 ob
= calloc (1, sizeof (struct object
));
148 dont_alloc
|= ob
== NULL
;
152 ob
->pc_begin
= (void *)-1;
155 ob
->u
.single
= (struct dwarf_fde
*)real_fde
;
157 ob
->s
.b
.encoding
= DW_EH_PE_omit
;
158 ob
->fde_end
= real_fde
+ sz
;
162 ob
->next
= unseen_objects
;
165 image
->destructor
= live_image_destructor
;
166 image
->object_info
= ob
;
168 image
->examined_p
|= EXAMINED_IMAGE_MASK
;
170 image
->fde
= real_fde
;
172 result
= search_object (ob
, pc
);
177 bases
->tbase
= ob
->tbase
;
178 bases
->dbase
= ob
->dbase
;
180 encoding
= ob
->s
.b
.encoding
;
181 if (ob
->s
.b
.mixed_encoding
)
182 encoding
= get_fde_encoding (result
);
183 read_encoded_value_with_base (encoding
,
184 base_from_object (encoding
, ob
),
186 (_Unwind_Ptr
*)&bases
->func
);
191 image
->examined_p
|= EXAMINED_IMAGE_MASK
;
194 _keymgr_unlock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST
);
200 _Unwind_Find_FDE (void *pc
, struct dwarf_eh_bases
*bases
)
202 struct km_object_info
*the_obj_info
;
206 _keymgr_get_and_lock_processwide_ptr (KEYMGR_GCC3_DW2_OBJ_LIST
);
208 the_obj_info
= calloc (1, sizeof (*the_obj_info
));
210 if (the_obj_info
!= NULL
)
212 seen_objects
= the_obj_info
->seen_objects
;
213 unseen_objects
= the_obj_info
->unseen_objects
;
215 ret
= _Unwind_Find_registered_FDE (pc
, bases
);
218 /* OK, didn't find it in the list of FDEs we've seen before,
219 so go through and look at the new ones. */
221 ret
= examine_objects (pc
, bases
, the_obj_info
== NULL
);
223 if (the_obj_info
!= NULL
)
225 the_obj_info
->seen_objects
= seen_objects
;
226 the_obj_info
->unseen_objects
= unseen_objects
;
227 _keymgr_set_and_unlock_processwide_ptr (KEYMGR_GCC3_DW2_OBJ_LIST
,