Beispiel #1
0
static void* getStubAddr()
{
#if __LP64__
	uint64_t size;
#else
	uint32_t size;
#endif
	uintptr_t slide = (uintptr_t)&_mh_dylib_header; // assume dylib is zero-base so slide == load address
#if __i386__
	return getsectdatafromheader(&_mh_dylib_header, "__IMPORT", "__jump_table", &size) + slide;
#elif __ppc__
	return getsectdatafromheader(&_mh_dylib_header, "TEXT", "__picsymbolstub1", &size) + slide;
#elif __ppc64__
	return getsectdatafromheader_64(&_mh_dylib_header, "__TEXT", "__picsymbolstub1", &size) + slide;
#elif __x86_64__
	return getsectdatafromheader_64(&_mh_dylib_header, "__TEXT", "__symbol_stub1", &size) + slide;
#elif __arm__
	void* p = getsectdata("__TEXT", "__picsymbolstub4", (unsigned long*)&size);
	if ( p != NULL ) 
		return getsectdatafromheader(&_mh_dylib_header, "__TEXT", "__picsymbolstub4", &size) + slide;
	return getsectdatafromheader(&_mh_dylib_header, "__TEXT", "__symbolstub1", &size) + slide;
#else
	#error unknown arch
#endif
}
Beispiel #2
0
static void
set_text_segment(const struct mach_header *header, const char *sectname)
{
  text_segment = getsectdatafromheader_64((const struct mach_header_64*)header, "__TEXT", sectname, (uint64_t*)&text_segment_len);
  if (!text_segment)
    errx(EX_UNAVAILABLE, "Failed to locate the %s section", sectname);
}
Beispiel #3
0
static inline const fde *
examine_objects (void *pc, struct dwarf_eh_bases *bases, int dont_alloc)
{
  const fde *result = NULL;
  struct live_images *image;

  image = _keymgr_get_and_lock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST);

  for (; image != NULL; image = image->next)
    if ((image->examined_p & EXAMINED_IMAGE_MASK) == 0)
      {
        char *fde = NULL;
        unsigned long sz;

        /* For ppc only check whether or not we have __DATA eh frames.  */
#ifdef __ppc__
        fde = getsectdatafromheader (image->mh, "__DATA", "__eh_frame", &sz);
#endif

        if (fde == NULL)
          {
#if __LP64__
            fde = getsectdatafromheader_64 ((struct mach_header_64 *) image->mh,
                                            "__TEXT", "__eh_frame", &sz);
#else
            fde = getsectdatafromheader (image->mh, "__TEXT",
                                         "__eh_frame", &sz);
#endif
            if (fde != NULL)
              image->examined_p |= IMAGE_IS_TEXT_MASK;
          }

        /* If .eh_frame is empty, don't register at all.  */
        if (fde != NULL && sz > 0)
          {
            char *real_fde = (fde + image->vm_slide);
            struct object *ob = NULL;
            struct object panicob;

            if (! dont_alloc)
              ob = calloc (1, sizeof (struct object));
            dont_alloc |= ob == NULL;
            if (dont_alloc)
              ob = &panicob;

            ob->pc_begin = (void *)-1;
            ob->tbase = 0;
            ob->dbase = 0;
            ob->u.single = (struct dwarf_fde *)real_fde;
            ob->s.i = 0;
            ob->s.b.encoding = DW_EH_PE_omit;
            ob->fde_end = real_fde + sz;

            image->fde = real_fde;

            result = search_object (ob, pc);

            if (! dont_alloc)
              {
                struct object **p;

                image->destructor = live_image_destructor;
                image->object_info = ob;

                image->examined_p |= (EXAMINED_IMAGE_MASK
                                      | DESTRUCTOR_MAY_BE_CALLED_LIVE);

                /* Insert the object into the classified list.  */
                for (p = &seen_objects; *p ; p = &(*p)->next)
                  if ((*p)->pc_begin < ob->pc_begin)
                    break;
                ob->next = *p;
                *p = ob;
              }

            if (result)
              {
                int encoding;
                _Unwind_Ptr func;

                bases->tbase = ob->tbase;
                bases->dbase = ob->dbase;

                encoding = ob->s.b.encoding;
                if (ob->s.b.mixed_encoding)
                  encoding = get_fde_encoding (result);
                read_encoded_value_with_base (encoding,
                                              base_from_object (encoding, ob),
                                              result->pc_begin, &func);
                bases->func = (void *) func;
                break;
              }
          }
        else
          image->examined_p |= EXAMINED_IMAGE_MASK;
      }

  _keymgr_unlock_processwide_ptr (KEYMGR_GCC3_LIVE_IMAGE_LIST);

  return result;
}