#include "tconfig.h"
#include "tsystem.h"
#ifdef __ppc__
struct mach_header;
extern char *getsectdatafromheader (struct mach_header *, const char *,
const char *, unsigned long *);
extern void _dyld_register_func_for_add_image
(void (*) (struct mach_header *, unsigned long));
extern void _dyld_register_func_for_remove_image
(void (*) (struct mach_header *, unsigned long));
extern void __darwin_gcc3_preregister_frame_info (void);
extern void _init_keymgr (void);
extern void *_keymgr_get_and_lock_processwide_ptr (unsigned key);
extern void _keymgr_set_and_unlock_processwide_ptr (unsigned key, void *ptr);
extern void *__keymgr_global[];
typedef struct _Sinfo_Node {
unsigned int size ;
unsigned short major_version ;
unsigned short minor_version ;
} _Tinfo_Node ;
#define KEYMGR_API_MAJOR_GCC3 3
#define KEYMGR_GCC3_LIVE_IMAGE_LIST 301
#define KEYMGR_GCC3_DW2_OBJ_LIST 302
struct live_images {
unsigned long this_size;
struct mach_header *mh;
unsigned long vm_slide;
void (*destructor)(struct live_images *);
struct live_images *next;
unsigned int examined_p;
void *fde;
void *object_info;
unsigned long info[2];
};
static void darwin_unwind_dyld_remove_image_hook
(struct mach_header *m, unsigned long s);
static void darwin_unwind_dyld_remove_image_hook
(struct mach_header *m, unsigned long s);
extern void __darwin_gcc3_preregister_frame_info (void);
static void
darwin_unwind_dyld_add_image_hook (struct mach_header *mh, unsigned long slide)
{
struct live_images *l = (struct live_images *)calloc (1, sizeof (*l));
l->mh = mh;
l->vm_slide = slide;
l->this_size = sizeof (*l);
l->next = (struct live_images *)
_keymgr_get_and_lock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST);
_keymgr_set_and_unlock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST, l);
}
static void
darwin_unwind_dyld_remove_image_hook (struct mach_header *m, unsigned long s)
{
struct live_images *top, **lip, *destroy = NULL;
top = (struct live_images *)
_keymgr_get_and_lock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST);
for (lip = ⊤ *lip != NULL; lip = &(*lip)->next)
{
if ((*lip)->mh == m && (*lip)->vm_slide == s)
{
destroy = *lip;
*lip = destroy->next;
if (destroy->this_size != sizeof (*destroy))
abort ();
break;
}
}
_keymgr_set_and_unlock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST, top);
if (destroy != NULL)
{
if (destroy->destructor != NULL)
(*destroy->destructor) (destroy);
free (destroy);
}
}
void
__darwin_gcc3_preregister_frame_info (void)
{
const _Tinfo_Node *info;
_init_keymgr ();
info = (_Tinfo_Node *)__keymgr_global[2];
if (info != NULL)
{
if (info->major_version >= KEYMGR_API_MAJOR_GCC3)
return;
}
_dyld_register_func_for_add_image (darwin_unwind_dyld_add_image_hook);
_dyld_register_func_for_remove_image (darwin_unwind_dyld_remove_image_hook);
}
#endif