Mach-o callback to cfm function

Discussion in 'Programmer Misc' started by Jeff Flinn, Sep 30, 2010.

  1. Jeff Flinn

    Jeff Flinn Guest

    I'm trying to knit together a legacy Codewarrior CFM application with
    XCode Mach-o dll. I've used the approach described by mac support and on
    various forums. The approach described uses:

    UInt32 gluetab[6] = {0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004,
    0x7C0903A6, 0x4E800420};

    static void *MachOPtrVoid (void *cfmfp)
    {
    UInt32 *mfp = (UInt32*) NewPtr( sizeof(gluetab)); // Must later
    dispose of allocated memory
    mfp[0] = gluetab[0] | ((UInt32)cfmfp >> 16);
    mfp[1] = gluetab[1] | ((UInt32)cfmfp & 0xFFFF);
    mfp[2] = gluetab[2];
    mfp[3] = gluetab[3];
    mfp[4] = gluetab[4];
    mfp[5] = gluetab[5];
    MakeDataExecutable (mfp, sizeof(gluetab));
    return( mfp );
    }

    I'm trying to avoid the heap allocation, and to use a more encapsulated
    approach such as:

    struct MachOFunctionPointer
    {
    MachOFunctionPointer(void* cfmProcPtr)
    : m0(0x3D800000 | ((UInt32)cfmProcPtr >> 16))
    , m1(0x618C0000 | ((UInt32)cfmProcPtr & 0xFFFF))
    , m2(0x800C0000)
    , m3(0x804C0004)
    , m4(0x7C0903A6)
    , m5(0x4E800420)
    {
    MakeDataExecutable(this, sizeof(this));
    }

    UInt32 m0;
    UInt32 m1;
    UInt32 m2;
    UInt32 m3;
    UInt32 m4;
    UInt32 m5;
    };

    constructing an instance on the stack:

    MachOFunctionPointer moFncPtr(some_cfm_fnc);

    This leads to spurious crashes of the legacy codewarrior app, which I
    can't debug because the code warrior debugger won't run on mac intel
    machines.

    If I pad the above struct at the end to 32 bytes, there are no crashes.
    I'm conjecturing that when allocating the former array, that the
    allocator is actually allocating to the next power-of-2 size which is 32
    bytes. I've tried using CodeWarrior #pragmas to set alignment and
    packing, but this doesn't seem to fix the problem.

    Any thoughts on this topic are appreciated.

    Thanks, Jeff
     
    Jeff Flinn, Sep 30, 2010
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Hans Stoessel

    How can I load a CFM shared library in a Mach-O bundle?

    Hans Stoessel, Sep 19, 2003, in forum: Programmer Help
    Replies:
    0
    Views:
    269
    Hans Stoessel
    Sep 19, 2003
  2. Paul Miller

    Best way to load CFM shared libs from a Mach-O app?

    Paul Miller, Oct 7, 2003, in forum: Programmer Help
    Replies:
    1
    Views:
    259
    Miro Jurisic
    Oct 8, 2003
  3. Andreas Kromke
    Replies:
    19
    Views:
    1,042
    Benjamin Riefenstahl
    Dec 3, 2003
  4. Paul Miller
    Replies:
    3
    Views:
    315
    Miro Jurisic
    Dec 13, 2003
  5. Andreas Kromke

    Best way to load CFM shared libs from a Mach-O app?

    Andreas Kromke, Jan 7, 2004, in forum: Programmer Help
    Replies:
    2
    Views:
    259
    Marie Jung
    Jan 8, 2004
  6. Fonarix

    Using CFM with Mach-O on iMacs.

    Fonarix, Jul 2, 2007, in forum: Programmer Help
    Replies:
    1
    Views:
    288
    Patrick Machielse
    Jul 2, 2007
  7. Jeff Flinn

    Mach-o callback to cfm function

    Jeff Flinn, Sep 30, 2010, in forum: Programmer Help
    Replies:
    0
    Views:
    541
    Jeff Flinn
    Sep 30, 2010
  8. Fonarix
    Replies:
    0
    Views:
    319
    Fonarix
    Jun 21, 2007
Loading...