Re: Calling a CFM library from Mach-o and passing a Callback...
Re: Calling a CFM library from Mach-o and passing a Callback...
- Subject: Re: Calling a CFM library from Mach-o and passing a Callback...
- From: Frederick Cheung <email@hidden>
- Date: Thu, 20 Apr 2006 20:39:11 +0100
On 20 Apr 2006, at 17:34, Dave Thorup wrote:
Alright, I'm in the unfortunate position of having to use a third-
party CFM library with our Mach-o application. I have it working
for the most part using CFBundle to load the library and
CFBundleGetFunctionPointerForName to load the function pointers
that I need. The last thing that I need to do is be able to pass a
function pointer from my Mach-o application so that it can be used
by the CFM library.
I can't seem to find any way to do this, at least I haven't been
able to find it yet. The best I could do was locate the
CFM_MachO_CFM sample code. But this does the opposite of what I
need to do (CFM -> Mach-o -> CFM), I need to do Mach-o -> CFM ->
Mach-o. Can anybody point me in the right direction?
You need to massage your function pointer into a tvector. I've got
the following code in my browser plugin (mach-o browser plugin,
hosted in a cfm browser, and needs to provide its callbacks to the
browser). I believe it originally came from a code sample for mach-o
browser plugins
TransitionVector tVectorForFunctionPointer(FunctionPointer fp)
{
FunctionPointer *newGlue = NULL;
if (fp != NULL) {
newGlue = (FunctionPointer *)malloc(2 * sizeof
(FunctionPointer));
if (newGlue != NULL) {
newGlue[0] = fp;
newGlue[1] = NULL;
}
}
return (TransitionVector)newGlue;
}
FunctionPointer and TransitionVector are defined as
typedef void (* FunctionPointer) (void);
typedef void (* TransitionVector) (void);
just for clarity of code (you can use tVectorForFunctionPointer on
functions with a variety of signatures).
If you need the reverse operation you can do
const uint32 temp[6] = {0x3D800000, 0x618C0000, 0x800C0000,
0x804C0004, 0x7C0903A6, 0x4E800420};
uint32 *newGlue = NULL;
if (tvp != NULL) {
newGlue = (uint32 *)malloc(sizeof(temp));
if (newGlue != NULL) {
unsigned i;
for (i = 0; i < 6; i++) newGlue[i] = temp[i];
newGlue[0] |= ((UInt32)tvp >> 16);
newGlue[1] |= ((UInt32)tvp & 0xFFFF);
MakeDataExecutable(newGlue, sizeof(temp));
}
}
return (FunctionPointer)newGlue;
Fred
Thanks!
PS George, I've CCed you on this because I remember you telling me
that you were one of the last, if not THE last, people at Apple
with any CFM responsibilities.
_____________________________
Dave Thorup
Software Engineer
email@hidden
http://www.kuwan.net
HyperSpell - Check spelling in Mac OS X from any application.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden