Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mach-O app calling CFM plug-in?



George Warner a écrit :

On Mon, 28 Aug 2006 15:23:26 -0700, Wyatt Webb <email@hidden>
wrote:
In my code I call GetDiskFragment to find my CFM library. I then use
FindSymbol to get the function pointer I want. Then I pass that to
CFM2MachO. That gives me a Mach-O pointer I can now use.

The CFBundle API's will do all this for you.
That's good to know! Does it work on non-bundled plugins (e.g. 'cfrg' resource and data fork in one file)?

You only need to write the glue
code if the API you're calling requires a callback. That callback will have
to make the cross architecture call and you'll have to provide that glue
yourself.
Right. And, for the list's benefit, here is one way to do a callback from CFM into Mach-O (excerpt from http://www.mozilla.org/projects/plugins/plugin_scripting_ABI_technote.html):

----------------------------------------------


// glue for mapping outgoing Macho function pointers to TVectors struct TFPtoTVGlue{ void* glue[2]; };

static inline void* SetupFPtoTVGlue(TFPtoTVGlue* functionGlue, void* fp)
{
   functionGlue->glue[0] = fp;
   functionGlue->glue[1] = 0;
   return functionGlue;
}

----------------------------------------------


And for the list's benefit, here is the converse glue (CFM function to Mach-O function). It's virtually identical to what Wyatt proposed.


----------------------------------------------

static void* SetupTVtoFPGlue(TTVtoFPGlue* functionGlue, void* tvp)
{
   static const TTVtoFPGlue glueTemplate = { 0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004, 0x7C0903A6, 0x4E800420 };

   memcpy(functionGlue, &glueTemplate, sizeof(TTVtoFPGlue));
   functionGlue->glue[0] |= ((UInt32)tvp >> 16);
   functionGlue->glue[1] |= ((UInt32)tvp & 0xFFFF);
   ::MakeDataExecutable(functionGlue, sizeof(TTVtoFPGlue));
   return functionGlue;
}

----------------------------------------------

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden
References: 
 >Re: Mach-O app calling CFM plug-in? (From: George Warner <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.