/*============================================================================= CATink.h $Log: CATink.h,v $ Revision 1.2 2003/11/20 22:56:53 dwyatt __COREAUDIO_USE_FLAT_INCLUDES__ Revision 1.1 2003/01/22 00:37:34 jcm10 first checked in Revision 0.0 31 Jul 2001, 20:37, Doug Wyatt Created $NoKeywords: $ =============================================================================*/ #if !defined(__CATink_h__) #define __CATink_h__ //============================================================================= // Includes //============================================================================= // System Includes #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__) #include #else #include #endif //============================================================================= // CATink // // A Tink is a small jump island that can make one function appear as if it // has many addresses. //============================================================================= template class CATink { public: CATink(F proc) { /* thanks to CodeWarrior for the nice disassembler lis r11,0x1234 00000000: 3D601234 lis r11,4660 ori r11,r11,0x5678 00000004: 616B5678 ori r11,r11,$5678 mtctr r11 00000008: 7D6903A6 mtctr r11 bctr 0000000C: 4E800420 bctr */ UInt32 p = UInt32(proc); mCode[0] = 0x3D600000 | (p >> 16); mCode[1] = 0x616B0000 | (p & 0xFFFF); mCode[2] = 0x7D6903A6; mCode[3] = 0x4E800420; MakeDataExecutable(mCode, sizeof(mCode)); } operator F () { return F(mCode); } private: UInt32 mCode[4]; }; #endif