• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [ANN] Rax 1.0 released - ReWire
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ANN] Rax 1.0 released - ReWire


  • Subject: Re: [ANN] Rax 1.0 released - ReWire
  • From: Jesper Papmehl <email@hidden>
  • Date: Mon, 14 Jun 2004 12:33:40 +0200

12 jun 2004 kl. 18.56 skrev Lubor Prikryl:
I have noticed several apps in mach-o format using ReWire, but Propellerheads have their libs compiled in PEF (for CFM). Do you wrap all the functions using the mach-o/CFM pointer conversion, or is there another solution?


This is what I have changed in ReWireAPI.c to be able to use ReWire from a MachO app without changing anything in the code that uses ReWire:

// New code:
#if __MACH__
struct TMachOToCFMFunctionGlue {
UInt32 fGlueCode[6];
};
typedef struct TMachOToCFMFunctionGlue TMachOToCFMFunctionGlue;

static void MachOFunctionPointerForCFMFunctionPointer(ProcPtr cfmFunctionPointer, TMachOToCFMFunctionGlue* glueCodeDestination) {
static UInt32 kTemplate[6] = {0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004, 0x7C0903A6, 0x4E800420};
glueCodeDestination->fGlueCode[0] = kTemplate[0] | ((UInt32)cfmFunctionPointer >> 16);
glueCodeDestination->fGlueCode[1] = kTemplate[1] | ((UInt32)cfmFunctionPointer & 0xFFFF);
glueCodeDestination->fGlueCode[2] = kTemplate[2];
glueCodeDestination->fGlueCode[3] = kTemplate[3];
glueCodeDestination->fGlueCode[4] = kTemplate[4];
glueCodeDestination->fGlueCode[5] = kTemplate[5];
MakeDataExecutable(&glueCodeDestination->fGlueCode, sizeof(glueCodeDestination->fGlueCode));
}

static char gInitializedTable = FALSE;
#define kMaxNumFunctions 100
static Ptr gLookedUpFunctionPointers[kMaxNumFunctions];
static TMachOToCFMFunctionGlue gLookedUpFunctionGlues[kMaxNumFunctions];

#endif // __MACH__



// Changed code:
static REWIREPROC FindReWireDLLFunction(const char functionName[]) {
Ptr symbolAddress;
OSErr err;
CFragSymbolClass symClass;
TMacPascalChar pascalString[1 + kMacPascalStringSize];
#if __MACH__
int i;
int firstFreeIndex;
#endif // __MACH__

MacCToPascal(functionName, pascalString);
err = FindSymbol(gReWireDLLInstance, (StringPtr)pascalString, &symbolAddress, &symClass);
if (err == noErr) {
#if __MACH__
if (!gInitializedTable) {
memset(&gLookedUpFunctionPointers, 0, sizeof(gLookedUpFunctionPointers));
memset(&gLookedUpFunctionGlues, 0, sizeof(gLookedUpFunctionGlues));
gInitializedTable = TRUE;
}
firstFreeIndex = -1;
for (i = 0; i < kMaxNumFunctions; i++) {
if (gLookedUpFunctionPointers[i] == 0) {
firstFreeIndex = i;
break;
}
if (gLookedUpFunctionPointers[i] == symbolAddress) {
return (REWIREPROC)&gLookedUpFunctionGlues[i];
}
}
REWIRE_ASSERT(firstFreeIndex >= 0);
REWIRE_ASSERT(firstFreeIndex < kMaxNumFunctions);
MachOFunctionPointerForCFMFunctionPointer((ProcPtr)symbolAddress, &gLookedUpFunctionGlues[firstFreeIndex]);
gLookedUpFunctionPointers[firstFreeIndex] = symbolAddress;
return (REWIREPROC)&gLookedUpFunctionGlues[firstFreeIndex];
#else // __MACH__
return (REWIREPROC)symbolAddress;
#endif // __MACH__
}
else {
switch(err) {
/* Connection ID is not valid. */
case cfragConnectionIDErr:
return 0;
/* Symbol was not found in connection. */
case cfragNoSymbolErr:
return 0;
default:
return 0;
}
}
}

static void UnloadReWireDLL(){
if (0 != gReWireDLLInstance) {
OSErr err = CloseConnection(&gReWireDLLInstance);
gReWireDLLInstance = 0;
#if __MACH__
memset(&gLookedUpFunctionPointers, 0, sizeof(gLookedUpFunctionPointers));
memset(&gLookedUpFunctionGlues, 0, sizeof(gLookedUpFunctionGlues));
gInitializedTable = FALSE;
#endif // __MACH__
}
}



It isn't pretty, but it lets you switch from CFM to MachO without changing any code that uses ReWire.

This code hasn't been thoroughly tested, so use it with caution. Please let me know if you find any problems.

We'll probably release an updated ReWire SDK pretty soon (but I can't make any promises about that).

/Jesper
Propellerheads
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.


References: 
 >[ANN] Rax 1.0 released (From: Robert Grant <email@hidden>)
 >Re: [ANN] Rax 1.0 released - ReWire (From: Lubor Prikryl <email@hidden>)

  • Prev by Date: -10863 error - Help!
  • Next by Date: Re: [ANN] Rax 1.0 released - ReWire
  • Previous by thread: Re: [ANN] Rax 1.0 released - ReWire
  • Next by thread: Re: [ANN] Rax 1.0 released
  • Index(es):
    • Date
    • Thread