1.1 --- a/sourcehook/generate/sh_memfuncinfo.hxx Thu May 05 14:00:08 2005 +0000
1.2 +++ b/sourcehook/generate/sh_memfuncinfo.hxx Thu May 05 14:43:40 2005 +0000
1.3 @@ -54,16 +54,16 @@
1.4
1.5 # if SH_COMP == SH_COMP_GCC
1.6
1.7 - template<> struct MFI_Impl<8> // All of these have size==8
1.8 + template<> struct MFI_Impl<2*SH_PTRSIZE> // All of these have size==8/16
1.9 {
1.10 struct GCC_MemFunPtr
1.11 {
1.12 union
1.13 {
1.14 void *funcadr; // always even
1.15 - int vtable_index_plus1; // = vindex+1, always odd
1.16 + intptr_t vtable_index_plus1; // = vindex+1, always odd
1.17 };
1.18 - int delta;
1.19 + intptr_t delta;
1.20 };
1.21 template<class MFP> static inline void GetFuncInfo(MFP mfp, MemFuncInfo &out)
1.22 {
1.23 @@ -71,7 +71,7 @@
1.24 out.thisptroffs = mfp_detail->delta;
1.25 if (mfp_detail->vtable_index_plus1 & 1)
1.26 {
1.27 - out.vtblindex = (mfp_detail->vtable_index_plus1 - 1) / 4;
1.28 + out.vtblindex = (mfp_detail->vtable_index_plus1 - 1) / SH_PTRSIZE;
1.29 out.vtbloffs = 0;
1.30 out.isVirtual = true;
1.31 }
1.32 @@ -147,7 +147,7 @@
1.33 }
1.34 }
1.35
1.36 - template<> struct MFI_Impl<4> // simple ones
1.37 + template<> struct MFI_Impl<1*SH_PTRSIZE> // simple ones
1.38 {
1.39 template<class MFP> static inline void GetFuncInfo(MFP mfp, MemFuncInfo &out)
1.40 {
1.41 @@ -158,7 +158,7 @@
1.42 }
1.43 };
1.44
1.45 - template<> struct MFI_Impl<8> // more complicated ones!
1.46 + template<> struct MFI_Impl<2*SH_PTRSIZE> // more complicated ones!
1.47 {
1.48 struct MSVC_MemFunPtr2
1.49 {
1.50 @@ -175,7 +175,7 @@
1.51 };
1.52
1.53 // By Don Clugston, adapted
1.54 - template<> struct MFI_Impl<12> // WOW IT"S GETTING BIGGER OMGOMOGMG
1.55 + template<> struct MFI_Impl<3*SH_PTRSIZE> // WOW IT"S GETTING BIGGER OMGOMOGMG
1.56 {
1.57 class __single_inheritance GenericClass;
1.58 class GenericClass {};
1.59 @@ -228,7 +228,7 @@
1.60 // unknown_inheritance classes go here
1.61 // This is probably the ugliest bit of code I've ever written. Look at the casts!
1.62 // There is a compiler bug in MSVC6 which prevents it from using this code.
1.63 - template<> struct MFI_Impl<16> // THE BIGGEST ONE!!!1GABEN
1.64 + template<> struct MFI_Impl<4*SH_PTRSIZE> // THE BIGGEST ONE!!!1GABEN
1.65 {
1.66 template<class MFP> static inline void GetFuncInfo(MFP mfp, MemFuncInfo &out)
1.67 {
2.1 --- a/sourcehook/generate/sourcehook.hxx Thu May 05 14:00:08 2005 +0000
2.2 +++ b/sourcehook/generate/sourcehook.hxx Thu May 05 14:43:40 2005 +0000
2.3 @@ -63,6 +63,8 @@
2.4 # define vsnprintf _vsnprintf
2.5 #endif
2.6
2.7 +#define SH_PTRSIZE sizeof(void*)
2.8 +
2.9 #include "FastDelegate.h"
2.10 #include "sh_memfuncinfo.h"
2.11 #include "sh_memory.h"
2.12 @@ -86,8 +88,8 @@
2.13
2.14 namespace SourceHook
2.15 {
2.16 - const int STRBUF_LEN=8192; // In bytes, for "vafmt" functions
2.17 -
2.18 + const int STRBUF_LEN=4096; // In bytes, for "vafmt" functions
2.19 +
2.20 /**
2.21 * @brief An empty class. No inheritance used. Used for original-function-call hacks
2.22 */
2.23 @@ -677,8 +679,9 @@
2.24 //////////////////////////////////////////////////////////////////////////
2.25 // SH_CALL
2.26
2.27 +#if SH_COMP == SH_COMP_MSVC
2.28
2.29 -#define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
2.30 +# define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
2.31 { \
2.32 using namespace ::SourceHook; \
2.33 MemFuncInfo mfi; \
2.34 @@ -699,6 +702,34 @@
2.35 return (reinterpret_cast<EmptyClass*>(adjustedthisptr)->*u.mfpnew)call; \
2.36 }
2.37
2.38 +#elif SH_COMP == SH_COMP_GCC
2.39 +
2.40 +# define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
2.41 +{ \
2.42 + using namespace ::SourceHook; \
2.43 + MemFuncInfo mfi; \
2.44 + GetFuncInfo(m_CC->ptr, m_MFP, mfi); \
2.45 + OrigVTables::const_iterator iter = m_CC->vt.find(mfi.thisptroffs + mfi.vtbloffs); \
2.46 + if (iter == m_CC->vt.end() || mfi.vtblindex >= (int)iter->second.size() || iter->second[mfi.vtblindex] == NULL) \
2.47 + return (m_CC->ptr->*m_MFP)call; \
2.48 + \
2.49 + /* It's hooked. Call the original function. */ \
2.50 + union \
2.51 + { \
2.52 + RetType(EmptyClass::*mfpnew)prms; \
2.53 + struct \
2.54 + { \
2.55 + void *addr; \
2.56 + intptr_t adjustor; \
2.57 + } s; \
2.58 + } u; \
2.59 + u.s.addr = iter->second[mfi.vtblindex]; \
2.60 + u.s.adjustor = mfi.thisptroffs; \
2.61 + \
2.62 + return (reinterpret_cast<EmptyClass*>(m_CC->ptr)->*u.mfpnew)call; \
2.63 +}
2.64 +
2.65 +#endif
2.66
2.67 namespace SourceHook
2.68 {
3.1 --- a/sourcehook/sh_memfuncinfo.h Thu May 05 14:00:08 2005 +0000
3.2 +++ b/sourcehook/sh_memfuncinfo.h Thu May 05 14:43:40 2005 +0000
3.3 @@ -54,16 +54,16 @@
3.4
3.5 # if SH_COMP == SH_COMP_GCC
3.6
3.7 - template<> struct MFI_Impl<8> // All of these have size==8
3.8 + template<> struct MFI_Impl<2*SH_PTRSIZE> // All of these have size==8/16
3.9 {
3.10 struct GCC_MemFunPtr
3.11 {
3.12 union
3.13 {
3.14 void *funcadr; // always even
3.15 - int vtable_index_plus1; // = vindex+1, always odd
3.16 + intptr_t vtable_index_plus1; // = vindex+1, always odd
3.17 };
3.18 - int delta;
3.19 + intptr_t delta;
3.20 };
3.21 template<class MFP> static inline void GetFuncInfo(MFP mfp, MemFuncInfo &out)
3.22 {
3.23 @@ -71,7 +71,7 @@
3.24 out.thisptroffs = mfp_detail->delta;
3.25 if (mfp_detail->vtable_index_plus1 & 1)
3.26 {
3.27 - out.vtblindex = (mfp_detail->vtable_index_plus1 - 1) / 4;
3.28 + out.vtblindex = (mfp_detail->vtable_index_plus1 - 1) / SH_PTRSIZE;
3.29 out.vtbloffs = 0;
3.30 out.isVirtual = true;
3.31 }
3.32 @@ -147,7 +147,7 @@
3.33 }
3.34 }
3.35
3.36 - template<> struct MFI_Impl<4> // simple ones
3.37 + template<> struct MFI_Impl<1*SH_PTRSIZE> // simple ones
3.38 {
3.39 template<class MFP> static inline void GetFuncInfo(MFP mfp, MemFuncInfo &out)
3.40 {
3.41 @@ -158,7 +158,7 @@
3.42 }
3.43 };
3.44
3.45 - template<> struct MFI_Impl<8> // more complicated ones!
3.46 + template<> struct MFI_Impl<2*SH_PTRSIZE> // more complicated ones!
3.47 {
3.48 struct MSVC_MemFunPtr2
3.49 {
3.50 @@ -175,7 +175,7 @@
3.51 };
3.52
3.53 // By Don Clugston, adapted
3.54 - template<> struct MFI_Impl<12> // WOW IT"S GETTING BIGGER OMGOMOGMG
3.55 + template<> struct MFI_Impl<3*SH_PTRSIZE> // WOW IT"S GETTING BIGGER OMGOMOGMG
3.56 {
3.57 class __single_inheritance GenericClass;
3.58 class GenericClass {};
3.59 @@ -228,7 +228,7 @@
3.60 // unknown_inheritance classes go here
3.61 // This is probably the ugliest bit of code I've ever written. Look at the casts!
3.62 // There is a compiler bug in MSVC6 which prevents it from using this code.
3.63 - template<> struct MFI_Impl<16> // THE BIGGEST ONE!!!1GABEN
3.64 + template<> struct MFI_Impl<4*SH_PTRSIZE> // THE BIGGEST ONE!!!1GABEN
3.65 {
3.66 template<class MFP> static inline void GetFuncInfo(MFP mfp, MemFuncInfo &out)
3.67 {
4.1 --- a/sourcehook/sh_memory.h Thu May 05 14:00:08 2005 +0000
4.2 +++ b/sourcehook/sh_memory.h Thu May 05 14:43:40 2005 +0000
4.3 @@ -34,8 +34,8 @@
4.4
4.5 // We need to align addr down to pagesize on linux
4.6 // We assume PAGESIZE is a power of two
4.7 -# define SH_LALIGN(x) (void*)((int)(x) & ~(PAGESIZE-1))
4.8 -# define SH_LALDIF(x) ((int)(x) & (PAGESIZE-1))
4.9 +# define SH_LALIGN(x) (void*)((intptr_t)(x) & ~(PAGESIZE-1))
4.10 +# define SH_LALDIF(x) ((intptr_t)(x) & (PAGESIZE-1))
4.11 # else
4.12 # error Unsupported OS/Compiler
4.13 # endif
5.1 --- a/sourcehook/sourcehook.h Thu May 05 14:00:08 2005 +0000
5.2 +++ b/sourcehook/sourcehook.h Thu May 05 14:43:40 2005 +0000
5.3 @@ -63,6 +63,8 @@
5.4 # define vsnprintf _vsnprintf
5.5 #endif
5.6
5.7 +#define SH_PTRSIZE sizeof(void*)
5.8 +
5.9 #include "FastDelegate.h"
5.10 #include "sh_memfuncinfo.h"
5.11 #include "sh_memory.h"
5.12 @@ -86,8 +88,8 @@
5.13
5.14 namespace SourceHook
5.15 {
5.16 - const int STRBUF_LEN=8192; // In bytes, for "vafmt" functions
5.17 -
5.18 + const int STRBUF_LEN=4096; // In bytes, for "vafmt" functions
5.19 +
5.20 /**
5.21 * @brief An empty class. No inheritance used. Used for original-function-call hacks
5.22 */
5.23 @@ -1491,8 +1493,9 @@
5.24 //////////////////////////////////////////////////////////////////////////
5.25 // SH_CALL
5.26
5.27 +#if SH_COMP == SH_COMP_MSVC
5.28
5.29 -#define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
5.30 +# define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
5.31 { \
5.32 using namespace ::SourceHook; \
5.33 MemFuncInfo mfi; \
5.34 @@ -1513,6 +1516,34 @@
5.35 return (reinterpret_cast<EmptyClass*>(adjustedthisptr)->*u.mfpnew)call; \
5.36 }
5.37
5.38 +#elif SH_COMP == SH_COMP_GCC
5.39 +
5.40 +# define SH_MAKE_EXECUTABLECLASS_OB(call, prms) \
5.41 +{ \
5.42 + using namespace ::SourceHook; \
5.43 + MemFuncInfo mfi; \
5.44 + GetFuncInfo(m_CC->ptr, m_MFP, mfi); \
5.45 + OrigVTables::const_iterator iter = m_CC->vt.find(mfi.thisptroffs + mfi.vtbloffs); \
5.46 + if (iter == m_CC->vt.end() || mfi.vtblindex >= (int)iter->second.size() || iter->second[mfi.vtblindex] == NULL) \
5.47 + return (m_CC->ptr->*m_MFP)call; \
5.48 + \
5.49 + /* It's hooked. Call the original function. */ \
5.50 + union \
5.51 + { \
5.52 + RetType(EmptyClass::*mfpnew)prms; \
5.53 + struct \
5.54 + { \
5.55 + void *addr; \
5.56 + intptr_t adjustor; \
5.57 + } s; \
5.58 + } u; \
5.59 + u.s.addr = iter->second[mfi.vtblindex]; \
5.60 + u.s.adjustor = mfi.thisptroffs; \
5.61 + \
5.62 + return (reinterpret_cast<EmptyClass*>(m_CC->ptr)->*u.mfpnew)call; \
5.63 +}
5.64 +
5.65 +#endif
5.66
5.67 namespace SourceHook
5.68 {
6.1 --- a/sourcehook/test/testevents.h Thu May 05 14:00:08 2005 +0000
6.2 +++ b/sourcehook/test/testevents.h Thu May 05 14:43:40 2005 +0000
6.3 @@ -100,8 +100,7 @@
6.4 }
6.5 }
6.6
6.7 -//#define CHECK_STATES(mwah, myerr) if (!StatesOk mwah) { error=myerr; return false; } else if (g_Verbose) { std::cout << "No error: " << myerr << std::endl; }
6.8 -#define CHECK_STATES(mwah, myerr) if (!StatesOk mwah) { error=myerr; return false; }
6.9 +#define CHECK_STATES(mwah, myerr) if (!StatesOk mwah) { error=myerr; return false; } else if (g_Verbose) { std::cout << "No error: " << myerr << std::endl; }
6.10
6.11 #define MAKE_STATE(name) struct name : State { \
6.12 virtual void Dump() { \