1.1 --- a/sourcehook/generate/sourcehook.h Sat Nov 24 06:11:23 2007 +0000
1.2 +++ b/sourcehook/generate/sourcehook.h Mon Nov 26 14:03:25 2007 +0000
1.3 @@ -35,6 +35,11 @@
1.4 // 1 - standard
1.5 #define SH_HOOKMAN_VERSION 1
1.6
1.7 +// Hookmanautogen versions
1.8 +// 1 - initial
1.9 +#define SH_HOOKMANAUTOGEN_IFACE_VERSION 1
1.10 +#define SH_HOOKMANAUTOGEN_IMPL_VERSION 1
1.11 +
1.12 // The value of SH_GLOB_SHPTR has to be a pointer to SourceHook::ISourceHook
1.13 // It's used in various macros
1.14 #ifndef SH_GLOB_SHPTR
1.15 @@ -173,7 +178,13 @@
1.16 PassFlag_ODtor = (1<<2), /**< Object has a destructor */
1.17 PassFlag_OCtor = (1<<3), /**< Object has a normal non-trivial constructor */
1.18 PassFlag_AssignOp = (1<<4), /**< Object has a non-trivial assignment operator */
1.19 - PassFlag_CCtor = (1<<5) /**< Object has a copy constructor (which takes const Object& as only parameter) */
1.20 + PassFlag_CCtor = (1<<5), /**< Object has a copy constructor (which takes const Object& as only parameter) */
1.21 +
1.22 + // The following two flags are only relevant for byval return types.
1.23 + // SH tries to auto-detect these
1.24 + // If you want to override SH's auto-detection, pass them in yourself
1.25 + PassFlag_RetMem = (1<<6), /**< Object is returned in memory (through hidden first param */
1.26 + PassFlag_RetReg = (1<<7) /**< Object is returned in EAX(:EDX) */
1.27 };
1.28
1.29 size_t size; //!< Size of the data being passed
1.30 @@ -196,9 +207,13 @@
1.31 {
1.32 enum CallConvention
1.33 {
1.34 - CallConv_Unknown, /**< Unknown -- no extra info available */
1.35 - CallConv_ThisCall, /**< This call (object pointer required) */
1.36 - CallConv_Cdecl, /**< Standard C call */
1.37 + CallConv_Unknown, /**< Unknown -- no extra info available (0)*/
1.38 + CallConv_ThisCall, /**< This call (object pointer required) (1)*/
1.39 + CallConv_Cdecl, /**< C call (2)*/
1.40 + CallConv_StdCall, /**< Windows "stdcall" (3)*/
1.41 +
1.42 + CallConv_HasVarArgs = (1<<16), /**< Has variable arguments */
1.43 + CallConv_HasVafmt = CallConv_HasVarArgs | (1<<17) /**< last params: const char*, ... */
1.44 };
1.45
1.46 int numOfParams; //!< number of parameters
1.47 @@ -462,6 +477,17 @@
1.48 virtual void EndContext(IHookContext *pCtx) = 0;
1.49 };
1.50
1.51 +
1.52 + class IHookManagerAutoGen
1.53 + {
1.54 + public:
1.55 + virtual int GetIfaceVersion() = 0;
1.56 + virtual int GetImplVersion() = 0;
1.57 +
1.58 + virtual HookManagerPubFunc MakeHookMan(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx) = 0;
1.59 + virtual void ReleaseHookMan(HookManagerPubFunc pubFunc) = 0;
1.60 + };
1.61 +
1.62 // For META_RESULT_ORIG_RET and META_RESULT_OVERRIDE_RET:
1.63 // These have to be able to return references. If T is a reference, the pointers returned
1.64 // from the SH_GLOB_SHPTR are pointers to instances of ReferenceCarrier<T>::type.
1.65 @@ -1014,7 +1040,7 @@
1.66 char buf[::SourceHook::STRBUF_LEN]; \
1.67 va_list ap; \
1.68 va_start(ap, fmt); \
1.69 - vsnprintf(buf, sizeof(buf) - 1, fmt, ap); \
1.70 + vsnprintf(buf, sizeof(buf), fmt, ap); \
1.71 buf[sizeof(buf) - 1] = 0; \
1.72 va_end(ap);
1.73
1.74 @@ -6738,11 +6764,23 @@
1.75 }
1.76
1.77 template <class Iface, class RetType>
1.78 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(...))
1.79 + {
1.80 + return OverrideFunctor<RetType>();
1.81 + }
1.82 +
1.83 + template <class Iface, class RetType>
1.84 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)())
1.85 {
1.86 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.87 }
1.88
1.89 + template <class Iface, class RetType>
1.90 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(...))
1.91 + {
1.92 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.93 + }
1.94 +
1.95 template <class Iface, class RetType, class Param1>
1.96 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1))
1.97 {
1.98 @@ -6750,11 +6788,23 @@
1.99 }
1.100
1.101 template <class Iface, class RetType, class Param1>
1.102 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, ...))
1.103 + {
1.104 + return OverrideFunctor<RetType>();
1.105 + }
1.106 +
1.107 + template <class Iface, class RetType, class Param1>
1.108 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1))
1.109 {
1.110 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.111 }
1.112
1.113 + template <class Iface, class RetType, class Param1>
1.114 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, ...))
1.115 + {
1.116 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.117 + }
1.118 +
1.119 template <class Iface, class RetType, class Param1, class Param2>
1.120 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2))
1.121 {
1.122 @@ -6762,11 +6812,23 @@
1.123 }
1.124
1.125 template <class Iface, class RetType, class Param1, class Param2>
1.126 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, ...))
1.127 + {
1.128 + return OverrideFunctor<RetType>();
1.129 + }
1.130 +
1.131 + template <class Iface, class RetType, class Param1, class Param2>
1.132 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2))
1.133 {
1.134 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.135 }
1.136
1.137 + template <class Iface, class RetType, class Param1, class Param2>
1.138 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, ...))
1.139 + {
1.140 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.141 + }
1.142 +
1.143 template <class Iface, class RetType, class Param1, class Param2, class Param3>
1.144 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3))
1.145 {
1.146 @@ -6774,11 +6836,23 @@
1.147 }
1.148
1.149 template <class Iface, class RetType, class Param1, class Param2, class Param3>
1.150 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, ...))
1.151 + {
1.152 + return OverrideFunctor<RetType>();
1.153 + }
1.154 +
1.155 + template <class Iface, class RetType, class Param1, class Param2, class Param3>
1.156 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3))
1.157 {
1.158 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.159 }
1.160
1.161 + template <class Iface, class RetType, class Param1, class Param2, class Param3>
1.162 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, ...))
1.163 + {
1.164 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.165 + }
1.166 +
1.167 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4>
1.168 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4))
1.169 {
1.170 @@ -6786,11 +6860,23 @@
1.171 }
1.172
1.173 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4>
1.174 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, ...))
1.175 + {
1.176 + return OverrideFunctor<RetType>();
1.177 + }
1.178 +
1.179 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4>
1.180 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4))
1.181 {
1.182 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.183 }
1.184
1.185 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4>
1.186 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, ...))
1.187 + {
1.188 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.189 + }
1.190 +
1.191 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
1.192 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5))
1.193 {
1.194 @@ -6798,11 +6884,23 @@
1.195 }
1.196
1.197 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
1.198 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, ...))
1.199 + {
1.200 + return OverrideFunctor<RetType>();
1.201 + }
1.202 +
1.203 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
1.204 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5))
1.205 {
1.206 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.207 }
1.208
1.209 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
1.210 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, ...))
1.211 + {
1.212 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.213 + }
1.214 +
1.215 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
1.216 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6))
1.217 {
1.218 @@ -6810,11 +6908,23 @@
1.219 }
1.220
1.221 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
1.222 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, ...))
1.223 + {
1.224 + return OverrideFunctor<RetType>();
1.225 + }
1.226 +
1.227 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
1.228 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6))
1.229 {
1.230 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.231 }
1.232
1.233 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
1.234 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, ...))
1.235 + {
1.236 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.237 + }
1.238 +
1.239 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
1.240 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7))
1.241 {
1.242 @@ -6822,11 +6932,23 @@
1.243 }
1.244
1.245 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
1.246 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, ...))
1.247 + {
1.248 + return OverrideFunctor<RetType>();
1.249 + }
1.250 +
1.251 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
1.252 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7))
1.253 {
1.254 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.255 }
1.256
1.257 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
1.258 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, ...))
1.259 + {
1.260 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.261 + }
1.262 +
1.263 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
1.264 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8))
1.265 {
1.266 @@ -6834,11 +6956,23 @@
1.267 }
1.268
1.269 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
1.270 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, ...))
1.271 + {
1.272 + return OverrideFunctor<RetType>();
1.273 + }
1.274 +
1.275 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
1.276 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8))
1.277 {
1.278 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.279 }
1.280
1.281 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
1.282 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, ...))
1.283 + {
1.284 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.285 + }
1.286 +
1.287 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9>
1.288 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9))
1.289 {
1.290 @@ -6846,11 +6980,23 @@
1.291 }
1.292
1.293 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9>
1.294 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, ...))
1.295 + {
1.296 + return OverrideFunctor<RetType>();
1.297 + }
1.298 +
1.299 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9>
1.300 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9))
1.301 {
1.302 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.303 }
1.304
1.305 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9>
1.306 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, ...))
1.307 + {
1.308 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.309 + }
1.310 +
1.311 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10>
1.312 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10))
1.313 {
1.314 @@ -6858,11 +7004,23 @@
1.315 }
1.316
1.317 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10>
1.318 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, ...))
1.319 + {
1.320 + return OverrideFunctor<RetType>();
1.321 + }
1.322 +
1.323 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10>
1.324 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10))
1.325 {
1.326 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.327 }
1.328
1.329 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10>
1.330 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, ...))
1.331 + {
1.332 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.333 + }
1.334 +
1.335 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11>
1.336 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11))
1.337 {
1.338 @@ -6870,11 +7028,23 @@
1.339 }
1.340
1.341 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11>
1.342 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, ...))
1.343 + {
1.344 + return OverrideFunctor<RetType>();
1.345 + }
1.346 +
1.347 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11>
1.348 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11))
1.349 {
1.350 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.351 }
1.352
1.353 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11>
1.354 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, ...))
1.355 + {
1.356 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.357 + }
1.358 +
1.359 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12>
1.360 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12))
1.361 {
1.362 @@ -6882,11 +7052,23 @@
1.363 }
1.364
1.365 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12>
1.366 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, ...))
1.367 + {
1.368 + return OverrideFunctor<RetType>();
1.369 + }
1.370 +
1.371 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12>
1.372 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12))
1.373 {
1.374 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.375 }
1.376
1.377 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12>
1.378 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, ...))
1.379 + {
1.380 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.381 + }
1.382 +
1.383 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13>
1.384 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13))
1.385 {
1.386 @@ -6894,11 +7076,23 @@
1.387 }
1.388
1.389 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13>
1.390 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, ...))
1.391 + {
1.392 + return OverrideFunctor<RetType>();
1.393 + }
1.394 +
1.395 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13>
1.396 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13))
1.397 {
1.398 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.399 }
1.400
1.401 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13>
1.402 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, ...))
1.403 + {
1.404 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.405 + }
1.406 +
1.407 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14>
1.408 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14))
1.409 {
1.410 @@ -6906,11 +7100,23 @@
1.411 }
1.412
1.413 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14>
1.414 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, ...))
1.415 + {
1.416 + return OverrideFunctor<RetType>();
1.417 + }
1.418 +
1.419 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14>
1.420 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14))
1.421 {
1.422 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.423 }
1.424
1.425 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14>
1.426 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, ...))
1.427 + {
1.428 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.429 + }
1.430 +
1.431 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15>
1.432 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15))
1.433 {
1.434 @@ -6918,11 +7124,23 @@
1.435 }
1.436
1.437 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15>
1.438 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, ...))
1.439 + {
1.440 + return OverrideFunctor<RetType>();
1.441 + }
1.442 +
1.443 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15>
1.444 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15))
1.445 {
1.446 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.447 }
1.448
1.449 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15>
1.450 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, ...))
1.451 + {
1.452 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.453 + }
1.454 +
1.455 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16>
1.456 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16))
1.457 {
1.458 @@ -6930,11 +7148,23 @@
1.459 }
1.460
1.461 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16>
1.462 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16, ...))
1.463 + {
1.464 + return OverrideFunctor<RetType>();
1.465 + }
1.466 +
1.467 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16>
1.468 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16))
1.469 {
1.470 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.471 }
1.472
1.473 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16>
1.474 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16, ...))
1.475 + {
1.476 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
1.477 + }
1.478 +
1.479 }
1.480
1.481 #endif
2.1 --- a/sourcehook/generate/sourcehook.hxx Sat Nov 24 06:11:23 2007 +0000
2.2 +++ b/sourcehook/generate/sourcehook.hxx Mon Nov 26 14:03:25 2007 +0000
2.3 @@ -35,6 +35,11 @@
2.4 // 1 - standard
2.5 #define SH_HOOKMAN_VERSION 1
2.6
2.7 +// Hookmanautogen versions
2.8 +// 1 - initial
2.9 +#define SH_HOOKMANAUTOGEN_IFACE_VERSION 1
2.10 +#define SH_HOOKMANAUTOGEN_IMPL_VERSION 1
2.11 +
2.12 // The value of SH_GLOB_SHPTR has to be a pointer to SourceHook::ISourceHook
2.13 // It's used in various macros
2.14 #ifndef SH_GLOB_SHPTR
2.15 @@ -173,7 +178,13 @@
2.16 PassFlag_ODtor = (1<<2), /**< Object has a destructor */
2.17 PassFlag_OCtor = (1<<3), /**< Object has a normal non-trivial constructor */
2.18 PassFlag_AssignOp = (1<<4), /**< Object has a non-trivial assignment operator */
2.19 - PassFlag_CCtor = (1<<5) /**< Object has a copy constructor (which takes const Object& as only parameter) */
2.20 + PassFlag_CCtor = (1<<5), /**< Object has a copy constructor (which takes const Object& as only parameter) */
2.21 +
2.22 + // The following two flags are only relevant for byval return types.
2.23 + // SH tries to auto-detect these
2.24 + // If you want to override SH's auto-detection, pass them in yourself
2.25 + PassFlag_RetMem = (1<<6), /**< Object is returned in memory (through hidden first param */
2.26 + PassFlag_RetReg = (1<<7) /**< Object is returned in EAX(:EDX) */
2.27 };
2.28
2.29 size_t size; //!< Size of the data being passed
2.30 @@ -196,9 +207,13 @@
2.31 {
2.32 enum CallConvention
2.33 {
2.34 - CallConv_Unknown, /**< Unknown -- no extra info available */
2.35 - CallConv_ThisCall, /**< This call (object pointer required) */
2.36 - CallConv_Cdecl, /**< Standard C call */
2.37 + CallConv_Unknown, /**< Unknown -- no extra info available (0)*/
2.38 + CallConv_ThisCall, /**< This call (object pointer required) (1)*/
2.39 + CallConv_Cdecl, /**< C call (2)*/
2.40 + CallConv_StdCall, /**< Windows "stdcall" (3)*/
2.41 +
2.42 + CallConv_HasVarArgs = (1<<16), /**< Has variable arguments */
2.43 + CallConv_HasVafmt = CallConv_HasVarArgs | (1<<17) /**< last params: const char*, ... */
2.44 };
2.45
2.46 int numOfParams; //!< number of parameters
2.47 @@ -462,6 +477,17 @@
2.48 virtual void EndContext(IHookContext *pCtx) = 0;
2.49 };
2.50
2.51 +
2.52 + class IHookManagerAutoGen
2.53 + {
2.54 + public:
2.55 + virtual int GetIfaceVersion() = 0;
2.56 + virtual int GetImplVersion() = 0;
2.57 +
2.58 + virtual HookManagerPubFunc MakeHookMan(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx) = 0;
2.59 + virtual void ReleaseHookMan(HookManagerPubFunc pubFunc) = 0;
2.60 + };
2.61 +
2.62 // For META_RESULT_ORIG_RET and META_RESULT_OVERRIDE_RET:
2.63 // These have to be able to return references. If T is a reference, the pointers returned
2.64 // from the SH_GLOB_SHPTR are pointers to instances of ReferenceCarrier<T>::type.
2.65 @@ -1014,7 +1040,7 @@
2.66 char buf[::SourceHook::STRBUF_LEN]; \
2.67 va_list ap; \
2.68 va_start(ap, fmt); \
2.69 - vsnprintf(buf, sizeof(buf) - 1, fmt, ap); \
2.70 + vsnprintf(buf, sizeof(buf), fmt, ap); \
2.71 buf[sizeof(buf) - 1] = 0; \
2.72 va_end(ap);
2.73
2.74 @@ -1416,10 +1442,22 @@
2.75 }
2.76
2.77 template <class Iface, class RetType@[$2,1,$1:, class Param$2@]>
2.78 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(@[$2,1,$1:Param$2, @]...))
2.79 + {
2.80 + return OverrideFunctor<RetType>();
2.81 + }
2.82 +
2.83 + template <class Iface, class RetType@[$2,1,$1:, class Param$2@]>
2.84 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(@[$2,1,$1|, :Param$2@]))
2.85 {
2.86 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
2.87 }
2.88 +
2.89 + template <class Iface, class RetType@[$2,1,$1:, class Param$2@]>
2.90 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(@[$2,1,$1:Param$2, @]...))
2.91 + {
2.92 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
2.93 + }
2.94 @]
2.95 }
2.96
3.1 --- a/sourcehook/sh_list.h Sat Nov 24 06:11:23 2007 +0000
3.2 +++ b/sourcehook/sh_list.h Mon Nov 26 14:03:25 2007 +0000
3.3 @@ -103,6 +103,20 @@
3.4 insert(begin(), obj);
3.5 }
3.6
3.7 + void push_sorted(const T &obj)
3.8 + {
3.9 + iterator iter;
3.10 + for (iter = begin(); iter != end(); ++iter)
3.11 + {
3.12 + if (obj < *iter)
3.13 + {
3.14 + insert(iter, obj);
3.15 + return;
3.16 + }
3.17 + }
3.18 + push_back(obj);
3.19 + }
3.20 +
3.21 size_t size() const
3.22 {
3.23 return m_Size;
3.24 @@ -301,6 +315,7 @@
3.25 return *this;
3.26 }
3.27 };
3.28 +
3.29 }; //NAMESPACE
3.30
3.31 #endif //_INCLUDE_CSDM_LIST_H
4.1 --- a/sourcehook/sh_memory.h Sat Nov 24 06:11:23 2007 +0000
4.2 +++ b/sourcehook/sh_memory.h Mon Nov 26 14:03:25 2007 +0000
4.3 @@ -38,11 +38,12 @@
4.4 // We need to align addr down to pagesize on linux
4.5 // We assume PAGESIZE is a power of two
4.6 # define SH_LALIGN(x) (void*)((intptr_t)(x) & ~(PAGESIZE-1))
4.7 -# define SH_LALDIF(x) ((intptr_t)(x) & (PAGESIZE-1))
4.8 +# define SH_LALDIF(x) ((intptr_t)(x) % PAGESIZE)
4.9 # else
4.10 # error Unsupported OS/Compiler
4.11 # endif
4.12
4.13 +#include "sh_list.h"
4.14
4.15 namespace SourceHook
4.16 {
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/sourcehook/sh_pagealloc.h Mon Nov 26 14:03:25 2007 +0000
5.3 @@ -0,0 +1,288 @@
5.4 +#ifndef __SH_PAGEALLOC_H__
5.5 +#define __SH_PAGEALLOC_H__
5.6 +
5.7 +# if /********/ defined _WIN32
5.8 +# include <windows.h>
5.9 +# elif /******/ defined __linux__
5.10 +# include <sys/mman.h>
5.11 +# include <unistd.h>
5.12 +# else
5.13 +# error Unsupported OS/Compiler
5.14 +# endif
5.15 +
5.16 +
5.17 +namespace SourceHook
5.18 +{
5.19 +
5.20 + /*
5.21 + Class which lets us allocate memory regions in special pages only meant for on the fly code generation.
5.22 +
5.23 + If we alloc with malloc and then set the page access type to read/exec only, other regions returned by
5.24 + malloc that are in the same page would lose their write access as well and the process could crash.
5.25 +
5.26 + Allocating one page per code generation session is usually a waste of memory and on some platforms also
5.27 + a waste of virtual address space (Windows� VirtualAlloc has a granularity of 64K).
5.28 +
5.29 +
5.30 + IMPORTANT: the memory that Alloc() returns is not a in a defined state!
5.31 + It could be in read+exec OR read+write mode.
5.32 + -> call SetRE() or SetRW() before using allocated memory!
5.33 + */
5.34 + class CPageAlloc
5.35 + {
5.36 + struct AllocationUnit
5.37 + {
5.38 + size_t begin_offset;
5.39 + size_t size;
5.40 +
5.41 + AllocationUnit(size_t p_offs, size_t p_size) : begin_offset(p_offs), size(p_size)
5.42 + {
5.43 + }
5.44 +
5.45 + bool operator < (const AllocationUnit &other) const
5.46 + {
5.47 + return begin_offset < other.begin_offset;
5.48 + }
5.49 + };
5.50 +
5.51 + typedef List<AllocationUnit> AUList;
5.52 + struct AllocatedRegion
5.53 + {
5.54 + void *startPtr;
5.55 + size_t size;
5.56 + bool isolated; // may contain only one AU
5.57 + size_t minAlignment;
5.58 + AUList allocUnits;
5.59 +
5.60 + void CheckGap(size_t gap_begin, size_t gap_end, size_t reqsize,
5.61 + size_t &smallestgap_pos, size_t &smallestgap_size, size_t &outAlignBytes)
5.62 + {
5.63 + size_t gapsize = gap_end - gap_begin;
5.64 + // How many bytes do we actually need here?
5.65 + // = requested size + alignment bytes
5.66 + size_t neededSize = reqsize;
5.67 + size_t alignBytes = minAlignment - ((reinterpret_cast<intptr_t>(startPtr) + gap_begin) % minAlignment);
5.68 +
5.69 + alignBytes %= minAlignment;
5.70 + neededSize += alignBytes;
5.71 +
5.72 + if (gapsize >= neededSize)
5.73 + {
5.74 + if (gapsize < smallestgap_size)
5.75 + {
5.76 + smallestgap_size = gapsize;
5.77 + smallestgap_pos = gap_begin;
5.78 + outAlignBytes = alignBytes;
5.79 + }
5.80 + }
5.81 + }
5.82 +
5.83 + bool TryAlloc(size_t reqsize, void * &outAddr)
5.84 + {
5.85 + // Check for isolated
5.86 + if (isolated && !allocUnits.empty())
5.87 + return false;
5.88 +
5.89 + // Find the smallest gap where req fits
5.90 + size_t lastend = 0;
5.91 + size_t smallestgap_pos = size + 1;
5.92 + size_t smallestgap_size = size + 1;
5.93 + size_t alignmentbytes = 0;
5.94 +
5.95 + for (AUList::iterator iter = allocUnits.begin(); iter != allocUnits.end(); ++iter)
5.96 + {
5.97 + CheckGap(lastend, iter->begin_offset, reqsize, smallestgap_pos, smallestgap_size, alignmentbytes);
5.98 + lastend = iter->begin_offset + iter->size;
5.99 + }
5.100 +
5.101 + CheckGap(lastend, size, reqsize, smallestgap_pos, smallestgap_size, alignmentbytes);
5.102 +
5.103 + if (smallestgap_pos < size)
5.104 + {
5.105 + outAddr = reinterpret_cast<void*>(reinterpret_cast<char*>(startPtr) + smallestgap_pos + alignmentbytes);
5.106 + allocUnits.push_sorted( AllocationUnit(smallestgap_pos, reqsize + alignmentbytes) );
5.107 + return true;
5.108 + }
5.109 + else
5.110 + {
5.111 + return false;
5.112 + }
5.113 + }
5.114 +
5.115 + bool TryFree(void *addr)
5.116 + {
5.117 + if (addr < startPtr || addr >= reinterpret_cast<void*>(reinterpret_cast<char*>(startPtr) + size))
5.118 + return false;
5.119 +
5.120 + intptr_t start = reinterpret_cast<intptr_t>(startPtr);
5.121 +
5.122 + for (AUList::iterator iter = allocUnits.begin(); iter != allocUnits.end(); ++iter)
5.123 + {
5.124 + size_t AUBegin = start + iter->begin_offset;
5.125 + void *alignedAUBegin = reinterpret_cast<void*>(
5.126 + AUBegin + ((minAlignment - AUBegin % minAlignment) % minAlignment)
5.127 + );
5.128 +
5.129 + if (addr == alignedAUBegin)
5.130 + {
5.131 + allocUnits.erase(iter);
5.132 + return true;
5.133 + }
5.134 + }
5.135 +
5.136 + return false;
5.137 + }
5.138 +
5.139 + bool Contains(void *addr)
5.140 + {
5.141 + return addr >= startPtr && addr < reinterpret_cast<void*>(reinterpret_cast<char*>(startPtr) + size);
5.142 + }
5.143 +
5.144 + void FreeRegion()
5.145 + {
5.146 +#ifdef __linux__
5.147 + munmap(startPtr, size);
5.148 +#else
5.149 + VirtualFree(startPtr, 0, MEM_RELEASE);
5.150 +#endif
5.151 + }
5.152 + };
5.153 +
5.154 + typedef List<AllocatedRegion> ARList;
5.155 +
5.156 + size_t m_MinAlignment;
5.157 + size_t m_PageSize;
5.158 + ARList m_Regions;
5.159 +
5.160 + bool AddRegion(size_t minSize, bool isolated)
5.161 + {
5.162 + AllocatedRegion newRegion;
5.163 + newRegion.startPtr = 0;
5.164 + newRegion.isolated = isolated;
5.165 + newRegion.minAlignment = m_MinAlignment;
5.166 +
5.167 + // Compute real size -> align up to m_PageSize boundary
5.168 +
5.169 + newRegion.size = minSize - (minSize % m_PageSize);
5.170 + if (newRegion.size < minSize)
5.171 + newRegion.size += m_PageSize;
5.172 +
5.173 +#ifdef __linux__
5.174 + newRegion.startPtr = mmap(0, newRegion.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
5.175 +#else
5.176 + newRegion.startPtr = VirtualAlloc(NULL, newRegion.size, MEM_COMMIT, PAGE_READWRITE);
5.177 +#endif
5.178 +
5.179 + if (newRegion.startPtr)
5.180 + {
5.181 + m_Regions.push_back(newRegion);
5.182 + return true;
5.183 + }
5.184 + else
5.185 + {
5.186 + return false;
5.187 + }
5.188 +
5.189 + }
5.190 +
5.191 + void *AllocPriv(size_t size, bool isolated)
5.192 + {
5.193 + void *addr;
5.194 +
5.195 + if (!isolated)
5.196 + {
5.197 + for (ARList::iterator iter = m_Regions.begin(); iter != m_Regions.end(); ++iter)
5.198 + {
5.199 + if (iter->TryAlloc(size, addr))
5.200 + return addr;
5.201 + }
5.202 + }
5.203 +
5.204 + if (!AddRegion(size, isolated))
5.205 + return NULL;
5.206 +
5.207 + bool tmp = m_Regions.back().TryAlloc(size, addr);
5.208 + SH_ASSERT(tmp, ("TryAlloc fails after AddRegion"));
5.209 + return tmp ? addr : NULL;
5.210 + }
5.211 +
5.212 + public:
5.213 + CPageAlloc(size_t minAlignment = 1 /* power of 2 */ ) : m_MinAlignment(minAlignment)
5.214 + {
5.215 +#ifdef __linux__
5.216 + m_PageSize = sysconf(_SC_PAGESIZE);
5.217 +#else
5.218 + SYSTEM_INFO sysInfo;
5.219 + GetSystemInfo(&sysInfo);
5.220 + m_PageSize = sysInfo.dwPageSize;
5.221 +#endif
5.222 + }
5.223 +
5.224 + ~CPageAlloc()
5.225 + {
5.226 + // Free all regions
5.227 + for (ARList::iterator iter = m_Regions.begin(); iter != m_Regions.end(); ++iter)
5.228 + {
5.229 + iter->FreeRegion();
5.230 + }
5.231 + }
5.232 +
5.233 + void *Alloc(size_t size)
5.234 + {
5.235 + return AllocPriv(size, false);
5.236 + }
5.237 +
5.238 + void *AllocIsolated(size_t size)
5.239 + {
5.240 + return AllocPriv(size, true);
5.241 + }
5.242 +
5.243 + void Free(void *ptr)
5.244 + {
5.245 + for (ARList::iterator iter = m_Regions.begin(); iter != m_Regions.end(); ++iter)
5.246 + {
5.247 + if (iter->TryFree(ptr))
5.248 + {
5.249 + if (iter->allocUnits.empty())
5.250 + {
5.251 + iter->FreeRegion();
5.252 + m_Regions.erase(iter);
5.253 + }
5.254 + break;
5.255 + }
5.256 + }
5.257 + }
5.258 +
5.259 + void SetRE(void *ptr)
5.260 + {
5.261 + for (ARList::iterator iter = m_Regions.begin(); iter != m_Regions.end(); ++iter)
5.262 + {
5.263 + if (iter->Contains(ptr))
5.264 + {
5.265 + SetMemAccess(iter->startPtr, iter->size, SH_MEM_READ | SH_MEM_EXEC);
5.266 + break;
5.267 + }
5.268 + }
5.269 + }
5.270 +
5.271 + void SetRW(void *ptr)
5.272 + {
5.273 + for (ARList::iterator iter = m_Regions.begin(); iter != m_Regions.end(); ++iter)
5.274 + {
5.275 + if (iter->Contains(ptr))
5.276 + {
5.277 + SetMemAccess(iter->startPtr, iter->size, SH_MEM_READ | SH_MEM_WRITE);
5.278 + break;
5.279 + }
5.280 + }
5.281 + }
5.282 +
5.283 + size_t GetPageSize()
5.284 + {
5.285 + return m_PageSize;
5.286 + }
5.287 + };
5.288 +}
5.289 +
5.290 +#endif
5.291 +
6.1 --- a/sourcehook/sourcehook.cpp Sat Nov 24 06:11:23 2007 +0000
6.2 +++ b/sourcehook/sourcehook.cpp Mon Nov 26 14:03:25 2007 +0000
6.3 @@ -151,6 +151,25 @@
6.4
6.5 return true;
6.6 }
6.7 +
6.8 + bool CProto::ExactlyEqual(const CProto &other) const
6.9 + {
6.10 + if (m_Version != other.m_Version ||
6.11 + m_NumOfParams != other.m_NumOfParams ||
6.12 + m_Convention != other.m_Convention ||
6.13 + GetRet() != other.GetRet())
6.14 + {
6.15 + return false;
6.16 + }
6.17 +
6.18 + for (int i = 0; i < m_NumOfParams; ++i)
6.19 + {
6.20 + if(GetParam(i) != other.GetParam(i))
6.21 + return false;
6.22 + }
6.23 +
6.24 + return true;
6.25 + }
6.26
6.27 //////////////////////////////////////////////////////////////////////////
6.28 // CHookManager
7.1 --- a/sourcehook/sourcehook.h Sat Nov 24 06:11:23 2007 +0000
7.2 +++ b/sourcehook/sourcehook.h Mon Nov 26 14:03:25 2007 +0000
7.3 @@ -35,6 +35,11 @@
7.4 // 1 - standard
7.5 #define SH_HOOKMAN_VERSION 1
7.6
7.7 +// Hookmanautogen versions
7.8 +// 1 - initial
7.9 +#define SH_HOOKMANAUTOGEN_IFACE_VERSION 1
7.10 +#define SH_HOOKMANAUTOGEN_IMPL_VERSION 1
7.11 +
7.12 // The value of SH_GLOB_SHPTR has to be a pointer to SourceHook::ISourceHook
7.13 // It's used in various macros
7.14 #ifndef SH_GLOB_SHPTR
7.15 @@ -173,7 +178,13 @@
7.16 PassFlag_ODtor = (1<<2), /**< Object has a destructor */
7.17 PassFlag_OCtor = (1<<3), /**< Object has a normal non-trivial constructor */
7.18 PassFlag_AssignOp = (1<<4), /**< Object has a non-trivial assignment operator */
7.19 - PassFlag_CCtor = (1<<5) /**< Object has a copy constructor (which takes const Object& as only parameter) */
7.20 + PassFlag_CCtor = (1<<5), /**< Object has a copy constructor (which takes const Object& as only parameter) */
7.21 +
7.22 + // The following two flags are only relevant for byval return types.
7.23 + // SH tries to auto-detect these
7.24 + // If you want to override SH's auto-detection, pass them in yourself
7.25 + PassFlag_RetMem = (1<<6), /**< Object is returned in memory (through hidden first param */
7.26 + PassFlag_RetReg = (1<<7) /**< Object is returned in EAX(:EDX) */
7.27 };
7.28
7.29 size_t size; //!< Size of the data being passed
7.30 @@ -196,9 +207,13 @@
7.31 {
7.32 enum CallConvention
7.33 {
7.34 - CallConv_Unknown, /**< Unknown -- no extra info available */
7.35 - CallConv_ThisCall, /**< This call (object pointer required) */
7.36 - CallConv_Cdecl, /**< Standard C call */
7.37 + CallConv_Unknown, /**< Unknown -- no extra info available (0)*/
7.38 + CallConv_ThisCall, /**< This call (object pointer required) (1)*/
7.39 + CallConv_Cdecl, /**< C call (2)*/
7.40 + CallConv_StdCall, /**< Windows "stdcall" (3)*/
7.41 +
7.42 + CallConv_HasVarArgs = (1<<16), /**< Has variable arguments */
7.43 + CallConv_HasVafmt = CallConv_HasVarArgs | (1<<17) /**< last params: const char*, ... */
7.44 };
7.45
7.46 int numOfParams; //!< number of parameters
7.47 @@ -462,6 +477,17 @@
7.48 virtual void EndContext(IHookContext *pCtx) = 0;
7.49 };
7.50
7.51 +
7.52 + class IHookManagerAutoGen
7.53 + {
7.54 + public:
7.55 + virtual int GetIfaceVersion() = 0;
7.56 + virtual int GetImplVersion() = 0;
7.57 +
7.58 + virtual HookManagerPubFunc MakeHookMan(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx) = 0;
7.59 + virtual void ReleaseHookMan(HookManagerPubFunc pubFunc) = 0;
7.60 + };
7.61 +
7.62 // For META_RESULT_ORIG_RET and META_RESULT_OVERRIDE_RET:
7.63 // These have to be able to return references. If T is a reference, the pointers returned
7.64 // from the SH_GLOB_SHPTR are pointers to instances of ReferenceCarrier<T>::type.
7.65 @@ -1014,7 +1040,7 @@
7.66 char buf[::SourceHook::STRBUF_LEN]; \
7.67 va_list ap; \
7.68 va_start(ap, fmt); \
7.69 - vsnprintf(buf, sizeof(buf) - 1, fmt, ap); \
7.70 + vsnprintf(buf, sizeof(buf), fmt, ap); \
7.71 buf[sizeof(buf) - 1] = 0; \
7.72 va_end(ap);
7.73
7.74 @@ -6738,11 +6764,23 @@
7.75 }
7.76
7.77 template <class Iface, class RetType>
7.78 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(...))
7.79 + {
7.80 + return OverrideFunctor<RetType>();
7.81 + }
7.82 +
7.83 + template <class Iface, class RetType>
7.84 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)())
7.85 {
7.86 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.87 }
7.88
7.89 + template <class Iface, class RetType>
7.90 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(...))
7.91 + {
7.92 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.93 + }
7.94 +
7.95 template <class Iface, class RetType, class Param1>
7.96 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1))
7.97 {
7.98 @@ -6750,11 +6788,23 @@
7.99 }
7.100
7.101 template <class Iface, class RetType, class Param1>
7.102 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, ...))
7.103 + {
7.104 + return OverrideFunctor<RetType>();
7.105 + }
7.106 +
7.107 + template <class Iface, class RetType, class Param1>
7.108 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1))
7.109 {
7.110 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.111 }
7.112
7.113 + template <class Iface, class RetType, class Param1>
7.114 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, ...))
7.115 + {
7.116 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.117 + }
7.118 +
7.119 template <class Iface, class RetType, class Param1, class Param2>
7.120 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2))
7.121 {
7.122 @@ -6762,11 +6812,23 @@
7.123 }
7.124
7.125 template <class Iface, class RetType, class Param1, class Param2>
7.126 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, ...))
7.127 + {
7.128 + return OverrideFunctor<RetType>();
7.129 + }
7.130 +
7.131 + template <class Iface, class RetType, class Param1, class Param2>
7.132 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2))
7.133 {
7.134 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.135 }
7.136
7.137 + template <class Iface, class RetType, class Param1, class Param2>
7.138 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, ...))
7.139 + {
7.140 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.141 + }
7.142 +
7.143 template <class Iface, class RetType, class Param1, class Param2, class Param3>
7.144 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3))
7.145 {
7.146 @@ -6774,11 +6836,23 @@
7.147 }
7.148
7.149 template <class Iface, class RetType, class Param1, class Param2, class Param3>
7.150 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, ...))
7.151 + {
7.152 + return OverrideFunctor<RetType>();
7.153 + }
7.154 +
7.155 + template <class Iface, class RetType, class Param1, class Param2, class Param3>
7.156 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3))
7.157 {
7.158 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.159 }
7.160
7.161 + template <class Iface, class RetType, class Param1, class Param2, class Param3>
7.162 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, ...))
7.163 + {
7.164 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.165 + }
7.166 +
7.167 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4>
7.168 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4))
7.169 {
7.170 @@ -6786,11 +6860,23 @@
7.171 }
7.172
7.173 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4>
7.174 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, ...))
7.175 + {
7.176 + return OverrideFunctor<RetType>();
7.177 + }
7.178 +
7.179 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4>
7.180 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4))
7.181 {
7.182 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.183 }
7.184
7.185 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4>
7.186 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, ...))
7.187 + {
7.188 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.189 + }
7.190 +
7.191 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
7.192 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5))
7.193 {
7.194 @@ -6798,11 +6884,23 @@
7.195 }
7.196
7.197 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
7.198 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, ...))
7.199 + {
7.200 + return OverrideFunctor<RetType>();
7.201 + }
7.202 +
7.203 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
7.204 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5))
7.205 {
7.206 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.207 }
7.208
7.209 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5>
7.210 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, ...))
7.211 + {
7.212 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.213 + }
7.214 +
7.215 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
7.216 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6))
7.217 {
7.218 @@ -6810,11 +6908,23 @@
7.219 }
7.220
7.221 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
7.222 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, ...))
7.223 + {
7.224 + return OverrideFunctor<RetType>();
7.225 + }
7.226 +
7.227 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
7.228 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6))
7.229 {
7.230 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.231 }
7.232
7.233 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6>
7.234 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, ...))
7.235 + {
7.236 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.237 + }
7.238 +
7.239 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
7.240 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7))
7.241 {
7.242 @@ -6822,11 +6932,23 @@
7.243 }
7.244
7.245 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
7.246 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, ...))
7.247 + {
7.248 + return OverrideFunctor<RetType>();
7.249 + }
7.250 +
7.251 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
7.252 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7))
7.253 {
7.254 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.255 }
7.256
7.257 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7>
7.258 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, ...))
7.259 + {
7.260 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.261 + }
7.262 +
7.263 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
7.264 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8))
7.265 {
7.266 @@ -6834,11 +6956,23 @@
7.267 }
7.268
7.269 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
7.270 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, ...))
7.271 + {
7.272 + return OverrideFunctor<RetType>();
7.273 + }
7.274 +
7.275 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
7.276 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8))
7.277 {
7.278 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.279 }
7.280
7.281 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8>
7.282 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, ...))
7.283 + {
7.284 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.285 + }
7.286 +
7.287 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9>
7.288 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9))
7.289 {
7.290 @@ -6846,11 +6980,23 @@
7.291 }
7.292
7.293 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9>
7.294 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, ...))
7.295 + {
7.296 + return OverrideFunctor<RetType>();
7.297 + }
7.298 +
7.299 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9>
7.300 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9))
7.301 {
7.302 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.303 }
7.304
7.305 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9>
7.306 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, ...))
7.307 + {
7.308 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.309 + }
7.310 +
7.311 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10>
7.312 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10))
7.313 {
7.314 @@ -6858,11 +7004,23 @@
7.315 }
7.316
7.317 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10>
7.318 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, ...))
7.319 + {
7.320 + return OverrideFunctor<RetType>();
7.321 + }
7.322 +
7.323 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10>
7.324 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10))
7.325 {
7.326 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.327 }
7.328
7.329 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10>
7.330 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, ...))
7.331 + {
7.332 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.333 + }
7.334 +
7.335 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11>
7.336 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11))
7.337 {
7.338 @@ -6870,11 +7028,23 @@
7.339 }
7.340
7.341 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11>
7.342 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, ...))
7.343 + {
7.344 + return OverrideFunctor<RetType>();
7.345 + }
7.346 +
7.347 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11>
7.348 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11))
7.349 {
7.350 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.351 }
7.352
7.353 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11>
7.354 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, ...))
7.355 + {
7.356 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.357 + }
7.358 +
7.359 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12>
7.360 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12))
7.361 {
7.362 @@ -6882,11 +7052,23 @@
7.363 }
7.364
7.365 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12>
7.366 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, ...))
7.367 + {
7.368 + return OverrideFunctor<RetType>();
7.369 + }
7.370 +
7.371 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12>
7.372 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12))
7.373 {
7.374 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.375 }
7.376
7.377 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12>
7.378 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, ...))
7.379 + {
7.380 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.381 + }
7.382 +
7.383 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13>
7.384 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13))
7.385 {
7.386 @@ -6894,11 +7076,23 @@
7.387 }
7.388
7.389 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13>
7.390 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, ...))
7.391 + {
7.392 + return OverrideFunctor<RetType>();
7.393 + }
7.394 +
7.395 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13>
7.396 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13))
7.397 {
7.398 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.399 }
7.400
7.401 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13>
7.402 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, ...))
7.403 + {
7.404 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.405 + }
7.406 +
7.407 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14>
7.408 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14))
7.409 {
7.410 @@ -6906,11 +7100,23 @@
7.411 }
7.412
7.413 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14>
7.414 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, ...))
7.415 + {
7.416 + return OverrideFunctor<RetType>();
7.417 + }
7.418 +
7.419 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14>
7.420 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14))
7.421 {
7.422 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.423 }
7.424
7.425 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14>
7.426 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, ...))
7.427 + {
7.428 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.429 + }
7.430 +
7.431 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15>
7.432 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15))
7.433 {
7.434 @@ -6918,11 +7124,23 @@
7.435 }
7.436
7.437 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15>
7.438 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, ...))
7.439 + {
7.440 + return OverrideFunctor<RetType>();
7.441 + }
7.442 +
7.443 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15>
7.444 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15))
7.445 {
7.446 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.447 }
7.448
7.449 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15>
7.450 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, ...))
7.451 + {
7.452 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.453 + }
7.454 +
7.455 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16>
7.456 OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16))
7.457 {
7.458 @@ -6930,11 +7148,23 @@
7.459 }
7.460
7.461 template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16>
7.462 + OverrideFunctor<RetType> SetOverrideResult(RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16, ...))
7.463 + {
7.464 + return OverrideFunctor<RetType>();
7.465 + }
7.466 +
7.467 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16>
7.468 Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16))
7.469 {
7.470 return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.471 }
7.472
7.473 + template <class Iface, class RetType, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class Param14, class Param15, class Param16>
7.474 + Iface *RecallGetIface(ISourceHook *shptr, RetType (Iface::*mfp)(Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, Param14, Param15, Param16, ...))
7.475 + {
7.476 + return reinterpret_cast<Iface*>(shptr->GetIfacePtr());
7.477 + }
7.478 +
7.479 }
7.480
7.481 #endif
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/sourcehook/sourcehook_hookmangen.cpp Mon Nov 26 14:03:25 2007 +0000
8.3 @@ -0,0 +1,2030 @@
8.4 +/* ======== SourceHook ========
8.5 +* Copyright (C) 2004-2007 Metamod:Source Development Team
8.6 +* No warranties of any kind
8.7 +*
8.8 +* License: zlib/libpng
8.9 +*
8.10 +* Author(s): Pavol "PM OnoTo" Marko
8.11 +* Contributor(s): Borja "faluco" Ferav (many thanks for assitance!)
8.12 +* David "BAILOPAN" Anderson
8.13 +* ============================
8.14 +*/
8.15 +
8.16 +// recommended literature:
8.17 +// http://www.cs.umbc.edu/~chang/cs313.s02/stack.shtml
8.18 +// http://www.angelcode.com/dev/callconv/callconv.html
8.19 +// http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_6/CH06-1.html
8.20 +
8.21 +#include "sourcehook_impl.h"
8.22 +#include "sourcehook_hookmangen.h"
8.23 +#include "sourcehook_hookmangen_x86.h"
8.24 +#include "sh_memory.h"
8.25 +#include <stdarg.h> // we might need the address of vsnprintf
8.26 +#include <stdio.h>
8.27 +
8.28 +#if SH_COMP == SH_COMP_MSVC
8.29 +# define GCC_ONLY(x)
8.30 +# define MSVC_ONLY(x) x
8.31 +#elif SH_COMP == SH_COMP_GCC
8.32 +# define GCC_ONLY(x) x
8.33 +# define MSVC_ONLY(x)
8.34 +#endif
8.35 +
8.36 +// :TODO: test BIG vtable indices
8.37 +
8.38 +namespace SourceHook
8.39 +{
8.40 + namespace Impl
8.41 + {
8.42 + CPageAlloc GenBuffer::ms_Allocator(16);
8.43 +
8.44 + template <class T>
8.45 + jit_int32_t DownCastPtr(T ptr)
8.46 + {
8.47 + return reinterpret_cast<jit_int32_t>(ptr);
8.48 + }
8.49 +
8.50 + jit_uint32_t DownCastSize(size_t size)
8.51 + {
8.52 + return static_cast<jit_uint32_t>(size);
8.53 + }
8.54 +
8.55 + GenContext::GenContext(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx, ISourceHook *pSHPtr)
8.56 + : m_GeneratedPubFunc(NULL), m_OrigProto(proto), m_Proto(proto), m_VtblOffs(vtbl_offs),
8.57 + m_VtblIdx(vtbl_idx), m_SHPtr(pSHPtr), m_pHI(NULL), m_HookfuncVfnptr(NULL), m_RegCounter(0)
8.58 + {
8.59 + m_pHI = new void*;
8.60 + m_HookfuncVfnptr = new void*;
8.61 + m_BuiltPI = new ProtoInfo;
8.62 + m_BuiltPI_Params = NULL;
8.63 + m_BuiltPI_Params2 = NULL;
8.64 + }
8.65 +
8.66 + GenContext::~GenContext()
8.67 + {
8.68 + Clear();
8.69 + delete m_pHI;
8.70 + delete m_HookfuncVfnptr;
8.71 + delete m_BuiltPI;
8.72 + }
8.73 +
8.74 + void GenContext::Clear()
8.75 + {
8.76 + m_HookFunc.clear();
8.77 + m_PubFunc.clear();
8.78 + if (m_BuiltPI_Params)
8.79 + {
8.80 + delete m_BuiltPI_Params;
8.81 + m_BuiltPI_Params = NULL;
8.82 + }
8.83 + if (m_BuiltPI_Params2)
8.84 + {
8.85 + delete m_BuiltPI_Params2;
8.86 + m_BuiltPI_Params2 = NULL;
8.87 + }
8.88 + }
8.89 +
8.90 + void GenContext::BuildProtoInfo()
8.91 + {
8.92 + m_BuiltPI->convention = m_Proto.GetConvention();
8.93 + m_BuiltPI->numOfParams = m_Proto.GetNumOfParams();
8.94 +
8.95 + m_BuiltPI->retPassInfo.size = m_Proto.GetRet().size;
8.96 + m_BuiltPI->retPassInfo.type = m_Proto.GetRet().type;
8.97 + m_BuiltPI->retPassInfo.flags = m_Proto.GetRet().flags;
8.98 + m_BuiltPI->retPassInfo2.pNormalCtor = m_Proto.GetRet().pNormalCtor;
8.99 + m_BuiltPI->retPassInfo2.pCopyCtor = m_Proto.GetRet().pCopyCtor;
8.100 + m_BuiltPI->retPassInfo2.pDtor = m_Proto.GetRet().pDtor;
8.101 + m_BuiltPI->retPassInfo2.pAssignOperator = m_Proto.GetRet().pAssignOperator;
8.102 +
8.103 + if (m_BuiltPI_Params)
8.104 + delete m_BuiltPI_Params;
8.105 + m_BuiltPI_Params = new PassInfo[m_BuiltPI->numOfParams + 1];
8.106 + if (m_BuiltPI_Params2)
8.107 + delete m_BuiltPI_Params2;
8.108 + m_BuiltPI_Params2 = new PassInfo::V2Info[m_BuiltPI->numOfParams + 1];
8.109 +
8.110 + m_BuiltPI_Params[0].size = 1; // Version 1
8.111 + m_BuiltPI_Params[0].type = 0;
8.112 + m_BuiltPI_Params[0].flags = 0;
8.113 +
8.114 + for (int i = 0; i < m_Proto.GetNumOfParams(); ++i)
8.115 + {
8.116 + m_BuiltPI_Params[i+1].size = m_Proto.GetParam(i).size;
8.117 + m_BuiltPI_Params[i+1].type = m_Proto.GetParam(i).type;
8.118 + m_BuiltPI_Params[i+1].flags = m_Proto.GetParam(i).flags;
8.119 +
8.120 + m_BuiltPI_Params2[i+1].pNormalCtor = m_Proto.GetParam(i).pNormalCtor;
8.121 + m_BuiltPI_Params2[i+1].pCopyCtor = m_Proto.GetParam(i).pCopyCtor;
8.122 + m_BuiltPI_Params2[i+1].pDtor = m_Proto.GetParam(i).pDtor;
8.123 + m_BuiltPI_Params2[i+1].pAssignOperator = m_Proto.GetParam(i).pAssignOperator;
8.124 + }
8.125 +
8.126 + m_BuiltPI->paramsPassInfo = m_BuiltPI_Params;
8.127 + m_BuiltPI->paramsPassInfo2 = m_BuiltPI_Params2;
8.128 + }
8.129 +
8.130 + jit_int32_t GenContext::GetRealSize(const IntPassInfo &info)
8.131 + {
8.132 + if (info.flags & (PassInfo::PassFlag_ByRef | PassFlag_ForcedByRef))
8.133 + {
8.134 + return SIZE_PTR;
8.135 + }
8.136 + return static_cast<jit_int32_t>(info.size);
8.137 + }
8.138 +
8.139 + jit_int32_t GenContext::AlignSize(jit_int32_t x, jit_int32_t boundary)
8.140 + {
8.141 + if (x % boundary != 0)
8.142 + x = (x & ~(boundary-1)) + boundary;
8.143 + return x;
8.144 + }
8.145 +
8.146 + // Computes size on the stack
8.147 + jit_int32_t GenContext::GetParamStackSize(const IntPassInfo &info)
8.148 + {
8.149 + // Align up to 4 byte boundaries
8.150 + return AlignSize(GetRealSize(info), 4);
8.151 + }
8.152 +
8.153 + jit_int8_t GenContext::NextRegEBX_ECX_EDX()
8.154 + {
8.155 + switch ((m_RegCounter++) % 3)
8.156 + {
8.157 + case 0:
8.158 + return REG_EBX;
8.159 + case 1:
8.160 + return REG_ECX;
8.161 + case 2:
8.162 + default:
8.163 + m_RegCounter = 0;
8.164 + return REG_EDX;
8.165 + }
8.166 + }
8.167 +
8.168 + void GenContext::BitwiseCopy_Setup()
8.169 + {
8.170 + //cld
8.171 + //push edi
8.172 + //push esi
8.173 +
8.174 + IA32_Cld(&m_HookFunc);
8.175 + IA32_Push_Reg(&m_HookFunc, REG_EDI);
8.176 + IA32_Push_Reg(&m_HookFunc, REG_ESI);
8.177 + }
8.178 +
8.179 + void GenContext::BitwiseCopy_Do(size_t size)
8.180 + {
8.181 + jit_uint32_t dwords = DownCastSize(size) / 4;
8.182 + jit_uint32_t bytes = DownCastSize(size) % 4;
8.183 +
8.184 + //if dwords
8.185 + // mov ecx, <dwords>
8.186 + // rep movsd
8.187 + //if bytes
8.188 + // mov ecx, <bytes>
8.189 + // rep movsb
8.190 + //pop esi
8.191 + //pop edi
8.192 +
8.193 + if (dwords)
8.194 + {
8.195 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_ECX, dwords);
8.196 + IA32_Rep(&m_HookFunc);
8.197 + IA32_Movsd(&m_HookFunc);
8.198 + }
8.199 + if (bytes)
8.200 + {
8.201 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_ECX, bytes);
8.202 + IA32_Rep(&m_HookFunc);
8.203 + IA32_Movsb(&m_HookFunc);
8.204 + }
8.205 + IA32_Pop_Reg(&m_HookFunc, REG_ESI);
8.206 + IA32_Pop_Reg(&m_HookFunc, REG_EDI);
8.207 + }
8.208 +
8.209 + jit_int32_t GenContext::AlignStackBeforeCall(int paramsize, int flags)
8.210 + {
8.211 + paramsize +=
8.212 + GCC_ONLY( ((flags & AlignStack_GCC_ThisOnStack)!=0 ? SIZE_PTR : 0) + )
8.213 + MSVC_ONLY( ((flags & AlignStack_MSVC_ThisOnStack)!=0 ? SIZE_PTR : 0) + )
8.214 + ((flags & AlignStack_MemRet)!=0 ? SIZE_PTR : 0);
8.215 +
8.216 + // At the beginning of the hookfunc, the stack is aligned to a 16 bytes boundary.
8.217 + // Then, m_BytesPushedAfterInitialAlignment were pushed (can also be 0).
8.218 +
8.219 + // After this function is called, paramsize bytes will be pushed onto the stack
8.220 + // After that, the alignment has to be a 16 bytes boundary again.
8.221 +
8.222 +
8.223 + // How many bytes we would subtract if the alignment was alright now:
8.224 + int subtractFromEsp = 16 - (paramsize % 16);
8.225 + if (subtractFromEsp == 16)
8.226 + subtractFromEsp = 0;
8.227 +
8.228 + // But: there might be bytes pushed alreay!
8.229 + subtractFromEsp -= m_BytesPushedAfterInitialAlignment;
8.230 +
8.231 + // For example: paramsize was 0 and m_BytesPushedAfterInitialAlignment was 4.
8.232 + // we then have to push another 12 bytes to reach 16 bytes alignment again.
8.233 +
8.234 + if (subtractFromEsp < 0)
8.235 + subtractFromEsp = 16 - ((-subtractFromEsp) % 16);
8.236 +
8.237 + if (subtractFromEsp != 0)
8.238 + IA32_Sub_Rm_ImmAuto(&m_HookFunc, REG_ESP, subtractFromEsp, MOD_REG);
8.239 +
8.240 + return subtractFromEsp;
8.241 + }
8.242 +
8.243 + void GenContext::AlignStackAfterCall(jit_int32_t numofbytes)
8.244 + {
8.245 + if (numofbytes != 0)
8.246 + IA32_Add_Rm_ImmAuto(&m_HookFunc, REG_ESP, numofbytes, MOD_REG);
8.247 + }
8.248 +
8.249 + void GenContext::CheckAlignmentBeforeCall()
8.250 + {
8.251 +#if 0
8.252 + IA32_Test_Rm_Imm32(&m_HookFunc, REG_ESP, 15, MOD_REG);
8.253 + IA32_Jump_Cond_Imm8(&m_HookFunc, CC_Z, 1);
8.254 + IA32_Int3(&m_HookFunc);
8.255 +#endif
8.256 + }
8.257 +
8.258 + short GenContext::GetParamsTotalStackSize()
8.259 + {
8.260 + short acc = 0;
8.261 + for (int i = 0; i < m_Proto.GetNumOfParams(); ++i)
8.262 + {
8.263 + acc += GetParamStackSize(m_Proto.GetParam(i));
8.264 + }
8.265 +
8.266 + return acc;
8.267 + }
8.268 +
8.269 + short GenContext::GetForcedByRefParamOffset(int p)
8.270 + {
8.271 + short off = 0;
8.272 + for (int i = 0; i < p; ++i)
8.273 + {
8.274 + if (m_Proto.GetParam(i).flags & PassFlag_ForcedByRef)
8.275 + off += AlignSize(static_cast<jit_int32_t>(m_Proto.GetParam(i).size), 4);
8.276 + }
8.277 + return off;
8.278 + }
8.279 +
8.280 + short GenContext::GetForcedByRefParamsSize()
8.281 + {
8.282 + return GetForcedByRefParamOffset(m_Proto.GetNumOfParams());
8.283 + }
8.284 +
8.285 + jit_int32_t GenContext::PushRef(jit_int32_t param_offset, const IntPassInfo &pi)
8.286 + {
8.287 + // push [ebp+<offset>]
8.288 + IA32_Push_Rm_DispAuto(&m_HookFunc, REG_EBP, param_offset);
8.289 +
8.290 + return SIZE_PTR;
8.291 + }
8.292 +
8.293 + jit_int32_t GenContext::PushBasic(jit_int32_t param_offset, const IntPassInfo &pi)
8.294 + {
8.295 + int reg;
8.296 + int reg2;
8.297 +
8.298 + switch (pi.size)
8.299 + {
8.300 + default:
8.301 + SH_ASSERT(0, ("Unsupported!"));
8.302 + return 0;
8.303 + case 1:
8.304 + reg = NextRegEBX_ECX_EDX();
8.305 + //movzx reg, BYTE PTR [ebp+<offset>]
8.306 + //push reg
8.307 + IA32_Movzx_Reg32_Rm8_DispAuto(&m_HookFunc, reg, REG_EBP, param_offset);
8.308 + IA32_Push_Reg(&m_HookFunc, reg);
8.309 +
8.310 + return 4;
8.311 + case 2:
8.312 + reg = NextRegEBX_ECX_EDX();
8.313 + //movzx reg, WORD PTR [ebp+<offset>]
8.314 + //push reg
8.315 + m_HookFunc.write_ubyte(IA32_16BIT_PREFIX);
8.316 + IA32_Movzx_Reg32_Rm16_DispAuto(&m_HookFunc, reg, REG_EBP, param_offset);
8.317 + IA32_Push_Reg(&m_HookFunc, reg);
8.318 +
8.319 + return 4;
8.320 + case 4:
8.321 + reg = NextRegEBX_ECX_EDX();
8.322 + //mov reg, DWORD PTR [ebp+<offset>]
8.323 + //push reg
8.324 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, reg, REG_EBP, param_offset);
8.325 + IA32_Push_Reg(&m_HookFunc, reg);
8.326 +
8.327 + return 4;
8.328 + case 8:
8.329 + reg = NextRegEBX_ECX_EDX();
8.330 + reg2 = NextRegEBX_ECX_EDX();
8.331 + //mov reg, DWORD PTR [ebp+<offset>+4]
8.332 + //mov reg2, DWORD PTR [ebp+<offset>]
8.333 + //push reg
8.334 + //push reg2
8.335 +
8.336 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, reg, REG_EBP, param_offset+4);
8.337 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, reg2, REG_EBP, param_offset);
8.338 + IA32_Push_Reg(&m_HookFunc, reg);
8.339 + IA32_Push_Reg(&m_HookFunc, reg2);
8.340 +
8.341 + return 8;
8.342 + }
8.343 + }
8.344 +
8.345 + jit_int32_t GenContext::PushFloat(jit_int32_t param_offset, const IntPassInfo &pi)
8.346 + {
8.347 + switch (pi.size)
8.348 + {
8.349 + default:
8.350 + SH_ASSERT(0, ("Unsupported!"));
8.351 + return 0;
8.352 + case 4:
8.353 + //fld DWORD PTR [ebp+<offset>]
8.354 + //push reg
8.355 + //fstp DWORD PTR [esp]
8.356 + IA32_Fld_Mem32_DispAuto(&m_HookFunc, REG_EBP, param_offset);
8.357 + IA32_Push_Reg(&m_HookFunc, NextRegEBX_ECX_EDX());
8.358 + IA32_Fstp_Mem32_ESP(&m_HookFunc);
8.359 + return 4;
8.360 + case 8:
8.361 + //fld QWORD PTR [ebp+<offset>]
8.362 + //sub esp, 8
8.363 + //fstp QWORD PTR [esp]
8.364 + IA32_Fld_Mem64_DispAuto(&m_HookFunc, REG_EBP, param_offset);
8.365 + IA32_Sub_Rm_Imm8(&m_HookFunc, REG_ESP, 8, MOD_REG);
8.366 + IA32_Fstp_Mem64_ESP(&m_HookFunc);
8.367 + return 8;
8.368 + }
8.369 + }
8.370 +
8.371 + jit_int32_t GenContext::PushObject(jit_int32_t param_offset, const IntPassInfo &pi, jit_int32_t place_fbrr)
8.372 + {
8.373 + if ((pi.flags & PassFlag_ForcedByRef) == 0)
8.374 + {
8.375 + // make room on the stack
8.376 + // sub esp, <size>
8.377 + IA32_Sub_Rm_ImmAuto(&m_HookFunc, REG_ESP, GetParamStackSize(pi), MOD_REG);
8.378 + }
8.379 +
8.380 + // if there is a copy constructor..
8.381 + if (pi.pCopyCtor)
8.382 + {
8.383 + // :TODO: alignment here?
8.384 + // can't use normal alignment methods
8.385 + // because an unknown number of bytes has been pushed already (the other params)
8.386 +
8.387 + // save eax
8.388 + IA32_Push_Reg(&m_HookFunc, REG_EAX);
8.389 +
8.390 + // compute dest addr to ECX
8.391 + // = forcedbyref ? ebp+place_fbrr : esp+12
8.392 + if (pi.flags & PassFlag_ForcedByRef)
8.393 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, place_fbrr);
8.394 + else
8.395 + IA32_Lea_Reg_DispRegMultImm8(&m_HookFunc, REG_ECX, REG_NOIDX, REG_ESP, NOSCALE, 4);
8.396 +
8.397 + // compute src addr to EAX
8.398 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_EAX, REG_EBP, param_offset);
8.399 +
8.400 + // push params (gcc: also this)
8.401 + IA32_Push_Reg(&m_HookFunc, REG_EAX);
8.402 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.403 +
8.404 + // call
8.405 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EDX, DownCastPtr(pi.pCopyCtor));
8.406 + IA32_Call_Reg(&m_HookFunc, REG_EDX);
8.407 +
8.408 + // gcc: clean up stack
8.409 + GCC_ONLY(IA32_Add_Rm_ImmAuto(&m_HookFunc, REG_ESP, 2 * SIZE_PTR, MOD_REG));
8.410 +
8.411 + // restore eax
8.412 + IA32_Pop_Reg(&m_HookFunc, REG_EAX);
8.413 + }
8.414 + else
8.415 + {
8.416 + // bitwise copy
8.417 +
8.418 + BitwiseCopy_Setup();
8.419 +
8.420 + //if forcedbyref:
8.421 + // lea edi, [ebp_place_fbrr]
8.422 + //else
8.423 + // lea edi, [esp+8] - bc_setup pushed two regs onto the stack!
8.424 + //lea esi, [ebp+<offs>]
8.425 + if (pi.flags & PassFlag_ForcedByRef)
8.426 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_EDI, REG_EBP, place_fbrr);
8.427 + else
8.428 + IA32_Lea_Reg_DispRegMultImm8(&m_HookFunc, REG_EDI, REG_NOIDX, REG_ESP, NOSCALE, 8);
8.429 +
8.430 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ESI, REG_EBP, param_offset);
8.431 +
8.432 + BitwiseCopy_Do(pi.size);
8.433 + }
8.434 +
8.435 + // forcedref: push reference to ebp+place_fbrr
8.436 + if (pi.flags & PassFlag_ForcedByRef)
8.437 + {
8.438 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, place_fbrr);
8.439 + IA32_Push_Reg(&m_HookFunc, REG_ECX);
8.440 + return SIZE_PTR;
8.441 + }
8.442 +
8.443 + return GetParamStackSize(pi);
8.444 + }
8.445 +
8.446 + void GenContext::DestroyParams(jit_int32_t fbrr_base)
8.447 + {
8.448 + for (int i = m_Proto.GetNumOfParams() - 1; i >= 0; --i)
8.449 + {
8.450 + const IntPassInfo &pi = m_Proto.GetParam(i);
8.451 + if (pi.type == PassInfo::PassType_Object && (pi.flags & PassInfo::PassFlag_ODtor) &&
8.452 + (pi.flags & PassInfo::PassFlag_ByVal) && (pi.flags & PassFlag_ForcedByRef))
8.453 + {
8.454 + // Actually, this is only for GCC (see line above: ForcedByRef)
8.455 + jit_int32_t tmpAlign = AlignStackBeforeCall(0, AlignStack_GCC_ThisOnStack);
8.456 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, fbrr_base + GetForcedByRefParamOffset(i));
8.457 + IA32_Push_Reg(&m_HookFunc, REG_ECX);
8.458 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(pi.pDtor));
8.459 + CheckAlignmentBeforeCall();
8.460 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.461 + IA32_Pop_Reg(&m_HookFunc, REG_ECX);
8.462 +
8.463 + AlignStackAfterCall(tmpAlign);
8.464 + }
8.465 + }
8.466 + }
8.467 +
8.468 + // May not touch eax!
8.469 + jit_int32_t GenContext::PushParams(jit_int32_t param_base_offset, jit_int32_t save_ret_to, int v_place_for_memret,
8.470 + jit_int32_t v_place_fbrr_base)
8.471 + {
8.472 + jit_int32_t added_to_stack = 0;
8.473 + jit_int32_t ret = 0;
8.474 +
8.475 + // compute the offset _after_ the last parameter
8.476 + jit_int32_t cur_offset = param_base_offset;
8.477 + for (int i = 0; i < m_Proto.GetNumOfParams(); ++i)
8.478 + {
8.479 + cur_offset += GetParamStackSize(m_Proto.GetParam(i));
8.480 + }
8.481 +
8.482 + // push parameters in reverse order
8.483 + for (int i = m_Proto.GetNumOfParams() - 1; i >= 0; --i)
8.484 + {
8.485 + const IntPassInfo &pi = m_Proto.GetParam(i);
8.486 + cur_offset -= GetParamStackSize(pi);
8.487 + if (pi.flags & PassInfo::PassFlag_ByVal)
8.488 + {
8.489 + switch (pi.type)
8.490 + {
8.491 + case PassInfo::PassType_Basic:
8.492 + ret = PushBasic(cur_offset, pi);
8.493 + break;
8.494 + case PassInfo::PassType_Float:
8.495 + ret = PushFloat(cur_offset, pi);
8.496 + break;
8.497 + case PassInfo::PassType_Object:
8.498 + ret = PushObject(cur_offset, pi, v_place_fbrr_base + GetForcedByRefParamOffset(i));
8.499 + break;
8.500 + }
8.501 + }
8.502 + else if (pi.flags & PassInfo::PassFlag_ByRef)
8.503 + {
8.504 + ret = PushRef(cur_offset, pi);
8.505 + }
8.506 + else
8.507 + {
8.508 + SH_ASSERT(0, ("Unsupported!"));
8.509 + }
8.510 + added_to_stack += ret;
8.511 + }
8.512 +
8.513 + return added_to_stack;
8.514 + }
8.515 +
8.516 + // It is IMPORTANT that PushMemRetPtr doesn't touch ecx and eax
8.517 + jit_int32_t GenContext::PushMemRetPtr(jit_int32_t save_ret_to, jit_int32_t v_place_for_memret)
8.518 + {
8.519 + // Memory return support
8.520 + if (m_Proto.GetRet().flags & PassInfo::PassFlag_RetMem)
8.521 + {
8.522 + // push address where to save it!
8.523 + int reg = REG_EDX;
8.524 + IA32_Lea_DispRegImmAuto(&m_HookFunc, reg, REG_EBP,
8.525 + MemRetWithTempObj() ? v_place_for_memret : save_ret_to);
8.526 + IA32_Push_Reg(&m_HookFunc, reg);
8.527 +
8.528 + return (SH_COMP==SH_COMP_MSVC) ? 4 : 0; // varargs funcs on msvc might need this.
8.529 + // gcc doesn't: callee cleans the memret ptr, caller the other params :s
8.530 + }
8.531 + return 0;
8.532 + }
8.533 +
8.534 + void GenContext::SaveRetVal(int v_where, int v_place_for_memret)
8.535 + {
8.536 + size_t size = GetRealSize(m_Proto.GetRet());
8.537 + if (size == 0)
8.538 + {
8.539 + // No return value -> nothing
8.540 + return;
8.541 + }
8.542 +
8.543 + if (m_Proto.GetRet().flags & PassInfo::PassFlag_ByRef)
8.544 + {
8.545 + // mov [ebp + v_plugin_ret], eax
8.546 + IA32_Mov_Rm_Reg_DispAuto(&m_HookFunc, REG_EBP, REG_EAX, v_where);
8.547 + return;
8.548 + }
8.549 + // else: ByVal
8.550 +
8.551 +
8.552 + // Memory return:
8.553 + if (m_Proto.GetRet().flags & PassInfo::PassFlag_RetMem)
8.554 + {
8.555 + if (MemRetWithTempObj())
8.556 + {
8.557 + // *v_where = *v_place_for_memret
8.558 +
8.559 + // if we have an assign operator, use that
8.560 + if (m_Proto.GetRet().pAssignOperator)
8.561 + {
8.562 + // lea edx, [ebp + v_place_for_memret] <-- src addr
8.563 + // lea ecx, [ebp + v_where] <-- dest addr
8.564 + // push edx
8.565 + // gcc: push ecx
8.566 + // call it
8.567 + // gcc: clean up
8.568 +
8.569 + jit_int32_t tmpAlign = AlignStackBeforeCall(SIZE_PTR, AlignStack_GCC_ThisOnStack);
8.570 +
8.571 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_EDX, REG_EBP, v_place_for_memret);
8.572 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, v_where);
8.573 + IA32_Push_Reg(&m_HookFunc, REG_EDX);
8.574 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.575 +
8.576 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(m_Proto.GetRet().pAssignOperator));
8.577 + CheckAlignmentBeforeCall();
8.578 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.579 + GCC_ONLY(IA32_Add_Rm_ImmAuto(&m_HookFunc, REG_ESP, 2 * SIZE_PTR, MOD_REG));
8.580 +
8.581 + AlignStackAfterCall(tmpAlign);
8.582 + }
8.583 + else
8.584 + {
8.585 + // bitwise copy
8.586 + BitwiseCopy_Setup();
8.587 +
8.588 + //lea edi, [evp+v_where] <-- destination
8.589 + //lea esi, [ebp+v_place_for_memret] <-- src
8.590 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_EDI, REG_EBP, v_where);
8.591 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ESI, REG_EBP, v_place_for_memret);
8.592 +
8.593 + BitwiseCopy_Do(m_Proto.GetRet().size);
8.594 + }
8.595 +
8.596 + // Then: destruct *v_place_for_memret if required
8.597 + if (m_Proto.GetRet().pDtor)
8.598 + {
8.599 + //lea ecx, [ebp+v_place_for_memret]
8.600 + //gcc: push ecx
8.601 + //call it
8.602 + //gcc: clean up
8.603 +
8.604 + jit_int32_t tmpAlign = AlignStackBeforeCall(0, AlignStack_GCC_ThisOnStack);
8.605 +
8.606 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, v_place_for_memret);
8.607 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.608 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(m_Proto.GetRet().pDtor));
8.609 + CheckAlignmentBeforeCall();
8.610 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.611 + GCC_ONLY(IA32_Pop_Reg(&m_HookFunc, REG_ECX));
8.612 +
8.613 + AlignStackAfterCall(tmpAlign);
8.614 + }
8.615 + }
8.616 + else
8.617 + {
8.618 + // Already copied to correct address -> we're done
8.619 + return;
8.620 + }
8.621 + }
8.622 +
8.623 + if (m_Proto.GetRet().type == PassInfo::PassType_Float)
8.624 + {
8.625 + if (size == 4)
8.626 + IA32_Fstp_Mem32_DispAuto(&m_HookFunc, REG_EBP, v_where);
8.627 + else if (size == 8)
8.628 + IA32_Fstp_Mem64_DispAuto(&m_HookFunc, REG_EBP, v_where);
8.629 + }
8.630 + else if (m_Proto.GetRet().type == PassInfo::PassType_Basic)
8.631 + {
8.632 + if (size <= 4)
8.633 + {
8.634 + // size <= 4: return in EAX
8.635 + // We align <4 sizes up to 4
8.636 +
8.637 +
8.638 + // mov [ebp + v_plugin_ret], eax
8.639 + IA32_Mov_Rm_Reg_DispAuto(&m_HookFunc, REG_EBP, REG_EAX, v_where);
8.640 + }
8.641 + else if (size <= 8)
8.642 + {
8.643 + // size <= 4: return in EAX:EDX
8.644 + // We align 4<x<8 sizes up to 8
8.645 +
8.646 + // mov [ebp + v_plugin_ret], eax
8.647 + // mov [ebp + v_plugin_ret + 4], edx
8.648 + IA32_Mov_Rm_Reg_DispAuto(&m_HookFunc, REG_EBP, REG_EAX, v_where);
8.649 + IA32_Mov_Rm_Reg_DispAuto(&m_HookFunc, REG_EBP, REG_EDX, v_where + 4);
8.650 + }
8.651 + }
8.652 + else if (m_Proto.GetRet().type == PassInfo::PassType_Object)
8.653 + {
8.654 + if (m_Proto.GetRet().flags & PassInfo::PassFlag_RetReg)
8.655 + {
8.656 + if (size <= 4)
8.657 + {
8.658 + // size <= 4: return in EAX
8.659 + // We align <4 sizes up to 4
8.660 +
8.661 + // mov [ebp + v_plugin_ret], eax
8.662 + IA32_Mov_Rm_Reg_DispAuto(&m_HookFunc, REG_EBP, REG_EAX, v_where);
8.663 + }
8.664 + else if (size <= 8)
8.665 + {
8.666 + // size <= 4: return in EAX:EDX
8.667 + // We align 4<x<8 sizes up to 8
8.668 +
8.669 + // mov [ebp + v_plugin_ret], eax
8.670 + // mov [ebp + v_plugin_ret + 4], edx
8.671 + IA32_Mov_Rm_Reg_DispAuto(&m_HookFunc, REG_EBP, REG_EAX, v_where);
8.672 + IA32_Mov_Rm_Reg_DispAuto(&m_HookFunc, REG_EBP, REG_EDX, v_where + 4);
8.673 + }
8.674 + else
8.675 + {
8.676 + SH_ASSERT(0, ("RetReg and size > 8 !"));
8.677 + }
8.678 + }
8.679 + }
8.680 + }
8.681 +
8.682 + bool GenContext::MemRetWithTempObj()
8.683 + {
8.684 + // Memory return AND (has destructor OR has assign operator)
8.685 + return ((m_Proto.GetRet().flags & PassInfo::PassFlag_RetMem)
8.686 + && (m_Proto.GetRet().flags & (PassInfo::PassFlag_ODtor | PassInfo::PassFlag_AssignOp)));
8.687 + }
8.688 +
8.689 + void GenContext::ProcessPluginRetVal(int v_cur_res, int v_pContext, int v_plugin_ret)
8.690 + {
8.691 + // only for non-void functions!
8.692 + if (m_Proto.GetRet().size == 0)
8.693 + return;
8.694 +
8.695 + // if (cur_res >= MRES_OVERRIDE)
8.696 + // *reinterpret_cast<my_rettype*>(pContext->GetOverrideRetPtr()) = plugin_ret;
8.697 +
8.698 + // eax = cur_res
8.699 + // cmp eax,MRES_OVERRIDE
8.700 + // jnge thelabel
8.701 + // pContext->GetOverrideRetPtr() --> overrideretptr in eax
8.702 + // *eax = plugin_ret
8.703 + // thelabel:
8.704 + //
8.705 +
8.706 + jitoffs_t tmppos, counter;
8.707 +
8.708 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EAX, REG_EBP, v_cur_res);
8.709 +
8.710 + IA32_Cmp_Rm_Imm32(&m_HookFunc, MOD_REG, REG_EAX, MRES_OVERRIDE);
8.711 + tmppos = IA32_Jump_Cond_Imm8(&m_HookFunc, CC_NGE, 0);
8.712 + m_HookFunc.start_count(counter);
8.713 +
8.714 + // eax = pContext->GetOverrideRetPtr() no alignment needs
8.715 + // ECX = pContext
8.716 + // gcc: push ecx
8.717 + // eax = [ecx]
8.718 + // eax = [eax + 4]
8.719 + // call eax
8.720 + // gcc: clean up
8.721 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_ECX, REG_EBP, v_pContext);
8.722 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.723 +
8.724 + // vtbloffs=0, vtblidx=1
8.725 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EAX, REG_ECX, MOD_MEM_REG);
8.726 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EAX, REG_EAX, 4);
8.727 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.728 + GCC_ONLY(IA32_Pop_Reg(&m_HookFunc, REG_ECX));
8.729 +
8.730 +
8.731 + // *eax = plugin_ret
8.732 + if (m_Proto.GetRet().flags & PassInfo::PassFlag_ByRef)
8.733 + {
8.734 + // mov ecx, [ebp+v_plugin_ret]
8.735 + // mov [eax], ecx
8.736 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_ECX, REG_EBP, v_plugin_ret);
8.737 + IA32_Mov_Rm_Reg(&m_HookFunc, REG_EAX, REG_ECX, MOD_MEM_REG);
8.738 + }
8.739 + else
8.740 + {
8.741 + if (m_Proto.GetRet().pAssignOperator)
8.742 + {
8.743 + // lea edx, [ebp + v_plugin_ret]
8.744 + // push edx <-- src addr
8.745 + // msvc: ecx = eax <-- dest addr
8.746 + // gcc: push eax <-- dest addr
8.747 + // call it
8.748 + // gcc: clean up
8.749 +
8.750 + jit_int32_t tmpAlign = AlignStackBeforeCall(SIZE_PTR, AlignStack_GCC_ThisOnStack);
8.751 +
8.752 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_EDX, REG_EBP, v_plugin_ret);
8.753 + IA32_Push_Reg(&m_HookFunc, REG_EDX);
8.754 +#if SH_COMP == SH_COMP_MSVC
8.755 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_ECX, REG_EAX, MOD_REG);
8.756 +#elif SH_COMP == SH_COMP_GCC
8.757 + IA32_Push_Reg(&m_HookFunc, REG_EAX);
8.758 +#endif
8.759 +
8.760 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(m_Proto.GetRet().pAssignOperator));
8.761 + CheckAlignmentBeforeCall();
8.762 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.763 + GCC_ONLY(IA32_Add_Rm_ImmAuto(&m_HookFunc, REG_ESP, 2 * SIZE_PTR, MOD_REG));
8.764 +
8.765 + AlignStackAfterCall(tmpAlign);
8.766 + }
8.767 + else
8.768 + {
8.769 + // bitwise copy
8.770 + BitwiseCopy_Setup();
8.771 +
8.772 + //mov edi, eax <-- destination
8.773 + //lea esi, [ebp+v_plugin_ret] <-- src
8.774 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EDI, REG_EAX, MOD_REG);
8.775 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ESI, REG_EBP, v_plugin_ret);
8.776 +
8.777 + BitwiseCopy_Do(m_Proto.GetRet().size);
8.778 + }
8.779 + }
8.780 +
8.781 + m_HookFunc.end_count(counter);
8.782 + m_HookFunc.rewrite(tmppos, static_cast<jit_uint8_t>(counter));
8.783 + }
8.784 +
8.785 + void GenContext::PrepareReturn(int v_status, int v_pContext, int v_retptr)
8.786 + {
8.787 + // only for non-void functions!
8.788 + if (m_Proto.GetRet().size == 0)
8.789 + return;
8.790 +
8.791 + // retptr = status >= MRES_OVERRIDE ? pContext->GetOverrideRetPtr() : pContext->GetOrigRetPtr()
8.792 +
8.793 + // OverrideRetPtr: vtblidx = 1
8.794 + // OrigRetPtr: vtbldix = 2
8.795 + // vtblidx = (status >= MRES_OVERRIDE) ? 1 : 2
8.796 +
8.797 + //
8.798 + // eax = pContext->GetOverrideRetPtr()
8.799 + // ECX = pContext
8.800 + // gcc: push ecx
8.801 +
8.802 + // eax = (status < MRES_OVERRIDE) ? 1 : 0
8.803 + // xor eax, eax
8.804 + // cmp [ebp + v_status], MRES_OVERRIDE
8.805 + // setl al <-- setcc optimization for ternary operators,
8.806 +
8.807 +
8.808 + // lea eax, [4*eax + 0x4]
8.809 +
8.810 + // edx = [ecx]
8.811 + // add edx, eax
8.812 + // mov edx, [edx]
8.813 +
8.814 + // call edx
8.815 + // gcc: clean up
8.816 +
8.817 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_ECX, REG_EBP, v_pContext);
8.818 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.819 + IA32_Xor_Reg_Rm(&m_HookFunc, REG_EAX, REG_EAX, MOD_REG);
8.820 + IA32_Cmp_Rm_Disp8_Imm8(&m_HookFunc, REG_EBP, v_status, MRES_OVERRIDE);
8.821 + IA32_SetCC_Rm8(&m_HookFunc, REG_EAX, CC_L);
8.822 +
8.823 + IA32_Lea_Reg_RegMultImm32(&m_HookFunc, REG_EAX, REG_EAX, SCALE4, 4);
8.824 +
8.825 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EDX, REG_ECX, MOD_MEM_REG);
8.826 + IA32_Add_Reg_Rm(&m_HookFunc, REG_EDX, REG_EAX, MOD_REG);
8.827 +
8.828 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EDX, REG_EDX, MOD_MEM_REG);
8.829 + IA32_Call_Reg(&m_HookFunc, REG_EDX);
8.830 + GCC_ONLY(IA32_Pop_Reg(&m_HookFunc, REG_ECX));
8.831 +
8.832 + IA32_Mov_Rm_Reg_DispAuto(&m_HookFunc, REG_EBP, REG_EAX, v_retptr);
8.833 + }
8.834 +
8.835 + void GenContext::DoReturn(int v_retptr, int v_memret_outaddr)
8.836 + {
8.837 + size_t size = m_Proto.GetRet().size;
8.838 + if (!size)
8.839 + return;
8.840 +
8.841 + // Get real ret pointer into ecx
8.842 + // mov ecx, [ebp + v_ret_ptr]
8.843 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_ECX, REG_EBP, v_retptr);
8.844 +
8.845 + if (m_Proto.GetRet().flags & PassInfo::PassFlag_ByRef)
8.846 + {
8.847 + // mov eax, [ecx]
8.848 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EAX, REG_ECX, MOD_MEM_REG);
8.849 + return;
8.850 + }
8.851 + // else: byval
8.852 +
8.853 + if (m_Proto.GetRet().type == PassInfo::PassType_Float)
8.854 + {
8.855 + if (size == 4)
8.856 + IA32_Fld_Mem32(&m_HookFunc, REG_ECX);
8.857 + else if (size == 8)
8.858 + IA32_Fld_Mem64(&m_HookFunc, REG_ECX);
8.859 + }
8.860 + else if (m_Proto.GetRet().type == PassInfo::PassType_Basic ||
8.861 + ((m_Proto.GetRet().type == PassInfo::PassType_Object) && (m_Proto.GetRet().flags & PassInfo::PassFlag_RetReg)) )
8.862 + {
8.863 + if (size <= 4)
8.864 + {
8.865 + // size <= 4: return in EAX
8.866 + // We align <4 sizes up to 4
8.867 +
8.868 + // mov eax, [ecx]
8.869 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EAX, REG_ECX, MOD_MEM_REG);
8.870 + }
8.871 + else if (size <= 8)
8.872 + {
8.873 + // size <= 4: return in EAX:EDX
8.874 + // We align 4<x<8 sizes up to 8
8.875 +
8.876 + // mov eax, [ecx]
8.877 + // mov edx, [ecx+4]
8.878 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EAX, REG_ECX, MOD_MEM_REG);
8.879 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EAX, REG_ECX, 4);
8.880 + }
8.881 + else
8.882 + {
8.883 + // size >8: return in memory
8.884 + // handled later
8.885 + }
8.886 + }
8.887 +
8.888 + if (m_Proto.GetRet().flags & PassInfo::PassFlag_RetMem)
8.889 + {
8.890 + // *memret_outaddr = plugin_ret
8.891 + if (m_Proto.GetRet().pCopyCtor)
8.892 + {
8.893 + // mov edx, ecx <-- src ( we set ecx to [ebp+v_retptr] before )
8.894 + // push edx <-- src addr
8.895 + // msvc: ecx = [ebp + v_memret_outaddr] <-- dest addr
8.896 + // gcc: push [ebp + v_memret_outaddr] <-- dest addr
8.897 + // call it
8.898 + // gcc: clean up
8.899 +
8.900 + jit_int32_t tmpAlign = AlignStackBeforeCall(SIZE_PTR, AlignStack_GCC_ThisOnStack);
8.901 +
8.902 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EDX, REG_ECX, MOD_REG);
8.903 + IA32_Push_Reg(&m_HookFunc, REG_EDX);
8.904 +
8.905 +#if SH_COMP == SH_COMP_MSVC
8.906 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_ECX, REG_EBP, v_memret_outaddr);
8.907 +#elif SH_COMP == SH_COMP_GCC
8.908 + IA32_Push_Rm_DispAuto(&m_HookFunc, REG_EBP, v_memret_outaddr);
8.909 +#endif
8.910 +
8.911 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(m_Proto.GetRet().pCopyCtor));
8.912 + CheckAlignmentBeforeCall();
8.913 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.914 + GCC_ONLY(IA32_Add_Rm_ImmAuto(&m_HookFunc, REG_ESP, 2 * SIZE_PTR, MOD_REG));
8.915 +
8.916 + AlignStackAfterCall(tmpAlign);
8.917 + }
8.918 + else
8.919 + {
8.920 + // bitwise copy
8.921 + BitwiseCopy_Setup();
8.922 +
8.923 + //mov edi, [ebp+v_memret_outaddr] <-- destination
8.924 + //mov esi, ecx <-- src ( we set ecx to [ebp+v_retptr] before )
8.925 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EDI, REG_EBP, v_memret_outaddr);
8.926 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_ESI, REG_ECX, MOD_REG);
8.927 +
8.928 + BitwiseCopy_Do(m_Proto.GetRet().size);
8.929 + }
8.930 +
8.931 + // In both cases: return the pointer in EAX
8.932 + // mov eax, [ebp + v_memret_outaddr]
8.933 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EAX, REG_EBP, v_memret_outaddr);
8.934 + }
8.935 + }
8.936 +
8.937 + void GenContext::GenerateCallHooks(int v_status, int v_prev_res, int v_cur_res, int v_iter,
8.938 + int v_pContext, int base_param_offset, int v_plugin_ret, int v_place_for_memret, jit_int32_t v_place_fbrr_base, jit_int32_t v_va_buf)
8.939 + {
8.940 + jitoffs_t counter, tmppos;
8.941 + jitoffs_t counter2, tmppos2;
8.942 +
8.943 + jitoffs_t loop_begin_counter;
8.944 +
8.945 + // prev_res = MRES_IGNORED
8.946 + IA32_Mov_Rm_Imm32_Disp8(&m_HookFunc, REG_EBP, MRES_IGNORED, v_prev_res);
8.947 +
8.948 + m_HookFunc.start_count(loop_begin_counter);
8.949 +
8.950 + // eax = pContext->GetNext()
8.951 + // ECX = pContext
8.952 + // gcc: push ecx
8.953 + // eax = [ecx]
8.954 + // eax = [eax]
8.955 + // call eax
8.956 + // gcc: clean up
8.957 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_ECX, REG_EBP, v_pContext);
8.958 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.959 +
8.960 + // vtbloffs=0, vtblidx=0
8.961 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EAX, REG_ECX, MOD_MEM_REG);
8.962 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EAX, REG_EAX, MOD_MEM_REG);
8.963 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.964 + GCC_ONLY(IA32_Pop_Reg(&m_HookFunc, REG_ECX));
8.965 +
8.966 + // quit on zero
8.967 + // test eax, eax
8.968 + // jz exit
8.969 + IA32_Test_Rm_Reg(&m_HookFunc, REG_EAX, REG_EAX, MOD_REG);
8.970 + tmppos = IA32_Jump_Cond_Imm32(&m_HookFunc, CC_Z, 0);
8.971 + m_HookFunc.start_count(counter);
8.972 +
8.973 + // prev_res = MRES_IGNORED
8.974 + IA32_Mov_Rm_Imm32_Disp8(&m_HookFunc, REG_EBP, MRES_IGNORED, v_cur_res);
8.975 +
8.976 + // iter->call()
8.977 + // push params
8.978 + // ecx = eax
8.979 + // gcc: push ecx
8.980 + // eax = [ecx]
8.981 + // eax = [eax+2*SIZE_PTR]
8.982 + // call eax
8.983 + // gcc: clean up
8.984 +
8.985 + jit_int32_t caller_clean_bytes = 0; // gcc always, msvc never (hooks never have varargs!)
8.986 +
8.987 + jit_int32_t alignBytes = AlignStackBeforeCall(
8.988 + GetParamsTotalStackSize() + ((m_Proto.GetConvention() & ProtoInfo::CallConv_HasVafmt)!=0 ? SIZE_PTR : 0),
8.989 + AlignStack_GCC_ThisOnStack | ((m_Proto.GetRet().flags & PassInfo::PassFlag_RetMem) == 0 ? 0 : AlignStack_MemRet)
8.990 + );
8.991 +
8.992 + // vafmt: push va_buf
8.993 + if (m_Proto.GetConvention() & ProtoInfo::CallConv_HasVafmt)
8.994 + {
8.995 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, v_va_buf);
8.996 + IA32_Push_Reg(&m_HookFunc, REG_ECX);
8.997 + caller_clean_bytes += SIZE_PTR;
8.998 + }
8.999 +
8.1000 + caller_clean_bytes += PushParams(base_param_offset, v_plugin_ret, v_place_for_memret, v_place_fbrr_base);
8.1001 +
8.1002 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_ECX, REG_EAX, MOD_REG);
8.1003 + if (SH_COMP == SH_COMP_GCC)
8.1004 + IA32_Push_Reg(&m_HookFunc, REG_ECX);
8.1005 + caller_clean_bytes += PushMemRetPtr(v_plugin_ret, v_place_for_memret);
8.1006 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EAX, REG_ECX, MOD_MEM_REG);
8.1007 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EAX, REG_EAX, 2*SIZE_PTR);
8.1008 + CheckAlignmentBeforeCall();
8.1009 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1010 +
8.1011 + AlignStackAfterCall(alignBytes);
8.1012 +
8.1013 + // cleanup (gcc only)
8.1014 + // params + thisptr
8.1015 + if (SH_COMP == SH_COMP_GCC)
8.1016 + IA32_Add_Rm_ImmAuto(&m_HookFunc, REG_ESP, caller_clean_bytes + SIZE_PTR, MOD_REG);
8.1017 +
8.1018 + DestroyParams(v_place_fbrr_base);
8.1019 +
8.1020 + SaveRetVal(v_plugin_ret, v_place_for_memret);
8.1021 +
8.1022 + // process meta return:
8.1023 + // prev_res = cur_res
8.1024 + // if (cur_res > status) status = cur_res;
8.1025 + //
8.1026 + // eax = cur_res
8.1027 + // edx = status
8.1028 + // prev_res = eax
8.1029 + // cmp eax,edx
8.1030 + // jng thelabel
8.1031 + // status = eax
8.1032 + // thelabel:
8.1033 + //
8.1034 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EAX, REG_EBP, v_cur_res);
8.1035 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EDX, REG_EBP, v_status);
8.1036 + IA32_Mov_Rm_Reg_Disp8(&m_HookFunc, REG_EBP, REG_EAX, v_prev_res);
8.1037 +
8.1038 + IA32_Cmp_Reg_Rm(&m_HookFunc, REG_EAX, REG_EDX, MOD_REG);
8.1039 + tmppos2 = IA32_Jump_Cond_Imm8(&m_HookFunc, CC_NG, 0);
8.1040 + m_HookFunc.start_count(counter2);
8.1041 +
8.1042 + IA32_Mov_Rm_Reg_Disp8(&m_HookFunc, REG_EBP, REG_EAX, v_status);
8.1043 +
8.1044 + m_HookFunc.end_count(counter2);
8.1045 + m_HookFunc.rewrite(tmppos2, static_cast<jit_uint8_t>(counter2));
8.1046 +
8.1047 + // process retval for non-void functions
8.1048 + ProcessPluginRetVal(v_cur_res, v_pContext, v_plugin_ret);
8.1049 +
8.1050 + // jump back to loop begin
8.1051 + tmppos2 = IA32_Jump_Imm32(&m_HookFunc, 0);
8.1052 + m_HookFunc.end_count(loop_begin_counter);
8.1053 + m_HookFunc.rewrite(tmppos2, static_cast<jit_int32_t>(-loop_begin_counter));
8.1054 +
8.1055 + m_HookFunc.end_count(counter);
8.1056 + m_HookFunc.rewrite(tmppos, static_cast<jit_int32_t>(counter));
8.1057 + }
8.1058 +
8.1059 + void GenContext::GenerateCallOrig(int v_status, int v_pContext, int param_base_offs, int v_this,
8.1060 + int v_vfnptr_origentry, int v_orig_ret, int v_override_ret, int v_place_for_memret, jit_int32_t v_place_fbrr_base, jit_int32_t v_va_buf)
8.1061 + {
8.1062 + jitoffs_t counter, tmppos;
8.1063 + jitoffs_t counter2, tmppos2;
8.1064 + jitoffs_t counter3, tmppos3;
8.1065 +
8.1066 + // if (status != MRES_SUPERCEDE && pConteext->ShouldCallOrig())
8.1067 + // *v_orig_ret = orig_call()
8.1068 + // else
8.1069 + // *v_orig_ret = *v_override_ret
8.1070 +
8.1071 + // mov eax, status
8.1072 + // cmp eax, MRES_SUPERCEDE
8.1073 + // je dont_call
8.1074 + // call pContext->ShouldCallOrig()
8.1075 + // test al, al !! important: al, not eax! bool is only stored in the LSbyte
8.1076 + // jz dont_call
8.1077 + //
8.1078 + // orig_call()
8.1079 + // SaveRet(v_orig_ret)
8.1080 + // jmp skip_dont_call:
8.1081 + //
8.1082 + // dont_call:
8.1083 + // *v_orig_ret = *v_override_ret
8.1084 + // skip_dont_call:
8.1085 +
8.1086 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EAX, REG_EBP, v_status);
8.1087 + IA32_Cmp_Rm_Imm32(&m_HookFunc, MOD_REG, REG_EAX, MRES_SUPERCEDE);
8.1088 +
8.1089 + tmppos = IA32_Jump_Cond_Imm32(&m_HookFunc, CC_E, 0);
8.1090 + m_HookFunc.start_count(counter);
8.1091 +
8.1092 + // eax = pContext->ShouldCallOrig()
8.1093 + // ECX = pContext
8.1094 + // gcc: push ecx
8.1095 + // eax = [ecx]
8.1096 + // eax = [eax + 3*SIZE_PTR]
8.1097 + // call eax
8.1098 + // gcc: clean up
8.1099 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_ECX, REG_EBP, v_pContext);
8.1100 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.1101 +
8.1102 + // vtbloffs=0, vtblidx=3
8.1103 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EAX, REG_ECX, MOD_MEM_REG);
8.1104 + IA32_Mov_Reg_Rm_Disp8(&m_HookFunc, REG_EAX, REG_EAX, 3*SIZE_PTR);
8.1105 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1106 + GCC_ONLY(IA32_Pop_Reg(&m_HookFunc, REG_ECX));
8.1107 +
8.1108 + IA32_Test_Rm_Reg8(&m_HookFunc, REG_EAX, REG_EAX, MOD_REG);
8.1109 + tmppos2 = IA32_Jump_Cond_Imm32(&m_HookFunc, CC_Z, 0);
8.1110 + m_HookFunc.start_count(counter2);
8.1111 +
8.1112 + jit_int32_t caller_clean_bytes = 0; // gcc always, msvc when cdecl-like (varargs)
8.1113 +
8.1114 + jit_int32_t alignBytes = AlignStackBeforeCall(
8.1115 + GetParamsTotalStackSize() + ((m_Proto.GetConvention() & ProtoInfo::CallConv_HasVafmt)!=0 ? 2*SIZE_PTR : 0),
8.1116 + AlignStack_GCC_ThisOnStack |
8.1117 + ((m_Proto.GetRet().flags & PassInfo::PassFlag_RetMem) == 0 ? 0 : AlignStack_MemRet) |
8.1118 + ((m_Proto.GetConvention() & ProtoInfo::CallConv_HasVarArgs) == 0 ? 0 : AlignStack_MSVC_ThisOnStack)
8.1119 + );
8.1120 +
8.1121 + // vafmt: push va_buf, then "%s"
8.1122 + if (m_Proto.GetConvention() & ProtoInfo::CallConv_HasVafmt)
8.1123 + {
8.1124 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, v_va_buf);
8.1125 + IA32_Push_Reg(&m_HookFunc, REG_ECX);
8.1126 + IA32_Push_Imm32(&m_HookFunc, DownCastPtr("%s"));
8.1127 + caller_clean_bytes += 2*SIZE_PTR;
8.1128 + }
8.1129 +
8.1130 + // push params
8.1131 + caller_clean_bytes += PushParams(param_base_offs, v_orig_ret, v_place_for_memret, v_place_fbrr_base);
8.1132 +
8.1133 + // thisptr
8.1134 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_ECX, REG_EBP, v_this);
8.1135 + if (SH_COMP == SH_COMP_GCC)
8.1136 + {
8.1137 + // on gcc/mingw, this is the first parameter
8.1138 + IA32_Push_Reg(&m_HookFunc, REG_ECX);
8.1139 + // on msvc without varargs, simply leave it in ecx
8.1140 +
8.1141 + // actually, if we're returning in memory, this pointer is the second param
8.1142 + // and the memret pointer is the real first parameter
8.1143 + caller_clean_bytes += PushMemRetPtr(v_orig_ret, v_place_for_memret);
8.1144 + }
8.1145 + else
8.1146 + {
8.1147 + // On msvc, if we're returning in memory, the memret pointer is the first parameter
8.1148 + caller_clean_bytes += PushMemRetPtr(v_orig_ret, v_place_for_memret);
8.1149 +
8.1150 + // actually, with varargs, the this pointer is the first param and the memret ptr
8.1151 + // is the second one
8.1152 + if (m_Proto.GetConvention() & ProtoInfo::CallConv_HasVarArgs)
8.1153 + {
8.1154 + IA32_Push_Reg(&m_HookFunc, REG_ECX);
8.1155 + }
8.1156 + }
8.1157 +
8.1158 + // call
8.1159 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EAX, REG_EBP, v_vfnptr_origentry);
8.1160 + CheckAlignmentBeforeCall();
8.1161 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1162 +
8.1163 + AlignStackAfterCall(alignBytes);
8.1164 +
8.1165 + // cleanup
8.1166 + if (SH_COMP == SH_COMP_GCC || (m_Proto.GetConvention() & ProtoInfo::CallConv_HasVarArgs))
8.1167 + IA32_Add_Rm_ImmAuto(&m_HookFunc, REG_ESP, caller_clean_bytes + SIZE_PTR, MOD_REG);
8.1168 +
8.1169 + DestroyParams(v_place_fbrr_base);
8.1170 +
8.1171 + // save retval
8.1172 + SaveRetVal(v_orig_ret, v_place_for_memret);
8.1173 +
8.1174 + // Skip don't call variant
8.1175 + tmppos3 = IA32_Jump_Imm32(&m_HookFunc, 0);
8.1176 + m_HookFunc.start_count(counter3);
8.1177 +
8.1178 +
8.1179 + // don't call:
8.1180 + m_HookFunc.end_count(counter);
8.1181 + m_HookFunc.rewrite(tmppos, static_cast<jit_uint32_t>(counter));
8.1182 +
8.1183 + m_HookFunc.end_count(counter2);
8.1184 + m_HookFunc.rewrite(tmppos2, static_cast<jit_uint32_t>(counter2));
8.1185 +
8.1186 + // *v_orig_ret = *v_override_ret
8.1187 + if (m_Proto.GetRet().flags & PassInfo::PassFlag_ByRef)
8.1188 + {
8.1189 + // mov ecx, [ebp + v_override_ret]
8.1190 + // mov [ebp + v_orig_ret], ecx
8.1191 +
8.1192 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_ECX, REG_EBP, v_override_ret);
8.1193 + IA32_Mov_Rm_Reg_DispAuto(&m_HookFunc, REG_EBP, REG_ECX, v_orig_ret);
8.1194 + }
8.1195 + else
8.1196 + {
8.1197 + if (m_Proto.GetRet().pAssignOperator)
8.1198 + {
8.1199 + // lea edx, [ebp + v_override_ret] <-- src addr
8.1200 + // lea ecx, [ebp + v_orig_ret] <-- dest addr
8.1201 + // push edx <-- src addr
8.1202 + // gcc: push ecx
8.1203 + // call it
8.1204 + // gcc: clean up
8.1205 +
8.1206 + jit_int32_t tmpAlign = AlignStackBeforeCall(SIZE_PTR, AlignStack_GCC_ThisOnStack);
8.1207 +
8.1208 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_EDX, REG_EBP, v_override_ret);
8.1209 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, v_orig_ret);
8.1210 + IA32_Push_Reg(&m_HookFunc, REG_EDX);
8.1211 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.1212 +
8.1213 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(m_Proto.GetRet().pAssignOperator));
8.1214 + CheckAlignmentBeforeCall();
8.1215 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1216 + GCC_ONLY(IA32_Add_Rm_ImmAuto(&m_HookFunc, REG_ESP, 2*SIZE_PTR, MOD_REG));
8.1217 +
8.1218 + AlignStackAfterCall(tmpAlign);
8.1219 + }
8.1220 + else
8.1221 + {
8.1222 + // bitwise copy
8.1223 + BitwiseCopy_Setup();
8.1224 +
8.1225 + //lea edi, [ebp+v_orig_ret] <-- destination
8.1226 + //lea esi, [ebp+v_override_ret] <-- src
8.1227 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_EDI, REG_EBP, v_orig_ret);
8.1228 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ESI, REG_EBP, v_override_ret);
8.1229 +
8.1230 + BitwiseCopy_Do(m_Proto.GetRet().size);
8.1231 + }
8.1232 + }
8.1233 +
8.1234 + // skip don't call label target:
8.1235 + m_HookFunc.end_count(counter3);
8.1236 + m_HookFunc.rewrite(tmppos3, static_cast<jit_uint32_t>(counter3));
8.1237 + }
8.1238 +
8.1239 + // Sets *v_pContext to return value
8.1240 + void GenContext::CallSetupHookLoop(int v_orig_ret, int v_override_ret,
8.1241 + int v_cur_res, int v_prev_res, int v_status, int v_vfnptr_origentry,
8.1242 + int v_this, int v_pContext)
8.1243 + {
8.1244 + // call shptr->SetupHookLoop(ms_HI, ourvfnptr, reinterpret_cast<void*>(this),
8.1245 + // &vfnptr_origentry, &status, &prev_res, &cur_res, &orig_ret, &override_ret);
8.1246 + // The last two params are null for void funcs.
8.1247 +
8.1248 + if (m_Proto.GetRet().size == 0)
8.1249 + {
8.1250 + // void
8.1251 + IA32_Push_Imm8(&m_HookFunc, 0); // orig_ret
8.1252 + IA32_Push_Imm8(&m_HookFunc, 0); // override_ret
8.1253 + }
8.1254 + else
8.1255 + {
8.1256 + // orig_ret and override_ret
8.1257 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_EAX, REG_EBP, v_override_ret);
8.1258 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_EDX, REG_EBP, v_orig_ret);
8.1259 + IA32_Push_Reg(&m_HookFunc, REG_EAX);
8.1260 + IA32_Push_Reg(&m_HookFunc, REG_EDX);
8.1261 + }
8.1262 +
8.1263 + // cur_res and prev_res
8.1264 + IA32_Lea_DispRegImm8(&m_HookFunc, REG_EAX, REG_EBP, v_cur_res);
8.1265 + IA32_Lea_DispRegImm8(&m_HookFunc, REG_EDX, REG_EBP, v_prev_res);
8.1266 + IA32_Push_Reg(&m_HookFunc, REG_EAX);
8.1267 + IA32_Push_Reg(&m_HookFunc, REG_EDX);
8.1268 +
8.1269 + // status and vfnptr_origentry
8.1270 + IA32_Lea_DispRegImm8(&m_HookFunc, REG_EAX, REG_EBP, v_status);
8.1271 + IA32_Lea_DispRegImm8(&m_HookFunc, REG_EDX, REG_EBP, v_vfnptr_origentry);
8.1272 + IA32_Push_Reg(&m_HookFunc, REG_EAX);
8.1273 + IA32_Push_Reg(&m_HookFunc, REG_EDX);
8.1274 +
8.1275 + // this
8.1276 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EAX, REG_EBP, v_this);
8.1277 + IA32_Push_Reg(&m_HookFunc, REG_EAX);
8.1278 +
8.1279 + // our vfn ptr
8.1280 + // *(this + vtbloffs) + SIZE_PTR*vtblidx
8.1281 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_ECX, REG_EBP, v_this); // get this into ecx (gcc!)
8.1282 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EAX, REG_ECX, m_VtblOffs);
8.1283 + IA32_Add_Rm_ImmAuto(&m_HookFunc, REG_EAX, m_VtblIdx * SIZE_PTR, MOD_REG);
8.1284 + IA32_Push_Reg(&m_HookFunc, REG_EAX);
8.1285 +
8.1286 + // *m_pHI
8.1287 + IA32_Mov_Rm_Imm32(&m_HookFunc, REG_EDX, DownCastPtr(m_pHI), MOD_REG);
8.1288 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EAX, REG_EDX, MOD_MEM_REG);
8.1289 + IA32_Push_Reg(&m_HookFunc, REG_EAX);
8.1290 +
8.1291 + // set up thisptr
8.1292 +#if SH_COMP == SH_COMP_GCC
8.1293 + // on gcc/mingw, this is the first parameter
8.1294 + GCC_ONLY(IA32_Push_Imm32(&m_HookFunc, DownCastPtr(m_SHPtr)));
8.1295 +#elif SH_COMP == SH_COMP_MSVC
8.1296 + // on msvc, it's ecx
8.1297 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_ECX, DownCastPtr(m_SHPtr));
8.1298 +#endif
8.1299 +
8.1300 + // call the function. vtbloffs = 0, vtblidx = 19
8.1301 + // get vtptr into edx -- we know shptr on jit time -> dereference it here!
8.1302 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX,
8.1303 + (*reinterpret_cast<jit_uint32_t**>(m_SHPtr))[19]);
8.1304 +
8.1305 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1306 +
8.1307 + // on gcc/mingw, we have to clean up after the call
8.1308 + // 9 params + hidden thisptr param
8.1309 + GCC_ONLY(IA32_Add_Rm_Imm8(&m_HookFunc, REG_ESP, 10*SIZE_PTR, MOD_REG));
8.1310 +
8.1311 + // store return value
8.1312 + IA32_Mov_Rm_Reg_Disp8(&m_HookFunc, REG_EBP, REG_EAX, v_pContext);
8.1313 + }
8.1314 +
8.1315 + void GenContext::CallEndContext(int v_pContext)
8.1316 + {
8.1317 + // call endcontext:
8.1318 + // shptr->EndContext(pContex)
8.1319 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EAX, REG_EBP, v_pContext);
8.1320 + IA32_Push_Reg(&m_HookFunc, REG_EAX);
8.1321 +
8.1322 + // thisptr
8.1323 +#if SH_COMP == SH_COMP_GCC
8.1324 + // on gcc/mingw, this is the first parameter
8.1325 + IA32_Push_Imm32(&m_HookFunc, DownCastPtr(m_SHPtr));
8.1326 +#elif SH_COMP == SH_COMP_MSVC
8.1327 + // on msvc, it's ecx
8.1328 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_ECX, DownCastPtr(m_SHPtr));
8.1329 +#endif
8.1330 +
8.1331 + // get vtptr into edx -- we know shptr on jit time -> dereference it here!
8.1332 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX,
8.1333 + (*reinterpret_cast<jit_uint32_t**>(m_SHPtr))[20]);
8.1334 +
8.1335 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1336 +
8.1337 + // on gcc/mingw, we have to clean up after the call
8.1338 + // 1 param + hidden thisptr param
8.1339 + GCC_ONLY(IA32_Add_Rm_Imm8(&m_HookFunc, REG_ESP, 2*SIZE_PTR, MOD_REG));
8.1340 + }
8.1341 +
8.1342 + void GenContext::ResetFrame(jit_int32_t startOffset)
8.1343 + {
8.1344 + m_HookFunc_FrameOffset = startOffset;
8.1345 + m_HookFunc_FrameVarsSize = 0;
8.1346 + }
8.1347 +
8.1348 + jit_int32_t GenContext::AddVarToFrame(jit_int32_t size)
8.1349 + {
8.1350 + m_HookFunc_FrameOffset -= size;
8.1351 + m_HookFunc_FrameVarsSize += size;
8.1352 + return m_HookFunc_FrameOffset;
8.1353 + }
8.1354 +
8.1355 + jit_int32_t GenContext::ComputeVarsSize()
8.1356 + {
8.1357 + return m_HookFunc_FrameVarsSize;
8.1358 + }
8.1359 +
8.1360 + void * GenContext::GenerateHookFunc()
8.1361 + {
8.1362 + // prologue
8.1363 + IA32_Push_Reg(&m_HookFunc, REG_EBP);
8.1364 + IA32_Push_Reg(&m_HookFunc, REG_EBX);
8.1365 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_EBP, REG_ESP, MOD_REG);
8.1366 +
8.1367 + jit_int32_t v_this = 0;
8.1368 + jit_int32_t param_base_offs = 0;
8.1369 + if (SH_COMP == SH_COMP_GCC || (m_Proto.GetConvention() & ProtoInfo::CallConv_HasVarArgs))
8.1370 + {
8.1371 + // gcc or msvc with varargs:
8.1372 + v_this = 12; // first param
8.1373 + param_base_offs = 16;
8.1374 + ResetFrame(0);
8.1375 + }
8.1376 + else
8.1377 + {
8.1378 + // on msvc without varargs, save thisptr
8.1379 + v_this = -4;
8.1380 + param_base_offs = 12;
8.1381 + IA32_Push_Reg(&m_HookFunc, REG_ECX);
8.1382 + ResetFrame(-4); // start placing local vars on offset -4
8.1383 + // because there already is the thisptr variable
8.1384 + }
8.1385 +
8.1386 + // ********************** stack frame **********************
8.1387 + // MSVC without varargs
8.1388 + // second param (gcc: first real param) ebp + 16
8.1389 + // first param (gcc: thisptr) ebp + 12
8.1390 + // ret address: ebp + 8
8.1391 + // caller's ebp ebp + 4
8.1392 + // saved ebx ebp
8.1393 + // MSVC ONLY: current this ebp - 4
8.1394 + // void *vfnptr_origentry ebp - 4 -4
8.1395 + // META_RES status = MRES_IGNORED ebp - 8 -4
8.1396 + // META_RES prev_res ebp - 12 -4
8.1397 + // META_RES cur_res ebp - 16 -4
8.1398 + // IMyDelegate *iter ebp - 20 -4
8.1399 + // IHookContext *pContext ebp - 24 -4
8.1400 + // == 3 ptrs + 3 enums = 24 bytes
8.1401 + //
8.1402 + // non-void: add:
8.1403 + // my_rettype *ret_ptr ebp - 28 -4
8.1404 + // my_rettype orig_ret ebp - 28 - sizeof(my_rettype) -4
8.1405 + // my_rettype override_ret ebp - 28 - sizeof(my_rettype)*2 -4
8.1406 + // my_rettype plugin_ret ebp - 28 - sizeof(my_rettype)*3 -4
8.1407 + // == + 3 * sizeof(my_rettype) bytes
8.1408 +
8.1409 + // if required:
8.1410 + // my_rettype place_for_memret ebp - 28 - sizeof(my_rettype)*4 -4
8.1411 +
8.1412 + // gcc only: if required:
8.1413 + // place forced byref params ebp - 28 - sizeof(my_rettype)*{4 or 5}
8.1414 + //
8.1415 + // varargs:
8.1416 + // va_list argptr
8.1417 + // char va_buf[something];
8.1418 +
8.1419 +
8.1420 + const jit_int8_t v_vfnptr_origentry = AddVarToFrame(SIZE_PTR);
8.1421 + const jit_int8_t v_status = AddVarToFrame(sizeof(META_RES));
8.1422 + const jit_int8_t v_prev_res = AddVarToFrame(sizeof(META_RES));
8.1423 + const jit_int8_t v_cur_res = AddVarToFrame(sizeof(META_RES));
8.1424 + const jit_int8_t v_iter = AddVarToFrame(SIZE_PTR);
8.1425 + const jit_int8_t v_pContext = AddVarToFrame(SIZE_PTR);
8.1426 +
8.1427 + // Memory return: first param is the address
8.1428 + jit_int32_t v_memret_addr = 0;
8.1429 + if (m_Proto.GetRet().flags & PassInfo::PassFlag_RetMem)
8.1430 + {
8.1431 + if (SH_COMP == SH_COMP_GCC)
8.1432 + {
8.1433 + // gcc: now: first param = mem ret addr
8.1434 + // second param = this pointer
8.1435 + // third param = actual first param
8.1436 + v_memret_addr = 12;
8.1437 + v_this += 4;
8.1438 + param_base_offs += SIZE_PTR;
8.1439 + }
8.1440 + else // MSVC
8.1441 + {
8.1442 + if (m_Proto.GetConvention() & ProtoInfo::CallConv_HasVarArgs)
8.1443 + {
8.1444 + // varargs -> cdecl
8.1445 + // msvc: now:
8.1446 + // first param = this pointer
8.1447 + // second param = mem ret addr
8.1448 + // third param = actual first param
8.1449 +
8.1450 + // params_base_offs is already updated to point to after the this pointer
8.1451 + v_memret_addr = param_base_offs;
8.1452 + param_base_offs += SIZE_PTR;
8.1453 + }
8.1454 + else
8.1455 + {
8.1456 + v_memret_addr = param_base_offs;
8.1457 + param_base_offs += SIZE_PTR;
8.1458 + }
8.1459 + }
8.1460 + }
8.1461 +
8.1462 + jit_int32_t v_ret_ptr = 0;
8.1463 + jit_int32_t v_orig_ret = 0;
8.1464 + jit_int32_t v_override_ret = 0;
8.1465 + jit_int32_t v_plugin_ret = 0;
8.1466 +
8.1467 + if (m_Proto.GetRet().size != 0)
8.1468 + {
8.1469 + v_ret_ptr = AddVarToFrame(SIZE_PTR);
8.1470 + v_orig_ret = AddVarToFrame(GetParamStackSize(m_Proto.GetRet()));
8.1471 + v_override_ret = AddVarToFrame(GetParamStackSize(m_Proto.GetRet()));
8.1472 + v_plugin_ret = AddVarToFrame(GetParamStackSize(m_Proto.GetRet()));
8.1473 + }
8.1474 +
8.1475 + jit_int32_t v_place_for_memret = 0;
8.1476 + if (MemRetWithTempObj())
8.1477 + {
8.1478 + v_place_for_memret = AddVarToFrame(GetParamStackSize(m_Proto.GetRet()));
8.1479 + }
8.1480 +
8.1481 + jit_int32_t v_place_fbrr_base = 0;
8.1482 + if (SH_COMP == SH_COMP_GCC && GetForcedByRefParamsSize())
8.1483 + {
8.1484 + v_place_fbrr_base = AddVarToFrame(GetForcedByRefParamsSize());
8.1485 + }
8.1486 +
8.1487 + // Only exists for varargs functions
8.1488 + jit_int32_t v_va_argptr = 0;
8.1489 + if (m_Proto.GetConvention() & ProtoInfo::CallConv_HasVarArgs)
8.1490 + {
8.1491 + v_va_argptr = AddVarToFrame(SIZE_PTR);
8.1492 + }
8.1493 +
8.1494 + jit_int32_t v_va_buf = 0;
8.1495 + if (m_Proto.GetConvention() & ProtoInfo::CallConv_HasVafmt)
8.1496 + {
8.1497 + v_va_buf = AddVarToFrame(SourceHook::STRBUF_LEN);
8.1498 + }
8.1499 +
8.1500 + IA32_Sub_Rm_Imm32(&m_HookFunc, REG_ESP, ComputeVarsSize(), MOD_REG);
8.1501 +
8.1502 + // Initial stack alignment
8.1503 + IA32_And_Rm_Imm32(&m_HookFunc, REG_ESP, MOD_REG, -16);
8.1504 + m_BytesPushedAfterInitialAlignment = 0;
8.1505 +
8.1506 + // init status localvar
8.1507 + IA32_Mov_Rm_Imm32_Disp8(&m_HookFunc, REG_EBP, MRES_IGNORED, v_status);
8.1508 +
8.1509 + // VarArgs: init argptr & format
8.1510 + if (m_Proto.GetConvention() & ProtoInfo::CallConv_HasVarArgs)
8.1511 + {
8.1512 + // argptr = first vararg param
8.1513 + // lea eax, [ebp + param_base_offs + paramssize]
8.1514 + // mov argptr, eax
8.1515 +
8.1516 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_EAX, REG_EBP, param_base_offs + GetParamsTotalStackSize() + SIZE_PTR); // +SIZE_PTR: last const char * is not in protoinfo
8.1517 + IA32_Mov_Rm_Reg_DispAuto(&m_HookFunc, REG_EBP, REG_EAX, v_va_argptr);
8.1518 + }
8.1519 + if (m_Proto.GetConvention() & ProtoInfo::CallConv_HasVafmt)
8.1520 + {
8.1521 + // vsnprintf
8.1522 +
8.1523 + jit_int32_t tmpAlign = AlignStackBeforeCall(SIZE_PTR*3 + sizeof(size_t), 0);
8.1524 +
8.1525 + // push valist, fmt param, maxsize, buffer
8.1526 + IA32_Push_Reg(&m_HookFunc, REG_EAX);
8.1527 + IA32_Push_Rm_DispAuto(&m_HookFunc, REG_EBP, param_base_offs + GetParamsTotalStackSize()); // last given param (+4-4, see above)
8.1528 + IA32_Push_Imm32(&m_HookFunc, SourceHook::STRBUF_LEN - 1);
8.1529 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, v_va_buf);
8.1530 + IA32_Push_Reg(&m_HookFunc, REG_ECX);
8.1531 +
8.1532 + // call
8.1533 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(&vsnprintf));
8.1534 + CheckAlignmentBeforeCall();
8.1535 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1536 +
8.1537 + // Clean up (cdecl)
8.1538 + IA32_Add_Rm_Imm32(&m_HookFunc, REG_ESP, 0x10, MOD_REG);
8.1539 +
8.1540 + AlignStackAfterCall(tmpAlign);
8.1541 +
8.1542 + // Set trailing zero
8.1543 + IA32_Xor_Reg_Rm(&m_HookFunc, REG_EDX, REG_EDX, MOD_REG);
8.1544 + IA32_Mov_Rm8_Reg8_DispAuto(&m_HookFunc, REG_EBP, REG_EDX, v_va_buf + SourceHook::STRBUF_LEN - 1);
8.1545 + }
8.1546 +
8.1547 + // Call constructors for ret vars if required
8.1548 + if((m_Proto.GetRet().flags & PassInfo::PassFlag_ByVal) &&
8.1549 + m_Proto.GetRet().pNormalCtor)
8.1550 + {
8.1551 + jit_int32_t tmpAlign = AlignStackBeforeCall(0, AlignStack_GCC_ThisOnStack);
8.1552 +
8.1553 + // orig_reg
8.1554 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, v_orig_ret);
8.1555 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.1556 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(m_Proto.GetRet().pNormalCtor));
8.1557 + CheckAlignmentBeforeCall();
8.1558 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1559 + GCC_ONLY(IA32_Pop_Reg(&m_HookFunc, REG_ECX));
8.1560 +
8.1561 + // override_reg
8.1562 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, v_override_ret);
8.1563 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.1564 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(m_Proto.GetRet().pNormalCtor));
8.1565 + CheckAlignmentBeforeCall();
8.1566 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1567 + GCC_ONLY(IA32_Pop_Reg(&m_HookFunc, REG_ECX));
8.1568 +
8.1569 + // plugin_ret
8.1570 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, v_plugin_ret);
8.1571 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.1572 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(m_Proto.GetRet().pNormalCtor));
8.1573 + CheckAlignmentBeforeCall();
8.1574 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1575 + GCC_ONLY(IA32_Pop_Reg(&m_HookFunc, REG_ECX));
8.1576 +
8.1577 + AlignStackAfterCall(tmpAlign);
8.1578 +
8.1579 + // _don't_ call a constructor for v_place_for_memret !
8.1580 + }
8.1581 +
8.1582 + // ********************** SetupHookLoop **********************
8.1583 + CallSetupHookLoop(v_orig_ret, v_override_ret, v_cur_res, v_prev_res, v_status, v_vfnptr_origentry,
8.1584 + v_this, v_pContext);
8.1585 +
8.1586 + // ********************** call pre hooks **********************
8.1587 + GenerateCallHooks(v_status, v_prev_res, v_cur_res, v_iter, v_pContext, param_base_offs,
8.1588 + v_plugin_ret, v_place_for_memret, v_place_fbrr_base, v_va_buf);
8.1589 +
8.1590 + // ********************** call orig func **********************
8.1591 + GenerateCallOrig(v_status, v_pContext, param_base_offs, v_this, v_vfnptr_origentry, v_orig_ret,
8.1592 + v_override_ret, v_place_for_memret, v_place_fbrr_base, v_va_buf);
8.1593 +
8.1594 + // ********************** call post hooks **********************
8.1595 + GenerateCallHooks(v_status, v_prev_res, v_cur_res, v_iter, v_pContext, param_base_offs,
8.1596 + v_plugin_ret, v_place_for_memret, v_place_fbrr_base, v_va_buf);
8.1597 +
8.1598 + // ********************** end context and return **********************
8.1599 +
8.1600 + PrepareReturn(v_status, v_pContext, v_ret_ptr);
8.1601 +
8.1602 + CallEndContext(v_pContext);
8.1603 +
8.1604 + // Call destructors of byval object params which have a destructor
8.1605 +
8.1606 + jit_int32_t tmpAlign = AlignStackBeforeCall(0, AlignStack_GCC_ThisOnStack);
8.1607 +
8.1608 + jit_int32_t cur_param_pos = param_base_offs;
8.1609 + for (int i = 0; i < m_Proto.GetNumOfParams(); ++i)
8.1610 + {
8.1611 + const IntPassInfo &pi = m_Proto.GetParam(i);
8.1612 + // GCC: NOT of forced byref params. the caller destructs those.
8.1613 + if (pi.type == PassInfo::PassType_Object && (pi.flags & PassInfo::PassFlag_ODtor) &&
8.1614 + (pi.flags & PassInfo::PassFlag_ByVal) && !(pi.flags & PassFlag_ForcedByRef))
8.1615 + {
8.1616 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, cur_param_pos);
8.1617 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(pi.pDtor));
8.1618 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.1619 + CheckAlignmentBeforeCall();
8.1620 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1621 + GCC_ONLY(IA32_Pop_Reg(&m_HookFunc, REG_ECX));
8.1622 + }
8.1623 + cur_param_pos += GetParamStackSize(pi);
8.1624 + }
8.1625 +
8.1626 + AlignStackAfterCall(tmpAlign);
8.1627 +
8.1628 + DoReturn(v_ret_ptr, v_memret_addr);
8.1629 +
8.1630 + // Call destructors of orig_ret/ ...
8.1631 + if((m_Proto.GetRet().flags & PassInfo::PassFlag_ByVal) &&
8.1632 + m_Proto.GetRet().pDtor)
8.1633 + {
8.1634 + // Preserve return value in EAX(:EDX)
8.1635 + IA32_Push_Reg(&m_HookFunc, REG_EAX);
8.1636 + IA32_Push_Reg(&m_HookFunc, REG_EDX);
8.1637 +
8.1638 + m_BytesPushedAfterInitialAlignment += 8;
8.1639 +
8.1640 + jit_int32_t tmpAlign = AlignStackBeforeCall(0, AlignStack_GCC_ThisOnStack);
8.1641 +
8.1642 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, v_plugin_ret);
8.1643 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.1644 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(m_Proto.GetRet().pDtor));
8.1645 + CheckAlignmentBeforeCall();
8.1646 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1647 + GCC_ONLY(IA32_Pop_Reg(&m_HookFunc, REG_ECX));
8.1648 +
8.1649 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, v_override_ret);
8.1650 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.1651 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(m_Proto.GetRet().pDtor));
8.1652 + CheckAlignmentBeforeCall();
8.1653 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1654 + GCC_ONLY(IA32_Pop_Reg(&m_HookFunc, REG_ECX));
8.1655 +
8.1656 + IA32_Lea_DispRegImmAuto(&m_HookFunc, REG_ECX, REG_EBP, v_orig_ret);
8.1657 + GCC_ONLY(IA32_Push_Reg(&m_HookFunc, REG_ECX));
8.1658 + IA32_Mov_Reg_Imm32(&m_HookFunc, REG_EAX, DownCastPtr(m_Proto.GetRet().pDtor));
8.1659 + CheckAlignmentBeforeCall();
8.1660 + IA32_Call_Reg(&m_HookFunc, REG_EAX);
8.1661 + GCC_ONLY(IA32_Pop_Reg(&m_HookFunc, REG_ECX));
8.1662 +
8.1663 + AlignStackAfterCall(tmpAlign);
8.1664 +
8.1665 + IA32_Pop_Reg(&m_HookFunc, REG_EDX);
8.1666 + IA32_Pop_Reg(&m_HookFunc, REG_EAX);
8.1667 +
8.1668 + m_BytesPushedAfterInitialAlignment -= 8;
8.1669 + }
8.1670 +
8.1671 + // epilogue
8.1672 + IA32_Mov_Reg_Rm(&m_HookFunc, REG_ESP, REG_EBP, MOD_REG);
8.1673 + IA32_Pop_Reg(&m_HookFunc, REG_EBX);
8.1674 + IA32_Pop_Reg(&m_HookFunc, REG_EBP);
8.1675 +
8.1676 + if (SH_COMP == SH_COMP_MSVC && !(m_Proto.GetConvention() & ProtoInfo::CallConv_HasVarArgs))
8.1677 + {
8.1678 + // msvc without varargs:
8.1679 + // callee cleans the stack
8.1680 +
8.1681 + short cleansize = GetParamsTotalStackSize();
8.1682 + // Memory return: address is first param
8.1683 + if (m_Proto.GetRet().flags & PassInfo::PassFlag_RetMem)
8.1684 + cleansize += SIZE_PTR;
8.1685 +
8.1686 + IA32_Return_Popstack(&m_HookFunc, cleansize);
8.1687 + }
8.1688 + else
8.1689 + {
8.1690 + // gcc or msvc with varargs: caller cleans the stack
8.1691 + // exception: gcc removes the memret addr on memret:
8.1692 + if (SH_COMP == SH_COMP_GCC && (m_Proto.GetRet().flags & PassInfo::PassFlag_RetMem))
8.1693 + IA32_Return_Popstack(&m_HookFunc, SIZE_PTR);
8.1694 + else
8.1695 + IA32_Return(&m_HookFunc);
8.1696 + }
8.1697 +
8.1698 +
8.1699 + // Store pointer for later use
8.1700 + // m_HookfuncVfnPtr is a pointer to a void* because SH expects a pointer
8.1701 + // into the hookman's vtable
8.1702 + *m_HookfuncVfnptr = reinterpret_cast<void*>(m_HookFunc.GetData());
8.1703 +
8.1704 + m_HookFunc.SetRE();
8.1705 +
8.1706 + return m_HookFunc.GetData();
8.1707 + }
8.1708 +
8.1709 + // Pre-condition: GenerateHookFunc() has been called!
8.1710 + void * GenContext::GeneratePubFunc()
8.1711 + {
8.1712 + jitoffs_t counter, tmppos;
8.1713 +
8.1714 + // The pubfunc is a static cdecl function.
8.1715 + // C Code:
8.1716 + // int HookManPubFunc(
8.1717 + // bool store, ebp + 8
8.1718 + // IHookManagerInfo *hi ebp + 12
8.1719 + // )
8.1720 + // {
8.1721 + // if (store)
8.1722 + // *m_pHI = hi;
8.1723 + // if (hi)
8.1724 + // hi->SetInfo(HOOKMAN_VERSION, m_VtblOffs, m_VtblIdx, m_Proto.GetProto(), m_HookfuncVfnptr)
8.1725 + // }
8.1726 +
8.1727 + // prologue
8.1728 + IA32_Push_Reg(&m_PubFunc, REG_EBP);
8.1729 + IA32_Mov_Reg_Rm(&m_PubFunc, REG_EBP, REG_ESP, MOD_REG);
8.1730 +
8.1731 +
8.1732 + // save store in eax, hi in ecx
8.1733 + IA32_Movzx_Reg32_Rm8_Disp8(&m_PubFunc, REG_EAX, REG_EBP, 8);
8.1734 + IA32_Mov_Reg_Rm_DispAuto(&m_PubFunc, REG_ECX, REG_EBP, 12);
8.1735 +
8.1736 + // Check for store == 0
8.1737 + IA32_Test_Rm_Reg8(&m_PubFunc, REG_EAX, REG_EAX, MOD_REG);
8.1738 + tmppos = IA32_Jump_Cond_Imm8(&m_PubFunc, CC_Z, 0);
8.1739 + m_PubFunc.start_count(counter);
8.1740 +
8.1741 + // nonzero -> store hi
8.1742 + IA32_Mov_Rm_Imm32(&m_PubFunc, REG_EDX, DownCastPtr(m_pHI), MOD_REG);
8.1743 + IA32_Mov_Rm_Reg(&m_PubFunc, REG_EDX, REG_ECX, MOD_MEM_REG);
8.1744 +
8.1745 + // zero
8.1746 + m_PubFunc.end_count(counter);
8.1747 + m_PubFunc.rewrite(tmppos, static_cast<jit_uint8_t>(counter));
8.1748 +
8.1749 + // check for hi == 0
8.1750 + IA32_Test_Rm_Reg(&m_PubFunc, REG_ECX, REG_ECX, MOD_REG);
8.1751 + tmppos = IA32_Jump_Cond_Imm8(&m_PubFunc, CC_Z, 0);
8.1752 + m_PubFunc.start_count(counter);
8.1753 +
8.1754 + // nonzero -> call vfunc
8.1755 + // push params in reverse order
8.1756 + IA32_Push_Imm32(&m_PubFunc, DownCastPtr(m_HookfuncVfnptr));
8.1757 + IA32_Push_Imm32(&m_PubFunc, DownCastPtr(m_BuiltPI));
8.1758 + IA32_Push_Imm32(&m_PubFunc, m_VtblIdx);
8.1759 + IA32_Push_Imm32(&m_PubFunc, m_VtblOffs);
8.1760 + IA32_Push_Imm32(&m_PubFunc, SH_HOOKMAN_VERSION);
8.1761 +
8.1762 + // hi == this is in ecx
8.1763 + // on gcc/mingw, ecx is the first parameter
8.1764 +#if SH_COMP == SH_COMP_GCC
8.1765 + IA32_Push_Reg(&m_PubFunc, REG_ECX);
8.1766 +#endif
8.1767 +
8.1768 + // call the function. vtbloffs = 0, vtblidx = 0
8.1769 + // get vtptr into edx
8.1770 + IA32_Mov_Reg_Rm(&m_PubFunc, REG_EDX, REG_ECX, MOD_MEM_REG);
8.1771 + // get funcptr into eax
8.1772 + IA32_Mov_Reg_Rm(&m_PubFunc, REG_EAX, REG_EDX, MOD_MEM_REG);
8.1773 +
8.1774 + IA32_Call_Reg(&m_PubFunc, REG_EAX);
8.1775 +
8.1776 + // on gcc/mingw, we have to clean up after the call
8.1777 +#if SH_COMP == SH_COMP_GCC
8.1778 + // 5 params + hidden thisptr param
8.1779 + IA32_Add_Rm_Imm8(&m_PubFunc, REG_ESP, 6*SIZE_MWORD, MOD_REG);
8.1780 +#endif
8.1781 +
8.1782 + // zero
8.1783 + m_PubFunc.end_count(counter);
8.1784 + m_PubFunc.rewrite(tmppos, static_cast<jit_uint8_t>(counter));
8.1785 +
8.1786 + // return value
8.1787 + IA32_Xor_Reg_Rm(&m_PubFunc, REG_EAX, REG_EAX, MOD_REG);
8.1788 +
8.1789 + // epilogue
8.1790 + IA32_Mov_Reg_Rm(&m_PubFunc, REG_ESP, REG_EBP, MOD_REG);
8.1791 + IA32_Pop_Reg(&m_PubFunc, REG_EBP);
8.1792 + IA32_Return(&m_PubFunc);
8.1793 +
8.1794 + m_PubFunc.SetRE();
8.1795 +
8.1796 + return m_PubFunc;
8.1797 + }
8.1798 +
8.1799 + bool GenContext::PassInfoSupported(const IntPassInfo &pi, bool is_ret)
8.1800 + {
8.1801 + // :TODO: Error returns
8.1802 + if (pi.type != PassInfo::PassType_Basic &&
8.1803 + pi.type != PassInfo::PassType_Float &&
8.1804 + pi.type != PassInfo::PassType_Object)
8.1805 + {
8.1806 + return false;
8.1807 + }
8.1808 +
8.1809 + if (pi.type == PassInfo::PassType_Object &&
8.1810 + (pi.flags & PassInfo::PassFlag_ByVal))
8.1811 + {
8.1812 + if ((pi.flags & PassInfo::PassFlag_CCtor) && !pi.pCopyCtor)
8.1813 + {
8.1814 + return false;
8.1815 + }
8.1816 +
8.1817 + if ((pi.flags & PassInfo::PassFlag_ODtor) && !pi.pDtor)
8.1818 + {
8.1819 + return false;
8.1820 + }
8.1821 +
8.1822 + if ((pi.flags & PassInfo::PassFlag_AssignOp) && !pi.pAssignOperator)
8.1823 + {
8.1824 + return false;
8.1825 + }
8.1826 +
8.1827 + if ((pi.flags & PassInfo::PassFlag_OCtor) && !pi.pNormalCtor)
8.1828 + {
8.1829 + return false;
8.1830 + }
8.1831 + }
8.1832 +
8.1833 + if ((pi.flags & (PassInfo::PassFlag_ByVal | PassInfo::PassFlag_ByRef)) == 0)
8.1834 + {
8.1835 + return false; // Neither byval nor byref!
8.1836 + }
8.1837 + return true;
8.1838 + }
8.1839 +
8.1840 + void GenContext::AutoDetectRetType()
8.1841 + {
8.1842 + IntPassInfo &pi = m_Proto.GetRet();
8.1843 +
8.1844 + // Only relevant for byval types
8.1845 + if (pi.flags & PassInfo::PassFlag_ByVal)
8.1846 + {
8.1847 + // Basic + float:
8.1848 + if (pi.type == PassInfo::PassType_Basic ||
8.1849 + pi.type == PassInfo::PassType_Float)
8.1850 + {
8.1851 + // <= 8 bytes:
8.1852 + // _always_ in registers, no matter what the user says
8.1853 + if (pi.size <= 8)
8.1854 + {
8.1855 + pi.flags &= ~PassInfo::PassFlag_RetMem;
8.1856 + pi.flags |= PassInfo::PassFlag_RetReg;
8.1857 + }
8.1858 + else
8.1859 + {
8.1860 + // Does this even exist? No idea, if it does: in memory!
8.1861 + pi.flags &= ~PassInfo::PassFlag_RetReg;
8.1862 + pi.flags |= PassInfo::PassFlag_RetMem;
8.1863 + }
8.1864 + }
8.1865 + // Object:
8.1866 + else if (pi.type == PassInfo::PassType_Object)
8.1867 + {
8.1868 + // If the user says nothing, auto-detect
8.1869 + if ((pi.flags & (PassInfo::PassFlag_RetMem | PassInfo::PassFlag_RetReg)) == 0)
8.1870 + {
8.1871 +#if SH_COMP == SH_COMP_MSVC
8.1872 + // MSVC seems to return _all_ structs, classes, unions in memory
8.1873 + pi.flags |= PassInfo::PassFlag_RetMem;
8.1874 +#elif SH_COMP == SH_COMP_GCC
8.1875 + // Same goes for GCC :)
8.1876 + pi.flags |= PassInfo::PassFlag_RetMem;
8.1877 +#endif
8.1878 + }
8.1879 + }
8.1880 + }
8.1881 + else
8.1882 + {
8.1883 + // byref: make sure that the flag is _not_ set
8.1884 + pi.flags &= ~PassInfo::PassFlag_RetMem;
8.1885 + pi.flags |= PassInfo::PassFlag_RetReg;
8.1886 + }
8.1887 + }
8.1888 +
8.1889 + void GenContext::AutoDetectParamFlags()
8.1890 + {
8.1891 +#if SH_COMP == SH_COMP_GCC
8.1892 + // On GCC, all objects are passed by reference if they have a destructor
8.1893 + for (int i = 0; i < m_Proto.GetNumOfParams(); ++i)
8.1894 + {
8.1895 + IntPassInfo &pi = m_Proto.GetParam(i);
8.1896 + if (pi.type == PassInfo::PassType_Object && (pi.flags & PassInfo::PassFlag_ByVal) &&
8.1897 + (pi.flags & PassInfo::PassFlag_ODtor))
8.1898 + {
8.1899 + pi.flags |= PassFlag_ForcedByRef;
8.1900 + }
8.1901 + }
8.1902 +#endif
8.1903 + }
8.1904 +
8.1905 + HookManagerPubFunc GenContext::Generate()
8.1906 + {
8.1907 + Clear();
8.1908 +
8.1909 + // Check conditions:
8.1910 + // -1) good proto version
8.1911 + // 0) we don't support unknown passtypes, convention, ...
8.1912 + // 1) we don't support functions which return objects by value or take parameters by value
8.1913 + // that have a constructor, a destructor or an overloaded assignment op
8.1914 + // (we wouldn't know how to call it!)
8.1915 +
8.1916 + if (m_Proto.GetVersion() < 1)
8.1917 + {
8.1918 + return NULL;
8.1919 + }
8.1920 +
8.1921 + AutoDetectRetType();
8.1922 + AutoDetectParamFlags();
8.1923 +
8.1924 + // Basically, we only support ThisCall/thiscall with varargs
8.1925 + if ((m_Proto.GetConvention() & (~ProtoInfo::CallConv_HasVafmt)) != ProtoInfo::CallConv_ThisCall)
8.1926 + {
8.1927 + return NULL;
8.1928 + }
8.1929 +
8.1930 +
8.1931 + if (m_Proto.GetRet().size != 0 && !PassInfoSupported(m_Proto.GetRet(), true))
8.1932 + {
8.1933 + return NULL;
8.1934 + }
8.1935 +
8.1936 + for (int i = 0; i < m_Proto.GetNumOfParams(); ++i)
8.1937 + {
8.1938 + if (!PassInfoSupported(m_Proto.GetParam(i), false))
8.1939 + return NULL;
8.1940 + }
8.1941 +
8.1942 + BuildProtoInfo();
8.1943 + GenerateHookFunc();
8.1944 + return fastdelegate::detail::horrible_cast<HookManagerPubFunc>(GeneratePubFunc());
8.1945 + }
8.1946 +
8.1947 + HookManagerPubFunc GenContext::GetPubFunc()
8.1948 + {
8.1949 + if (m_GeneratedPubFunc == 0)
8.1950 + m_GeneratedPubFunc = Generate();
8.1951 +
8.1952 + return m_GeneratedPubFunc;
8.1953 + }
8.1954 +
8.1955 + bool GenContext::Equal(const CProto &proto, int vtbl_offs, int vtbl_idx)
8.1956 + {
8.1957 + return (m_OrigProto.ExactlyEqual(proto) && m_VtblOffs == vtbl_offs && m_VtblIdx == vtbl_idx);
8.1958 + }
8.1959 +
8.1960 + bool GenContext::Equal(HookManagerPubFunc other)
8.1961 + {
8.1962 + return m_GeneratedPubFunc == other;
8.1963 + }
8.1964 +
8.1965 + // *********************************** class GenContextContainer
8.1966 + CHookManagerAutoGen::CHookManagerAutoGen(ISourceHook *pSHPtr) : m_pSHPtr(pSHPtr)
8.1967 + {
8.1968 + }
8.1969 +
8.1970 + CHookManagerAutoGen::~CHookManagerAutoGen()
8.1971 + {
8.1972 + for (List<StoredContext>::iterator iter = m_Contexts.begin(); iter != m_Contexts.end(); ++iter)
8.1973 + {
8.1974 + delete iter->m_GenContext;
8.1975 + }
8.1976 + }
8.1977 +
8.1978 + int CHookManagerAutoGen::GetIfaceVersion()
8.1979 + {
8.1980 + return SH_HOOKMANAUTOGEN_IFACE_VERSION;
8.1981 + }
8.1982 +
8.1983 + int CHookManagerAutoGen::GetImplVersion()
8.1984 + {
8.1985 + return SH_HOOKMANAUTOGEN_IMPL_VERSION;
8.1986 + }
8.1987 +
8.1988 + HookManagerPubFunc CHookManagerAutoGen::MakeHookMan(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx)
8.1989 + {
8.1990 + CProto mproto(proto);
8.1991 + for (List<StoredContext>::iterator iter = m_Contexts.begin(); iter != m_Contexts.end(); ++iter)
8.1992 + {
8.1993 + if (iter->m_GenContext->Equal(mproto, vtbl_offs, vtbl_idx))
8.1994 + {
8.1995 + iter->m_RefCnt++;
8.1996 + return iter->m_GenContext->GetPubFunc();
8.1997 + }
8.1998 + }
8.1999 +
8.2000 + // Not found yet -> new one
8.2001 + StoredContext sctx;
8.2002 + sctx.m_RefCnt = 1;
8.2003 + sctx.m_GenContext = new GenContext(proto, vtbl_offs, vtbl_idx, m_pSHPtr);
8.2004 +
8.2005 + if (sctx.m_GenContext->GetPubFunc() == NULL)
8.2006 + {
8.2007 + return NULL;
8.2008 + }
8.2009 + else
8.2010 + {
8.2011 + m_Contexts.push_back(sctx);
8.2012 + return sctx.m_GenContext->GetPubFunc();
8.2013 + }
8.2014 + }
8.2015 +
8.2016 + void CHookManagerAutoGen::ReleaseHookMan(HookManagerPubFunc pubFunc)
8.2017 + {
8.2018 + for (List<StoredContext>::iterator iter = m_Contexts.begin(); iter != m_Contexts.end(); ++iter)
8.2019 + {
8.2020 + if (iter->m_GenContext->Equal(pubFunc))
8.2021 + {
8.2022 + iter->m_RefCnt--;
8.2023 + if (iter->m_RefCnt == 0)
8.2024 + {
8.2025 + delete iter->m_GenContext;
8.2026 + m_Contexts.erase(iter);
8.2027 + }
8.2028 + break;
8.2029 + }
8.2030 + }
8.2031 + }
8.2032 + }
8.2033 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/sourcehook/sourcehook_hookmangen.h Mon Nov 26 14:03:25 2007 +0000
9.3 @@ -0,0 +1,299 @@
9.4 +/* ======== SourceHook ========
9.5 +* Copyright (C) 2004-2007 Metamod:Source Development Team
9.6 +* No warranties of any kind
9.7 +*
9.8 +* License: zlib/libpng
9.9 +*
9.10 +* Author(s): Pavol "PM OnoTo" Marko
9.11 +* ============================
9.12 +*/
9.13 +
9.14 +#ifndef __SOURCEHOOK_HOOKMANGEN_H__
9.15 +#define __SOURCEHOOK_HOOKMANGEN_H__
9.16 +
9.17 +#include "sh_pagealloc.h"
9.18 +
9.19 +namespace SourceHook
9.20 +{
9.21 + namespace Impl
9.22 + {
9.23 +
9.24 + // Code gen stuff
9.25 +#if SH_COMP == SH_COMP_GCC
9.26 +#include <stdint.h>
9.27 + typedef int8_t jit_int8_t;
9.28 + typedef uint8_t jit_uint8_t;
9.29 + typedef int32_t jit_int32_t;
9.30 + typedef uint32_t jit_uint32_t;
9.31 + typedef int64_t jit_int64_t;
9.32 + typedef uint64_t jit_uint64_t;
9.33 +#elif SH_COMP == SH_COMP_MSVC
9.34 + typedef __int8 jit_int8_t;
9.35 + typedef unsigned __int8 jit_uint8_t;
9.36 + typedef __int32 jit_int32_t;
9.37 + typedef unsigned __int32 jit_uint32_t;
9.38 + typedef __int64 jit_int64_t;
9.39 + typedef unsigned __int64 jit_uint64_t;
9.40 +#endif
9.41 + typedef unsigned int jitoffs_t;
9.42 + typedef signed int jitrel_t;
9.43 +
9.44 +
9.45 + class GenBuffer
9.46 + {
9.47 + static CPageAlloc ms_Allocator;
9.48 +
9.49 + unsigned char *m_pData;
9.50 + jitoffs_t m_Size;
9.51 + jitoffs_t m_AllocatedSize;
9.52 +
9.53 + public:
9.54 + GenBuffer() : m_pData(NULL), m_Size(0), m_AllocatedSize(0)
9.55 + {
9.56 + }
9.57 + ~GenBuffer()
9.58 + {
9.59 + clear();
9.60 + }
9.61 + jitoffs_t GetSize()
9.62 + {
9.63 + return m_Size;
9.64 + }
9.65 + unsigned char *GetData()
9.66 + {
9.67 + return m_pData;
9.68 + }
9.69 +
9.70 + template <class PT> void push(PT what)
9.71 + {
9.72 + push((const unsigned char *)&what, sizeof(PT));
9.73 + }
9.74 +
9.75 + void push(const unsigned char *data, jitoffs_t size)
9.76 + {
9.77 + jitoffs_t newSize = m_Size + size;
9.78 + if (newSize > m_AllocatedSize)
9.79 + {
9.80 + m_AllocatedSize = newSize > m_AllocatedSize*2 ? newSize : m_AllocatedSize*2;
9.81 + if (m_AllocatedSize < 64)
9.82 + m_AllocatedSize = 64;
9.83 +
9.84 + unsigned char *newBuf;
9.85 + newBuf = reinterpret_cast<unsigned char*>(ms_Allocator.Alloc(m_AllocatedSize));
9.86 + ms_Allocator.SetRW(newBuf);
9.87 + if (!newBuf)
9.88 + {
9.89 + SH_ASSERT(0, ("bad_alloc: couldn't allocate 0x%08X bytes of memory\n", m_AllocatedSize));
9.90 + return;
9.91 + }
9.92 + memset((void*)newBuf, 0xCC, m_AllocatedSize); // :TODO: remove this !
9.93 + memcpy((void*)newBuf, (const void*)m_pData, m_Size);
9.94 + if (m_pData)
9.95 + {
9.96 + ms_Allocator.SetRE(reinterpret_cast<void*>(m_pData));
9.97 + ms_Allocator.SetRW(newBuf);
9.98 + ms_Allocator.Free(reinterpret_cast<void*>(m_pData));
9.99 + }
9.100 + m_pData = newBuf;
9.101 + }
9.102 + memcpy((void*)(m_pData + m_Size), (const void*)data, size);
9.103 + m_Size = newSize;
9.104 + }
9.105 +
9.106 + template <class PT> void rewrite(jitoffs_t offset, PT what)
9.107 + {
9.108 + rewrite(offset, (const unsigned char *)&what, sizeof(PT));
9.109 + }
9.110 +
9.111 + void rewrite(jitoffs_t offset, const unsigned char *data, jitoffs_t size)
9.112 + {
9.113 + SH_ASSERT(offset + size <= m_AllocatedSize, ("rewrite too far"));
9.114 +
9.115 + memcpy((void*)(m_pData + offset), (const void*)data, size);
9.116 + }
9.117 +
9.118 + void clear()
9.119 + {
9.120 + if (m_pData)
9.121 + ms_Allocator.Free(reinterpret_cast<void*>(m_pData));
9.122 + m_pData = NULL;
9.123 + m_Size = 0;
9.124 + m_AllocatedSize = 0;
9.125 + }
9.126 +
9.127 + void SetRE()
9.128 + {
9.129 + ms_Allocator.SetRE(reinterpret_cast<void*>(m_pData));
9.130 + }
9.131 +
9.132 + operator void *()
9.133 + {
9.134 + return reinterpret_cast<void*>(GetData());
9.135 + }
9.136 +
9.137 + void write_ubyte(jit_uint8_t x) { push(x); }
9.138 + void write_byte(jit_uint8_t x) { push(x); }
9.139 +
9.140 + void write_ushort(unsigned short x) { push(x); }
9.141 + void write_short(signed short x) { push(x); }
9.142 +
9.143 + void write_uint32(jit_uint32_t x) { push(x); }
9.144 + void write_int32(jit_uint32_t x) { push(x); }
9.145 +
9.146 + jitoffs_t get_outputpos()
9.147 + {
9.148 + return m_Size;
9.149 + }
9.150 +
9.151 + void start_count(jitoffs_t &offs)
9.152 + {
9.153 + offs = get_outputpos();
9.154 + }
9.155 + void end_count(jitoffs_t &offs)
9.156 + {
9.157 + offs = get_outputpos() - offs;
9.158 + }
9.159 + };
9.160 +
9.161 + class GenContext
9.162 + {
9.163 + const static int SIZE_MWORD = 4;
9.164 + const static int SIZE_PTR = sizeof(void*);
9.165 + const static int PassFlag_ForcedByRef = (1<<30); // ByVal in source, but actually passed by reference (GCC) -> private pass, destruct
9.166 +
9.167 + HookManagerPubFunc m_GeneratedPubFunc;
9.168 +
9.169 + CProto m_OrigProto; // original passed-in prototype
9.170 + CProto m_Proto;
9.171 + int m_VtblOffs;
9.172 + int m_VtblIdx;
9.173 + ISourceHook *m_SHPtr;
9.174 +
9.175 + GenBuffer m_HookFunc;
9.176 + GenBuffer m_PubFunc;
9.177 +
9.178 + ProtoInfo *m_BuiltPI;
9.179 + PassInfo *m_BuiltPI_Params;
9.180 + PassInfo::V2Info *m_BuiltPI_Params2;
9.181 +
9.182 + // For hookfunc
9.183 + void **m_pHI;
9.184 + void **m_HookfuncVfnptr;
9.185 +
9.186 + // Level 3 - Helpers
9.187 + int m_RegCounter;
9.188 + jit_int8_t NextRegEBX_ECX_EDX();
9.189 +
9.190 + int m_BytesPushedAfterInitialAlignment;
9.191 + enum AlignStackFlags
9.192 + {
9.193 + AlignStack_GCC_ThisOnStack = 1,
9.194 + AlignStack_MSVC_ThisOnStack = 2,
9.195 + AlignStack_MemRet = 4
9.196 + };
9.197 + jit_int32_t AlignStackBeforeCall(int paramsize, int flags);
9.198 + void AlignStackAfterCall(jit_int32_t numofbytes);
9.199 + void CheckAlignmentBeforeCall();
9.200 +
9.201 + // size info
9.202 + jit_int32_t GetRealSize(const IntPassInfo &info); // checks for reference
9.203 + jit_int32_t AlignSize(jit_int32_t x, jit_int32_t boundary); // align a size
9.204 + jit_int32_t GetParamStackSize(const IntPassInfo &info); // get the size of a param in the param stack
9.205 + short GetParamsTotalStackSize(); // sum(GetParamStackSize(param[i]), 0 <= i < numOfParams)
9.206 +
9.207 + // Helpers
9.208 + void BitwiseCopy_Setup();
9.209 + void BitwiseCopy_Do(size_t size);
9.210 +
9.211 +
9.212 + // HookFunc frame
9.213 + jit_int32_t m_HookFunc_FrameOffset;
9.214 + jit_int32_t m_HookFunc_FrameVarsSize;
9.215 +
9.216 + void ResetFrame(jit_int32_t startOffset);
9.217 + jit_int32_t AddVarToFrame(jit_int32_t size);
9.218 + jit_int32_t ComputeVarsSize();
9.219 +
9.220 + // Param push
9.221 + short GetForcedByRefParamsSize(); // sum(param[i] is forcedbyref ? GetStackSize(param[i]) : 0, 0 <= i < numOfParams)
9.222 + short GetForcedByRefParamOffset(int p); // sum(param[i] is forcedbyref ? GetStackSize(param[i]) : 0, 0 <= i < p)
9.223 + jit_int32_t PushParams(jit_int32_t param_base_offset, jit_int32_t save_ret_to,
9.224 + jit_int32_t v_place_for_memret, jit_int32_t v_place_fbrr_base); // save_ret_to and v_place_for_memret only used for memory returns
9.225 + jit_int32_t PushRef(jit_int32_t param_offset, const IntPassInfo &pi);
9.226 + jit_int32_t PushBasic(jit_int32_t param_offset, const IntPassInfo &pi);
9.227 + jit_int32_t PushFloat(jit_int32_t param_offset, const IntPassInfo &pi);
9.228 + jit_int32_t PushObject(jit_int32_t param_offset, const IntPassInfo &pi, jit_int32_t v_place_fbrr);
9.229 + jit_int32_t PushMemRetPtr(jit_int32_t save_ret_to, jit_int32_t v_place_for_memret);
9.230 + void DestroyParams(jit_int32_t fbrr_base);
9.231 +
9.232 + // Ret val processing
9.233 + void SaveRetVal(jit_int32_t v_where, jit_int32_t v_place_for_memret);
9.234 + void ProcessPluginRetVal(jit_int32_t v_cur_res, jit_int32_t v_pContext, jit_int32_t v_plugin_ret);
9.235 +
9.236 + void PrepareReturn(jit_int32_t v_status, jit_int32_t v_pContext, jit_int32_t v_retptr);
9.237 + void DoReturn(jit_int32_t v_retptr, jit_int32_t v_memret_outaddr);
9.238 +
9.239 + bool MemRetWithTempObj(); // do we do a memory return AND need a temporary place for it?
9.240 +
9.241 + // Call hooks
9.242 + void GenerateCallHooks(int v_status, int v_prev_res, int v_cur_res, int v_iter,
9.243 + int v_pContext, int base_param_offset, int v_plugin_ret, int v_place_for_memret, jit_int32_t v_place_fbrr_base, jit_int32_t v_va_buf);
9.244 +
9.245 + // Call orig
9.246 + void GenerateCallOrig(int v_status, int v_pContext, int param_base_offs, int v_this,
9.247 + int v_vfnptr_origentry, int v_orig_ret, int v_override_ret, int v_place_for_memret, jit_int32_t v_place_fbrr_base, jit_int32_t v_va_buf);
9.248 +
9.249 + // Hook loop
9.250 + void CallSetupHookLoop(int v_orig_ret, int v_override_ret,
9.251 + int v_cur_res, int v_prev_res, int v_status, int v_vnfptr_origentry,
9.252 + int v_this, int v_pContext);
9.253 +
9.254 + void CallEndContext(int v_pContext);
9.255 +
9.256 + // Level 2 -> called from Generate()
9.257 + void AutoDetectRetType();
9.258 + void AutoDetectParamFlags();
9.259 + bool PassInfoSupported(const IntPassInfo &pi, bool is_ret);
9.260 + void Clear();
9.261 + void BuildProtoInfo();
9.262 + void *GenerateHookFunc();
9.263 + void *GeneratePubFunc();
9.264 +
9.265 + HookManagerPubFunc Generate();
9.266 + public:
9.267 + // Level 1 -> Public interface
9.268 + GenContext(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx, ISourceHook *pSHPtr);
9.269 + ~GenContext();
9.270 +
9.271 + bool Equal(const CProto &proto, int vtbl_offs, int vtbl_idx);
9.272 + bool Equal(HookManagerPubFunc other);
9.273 +
9.274 + HookManagerPubFunc GetPubFunc();
9.275 + };
9.276 +
9.277 + class CHookManagerAutoGen : public IHookManagerAutoGen
9.278 + {
9.279 + struct StoredContext
9.280 + {
9.281 + int m_RefCnt;
9.282 + GenContext *m_GenContext;
9.283 + };
9.284 + List<StoredContext> m_Contexts;
9.285 + ISourceHook *m_pSHPtr;
9.286 +
9.287 + public:
9.288 + CHookManagerAutoGen(ISourceHook *pSHPtr);
9.289 + ~CHookManagerAutoGen();
9.290 +
9.291 + int GetIfaceVersion();
9.292 + int GetImplVersion();
9.293 +
9.294 + HookManagerPubFunc MakeHookMan(const ProtoInfo *proto, int vtbl_offs, int vtbl_idx);
9.295 + void ReleaseHookMan(HookManagerPubFunc pubFunc);
9.296 + };
9.297 +
9.298 + }
9.299 +}
9.300 +
9.301 +
9.302 +#endif
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/sourcehook/sourcehook_hookmangen_x86.h Mon Nov 26 14:03:25 2007 +0000
10.3 @@ -0,0 +1,1611 @@
10.4 +/* ======== SourceHook ========
10.5 +* vim: set ts=4 :
10.6 +* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
10.7 +* No warranties of any kind
10.8 +*
10.9 +* License: zlib/libpng
10.10 +*
10.11 +* from the SourcePawn JIT SDK
10.12 +* ============================
10.13 +*/
10.14 +
10.15 +#ifndef __SOURCEHOOK_HOOKMANGEN_X86_H__
10.16 +#define __SOURCEHOOK_HOOKMANGEN_X86_H__
10.17 +
10.18 +#include <limits.h>
10.19 +
10.20 +#undef REG_EAX
10.21 +#undef REG_ECX
10.22 +#undef REG_EDX
10.23 +#undef REG_EBX
10.24 +#undef REG_ESP
10.25 +#undef REG_SIB
10.26 +#undef REG_EBP
10.27 +#undef REG_ESI
10.28 +#undef REG_EDI
10.29 +
10.30 +//MOD R/M
10.31 +#define MOD_MEM_REG 0
10.32 +#define MOD_DISP8 1
10.33 +#define MOD_DISP32 2
10.34 +#define MOD_REG 3
10.35 +
10.36 +//SIB
10.37 +#define NOSCALE 0
10.38 +#define SCALE2 1
10.39 +#define SCALE4 2
10.40 +#define SCALE8 3
10.41 +
10.42 +//Register codes
10.43 +#define REG_EAX 0
10.44 +#define REG_ECX 1
10.45 +#define REG_EDX 2
10.46 +#define REG_EBX 3
10.47 +#define REG_ESP 4
10.48 +#define REG_SIB 4
10.49 +#define REG_NOIDX 4
10.50 +#define REG_IMM_BASE 5
10.51 +#define REG_EBP 5
10.52 +#define REG_ESI 6
10.53 +#define REG_EDI 7
10.54 +
10.55 +#define IA32_16BIT_PREFIX 0x66
10.56 +
10.57 +//condition codes (for example, Jcc opcodes)
10.58 +#define CC_B 0x2
10.59 +#define CC_NAE CC_B
10.60 +#define CC_NB 0x3
10.61 +#define CC_AE CC_NB
10.62 +#define CC_E 0x4
10.63 +#define CC_Z CC_E
10.64 +#define CC_NE 0x5
10.65 +#define CC_NZ CC_NE
10.66 +#define CC_NA 0x6
10.67 +#define CC_BE CC_NA
10.68 +#define CC_A 0x7
10.69 +#define CC_NBE CC_A
10.70 +#define CC_L 0xC
10.71 +#define CC_NGE CC_L
10.72 +#define CC_NL 0xD
10.73 +#define CC_GE CC_NL
10.74 +#define CC_NG 0xE
10.75 +#define CC_LE CC_NG
10.76 +#define CC_G 0xF
10.77 +#define CC_NLE CC_G
10.78 +
10.79 +//Opcodes with encoding information
10.80 +#define IA32_XOR_RM_REG 0x31 // encoding is /r
10.81 +#define IA32_XOR_REG_RM 0x33 // encoding is /r
10.82 +#define IA32_XOR_EAX_IMM32 0x35 // encoding is /r
10.83 +#define IA32_XOR_RM_IMM32 0x81 // encoding is /6
10.84 +#define IA32_XOR_RM_IMM8 0x83 // encoding is /6
10.85 +#define IA32_ADD_RM_REG 0x01 // encoding is /r
10.86 +#define IA32_ADD_REG_RM 0x03 // encoding is /r
10.87 +#define IA32_ADD_RM_IMM32 0x81 // encoding is /0
10.88 +#define IA32_ADD_RM_IMM8 0x83 // encoding is /0
10.89 +#define IA32_ADD_EAX_IMM32 0x05 // no extra encoding
10.90 +#define IA32_SUB_RM_REG 0x29 // encoding is /r
10.91 +#define IA32_SUB_REG_RM 0x2B // encoding is /r
10.92 +#define IA32_SUB_RM_IMM8 0x83 // encoding is /5 <imm8>
10.93 +#define IA32_SUB_RM_IMM32 0x81 // encoding is /5 <imm32>
10.94 +#define IA32_SBB_REG_RM 0x1B // encoding is /r
10.95 +#define IA32_SBB_RM_IMM8 0x83 // encoding is <imm32>
10.96 +#define IA32_JMP_IMM32 0xE9 // encoding is imm32
10.97 +#define IA32_JMP_IMM8 0xEB // encoding is imm8
10.98 +#define IA32_JMP_RM 0xFF // encoding is /4
10.99 +#define IA32_CALL_IMM32 0xE8 // relative call, <imm32>
10.100 +#define IA32_CALL_RM 0xFF // encoding is /2
10.101 +#define IA32_MOV_REG_IMM 0xB8 // encoding is +r <imm32>
10.102 +#define IA32_MOV_RM8_REG 0x88 // encoding is /r
10.103 +#define IA32_MOV_RM_REG 0x89 // encoding is /r
10.104 +#define IA32_MOV_REG_RM 0x8B // encoding is /r
10.105 +#define IA32_MOV_REG8_RM8 0x8A // encoding is /r
10.106 +#define IA32_MOV_RM8_REG8 0x88 // encoding is /r
10.107 +#define IA32_MOV_RM_IMM32 0xC7 // encoding is /0
10.108 +#define IA32_CMP_RM_IMM32 0x81 // encoding is /7 <imm32>
10.109 +#define IA32_CMP_RM_IMM8 0x83 // encoding is /7 <imm8>
10.110 +#define IA32_CMP_AL_IMM32 0x3C // no extra encoding
10.111 +#define IA32_CMP_EAX_IMM32 0x3D // no extra encoding
10.112 +#define IA32_CMP_RM_REG 0x39 // encoding is /r
10.113 +#define IA32_CMP_REG_RM 0x3B // encoding is /r
10.114 +#define IA32_CMPSB 0xA6 // no extra encoding
10.115 +#define IA32_TEST_RM_REG8 0x84 // encoding is /r
10.116 +#define IA32_TEST_RM_REG 0x85 // encoding is /r
10.117 +#define IA32_TEST_RM_IMM32 0xF7 // encoding is /0 <imm32>
10.118 +#define IA32_JCC_IMM 0x70 // encoding is +cc <imm8>
10.119 +#define IA32_JCC_IMM32_1 0x0F // opcode part 1
10.120 +#define IA32_JCC_IMM32_2 0x80 // encoding is +cc <imm32>
10.121 +#define IA32_RET 0xC3 // no extra encoding
10.122 +#define IA32_RETN 0xC2 // encoding is <imm16>
10.123 +#define IA32_NEG_RM 0xF7 // encoding is /3
10.124 +#define IA32_INC_REG 0x40 // encoding is +r
10.125 +#define IA32_INC_RM 0xFF // encoding is /0
10.126 +#define IA32_DEC_REG 0x48 // encoding is +r
10.127 +#define IA32_DEC_RM 0xFF // encoding is /1
10.128 +#define IA32_OR_REG_RM 0x0B // encoding is /r
10.129 +#define IA32_AND_REG_RM 0x23 // encoding is /r
10.130 +#define IA32_AND_EAX_IMM32 0x25 // encoding is <imm32>
10.131 +#define IA32_AND_RM_IMM32 0x81 // encoding is /4
10.132 +#define IA32_AND_RM_IMM8 0x83 // encoding is /4
10.133 +#define IA32_NOT_RM 0xF7 // encoding is /2
10.134 +#define IA32_DIV_RM 0xF7 // encoding is /6
10.135 +#define IA32_MUL_RM 0xF7 // encoding is /4
10.136 +#define IA32_IDIV_RM 0xF7 // encoding is /7
10.137 +#define IA32_IMUL_RM 0xF7 // encoding is /5
10.138 +#define IA32_IMUL_REG_IMM32 0x69 // encoding is /r
10.139 +#define IA32_IMUL_REG_IMM8 0x6B // encoding is /r
10.140 +#define IA32_IMUL_REG_RM_1 0x0F // encoding is _2
10.141 +#define IA32_IMUL_REG_RM_2 0xAF // encoding is /r
10.142 +#define IA32_SHR_RM_IMM8 0xC1 // encoding is /5 <ib>
10.143 +#define IA32_SHR_RM_1 0xD1 // encoding is /5
10.144 +#define IA32_SHL_RM_IMM8 0xC1 // encoding is /4 <ib>
10.145 +#define IA32_SHL_RM_1 0xD1 // encoding is /4
10.146 +#define IA32_SAR_RM_CL 0xD3 // encoding is /7
10.147 +#define IA32_SAR_RM_1 0xD1 // encoding is /7
10.148 +#define IA32_SHR_RM_CL 0xD3 // encoding is /5
10.149 +#define IA32_SHL_RM_CL 0xD3 // encoding is /4
10.150 +#define IA32_SAR_RM_IMM8 0xC1 // encoding is /7 <ib>
10.151 +#define IA32_SETCC_RM8_1 0x0F // opcode part 1
10.152 +#define IA32_SETCC_RM8_2 0x90 // encoding is +cc /0 (8bits)
10.153 +#define IA32_CMOVCC_RM_1 0x0F // opcode part 1
10.154 +#define IA32_CMOVCC_RM_2 0x40 // encoding is +cc /r
10.155 +#define IA32_XCHG_EAX_REG 0x90 // encoding is +r
10.156 +#define IA32_LEA_REG_MEM 0x8D // encoding is /r
10.157 +#define IA32_POP_REG 0x58 // encoding is +r
10.158 +#define IA32_PUSH_REG 0x50 // encoding is +r
10.159 +#define IA32_PUSH_RM 0xFF // encoding is /6
10.160 +#define IA32_PUSH_IMM32 0x68 // encoding is <imm32>
10.161 +#define IA32_PUSH_IMM8 0x6A // encoding is <imm8>
10.162 +#define IA32_REP 0xF3 // no extra encoding
10.163 +#define IA32_MOVSD 0xA5 // no extra encoding
10.164 +#define IA32_MOVSB 0xA4 // no extra encoding
10.165 +#define IA32_STOSD 0xAB // no extra encoding
10.166 +#define IA32_CLD 0xFC // no extra encoding
10.167 +#define IA32_PUSHAD 0x60 // no extra encoding
10.168 +#define IA32_POPAD 0x61 // no extra encoding
10.169 +#define IA32_NOP 0x90 // no extra encoding
10.170 +#define IA32_INT3 0xCC // no extra encoding
10.171 +#define IA32_FSTP_MEM32 0xD9 // encoding is /3
10.172 +#define IA32_FSTP_MEM64 0xDD // encoding is /3
10.173 +#define IA32_FLD_MEM32 0xD9 // encoding is /0
10.174 +#define IA32_FLD_MEM64 0xDD // encoding is /0
10.175 +#define IA32_FILD_MEM32 0xDB // encoding is /0
10.176 +#define IA32_FADD_MEM32 0xD8 // encoding is /0
10.177 +#define IA32_FADD_FPREG_ST0_1 0xDC // opcode part 1
10.178 +#define IA32_FADD_FPREG_ST0_2 0xC0 // encoding is +r
10.179 +#define IA32_FSUB_MEM32 0xD8 // encoding is /4
10.180 +#define IA32_FMUL_MEM32 0xD8 // encoding is /1
10.181 +#define IA32_FDIV_MEM32 0xD8 // encoding is /6
10.182 +#define IA32_FSTCW_MEM16_1 0x9B // opcode part 1
10.183 +#define IA32_FSTCW_MEM16_2 0xD9 // encoding is /7
10.184 +#define IA32_FLDCW_MEM16 0xD9 // encoding is /5
10.185 +#define IA32_FISTP_MEM32 0xDB // encoding is /3
10.186 +#define IA32_FUCOMIP_1 0xDF // opcode part 1
10.187 +#define IA32_FUCOMIP_2 0xE8 // encoding is +r
10.188 +#define IA32_FSTP_FPREG_1 0xDD // opcode part 1
10.189 +#define IA32_FSTP_FPREG_2 0xD8 // encoding is +r
10.190 +#define IA32_MOVZX_R32_RM8_1 0x0F // opcode part 1
10.191 +#define IA32_MOVZX_R32_RM8_2 0xB6 // encoding is /r
10.192 +#define IA32_MOVZX_R32_RM16_1 0x0F // opcode part 1
10.193 +#define IA32_MOVZX_R32_RM16_2 0xB7 // encoding is /r
10.194 +
10.195 +
10.196 +namespace SourceHook
10.197 +{
10.198 + namespace Impl
10.199 + {
10.200 + typedef GenBuffer JitWriter;
10.201 +
10.202 + inline jit_uint8_t ia32_modrm(jit_uint8_t mode, jit_uint8_t reg, jit_uint8_t rm)
10.203 + {
10.204 + jit_uint8_t modrm = (mode << 6);
10.205 +
10.206 + modrm |= (reg << 3);
10.207 + modrm |= (rm);
10.208 +
10.209 + return modrm;
10.210 + }
10.211 +
10.212 + //mode is the scaling method - NOSCALE ... SCALE8
10.213 + //index is the register that is scaled
10.214 + //base is the base register
10.215 + inline jit_uint8_t ia32_sib(jit_uint8_t mode, jit_uint8_t index, jit_uint8_t base)
10.216 + {
10.217 + jit_uint8_t sib = (mode << 6);
10.218 +
10.219 + sib |= (index << 3);
10.220 + sib |= (base);
10.221 +
10.222 + return sib;
10.223 + }
10.224 +
10.225 + inline void IA32_Int3(JitWriter *jit)
10.226 + {
10.227 + jit->write_ubyte(IA32_INT3);
10.228 + }
10.229 +
10.230 + /***********************
10.231 + * INCREMENT/DECREMENT *
10.232 + ***********************/
10.233 +
10.234 + inline void IA32_Inc_Reg(JitWriter *jit, jit_uint8_t reg)
10.235 + {
10.236 + jit->write_ubyte(IA32_INC_REG+reg);
10.237 + }
10.238 +
10.239 + inline void IA32_Inc_Rm_Disp8(JitWriter *jit, jit_uint8_t reg, jit_int8_t disp)
10.240 + {
10.241 + jit->write_ubyte(IA32_INC_RM);
10.242 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 0, reg));
10.243 + jit->write_byte(disp);
10.244 + }
10.245 +
10.246 + inline void IA32_Inc_Rm_Disp32(JitWriter *jit, jit_uint8_t reg, jit_int32_t disp)
10.247 + {
10.248 + jit->write_ubyte(IA32_INC_RM);
10.249 + jit->write_ubyte(ia32_modrm(MOD_DISP32, 0, reg));
10.250 + jit->write_int32(disp);
10.251 + }
10.252 +
10.253 + inline void IA32_Inc_Rm_Disp_Reg(JitWriter *jit, jit_uint8_t base, jit_uint8_t reg, jit_uint8_t scale)
10.254 + {
10.255 + jit->write_ubyte(IA32_INC_RM);
10.256 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 0, REG_SIB));
10.257 + jit->write_ubyte(ia32_sib(scale, reg, base));
10.258 + }
10.259 +
10.260 + inline void IA32_Dec_Reg(JitWriter *jit, jit_uint8_t reg)
10.261 + {
10.262 + jit->write_ubyte(IA32_DEC_REG+reg);
10.263 + }
10.264 +
10.265 + inline void IA32_Dec_Rm_Disp8(JitWriter *jit, jit_uint8_t reg, jit_int8_t disp)
10.266 + {
10.267 + jit->write_ubyte(IA32_DEC_RM);
10.268 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 1, reg));
10.269 + jit->write_byte(disp);
10.270 + }
10.271 +
10.272 + inline void IA32_Dec_Rm_Disp32(JitWriter *jit, jit_uint8_t reg, jit_int32_t disp)
10.273 + {
10.274 + jit->write_ubyte(IA32_DEC_RM);
10.275 + jit->write_ubyte(ia32_modrm(MOD_DISP32, 1, reg));
10.276 + jit->write_int32(disp);
10.277 + }
10.278 +
10.279 + inline void IA32_Dec_Rm_Disp_Reg(JitWriter *jit, jit_uint8_t base, jit_uint8_t reg, jit_uint8_t scale)
10.280 + {
10.281 + jit->write_ubyte(IA32_DEC_RM);
10.282 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 1, REG_SIB));
10.283 + jit->write_ubyte(ia32_sib(scale, reg, base));
10.284 + }
10.285 +
10.286 + /****************
10.287 + * BINARY LOGIC *
10.288 + ****************/
10.289 +
10.290 + inline void IA32_Xor_Rm_Reg(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t dest_mode)
10.291 + {
10.292 + jit->write_ubyte(IA32_XOR_RM_REG);
10.293 + jit->write_ubyte(ia32_modrm(dest_mode, src, dest));
10.294 + }
10.295 +
10.296 + inline void IA32_Xor_Reg_Rm(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t dest_mode)
10.297 + {
10.298 + jit->write_ubyte(IA32_XOR_REG_RM);
10.299 + jit->write_ubyte(ia32_modrm(dest_mode, dest, src));
10.300 + }
10.301 +
10.302 + inline void IA32_Xor_Rm_Imm8(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode, jit_int8_t value)
10.303 + {
10.304 + jit->write_ubyte(IA32_XOR_RM_IMM8);
10.305 + jit->write_ubyte(ia32_modrm(mode, 6, reg));
10.306 + jit->write_byte(value);
10.307 + }
10.308 +
10.309 + inline void IA32_Xor_Rm_Imm32(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode, jit_int32_t value)
10.310 + {
10.311 + jit->write_ubyte(IA32_XOR_RM_IMM32);
10.312 + jit->write_ubyte(ia32_modrm(mode, 6, reg));
10.313 + jit->write_int32(value);
10.314 + }
10.315 +
10.316 + inline void IA32_Xor_Eax_Imm32(JitWriter *jit, jit_int32_t value)
10.317 + {
10.318 + jit->write_ubyte(IA32_XOR_EAX_IMM32);
10.319 + jit->write_int32(value);
10.320 + }
10.321 +
10.322 + inline void IA32_Neg_Rm(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode)
10.323 + {
10.324 + jit->write_ubyte(IA32_NEG_RM);
10.325 + jit->write_ubyte(ia32_modrm(mode, 3, reg));
10.326 + }
10.327 +
10.328 + inline void IA32_Or_Reg_Rm(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.329 + {
10.330 + jit->write_ubyte(IA32_OR_REG_RM);
10.331 + jit->write_ubyte(ia32_modrm(mode, dest, src));
10.332 + }
10.333 +
10.334 + inline void IA32_And_Reg_Rm(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.335 + {
10.336 + jit->write_ubyte(IA32_AND_REG_RM);
10.337 + jit->write_ubyte(ia32_modrm(mode, dest, src));
10.338 + }
10.339 +
10.340 + inline void IA32_And_Rm_Imm32(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode, jit_int32_t value)
10.341 + {
10.342 + jit->write_ubyte(IA32_AND_RM_IMM32);
10.343 + jit->write_ubyte(ia32_modrm(mode, 4, reg));
10.344 + jit->write_int32(value);
10.345 + }
10.346 +
10.347 + inline void IA32_And_Rm_Imm8(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode, jit_int8_t value)
10.348 + {
10.349 + jit->write_ubyte(IA32_AND_RM_IMM8);
10.350 + jit->write_ubyte(ia32_modrm(mode, 4, reg));
10.351 + jit->write_byte(value);
10.352 + }
10.353 +
10.354 + inline void IA32_And_Eax_Imm32(JitWriter *jit, jit_int32_t value)
10.355 + {
10.356 + jit->write_ubyte(IA32_AND_EAX_IMM32);
10.357 + jit->write_int32(value);
10.358 + }
10.359 +
10.360 + inline void IA32_Not_Rm(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode)
10.361 + {
10.362 + jit->write_ubyte(IA32_NOT_RM);
10.363 + jit->write_ubyte(ia32_modrm(mode, 2, reg));
10.364 + }
10.365 +
10.366 + inline void IA32_Shr_Rm_Imm8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t value, jit_uint8_t mode)
10.367 + {
10.368 + jit->write_ubyte(IA32_SHR_RM_IMM8);
10.369 + jit->write_ubyte(ia32_modrm(mode, 5, dest));
10.370 + jit->write_ubyte(value);
10.371 + }
10.372 +
10.373 + inline void IA32_Shr_Rm_1(JitWriter *jit, jit_uint8_t dest, jit_uint8_t mode)
10.374 + {
10.375 + jit->write_ubyte(IA32_SHR_RM_1);
10.376 + jit->write_ubyte(ia32_modrm(mode, 5, dest));
10.377 + }
10.378 +
10.379 + inline void IA32_Shl_Rm_Imm8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t value, jit_uint8_t mode)
10.380 + {
10.381 + jit->write_ubyte(IA32_SHL_RM_IMM8);
10.382 + jit->write_ubyte(ia32_modrm(mode, 4, dest));
10.383 + jit->write_ubyte(value);
10.384 + }
10.385 +
10.386 + inline void IA32_Shl_Rm_1(JitWriter *jit, jit_uint8_t dest, jit_uint8_t mode)
10.387 + {
10.388 + jit->write_ubyte(IA32_SHL_RM_1);
10.389 + jit->write_ubyte(ia32_modrm(mode, 4, dest));
10.390 + }
10.391 +
10.392 + inline void IA32_Sar_Rm_Imm8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t value, jit_uint8_t mode)
10.393 + {
10.394 + jit->write_ubyte(IA32_SAR_RM_IMM8);
10.395 + jit->write_ubyte(ia32_modrm(mode, 7, dest));
10.396 + jit->write_ubyte(value);
10.397 + }
10.398 +
10.399 + inline void IA32_Sar_Rm_CL(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode)
10.400 + {
10.401 + jit->write_ubyte(IA32_SAR_RM_CL);
10.402 + jit->write_ubyte(ia32_modrm(mode, 7, reg));
10.403 + }
10.404 +
10.405 + inline void IA32_Sar_Rm_1(JitWriter *jit, jit_uint8_t dest, jit_uint8_t mode)
10.406 + {
10.407 + jit->write_ubyte(IA32_SAR_RM_1);
10.408 + jit->write_ubyte(ia32_modrm(mode, 7, dest));
10.409 + }
10.410 +
10.411 + inline void IA32_Shr_Rm_CL(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode)
10.412 + {
10.413 + jit->write_ubyte(IA32_SHR_RM_CL);
10.414 + jit->write_ubyte(ia32_modrm(mode, 5, reg));
10.415 + }
10.416 +
10.417 + inline void IA32_Shl_Rm_CL(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode)
10.418 + {
10.419 + jit->write_ubyte(IA32_SHL_RM_CL);
10.420 + jit->write_ubyte(ia32_modrm(mode, 4, reg));
10.421 + }
10.422 +
10.423 + inline void IA32_Xchg_Eax_Reg(JitWriter *jit, jit_uint8_t reg)
10.424 + {
10.425 + jit->write_ubyte(IA32_XCHG_EAX_REG+reg);
10.426 + }
10.427 +
10.428 + /**********************
10.429 + * ARITHMETIC (BASIC) *
10.430 + **********************/
10.431 +
10.432 + inline void IA32_Add_Rm_Reg(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.433 + {
10.434 + jit->write_ubyte(IA32_ADD_RM_REG);
10.435 + jit->write_ubyte(ia32_modrm(mode, src, dest));
10.436 + }
10.437 +
10.438 + inline void IA32_Add_Reg_Rm(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.439 + {
10.440 + jit->write_ubyte(IA32_ADD_REG_RM);
10.441 + jit->write_ubyte(ia32_modrm(mode, dest, src));
10.442 + }
10.443 +
10.444 + inline void IA32_Add_Rm_Imm8(JitWriter *jit, jit_uint8_t reg, jit_int8_t value, jit_uint8_t mode)
10.445 + {
10.446 + jit->write_ubyte(IA32_ADD_RM_IMM8);
10.447 + jit->write_ubyte(ia32_modrm(mode, 0, reg));
10.448 + jit->write_byte(value);
10.449 + }
10.450 +
10.451 + inline void IA32_Add_Rm_Imm32(JitWriter *jit, jit_uint8_t reg, jit_int32_t value, jit_uint8_t mode)
10.452 + {
10.453 + jit->write_ubyte(IA32_ADD_RM_IMM32);
10.454 + jit->write_ubyte(ia32_modrm(mode, 0, reg));
10.455 + jit->write_int32(value);
10.456 + }
10.457 +
10.458 + inline void IA32_Add_Rm_ImmAuto(JitWriter *jit, jit_uint8_t reg, jit_int32_t value, jit_uint8_t mode)
10.459 + {
10.460 + if (value >= SCHAR_MIN && value <= SCHAR_MAX)
10.461 + IA32_Add_Rm_Imm8(jit, reg, static_cast<jit_int8_t>(value), mode);
10.462 + else
10.463 + IA32_Add_Rm_Imm32(jit, reg, value, mode);
10.464 + }
10.465 +
10.466 + inline void IA32_Add_Eax_Imm32(JitWriter *jit, jit_int32_t value)
10.467 + {
10.468 + jit->write_ubyte(IA32_ADD_EAX_IMM32);
10.469 + jit->write_int32(value);
10.470 + }
10.471 +
10.472 + inline void IA32_Sub_Rm_Reg(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.473 + {
10.474 + jit->write_ubyte(IA32_SUB_RM_REG);
10.475 + jit->write_ubyte(ia32_modrm(mode, src, dest));
10.476 + }
10.477 +
10.478 + inline void IA32_Sub_Reg_Rm(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.479 + {
10.480 + jit->write_ubyte(IA32_SUB_REG_RM);
10.481 + jit->write_ubyte(ia32_modrm(mode, dest, src));
10.482 + }
10.483 +
10.484 + inline void IA32_Sub_Reg_Rm_Disp8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int8_t disp8)
10.485 + {
10.486 + jit->write_ubyte(IA32_SUB_REG_RM);
10.487 + jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, src));
10.488 + jit->write_byte(disp8);
10.489 + }
10.490 +
10.491 + inline void IA32_Sub_Rm_Reg_Disp8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int8_t disp8)
10.492 + {
10.493 + jit->write_ubyte(IA32_SUB_RM_REG);
10.494 + jit->write_ubyte(ia32_modrm(MOD_DISP8, src, dest));
10.495 + jit->write_byte(disp8);
10.496 + }
10.497 +
10.498 + inline void IA32_Sub_Rm_Imm8(JitWriter *jit, jit_uint8_t reg, jit_int8_t val, jit_uint8_t mode)
10.499 + {
10.500 + jit->write_ubyte(IA32_SUB_RM_IMM8);
10.501 + jit->write_ubyte(ia32_modrm(mode, 5, reg));
10.502 + jit->write_byte(val);
10.503 + }
10.504 +
10.505 + inline void IA32_Sub_Rm_Imm32(JitWriter *jit, jit_uint8_t reg, jit_int32_t val, jit_uint8_t mode)
10.506 + {
10.507 + jit->write_ubyte(IA32_SUB_RM_IMM32);
10.508 + jit->write_ubyte(ia32_modrm(mode, 5, reg));
10.509 + jit->write_int32(val);
10.510 + }
10.511 +
10.512 + inline void IA32_Sub_Rm_ImmAuto(JitWriter *jit, jit_uint8_t reg, jit_int32_t val, jit_uint8_t mode)
10.513 + {
10.514 + if (val >= SCHAR_MIN && val <= SCHAR_MAX)
10.515 + IA32_Sub_Rm_Imm8(jit, reg, static_cast<jit_int8_t>(val), mode);
10.516 + else
10.517 + IA32_Sub_Rm_Imm32(jit, reg, val, mode);
10.518 + }
10.519 +
10.520 + inline void IA32_Sbb_Reg_Rm(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.521 + {
10.522 + jit->write_ubyte(IA32_SBB_REG_RM);
10.523 + jit->write_ubyte(ia32_modrm(mode, dest, src));
10.524 + }
10.525 +
10.526 + inline void IA32_Sbb_Rm_Imm8(JitWriter *jit, jit_uint8_t dest, jit_int8_t value, jit_uint8_t mode)
10.527 + {
10.528 + jit->write_ubyte(IA32_SBB_RM_IMM8);
10.529 + jit->write_ubyte(ia32_modrm(mode, 3, dest));
10.530 + jit->write_byte(value);
10.531 + }
10.532 +
10.533 + inline void IA32_Div_Rm(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode)
10.534 + {
10.535 + jit->write_ubyte(IA32_DIV_RM);
10.536 + jit->write_ubyte(ia32_modrm(mode, 6, reg));
10.537 + }
10.538 +
10.539 + inline void IA32_IDiv_Rm(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode)
10.540 + {
10.541 + jit->write_ubyte(IA32_IDIV_RM);
10.542 + jit->write_ubyte(ia32_modrm(mode, 7, reg));
10.543 + }
10.544 +
10.545 + inline void IA32_Mul_Rm(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode)
10.546 + {
10.547 + jit->write_ubyte(IA32_MUL_RM);
10.548 + jit->write_ubyte(ia32_modrm(mode, 4, reg));
10.549 + }
10.550 +
10.551 + inline void IA32_IMul_Rm(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode)
10.552 + {
10.553 + jit->write_ubyte(IA32_IMUL_RM);
10.554 + jit->write_ubyte(ia32_modrm(mode, 5, reg));
10.555 + }
10.556 +
10.557 + inline void IA32_IMul_Reg_Imm8(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode, jit_int8_t value)
10.558 + {
10.559 + jit->write_ubyte(IA32_IMUL_REG_IMM8);
10.560 + jit->write_ubyte(ia32_modrm(mode, 0, reg));
10.561 + jit->write_byte(value);
10.562 + }
10.563 +
10.564 + inline void IA32_IMul_Reg_Imm32(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode, jit_int32_t value)
10.565 + {
10.566 + jit->write_ubyte(IA32_IMUL_REG_IMM32);
10.567 + jit->write_ubyte(ia32_modrm(mode, 0, reg));
10.568 + jit->write_int32(value);
10.569 + }
10.570 +
10.571 + inline void IA32_IMul_Reg_Rm(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.572 + {
10.573 + jit->write_ubyte(IA32_IMUL_REG_RM_1);
10.574 + jit->write_ubyte(IA32_IMUL_REG_RM_2);
10.575 + jit->write_ubyte(ia32_modrm(mode, dest, src));
10.576 + }
10.577 +
10.578 + inline void IA32_Add_Rm_Reg_Disp8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int8_t disp)
10.579 + {
10.580 + jit->write_ubyte(IA32_ADD_RM_REG);
10.581 + jit->write_ubyte(ia32_modrm(MOD_DISP8, src, dest));
10.582 + jit->write_byte(disp);
10.583 + }
10.584 +
10.585 + inline void IA32_Add_Reg_Rm_Disp8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int8_t disp)
10.586 + {
10.587 + jit->write_ubyte(IA32_ADD_REG_RM);
10.588 + jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, src));
10.589 + jit->write_byte(disp);
10.590 + }
10.591 +
10.592 + inline void IA32_Add_Rm_Imm8_Disp8(JitWriter *jit,
10.593 + jit_uint8_t dest,
10.594 + jit_int8_t val,
10.595 + jit_int8_t disp8)
10.596 + {
10.597 + jit->write_ubyte(IA32_ADD_RM_IMM8);
10.598 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 0, dest));
10.599 + jit->write_byte(disp8);
10.600 + jit->write_byte(val);
10.601 + }
10.602 +
10.603 + inline void IA32_Add_Rm_Imm32_Disp8(JitWriter *jit,
10.604 + jit_uint8_t dest,
10.605 + jit_int32_t val,
10.606 + jit_int8_t disp8)
10.607 + {
10.608 + jit->write_ubyte(IA32_ADD_RM_IMM32);
10.609 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 0, dest));
10.610 + jit->write_byte(disp8);
10.611 + jit->write_int32(val);
10.612 + }
10.613 +
10.614 + inline jitoffs_t IA32_Add_Rm_Imm32_Later(JitWriter *jit,
10.615 + jit_uint8_t dest,
10.616 + jit_uint8_t mode)
10.617 + {
10.618 + jit->write_ubyte(IA32_ADD_RM_IMM32);
10.619 + jit->write_ubyte(ia32_modrm(mode, 0, dest));
10.620 + jitoffs_t ptr = jit->get_outputpos();
10.621 + jit->write_int32(0);
10.622 + return ptr;
10.623 + }
10.624 +
10.625 + inline void IA32_Add_Rm_Imm8_Disp32(JitWriter *jit,
10.626 + jit_uint8_t dest,
10.627 + jit_int8_t val,
10.628 + jit_int32_t disp32)
10.629 + {
10.630 + jit->write_ubyte(IA32_ADD_RM_IMM8);
10.631 + jit->write_ubyte(ia32_modrm(MOD_DISP32, 0, dest));
10.632 + jit->write_int32(disp32);
10.633 + jit->write_byte(val);
10.634 + }
10.635 +
10.636 + inline void IA32_Add_RmEBP_Imm8_Disp_Reg(JitWriter *jit,
10.637 + jit_uint8_t dest_base,
10.638 + jit_uint8_t dest_index,
10.639 + jit_uint8_t dest_scale,
10.640 + jit_int8_t val)
10.641 + {
10.642 + jit->write_ubyte(IA32_ADD_RM_IMM8);
10.643 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 0, REG_SIB));
10.644 + jit->write_ubyte(ia32_sib(dest_scale, dest_index, dest_base));
10.645 + jit->write_byte(0);
10.646 + jit->write_byte(val);
10.647 + }
10.648 +
10.649 + inline void IA32_Sub_Rm_Imm8_Disp8(JitWriter *jit,
10.650 + jit_uint8_t dest,
10.651 + jit_int8_t val,
10.652 + jit_int8_t disp8)
10.653 + {
10.654 + jit->write_ubyte(IA32_SUB_RM_IMM8);
10.655 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 5, dest));
10.656 + jit->write_byte(disp8);
10.657 + jit->write_byte(val);
10.658 + }
10.659 +
10.660 + inline void IA32_Sub_Rm_Imm8_Disp32(JitWriter *jit,
10.661 + jit_uint8_t dest,
10.662 + jit_int8_t val,
10.663 + jit_int32_t disp32)
10.664 + {
10.665 + jit->write_ubyte(IA32_SUB_RM_IMM8);
10.666 + jit->write_ubyte(ia32_modrm(MOD_DISP32, 5, dest));
10.667 + jit->write_int32(disp32);
10.668 + jit->write_byte(val);
10.669 + }
10.670 +
10.671 + inline void IA32_Sub_RmEBP_Imm8_Disp_Reg(JitWriter *jit,
10.672 + jit_uint8_t dest_base,
10.673 + jit_uint8_t dest_index,
10.674 + jit_uint8_t dest_scale,
10.675 + jit_int8_t val)
10.676 + {
10.677 + jit->write_ubyte(IA32_SUB_RM_IMM8);
10.678 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 5, REG_SIB));
10.679 + jit->write_ubyte(ia32_sib(dest_scale, dest_index, dest_base));
10.680 + jit->write_byte(0);
10.681 + jit->write_byte(val);
10.682 + }
10.683 +
10.684 + /**
10.685 + * Memory Instructions
10.686 + */
10.687 +
10.688 + inline void IA32_Lea_Reg_DispRegMult(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src_base, jit_uint8_t src_index, jit_uint8_t scale)
10.689 + {
10.690 + jit->write_ubyte(IA32_LEA_REG_MEM);
10.691 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, dest, REG_SIB));
10.692 + jit->write_ubyte(ia32_sib(scale, src_index, src_base));
10.693 + }
10.694 +
10.695 + inline void IA32_Lea_Reg_DispEBPRegMult(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src_base, jit_uint8_t src_index, jit_uint8_t scale)
10.696 + {
10.697 + jit->write_ubyte(IA32_LEA_REG_MEM);
10.698 + jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, REG_SIB));
10.699 + jit->write_ubyte(ia32_sib(scale, src_index, src_base));
10.700 + jit->write_byte(0);
10.701 + }
10.702 +
10.703 + inline void IA32_Lea_Reg_DispRegMultImm8(JitWriter *jit,
10.704 + jit_uint8_t dest,
10.705 + jit_uint8_t src_base,
10.706 + jit_uint8_t src_index,
10.707 + jit_uint8_t scale,
10.708 + jit_int8_t val)
10.709 + {
10.710 + jit->write_ubyte(IA32_LEA_REG_MEM);
10.711 + jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, REG_SIB));
10.712 + jit->write_ubyte(ia32_sib(scale, src_index, src_base));
10.713 + jit->write_byte(val);
10.714 + }
10.715 +
10.716 + inline void IA32_Lea_Reg_DispRegMultImm32(JitWriter *jit,
10.717 + jit_uint8_t dest,
10.718 + jit_uint8_t src_base,
10.719 + jit_uint8_t src_index,
10.720 + jit_uint8_t scale,
10.721 + jit_int32_t val)
10.722 + {
10.723 + jit->write_ubyte(IA32_LEA_REG_MEM);
10.724 + jit->write_ubyte(ia32_modrm(MOD_DISP32, dest, REG_SIB));
10.725 + jit->write_ubyte(ia32_sib(scale, src_index, src_base));
10.726 + jit->write_int32(val);
10.727 + }
10.728 +
10.729 + inline void IA32_Lea_Reg_RegMultImm32(JitWriter *jit,
10.730 + jit_uint8_t dest,
10.731 + jit_uint8_t src_index,
10.732 + jit_uint8_t scale,
10.733 + jit_int32_t val)
10.734 + {
10.735 + jit->write_ubyte(IA32_LEA_REG_MEM);
10.736 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, dest, REG_SIB));
10.737 + jit->write_ubyte(ia32_sib(scale, src_index, REG_IMM_BASE));
10.738 + jit->write_int32(val);
10.739 + }
10.740 +
10.741 + inline void IA32_Lea_DispRegImm8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src_base, jit_int8_t val)
10.742 + {
10.743 + jit->write_ubyte(IA32_LEA_REG_MEM);
10.744 + jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, src_base));
10.745 + jit->write_byte(val);
10.746 + }
10.747 +
10.748 + inline void IA32_Lea_DispRegImm32(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src_base, jit_int32_t val)
10.749 + {
10.750 + jit->write_ubyte(IA32_LEA_REG_MEM);
10.751 + jit->write_ubyte(ia32_modrm(MOD_DISP32, dest, src_base));
10.752 + jit->write_int32(val);
10.753 + }
10.754 +
10.755 + inline void IA32_Lea_DispRegImmAuto(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src_base, jit_int32_t val)
10.756 + {
10.757 + if (val >= SCHAR_MIN && val <= SCHAR_MAX)
10.758 + IA32_Lea_DispRegImm8(jit, dest, src_base, static_cast<jit_int8_t>(val));
10.759 + else
10.760 + IA32_Lea_DispRegImm32(jit, dest, src_base, val);
10.761 + }
10.762 +
10.763 + /**
10.764 + * Stack Instructions
10.765 + */
10.766 +
10.767 + inline void IA32_Pop_Reg(JitWriter *jit, jit_uint8_t reg)
10.768 + {
10.769 + jit->write_ubyte(IA32_POP_REG+reg);
10.770 + }
10.771 +
10.772 + inline void IA32_Push_Reg(JitWriter *jit, jit_uint8_t reg)
10.773 + {
10.774 + jit->write_ubyte(IA32_PUSH_REG+reg);
10.775 + }
10.776 +
10.777 + inline void IA32_Push_Imm8(JitWriter *jit, jit_int8_t val)
10.778 + {
10.779 + jit->write_ubyte(IA32_PUSH_IMM8);
10.780 + jit->write_byte(val);
10.781 + }
10.782 +
10.783 + inline void IA32_Push_Imm32(JitWriter *jit, jit_int32_t val)
10.784 + {
10.785 + jit->write_ubyte(IA32_PUSH_IMM32);
10.786 + jit->write_int32(val);
10.787 + }
10.788 +
10.789 + inline void IA32_Pushad(JitWriter *jit)
10.790 + {
10.791 + jit->write_ubyte(IA32_PUSHAD);
10.792 + }
10.793 +
10.794 + inline void IA32_Popad(JitWriter *jit)
10.795 + {
10.796 + jit->write_ubyte(IA32_POPAD);
10.797 + }
10.798 +
10.799 + inline void IA32_Push_Rm_Disp8(JitWriter *jit, jit_uint8_t reg, jit_int8_t disp8)
10.800 + {
10.801 + jit->write_ubyte(IA32_PUSH_RM);
10.802 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 6, reg));
10.803 + jit->write_byte(disp8);
10.804 + }
10.805 +
10.806 + inline void IA32_Push_Rm_Disp32(JitWriter *jit, jit_uint8_t reg, jit_int32_t disp32)
10.807 + {
10.808 + jit->write_ubyte(IA32_PUSH_RM);
10.809 + jit->write_ubyte(ia32_modrm(MOD_DISP32, 6, reg));
10.810 + jit->write_int32(disp32);
10.811 + }
10.812 +
10.813 + inline void IA32_Push_Rm_DispAuto(JitWriter *jit, jit_uint8_t reg, jit_int32_t disp)
10.814 + {
10.815 + if (disp >= SCHAR_MIN && disp <= SCHAR_MAX)
10.816 + IA32_Push_Rm_Disp8(jit, reg, static_cast<jit_int8_t>(disp));
10.817 + else
10.818 + IA32_Push_Rm_Disp32(jit, reg, disp);
10.819 + }
10.820 +
10.821 + inline void IA32_Push_Rm_Disp8_ESP(JitWriter *jit, jit_int8_t disp8)
10.822 + {
10.823 + jit->write_ubyte(IA32_PUSH_RM);
10.824 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 6, REG_SIB));
10.825 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.826 + jit->write_byte(disp8);
10.827 + }
10.828 +
10.829 + /**
10.830 + * Moving from REGISTER/MEMORY to REGISTER
10.831 + */
10.832 +
10.833 + inline void IA32_Mov_Reg_Rm(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.834 + {
10.835 + jit->write_ubyte(IA32_MOV_REG_RM);
10.836 + jit->write_ubyte(ia32_modrm(mode, dest, src));
10.837 + }
10.838 +
10.839 + inline void IA32_Mov_Reg8_Rm8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.840 + {
10.841 + jit->write_ubyte(IA32_MOV_REG8_RM8);
10.842 + jit->write_ubyte(ia32_modrm(mode, dest, src));
10.843 + }
10.844 +
10.845 + inline void IA32_Mov_Reg_RmESP(JitWriter *jit, jit_uint8_t dest)
10.846 + {
10.847 + jit->write_ubyte(IA32_MOV_REG_RM);
10.848 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, dest, REG_ESP));
10.849 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.850 + }
10.851 +
10.852 + inline void IA32_Mov_Reg_Rm_Disp8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int8_t disp)
10.853 + {
10.854 + jit->write_ubyte(IA32_MOV_REG_RM);
10.855 + jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, src));
10.856 + jit->write_byte(disp);
10.857 + }
10.858 +
10.859 + inline void IA32_Mov_Reg8_Rm8_Disp8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int8_t disp)
10.860 + {
10.861 + jit->write_ubyte(IA32_MOV_REG8_RM8);
10.862 + jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, src));
10.863 + jit->write_byte(disp);
10.864 + }
10.865 +
10.866 + inline void IA32_Mov_Reg_Esp_Disp8(JitWriter *jit, jit_uint8_t dest, jit_int8_t disp)
10.867 + {
10.868 + jit->write_ubyte(IA32_MOV_REG_RM);
10.869 + jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, REG_SIB));
10.870 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.871 + jit->write_byte(disp);
10.872 + }
10.873 +
10.874 + inline void IA32_Mov_Reg_Rm_Disp32(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int32_t disp)
10.875 + {
10.876 + jit->write_ubyte(IA32_MOV_REG_RM);
10.877 + jit->write_ubyte(ia32_modrm(MOD_DISP32, dest, src));
10.878 + jit->write_int32(disp);
10.879 + }
10.880 +
10.881 + inline void IA32_Mov_Reg8_Rm8_Disp32(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int32_t disp)
10.882 + {
10.883 + jit->write_ubyte(IA32_MOV_REG8_RM8);
10.884 + jit->write_ubyte(ia32_modrm(MOD_DISP32, dest, src));
10.885 + jit->write_int32(disp);
10.886 + }
10.887 +
10.888 + inline void IA32_Mov_Reg_Rm_Disp_Reg(JitWriter *jit,
10.889 + jit_uint8_t dest,
10.890 + jit_uint8_t src_base,
10.891 + jit_uint8_t src_index,
10.892 + jit_uint8_t src_scale)
10.893 + {
10.894 + jit->write_ubyte(IA32_MOV_REG_RM);
10.895 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, dest, REG_SIB));
10.896 + jit->write_ubyte(ia32_sib(src_scale, src_index, src_base));
10.897 + }
10.898 +
10.899 + inline void IA32_Mov_Reg_Rm_Disp_Reg_Disp8(JitWriter *jit,
10.900 + jit_uint8_t dest,
10.901 + jit_uint8_t src_base,
10.902 + jit_uint8_t src_index,
10.903 + jit_uint8_t src_scale,
10.904 + jit_int8_t disp8)
10.905 + {
10.906 + jit->write_ubyte(IA32_MOV_REG_RM);
10.907 + jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, REG_SIB));
10.908 + jit->write_ubyte(ia32_sib(src_scale, src_index, src_base));
10.909 + jit->write_byte(disp8);
10.910 + }
10.911 +
10.912 + inline void IA32_Mov_Reg_RmEBP_Disp_Reg(JitWriter *jit,
10.913 + jit_uint8_t dest,
10.914 + jit_uint8_t src_base,
10.915 + jit_uint8_t src_index,
10.916 + jit_uint8_t src_scale)
10.917 + {
10.918 + jit->write_ubyte(IA32_MOV_REG_RM);
10.919 + jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, REG_SIB));
10.920 + jit->write_ubyte(ia32_sib(src_scale, src_index, src_base));
10.921 + jit->write_byte(0);
10.922 + }
10.923 +
10.924 + inline void IA32_Mov_Reg_Rm_DispAuto(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int32_t disp)
10.925 + {
10.926 + if (disp == 0)
10.927 + IA32_Mov_Reg_Rm(jit, dest, src, MOD_MEM_REG);
10.928 + else if (disp <= SCHAR_MAX)
10.929 + IA32_Mov_Reg_Rm_Disp8(jit, dest, src, static_cast<jit_int8_t>(disp));
10.930 + else
10.931 + IA32_Mov_Reg_Rm_Disp32(jit, dest, src, disp);
10.932 + }
10.933 +
10.934 + /**
10.935 + * Moving from REGISTER to REGISTER/MEMORY
10.936 + */
10.937 +
10.938 + inline void IA32_Mov_Rm_Reg(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.939 + {
10.940 + jit->write_ubyte(IA32_MOV_RM_REG);
10.941 + jit->write_ubyte(ia32_modrm(mode, src, dest));
10.942 + }
10.943 +
10.944 + inline void IA32_Mov_Rm8_Reg8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.945 + {
10.946 + jit->write_ubyte(IA32_MOV_RM8_REG8);
10.947 + jit->write_ubyte(ia32_modrm(mode, src, dest));
10.948 + }
10.949 +
10.950 + inline void IA32_Mov_Rm8_Reg8_Disp8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int8_t disp)
10.951 + {
10.952 + jit->write_ubyte(IA32_MOV_RM8_REG8);
10.953 + jit->write_ubyte(ia32_modrm(MOD_DISP8, src, dest));
10.954 + jit->write_byte(disp);
10.955 + }
10.956 +
10.957 + inline void IA32_Mov_Rm8_Reg8_Disp32(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int32_t disp)
10.958 + {
10.959 + jit->write_ubyte(IA32_MOV_RM8_REG8);
10.960 + jit->write_ubyte(ia32_modrm(MOD_DISP32, src, dest));
10.961 + jit->write_int32(disp);
10.962 + }
10.963 +
10.964 + inline void IA32_Mov_Rm8_Reg8_DispAuto(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int32_t disp)
10.965 + {
10.966 + if (disp >= SCHAR_MIN && disp <= SCHAR_MAX)
10.967 + IA32_Mov_Rm8_Reg8_Disp8(jit, dest, src, static_cast<jit_int8_t>(disp));
10.968 + else
10.969 + IA32_Mov_Rm8_Reg8_Disp32(jit, dest, src, disp);
10.970 + }
10.971 +
10.972 + inline void IA32_Mov_RmESP_Reg(JitWriter *jit, jit_uint8_t src)
10.973 + {
10.974 + jit->write_ubyte(IA32_MOV_RM_REG);
10.975 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, src, REG_ESP));
10.976 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.977 + }
10.978 +
10.979 + inline void IA32_Mov_Rm_Reg_Disp8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int8_t disp)
10.980 + {
10.981 + jit->write_ubyte(IA32_MOV_RM_REG);
10.982 + jit->write_ubyte(ia32_modrm(MOD_DISP8, src, dest));
10.983 + jit->write_byte(disp);
10.984 + }
10.985 +
10.986 + inline void IA32_Mov_Rm_Reg_Disp32(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int32_t disp)
10.987 + {
10.988 + jit->write_ubyte(IA32_MOV_RM_REG);
10.989 + jit->write_ubyte(ia32_modrm(MOD_DISP32, src, dest));
10.990 + jit->write_int32(disp);
10.991 + }
10.992 +
10.993 + inline void IA32_Mov_Rm_Reg_DispAuto(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int32_t disp)
10.994 + {
10.995 + if (disp >= SCHAR_MIN && disp <= SCHAR_MAX)
10.996 + IA32_Mov_Rm_Reg_Disp8(jit, dest, src, static_cast<jit_int8_t>(disp));
10.997 + else
10.998 + IA32_Mov_Rm_Reg_Disp32(jit, dest, src, disp);
10.999 + }
10.1000 +
10.1001 + inline void IA32_Mov_RmEBP_Reg_Disp_Reg(JitWriter *jit,
10.1002 + jit_uint8_t dest_base,
10.1003 + jit_uint8_t dest_index,
10.1004 + jit_uint8_t dest_scale,
10.1005 + jit_uint8_t src)
10.1006 + {
10.1007 + jit->write_ubyte(IA32_MOV_RM_REG);
10.1008 + jit->write_ubyte(ia32_modrm(MOD_DISP8, src, REG_SIB));
10.1009 + jit->write_ubyte(ia32_sib(dest_scale, dest_index, dest_base));
10.1010 + jit->write_byte(0);
10.1011 + }
10.1012 +
10.1013 + inline void IA32_Mov_Rm8EBP_Reg_Disp_Reg(JitWriter *jit,
10.1014 + jit_uint8_t dest_base,
10.1015 + jit_uint8_t dest_index,
10.1016 + jit_uint8_t dest_scale,
10.1017 + jit_uint8_t src)
10.1018 + {
10.1019 + jit->write_ubyte(IA32_MOV_RM8_REG);
10.1020 + jit->write_ubyte(ia32_modrm(MOD_DISP8, src, REG_SIB));
10.1021 + jit->write_ubyte(ia32_sib(dest_scale, dest_index, dest_base));
10.1022 + jit->write_byte(0);
10.1023 + }
10.1024 +
10.1025 + inline void IA32_Mov_Rm16EBP_Reg_Disp_Reg(JitWriter *jit,
10.1026 + jit_uint8_t dest_base,
10.1027 + jit_uint8_t dest_index,
10.1028 + jit_uint8_t dest_scale,
10.1029 + jit_uint8_t src)
10.1030 + {
10.1031 + jit->write_ubyte(IA32_16BIT_PREFIX);
10.1032 + jit->write_ubyte(IA32_MOV_RM_REG);
10.1033 + jit->write_ubyte(ia32_modrm(MOD_DISP8, src, REG_SIB));
10.1034 + jit->write_ubyte(ia32_sib(dest_scale, dest_index, dest_base));
10.1035 + jit->write_byte(0);
10.1036 + }
10.1037 +
10.1038 + /**
10.1039 + * Moving from IMMEDIATE to REGISTER
10.1040 + */
10.1041 +
10.1042 + inline jitoffs_t IA32_Mov_Reg_Imm32(JitWriter *jit, jit_uint8_t dest, jit_int32_t num)
10.1043 + {
10.1044 + jitoffs_t offs;
10.1045 + jit->write_ubyte(IA32_MOV_REG_IMM+dest);
10.1046 + offs = jit->get_outputpos();
10.1047 + jit->write_int32(num);
10.1048 + return offs;
10.1049 + }
10.1050 +
10.1051 + inline void IA32_Mov_Rm_Imm32(JitWriter *jit, jit_uint8_t dest, jit_int32_t val, jit_uint8_t mode)
10.1052 + {
10.1053 + jit->write_ubyte(IA32_MOV_RM_IMM32);
10.1054 + jit->write_ubyte(ia32_modrm(mode, 0, dest));
10.1055 + jit->write_int32(val);
10.1056 + }
10.1057 +
10.1058 + inline void IA32_Mov_Rm_Imm32_Disp8(JitWriter *jit,
10.1059 + jit_uint8_t dest,
10.1060 + jit_int32_t val,
10.1061 + jit_int8_t disp8)
10.1062 + {
10.1063 + jit->write_ubyte(IA32_MOV_RM_IMM32);
10.1064 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 0, dest));
10.1065 + jit->write_byte(disp8);
10.1066 + jit->write_int32(val);
10.1067 + }
10.1068 +
10.1069 + inline void IA32_Mov_Rm_Imm32_Disp32(JitWriter *jit,
10.1070 + jit_uint8_t dest,
10.1071 + jit_int32_t val,
10.1072 + jit_int32_t disp32)
10.1073 + {
10.1074 + jit->write_ubyte(IA32_MOV_RM_IMM32);
10.1075 + jit->write_ubyte(ia32_modrm(MOD_DISP32, 0, dest));
10.1076 + jit->write_int32(disp32);
10.1077 + jit->write_int32(val);
10.1078 + }
10.1079 +
10.1080 + inline void IA32_Mov_RmEBP_Imm32_Disp_Reg(JitWriter *jit,
10.1081 + jit_uint8_t dest_base,
10.1082 + jit_uint8_t dest_index,
10.1083 + jit_uint8_t dest_scale,
10.1084 + jit_int32_t val)
10.1085 + {
10.1086 + jit->write_ubyte(IA32_MOV_RM_IMM32);
10.1087 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 0, REG_SIB));
10.1088 + jit->write_ubyte(ia32_sib(dest_scale, dest_index, dest_base));
10.1089 + jit->write_byte(0);
10.1090 + jit->write_int32(val);
10.1091 + }
10.1092 +
10.1093 + inline void IA32_Mov_ESP_Disp8_Imm32(JitWriter *jit, jit_int8_t disp8, jit_int32_t val)
10.1094 + {
10.1095 + jit->write_ubyte(IA32_MOV_RM_IMM32);
10.1096 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 0, REG_SIB));
10.1097 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.1098 + jit->write_byte(disp8);
10.1099 + jit->write_int32(val);
10.1100 + }
10.1101 +
10.1102 + /**
10.1103 + * Floating Point Instructions
10.1104 + */
10.1105 +
10.1106 + inline void IA32_Fstcw_Mem16_ESP(JitWriter *jit)
10.1107 + {
10.1108 + jit->write_ubyte(IA32_FSTCW_MEM16_1);
10.1109 + jit->write_ubyte(IA32_FSTCW_MEM16_2);
10.1110 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 7, REG_SIB));
10.1111 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.1112 + }
10.1113 +
10.1114 + inline void IA32_Fldcw_Mem16_ESP(JitWriter *jit)
10.1115 + {
10.1116 + jit->write_ubyte(IA32_FLDCW_MEM16);
10.1117 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 5, REG_SIB));
10.1118 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.1119 + }
10.1120 +
10.1121 + inline void IA32_Fldcw_Mem16_Disp8_ESP(JitWriter *jit, jit_int8_t disp8)
10.1122 + {
10.1123 + jit->write_ubyte(IA32_FLDCW_MEM16);
10.1124 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 5, REG_SIB));
10.1125 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.1126 + jit->write_byte(disp8);
10.1127 + }
10.1128 +
10.1129 + inline void IA32_Fistp_Mem32_ESP(JitWriter *jit)
10.1130 + {
10.1131 + jit->write_ubyte(IA32_FISTP_MEM32);
10.1132 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 3, REG_SIB));
10.1133 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.1134 + }
10.1135 +
10.1136 + inline void IA32_Fistp_Mem32_Disp8_Esp(JitWriter *jit, jit_int8_t disp8)
10.1137 + {
10.1138 + jit->write_ubyte(IA32_FISTP_MEM32);
10.1139 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 3, REG_SIB));
10.1140 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.1141 + jit->write_byte(disp8);
10.1142 + }
10.1143 +
10.1144 + inline void IA32_Fucomip_ST0_FPUreg(JitWriter *jit, jit_uint8_t reg)
10.1145 + {
10.1146 + jit->write_ubyte(IA32_FUCOMIP_1);
10.1147 + jit->write_ubyte(IA32_FUCOMIP_2+reg);
10.1148 + }
10.1149 +
10.1150 + inline void IA32_Fadd_FPUreg_ST0(JitWriter *jit, jit_uint8_t reg)
10.1151 + {
10.1152 + jit->write_ubyte(IA32_FADD_FPREG_ST0_1);
10.1153 + jit->write_ubyte(IA32_FADD_FPREG_ST0_2+reg);
10.1154 + }
10.1155 +
10.1156 + inline void IA32_Fadd_Mem32_Disp8(JitWriter *jit, jit_uint8_t src, jit_int8_t val)
10.1157 + {
10.1158 + jit->write_ubyte(IA32_FADD_MEM32);
10.1159 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 0, src));
10.1160 + jit->write_byte(val);
10.1161 + }
10.1162 +
10.1163 + inline void IA32_Fadd_Mem32_ESP(JitWriter *jit)
10.1164 + {
10.1165 + jit->write_ubyte(IA32_FADD_MEM32);
10.1166 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 0, REG_SIB));
10.1167 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.1168 + }
10.1169 +
10.1170 + inline void IA32_Fsub_Mem32_Disp8(JitWriter *jit, jit_uint8_t src, jit_int8_t val)
10.1171 + {
10.1172 + jit->write_ubyte(IA32_FSUB_MEM32);
10.1173 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 4, src));
10.1174 + jit->write_byte(val);
10.1175 + }
10.1176 +
10.1177 + inline void IA32_Fmul_Mem32_Disp8(JitWriter *jit, jit_uint8_t src, jit_int8_t val)
10.1178 + {
10.1179 + jit->write_ubyte(IA32_FMUL_MEM32);
10.1180 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 1, src));
10.1181 + jit->write_byte(val);
10.1182 + }
10.1183 +
10.1184 + inline void IA32_Fdiv_Mem32_Disp8(JitWriter *jit, jit_uint8_t src, jit_int8_t val)
10.1185 + {
10.1186 + jit->write_ubyte(IA32_FDIV_MEM32);
10.1187 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 6, src));
10.1188 + jit->write_byte(val);
10.1189 + }
10.1190 +
10.1191 + inline void IA32_Fild_Mem32(JitWriter *jit, jit_uint8_t src)
10.1192 + {
10.1193 + jit->write_ubyte(IA32_FILD_MEM32);
10.1194 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 0, src));
10.1195 + }
10.1196 +
10.1197 + inline void IA32_Fstp_Mem32(JitWriter *jit, jit_uint8_t dest)
10.1198 + {
10.1199 + jit->write_ubyte(IA32_FSTP_MEM32);
10.1200 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 3, dest));
10.1201 + }
10.1202 +
10.1203 + inline void IA32_Fstp_Mem32_DispAuto(JitWriter *jit, jit_uint8_t dest, jit_int32_t disp)
10.1204 + {
10.1205 + jit->write_ubyte(IA32_FSTP_MEM32);
10.1206 +
10.1207 + if (disp > SCHAR_MIN && disp < SCHAR_MAX)
10.1208 + {
10.1209 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 3, dest));
10.1210 + jit->write_byte(static_cast<jit_int8_t>(disp));
10.1211 + }
10.1212 + else
10.1213 + {
10.1214 + jit->write_ubyte(ia32_modrm(MOD_DISP32, 3, dest));
10.1215 + jit->write_byte(disp);
10.1216 + }
10.1217 + }
10.1218 +
10.1219 + inline void IA32_Fstp_Mem64(JitWriter *jit, jit_uint8_t dest)
10.1220 + {
10.1221 + jit->write_ubyte(IA32_FSTP_MEM64);
10.1222 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 3, dest));
10.1223 + }
10.1224 +
10.1225 + inline void IA32_Fstp_Mem64_DispAuto(JitWriter *jit, jit_uint8_t dest, jit_int32_t disp)
10.1226 + {
10.1227 + jit->write_ubyte(IA32_FSTP_MEM64);
10.1228 +
10.1229 + if (disp > SCHAR_MIN && disp < SCHAR_MAX)
10.1230 + {
10.1231 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 3, dest));
10.1232 + jit->write_byte(static_cast<jit_int8_t>(disp));
10.1233 + }
10.1234 + else
10.1235 + {
10.1236 + jit->write_ubyte(ia32_modrm(MOD_DISP32, 3, dest));
10.1237 + jit->write_byte(disp);
10.1238 + }
10.1239 + }
10.1240 +
10.1241 + inline void IA32_Fstp_Mem32_ESP(JitWriter *jit)
10.1242 + {
10.1243 + jit->write_ubyte(IA32_FSTP_MEM32);
10.1244 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 3, REG_SIB));
10.1245 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.1246 + }
10.1247 +
10.1248 + inline void IA32_Fstp_Mem64_ESP(JitWriter *jit)
10.1249 + {
10.1250 + jit->write_ubyte(IA32_FSTP_MEM64);
10.1251 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 3, REG_SIB));
10.1252 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.1253 + }
10.1254 +
10.1255 + inline void IA32_Fstp_FPUreg(JitWriter *jit, jit_uint8_t reg)
10.1256 + {
10.1257 + jit->write_ubyte(IA32_FSTP_FPREG_1);
10.1258 + jit->write_ubyte(IA32_FSTP_FPREG_2+reg);
10.1259 + }
10.1260 +
10.1261 + inline void IA32_Fld_Mem32(JitWriter *jit, jit_uint8_t src)
10.1262 + {
10.1263 + jit->write_ubyte(IA32_FLD_MEM32);
10.1264 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 0, src));
10.1265 + }
10.1266 +
10.1267 + inline void IA32_Fld_Mem64(JitWriter *jit, jit_uint8_t src)
10.1268 + {
10.1269 + jit->write_ubyte(IA32_FLD_MEM64);
10.1270 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 0, src));
10.1271 + }
10.1272 +
10.1273 + inline void IA32_Fld_Mem32_Disp8(JitWriter *jit, jit_uint8_t src, jit_int8_t val)
10.1274 + {
10.1275 + jit->write_ubyte(IA32_FLD_MEM32);
10.1276 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 0, src));
10.1277 + jit->write_byte(val);
10.1278 + }
10.1279 +
10.1280 + inline void IA32_Fld_Mem64_Disp8(JitWriter *jit, jit_uint8_t src, jit_int8_t val)
10.1281 + {
10.1282 + jit->write_ubyte(IA32_FLD_MEM64);
10.1283 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 0, src));
10.1284 + jit->write_byte(val);
10.1285 + }
10.1286 +
10.1287 + inline void IA32_Fld_Mem32_Disp32(JitWriter *jit, jit_uint8_t src, jit_int32_t val)
10.1288 + {
10.1289 + jit->write_ubyte(IA32_FLD_MEM32);
10.1290 + jit->write_ubyte(ia32_modrm(MOD_DISP32, 0, src));
10.1291 + jit->write_int32(val);
10.1292 + }
10.1293 +
10.1294 + inline void IA32_Fld_Mem64_Disp32(JitWriter *jit, jit_uint8_t src, jit_int32_t val)
10.1295 + {
10.1296 + jit->write_ubyte(IA32_FLD_MEM64);
10.1297 + jit->write_ubyte(ia32_modrm(MOD_DISP32, 0, src));
10.1298 + jit->write_int32(val);
10.1299 + }
10.1300 +
10.1301 + inline void IA32_Fld_Mem32_DispAuto(JitWriter *jit, jit_uint8_t src, jit_int32_t disp)
10.1302 + {
10.1303 + if (disp == 0)
10.1304 + IA32_Fld_Mem32(jit, src);
10.1305 + else if (disp <= SCHAR_MAX)
10.1306 + IA32_Fld_Mem32_Disp8(jit, src, static_cast<jit_int8_t>(disp));
10.1307 + else
10.1308 + IA32_Fld_Mem32_Disp32(jit, src, disp);
10.1309 + }
10.1310 +
10.1311 + inline void IA32_Fld_Mem64_DispAuto(JitWriter *jit, jit_uint8_t src, jit_int32_t disp)
10.1312 + {
10.1313 + if (disp == 0)
10.1314 + IA32_Fld_Mem64(jit, src);
10.1315 + else if (disp <= SCHAR_MAX)
10.1316 + IA32_Fld_Mem64_Disp8(jit, src, static_cast<jit_int8_t>(disp));
10.1317 + else
10.1318 + IA32_Fld_Mem64_Disp32(jit, src, disp);
10.1319 + }
10.1320 +
10.1321 + /**
10.1322 + * Move data with zero extend
10.1323 + */
10.1324 +
10.1325 + inline void IA32_Movzx_Reg32_Rm8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.1326 + {
10.1327 + jit->write_ubyte(IA32_MOVZX_R32_RM8_1);
10.1328 + jit->write_ubyte(IA32_MOVZX_R32_RM8_2);
10.1329 + jit->write_ubyte(ia32_modrm(mode, dest, src));
10.1330 + }
10.1331 +
10.1332 + inline void IA32_Movzx_Reg32_Rm8_Disp8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int8_t disp)
10.1333 + {
10.1334 + jit->write_ubyte(IA32_MOVZX_R32_RM8_1);
10.1335 + jit->write_ubyte(IA32_MOVZX_R32_RM8_2);
10.1336 + jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, src));
10.1337 + jit->write_byte(disp);
10.1338 + }
10.1339 +
10.1340 + inline void IA32_Movzx_Reg32_Rm8_Disp32(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int32_t disp)
10.1341 + {
10.1342 + jit->write_ubyte(IA32_MOVZX_R32_RM8_1);
10.1343 + jit->write_ubyte(IA32_MOVZX_R32_RM8_2);
10.1344 + jit->write_ubyte(ia32_modrm(MOD_DISP32, dest, src));
10.1345 + jit->write_int32(disp);
10.1346 + }
10.1347 +
10.1348 + inline void IA32_Movzx_Reg32_Rm8_DispAuto(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int32_t disp)
10.1349 + {
10.1350 + if (disp >= SCHAR_MIN && disp <= SCHAR_MAX)
10.1351 + IA32_Movzx_Reg32_Rm8_Disp8(jit, dest, src, static_cast<jit_int8_t>(disp));
10.1352 + else
10.1353 + IA32_Movzx_Reg32_Rm8_Disp32(jit, dest, src, disp);
10.1354 + }
10.1355 +
10.1356 + inline void IA32_Movzx_Reg32_Rm16(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.1357 + {
10.1358 + jit->write_ubyte(IA32_MOVZX_R32_RM16_1);
10.1359 + jit->write_ubyte(IA32_MOVZX_R32_RM16_2);
10.1360 + jit->write_ubyte(ia32_modrm(mode, dest, src));
10.1361 + }
10.1362 +
10.1363 + inline void IA32_Movzx_Reg32_Rm16_Disp8(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int8_t disp)
10.1364 + {
10.1365 + jit->write_ubyte(IA32_MOVZX_R32_RM16_1);
10.1366 + jit->write_ubyte(IA32_MOVZX_R32_RM16_2);
10.1367 + jit->write_ubyte(ia32_modrm(MOD_DISP8, dest, src));
10.1368 + jit->write_byte(disp);
10.1369 + }
10.1370 +
10.1371 + inline void IA32_Movzx_Reg32_Rm16_Disp32(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int32_t disp)
10.1372 + {
10.1373 + jit->write_ubyte(IA32_MOVZX_R32_RM16_1);
10.1374 + jit->write_ubyte(IA32_MOVZX_R32_RM16_2);
10.1375 + jit->write_ubyte(ia32_modrm(MOD_DISP32, dest, src));
10.1376 + jit->write_int32(disp);
10.1377 + }
10.1378 +
10.1379 + inline void IA32_Movzx_Reg32_Rm16_DispAuto(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_int32_t disp)
10.1380 + {
10.1381 + if (disp >= SCHAR_MIN && disp <= SCHAR_MAX)
10.1382 + IA32_Movzx_Reg32_Rm16_Disp8(jit, dest, src, static_cast<jit_int8_t>(disp));
10.1383 + else
10.1384 + IA32_Movzx_Reg32_Rm16_Disp32(jit, dest, src, disp);
10.1385 + }
10.1386 +
10.1387 + /**
10.1388 + * Branching/Jumping
10.1389 + */
10.1390 +
10.1391 + inline jitoffs_t IA32_Jump_Cond_Imm8(JitWriter *jit, jit_uint8_t cond, jit_int8_t disp)
10.1392 + {
10.1393 + jitoffs_t ptr;
10.1394 + jit->write_ubyte(IA32_JCC_IMM+cond);
10.1395 + ptr = jit->get_outputpos();
10.1396 + jit->write_byte(disp);
10.1397 + return ptr;
10.1398 + }
10.1399 +
10.1400 + inline jitoffs_t IA32_Jump_Imm32(JitWriter *jit, jit_int32_t disp)
10.1401 + {
10.1402 + jitoffs_t ptr;
10.1403 + jit->write_ubyte(IA32_JMP_IMM32);
10.1404 + ptr = jit->get_outputpos();
10.1405 + jit->write_int32(disp);
10.1406 + return ptr;
10.1407 + }
10.1408 +
10.1409 + inline jitoffs_t IA32_Jump_Imm8(JitWriter *jit, jit_int8_t disp)
10.1410 + {
10.1411 + jitoffs_t ptr;
10.1412 + jit->write_ubyte(IA32_JMP_IMM8);
10.1413 + ptr = jit->get_outputpos();
10.1414 + jit->write_byte(disp);
10.1415 + return ptr;
10.1416 + }
10.1417 +
10.1418 + inline jitoffs_t IA32_Jump_Cond_Imm32(JitWriter *jit, jit_uint8_t cond, jit_int32_t disp)
10.1419 + {
10.1420 + jitoffs_t ptr;
10.1421 + jit->write_ubyte(IA32_JCC_IMM32_1);
10.1422 + jit->write_ubyte(IA32_JCC_IMM32_2+cond);
10.1423 + ptr = jit->get_outputpos();
10.1424 + jit->write_int32(disp);
10.1425 + return ptr;
10.1426 + }
10.1427 +
10.1428 + inline void IA32_Jump_Reg(JitWriter *jit, jit_uint8_t reg)
10.1429 + {
10.1430 + jit->write_ubyte(IA32_JMP_RM);
10.1431 + jit->write_ubyte(ia32_modrm(MOD_REG, 4, reg));
10.1432 + }
10.1433 +
10.1434 + inline void IA32_Jump_Rm(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode)
10.1435 + {
10.1436 + jit->write_ubyte(IA32_JMP_RM);
10.1437 + jit->write_ubyte(ia32_modrm(mode, 4, reg));
10.1438 + }
10.1439 +
10.1440 + inline jitoffs_t IA32_Call_Imm32(JitWriter *jit, jit_int32_t disp)
10.1441 + {
10.1442 + jitoffs_t ptr;
10.1443 + jit->write_ubyte(IA32_CALL_IMM32);
10.1444 + ptr = jit->get_outputpos();
10.1445 + jit->write_int32(disp);
10.1446 + return ptr;
10.1447 + }
10.1448 +
10.1449 + inline void IA32_Call_Reg(JitWriter *jit, jit_uint8_t reg)
10.1450 + {
10.1451 + jit->write_ubyte(IA32_CALL_RM);
10.1452 + jit->write_ubyte(ia32_modrm(MOD_REG, 2, reg));
10.1453 + }
10.1454 +
10.1455 + inline void IA32_Call_Rm(JitWriter *jit, jit_uint8_t reg, jit_uint8_t mode)
10.1456 + {
10.1457 + jit->write_ubyte(IA32_CALL_RM);
10.1458 + jit->write_ubyte(ia32_modrm(mode, 4, reg));
10.1459 + }
10.1460 +
10.1461 + inline void IA32_Return(JitWriter *jit)
10.1462 + {
10.1463 + jit->write_ubyte(IA32_RET);
10.1464 + }
10.1465 +
10.1466 + inline void IA32_Return_Popstack(JitWriter *jit, unsigned short bytes)
10.1467 + {
10.1468 + jit->write_ubyte(IA32_RETN);
10.1469 + jit->write_ushort(bytes);
10.1470 + }
10.1471 +
10.1472 + inline void IA32_Test_Rm_Reg(JitWriter *jit, jit_uint8_t reg1, jit_uint8_t reg2, jit_uint8_t mode)
10.1473 + {
10.1474 + jit->write_ubyte(IA32_TEST_RM_REG);
10.1475 + jit->write_ubyte(ia32_modrm(mode, reg2, reg1));
10.1476 + }
10.1477 +
10.1478 + inline void IA32_Test_Rm_Reg8(JitWriter *jit, jit_uint8_t reg1, jit_uint8_t reg2, jit_uint8_t mode)
10.1479 + {
10.1480 + jit->write_ubyte(IA32_TEST_RM_REG8);
10.1481 + jit->write_ubyte(ia32_modrm(mode, reg2, reg1));
10.1482 + }
10.1483 +
10.1484 + inline void IA32_Test_Rm_Imm32(JitWriter *jit, jit_uint8_t operand1, jit_int32_t imm_operand, jit_uint8_t mode)
10.1485 + {
10.1486 + jit->write_ubyte(IA32_TEST_RM_IMM32);
10.1487 + jit->write_ubyte(ia32_modrm(mode, 0, operand1));
10.1488 + jit->write_int32(imm_operand);
10.1489 + }
10.1490 +
10.1491 + inline void IA32_Cmp_Rm_Reg(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.1492 + {
10.1493 + jit->write_ubyte(IA32_CMP_RM_REG);
10.1494 + jit->write_ubyte(ia32_modrm(mode, src, dest));
10.1495 + }
10.1496 +
10.1497 + inline void IA32_Cmp_Reg_Rm(JitWriter *jit, jit_uint8_t dest, jit_uint8_t src, jit_uint8_t mode)
10.1498 + {
10.1499 + jit->write_ubyte(IA32_CMP_REG_RM);
10.1500 + jit->write_ubyte(ia32_modrm(mode, dest, src));
10.1501 + }
10.1502 +
10.1503 + inline void IA32_Cmp_Reg_Rm_ESP(JitWriter *jit, jit_uint8_t cmpreg)
10.1504 + {
10.1505 + jit->write_ubyte(IA32_CMP_REG_RM);
10.1506 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, cmpreg, REG_SIB));
10.1507 + jit->write_ubyte(ia32_sib(NOSCALE, REG_NOIDX, REG_ESP));
10.1508 + }
10.1509 +
10.1510 + inline void IA32_Cmp_Reg_Rm_Disp8(JitWriter *jit, jit_uint8_t reg1, jit_uint8_t reg2, jit_int8_t disp8)
10.1511 + {
10.1512 + jit->write_ubyte(IA32_CMP_REG_RM);
10.1513 + jit->write_ubyte(ia32_modrm(MOD_DISP8, reg1, reg2));
10.1514 + jit->write_byte(disp8);
10.1515 + }
10.1516 +
10.1517 + inline void IA32_Cmp_Rm_Imm8(JitWriter *jit, jit_uint8_t mode, jit_uint8_t rm, jit_int8_t imm8)
10.1518 + {
10.1519 + jit->write_ubyte(IA32_CMP_RM_IMM8);
10.1520 + jit->write_ubyte(ia32_modrm(mode, 7, rm));
10.1521 + jit->write_byte(imm8);
10.1522 + }
10.1523 +
10.1524 + inline void IA32_Cmp_Rm_Imm32(JitWriter *jit, jit_uint8_t mode, jit_uint8_t rm, jit_int32_t imm32)
10.1525 + {
10.1526 + jit->write_ubyte(IA32_CMP_RM_IMM32);
10.1527 + jit->write_ubyte(ia32_modrm(mode, 7, rm));
10.1528 + jit->write_int32(imm32);
10.1529 + }
10.1530 +
10.1531 + inline void IA32_Cmp_Rm_Imm32_Disp8(JitWriter *jit, jit_uint8_t reg, jit_int8_t disp8, jit_int32_t imm32)
10.1532 + {
10.1533 + jit->write_ubyte(IA32_CMP_RM_IMM32);
10.1534 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 7, reg));
10.1535 + jit->write_byte(disp8);
10.1536 + jit->write_int32(imm32);
10.1537 + }
10.1538 +
10.1539 + inline void IA32_Cmp_Rm_Disp8_Imm8(JitWriter *jit, jit_uint8_t reg, jit_int8_t disp, jit_int8_t imm8)
10.1540 + {
10.1541 + jit->write_ubyte(IA32_CMP_RM_IMM8);
10.1542 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 7, reg));
10.1543 + jit->write_byte(disp);
10.1544 + jit->write_byte(imm8);
10.1545 + }
10.1546 +
10.1547 + inline void IA32_Cmp_Al_Imm8(JitWriter *jit, jit_int8_t value)
10.1548 + {
10.1549 + jit->write_ubyte(IA32_CMP_AL_IMM32);
10.1550 + jit->write_byte(value);
10.1551 + }
10.1552 +
10.1553 + inline void IA32_Cmp_Eax_Imm32(JitWriter *jit, jit_int32_t value)
10.1554 + {
10.1555 + jit->write_ubyte(IA32_CMP_EAX_IMM32);
10.1556 + jit->write_int32(value);
10.1557 + }
10.1558 +
10.1559 + inline void IA32_SetCC_Rm8(JitWriter *jit, jit_uint8_t reg, jit_uint8_t cond)
10.1560 + {
10.1561 + jit->write_ubyte(IA32_SETCC_RM8_1);
10.1562 + jit->write_ubyte(IA32_SETCC_RM8_2+cond);
10.1563 + jit->write_ubyte(ia32_modrm(MOD_REG, 0, reg));
10.1564 + }
10.1565 +
10.1566 + inline void IA32_CmovCC_Rm(JitWriter *jit, jit_uint8_t src, jit_uint8_t cond)
10.1567 + {
10.1568 + jit->write_ubyte(IA32_CMOVCC_RM_1);
10.1569 + jit->write_ubyte(IA32_CMOVCC_RM_2+cond);
10.1570 + jit->write_ubyte(ia32_modrm(MOD_MEM_REG, 0, src));
10.1571 + }
10.1572 +
10.1573 + inline void IA32_CmovCC_Rm_Disp8(JitWriter *jit, jit_uint8_t src, jit_uint8_t cond, jit_int8_t disp)
10.1574 + {
10.1575 + jit->write_ubyte(IA32_CMOVCC_RM_1);
10.1576 + jit->write_ubyte(IA32_CMOVCC_RM_2+cond);
10.1577 + jit->write_ubyte(ia32_modrm(MOD_DISP8, 0, src));
10.1578 + jit->write_byte(disp);
10.1579 + }
10.1580 +
10.1581 + inline void IA32_Cmpsb(JitWriter *jit)
10.1582 + {
10.1583 + jit->write_ubyte(IA32_CMPSB);
10.1584 + }
10.1585 +
10.1586 + inline void IA32_Rep(JitWriter *jit)
10.1587 + {
10.1588 + jit->write_ubyte(IA32_REP);
10.1589 + }
10.1590 +
10.1591 + inline void IA32_Movsd(JitWriter *jit)
10.1592 + {
10.1593 + jit->write_ubyte(IA32_MOVSD);
10.1594 + }
10.1595 +
10.1596 + inline void IA32_Movsb(JitWriter *jit)
10.1597 + {
10.1598 + jit->write_ubyte(IA32_MOVSB);
10.1599 + }
10.1600 +
10.1601 + inline void IA32_Stosd(JitWriter *jit)
10.1602 + {
10.1603 + jit->write_ubyte(IA32_STOSD);
10.1604 + }
10.1605 +
10.1606 + inline void IA32_Cld(JitWriter *jit)
10.1607 + {
10.1608 + jit->write_ubyte(IA32_CLD);
10.1609 + }
10.1610 +
10.1611 + }
10.1612 +}
10.1613 +
10.1614 +#endif //_INCLUDE_JIT_X86_MACROS_H
11.1 --- a/sourcehook/sourcehook_impl_cproto.h Sat Nov 24 06:11:23 2007 +0000
11.2 +++ b/sourcehook/sourcehook_impl_cproto.h Mon Nov 26 14:03:25 2007 +0000
11.3 @@ -26,6 +26,21 @@
11.4 void *pCopyCtor;
11.5 void *pDtor;
11.6 void *pAssignOperator;
11.7 +
11.8 + bool operator == (const IntPassInfo &other) const
11.9 + {
11.10 + return size == other.size
11.11 + && type == other.type
11.12 + && flags == other.flags
11.13 + && pNormalCtor == other.pNormalCtor
11.14 + && pDtor == other.pDtor
11.15 + && pAssignOperator == other.pAssignOperator;
11.16 + }
11.17 +
11.18 + bool operator != (const IntPassInfo &other) const
11.19 + {
11.20 + return !(*this == other);
11.21 + }
11.22 };
11.23
11.24 class CProto
11.25 @@ -72,6 +87,8 @@
11.26
11.27 bool operator == (const CProto &other) const;
11.28
11.29 + bool ExactlyEqual(const CProto &other) const;
11.30 +
11.31 int GetVersion() const
11.32 {
11.33 return m_Version;
11.34 @@ -87,11 +104,21 @@
11.35 return m_ParamsPassInfo[i];
11.36 }
11.37
11.38 + IntPassInfo & GetParam(int i)
11.39 + {
11.40 + return m_ParamsPassInfo[i];
11.41 + }
11.42 +
11.43 const IntPassInfo & GetRet() const
11.44 {
11.45 return m_RetPassInfo;
11.46 }
11.47
11.48 + IntPassInfo & GetRet()
11.49 + {
11.50 + return m_RetPassInfo;
11.51 + }
11.52 +
11.53 int GetConvention() const
11.54 {
11.55 return m_Convention;
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/sourcehook/sourcehook_pibuilder.h Mon Nov 26 14:03:25 2007 +0000
12.3 @@ -0,0 +1,109 @@
12.4 +/* ======== SourceHook ========
12.5 +* Copyright (C) 2004-2007 Metamod:Source Development Team
12.6 +* No warranties of any kind
12.7 +*
12.8 +* License: zlib/libpng
12.9 +*
12.10 +* Author(s): Pavol "PM OnoTo" Marko
12.11 +* ============================
12.12 +*/
12.13 +
12.14 +#ifndef __SOURCEHOOK_PIBUILDER_H__
12.15 +#define __SOURCEHOOK_PIBUILDER_H__
12.16 +
12.17 +#include "sourcehook.h"
12.18 +#include "sh_vector.h"
12.19 +
12.20 +namespace SourceHook
12.21 +{
12.22 + // Helper class: protocol information builder
12.23 + class CProtoInfoBuilder
12.24 + {
12.25 + ProtoInfo m_PI;
12.26 + CVector<PassInfo> m_Params;
12.27 + CVector<PassInfo::V2Info> m_Params2;
12.28 + public:
12.29 + CProtoInfoBuilder(int cc)
12.30 + {
12.31 + memset(reinterpret_cast<void*>(&m_PI), 0, sizeof(ProtoInfo));
12.32 + m_PI.convention = cc;
12.33 +
12.34 + // dummy 0 params
12.35 + PassInfo dummy;
12.36 + PassInfo::V2Info dummy2;
12.37 + memset(reinterpret_cast<void*>(&dummy), 0, sizeof(PassInfo));
12.38 + memset(reinterpret_cast<void*>(&dummy2), 0, sizeof(PassInfo::V2Info));
12.39 +
12.40 + dummy.size = 1; // Version1
12.41 +
12.42 + m_Params.push_back(dummy);
12.43 + m_Params2.push_back(dummy2);
12.44 + }
12.45 +
12.46 + void SetReturnType(size_t size, PassInfo::PassType type, int flags,
12.47 + void *pNormalCtor, void *pCopyCtor, void *pDtor, void *pAssignOperator)
12.48 + {
12.49 + if (pNormalCtor)
12.50 + flags |= PassInfo::PassFlag_OCtor;
12.51 +
12.52 + if (pCopyCtor)
12.53 + flags |= PassInfo::PassFlag_CCtor;
12.54 +
12.55 + if (pDtor)
12.56 + flags |= PassInfo::PassFlag_ODtor;
12.57 +
12.58 + if (pAssignOperator)
12.59 + flags |= PassInfo::PassFlag_AssignOp;
12.60 +
12.61 + m_PI.retPassInfo.size = size;
12.62 + m_PI.retPassInfo.type = type;
12.63 + m_PI.retPassInfo.flags = flags;
12.64 + m_PI.retPassInfo2.pNormalCtor = pNormalCtor;
12.65 + m_PI.retPassInfo2.pCopyCtor = pCopyCtor;
12.66 + m_PI.retPassInfo2.pDtor = pDtor;
12.67 + m_PI.retPassInfo2.pAssignOperator = pAssignOperator;
12.68 + }
12.69 +
12.70 + void AddParam(size_t size, PassInfo::PassType type, int flags,
12.71 + void *pNormalCtor, void *pCopyCtor, void *pDtor, void *pAssignOperator)
12.72 + {
12.73 + PassInfo pi;
12.74 + PassInfo::V2Info pi2;
12.75 +
12.76 + if (pNormalCtor)
12.77 + flags |= PassInfo::PassFlag_OCtor;
12.78 +
12.79 + if (pCopyCtor)
12.80 + flags |= PassInfo::PassFlag_CCtor;
12.81 +
12.82 + if (pDtor)
12.83 + flags |= PassInfo::PassFlag_ODtor;
12.84 +
12.85 + if (pAssignOperator)
12.86 + flags |= PassInfo::PassFlag_AssignOp;
12.87 +
12.88 +
12.89 + pi.size = size;
12.90 + pi.type = type;
12.91 + pi.flags = flags;
12.92 + pi2.pNormalCtor = pNormalCtor;
12.93 + pi2.pCopyCtor = pCopyCtor;
12.94 + pi2.pDtor = pDtor;
12.95 + pi2.pAssignOperator = pAssignOperator;
12.96 +
12.97 + m_Params.push_back(pi);
12.98 + m_Params2.push_back(pi2);
12.99 + ++m_PI.numOfParams;
12.100 + }
12.101 +
12.102 + operator ProtoInfo*()
12.103 + {
12.104 + m_PI.paramsPassInfo = &(m_Params[0]);
12.105 + m_PI.paramsPassInfo2 = &(m_Params2[0]);
12.106 + return &m_PI;
12.107 + }
12.108 + };
12.109 +}
12.110 +
12.111 +#endif
12.112 +
13.1 --- a/sourcehook/test/Makefile Sat Nov 24 06:11:23 2007 +0000
13.2 +++ b/sourcehook/test/Makefile Mon Nov 26 14:03:25 2007 +0000
13.3 @@ -9,7 +9,7 @@
13.4 MAX_PARAMS=20
13.5
13.6 BINARY = sourcehook_test
13.7 -OBJECTS = main.cpp sourcehook.cpp $(shell ls -t test*.cpp)
13.8 +OBJECTS = main.cpp sourcehook.cpp ../sourcehook_hookmangen.cpp $(shell ls -t test*.cpp)
13.9 HEADERS = ../sh_list.h ../sh_tinyhash.h ../sh_memory.h ../sh_string.h ../sh_vector.h ../sourcehook_impl.h ../FastDelegate.h ../sourcehook.h ../sh_memfuncinfo.h
13.10
13.11 ifeq "$(DEBUG)" "true"
13.12 @@ -20,7 +20,7 @@
13.13 CFLAGS = $(OPT_FLAGS)
13.14 endif
13.15
13.16 -CFLAGS += -Wall
13.17 +CFLAGS += -Wall -Wno-non-virtual-dtor
13.18 # Also, enable SH_ASSERT
13.19 CFLAGS += -DSH_DEBUG
13.20
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/sourcehook/test/generate.bat Mon Nov 26 14:03:25 2007 +0000
14.3 @@ -0,0 +1,6 @@
14.4 +:: Generates everything
14.5 +:: Usage:
14.6 +:: generate.bat <num-of-arguments>
14.7 +
14.8 +
14.9 +..\generate\shworker iter testhookmangen.hxx testhookmangen.h %1
14.10 \ No newline at end of file
15.1 --- a/sourcehook/test/main.cpp Sat Nov 24 06:11:23 2007 +0000
15.2 +++ b/sourcehook/test/main.cpp Mon Nov 26 14:03:25 2007 +0000
15.3 @@ -13,6 +13,7 @@
15.4
15.5 #include "sourcehook_impl.h"
15.6 #include "sourcehook.h"
15.7 +#include "sourcehook_hookmangen.h"
15.8
15.9 using namespace std;
15.10 bool g_Verbose;
15.11 @@ -46,6 +47,8 @@
15.12 DECL_TEST(Ref);
15.13 DECL_TEST(RefRet);
15.14 DECL_TEST(VPHooks);
15.15 +DECL_TEST(CPageAlloc); // in testhookmangen.cpp
15.16 +DECL_TEST(HookManGen);
15.17
15.18 int main(int argc, char *argv[])
15.19 {
15.20 @@ -68,6 +71,8 @@
15.21 DO_TEST(Ref);
15.22 DO_TEST(RefRet);
15.23 DO_TEST(VPHooks);
15.24 + DO_TEST(CPageAlloc);
15.25 + DO_TEST(HookManGen);
15.26
15.27 cout << endl << "----" << endl << "Passed: " << passed << endl << "Failed: " << failed << endl;
15.28 cout << "Total: " << passed + failed << endl;
15.29 @@ -107,3 +112,14 @@
15.30 {
15.31 static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
15.32 }
15.33 +
15.34 +SourceHook::IHookManagerAutoGen *Test_HMAG_Factory(SourceHook::ISourceHook *shptr)
15.35 +{
15.36 + return new SourceHook::Impl::CHookManagerAutoGen(shptr);
15.37 +}
15.38 +
15.39 +void Test_HMAG_Delete(SourceHook::IHookManagerAutoGen *ptr)
15.40 +{
15.41 + delete static_cast<SourceHook::Impl::CHookManagerAutoGen*>(ptr);
15.42 +}
15.43 +
16.1 --- a/sourcehook/test/msvc7/test.vcproj Sat Nov 24 06:11:23 2007 +0000
16.2 +++ b/sourcehook/test/msvc7/test.vcproj Mon Nov 26 14:03:25 2007 +0000
16.3 @@ -249,6 +249,9 @@
16.4 RelativePath="..\..\sourcehook.cpp">
16.5 </File>
16.6 <File
16.7 + RelativePath="..\..\sourcehook_hookmangen.cpp">
16.8 + </File>
16.9 + <File
16.10 RelativePath="..\test1.cpp">
16.11 </File>
16.12 <File
16.13 @@ -267,6 +270,9 @@
16.14 RelativePath="..\testbail2.cpp">
16.15 </File>
16.16 <File
16.17 + RelativePath="..\testhookmangen.cpp">
16.18 + </File>
16.19 + <File
16.20 RelativePath="..\testlist.cpp">
16.21 </File>
16.22 <File
16.23 @@ -307,6 +313,12 @@
16.24 RelativePath="..\..\sh_list.h">
16.25 </File>
16.26 <File
16.27 + RelativePath="..\..\sh_memory.h">
16.28 + </File>
16.29 + <File
16.30 + RelativePath="..\..\sh_pagealloc.h">
16.31 + </File>
16.32 + <File
16.33 RelativePath="..\..\sh_stack.h">
16.34 </File>
16.35 <File
16.36 @@ -322,6 +334,12 @@
16.37 RelativePath="..\..\sourcehook.h">
16.38 </File>
16.39 <File
16.40 + RelativePath="..\..\sourcehook_hookmangen.h">
16.41 + </File>
16.42 + <File
16.43 + RelativePath="..\..\sourcehook_hookmangen_x86.h">
16.44 + </File>
16.45 + <File
16.46 RelativePath="..\..\sourcehook_impl.h">
16.47 </File>
16.48 <File
16.49 @@ -346,6 +364,9 @@
16.50 RelativePath="..\..\sourcehook_impl_cvfnptr.h">
16.51 </File>
16.52 <File
16.53 + RelativePath="..\..\sourcehook_pibuilder.h">
16.54 + </File>
16.55 + <File
16.56 RelativePath="..\sourcehook_test.h">
16.57 </File>
16.58 <File
16.59 @@ -354,6 +375,9 @@
16.60 <File
16.61 RelativePath="..\testevents.h">
16.62 </File>
16.63 + <File
16.64 + RelativePath="..\testhookmangen.h">
16.65 + </File>
16.66 <Filter
16.67 Name="generate"
16.68 Filter="">
16.69 @@ -378,6 +402,9 @@
16.70 Outputs="..\sourcehook.h"/>
16.71 </FileConfiguration>
16.72 </File>
16.73 + <File
16.74 + RelativePath="..\testhookmangen.hxx">
16.75 + </File>
16.76 </Filter>
16.77 </Filter>
16.78 <Filter
17.1 --- a/sourcehook/test/msvc8/test.vcproj Sat Nov 24 06:11:23 2007 +0000
17.2 +++ b/sourcehook/test/msvc8/test.vcproj Mon Nov 26 14:03:25 2007 +0000
17.3 @@ -303,6 +303,7 @@
17.4 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
17.5 StringPooling="true"
17.6 MinimalRebuild="true"
17.7 + ExceptionHandling="1"
17.8 BasicRuntimeChecks="3"
17.9 RuntimeLibrary="0"
17.10 EnableFunctionLevelLinking="true"
17.11 @@ -372,6 +373,10 @@
17.12 >
17.13 </File>
17.14 <File
17.15 + RelativePath="..\..\sourcehook_hookmangen.cpp"
17.16 + >
17.17 + </File>
17.18 + <File
17.19 RelativePath="..\test1.cpp"
17.20 >
17.21 </File>
17.22 @@ -396,6 +401,10 @@
17.23 >
17.24 </File>
17.25 <File
17.26 + RelativePath="..\testhookmangen.cpp"
17.27 + >
17.28 + </File>
17.29 + <File
17.30 RelativePath="..\testlist.cpp"
17.31 >
17.32 </File>
17.33 @@ -473,6 +482,14 @@
17.34 >
17.35 </File>
17.36 <File
17.37 + RelativePath="..\..\sourcehook_hookmangen.h"
17.38 + >
17.39 + </File>
17.40 + <File
17.41 + RelativePath="..\..\sourcehook_hookmangen_x86.h"
17.42 + >
17.43 + </File>
17.44 + <File
17.45 RelativePath="..\..\sourcehook_impl.h"
17.46 >
17.47 </File>
17.48 @@ -501,6 +518,10 @@
17.49 >
17.50 </File>
17.51 <File
17.52 + RelativePath="..\..\sourcehook_pibuilder.h"
17.53 + >
17.54 + </File>
17.55 + <File
17.56 RelativePath="..\sourcehook_test.h"
17.57 >
17.58 </File>
17.59 @@ -512,6 +533,10 @@
17.60 RelativePath="..\testevents.h"
17.61 >
17.62 </File>
17.63 + <File
17.64 + RelativePath="..\testhookmangen.h"
17.65 + >
17.66 + </File>
17.67 <Filter
17.68 Name="generate"
17.69 >
17.70 @@ -536,6 +561,10 @@
17.71 />
17.72 </FileConfiguration>
17.73 </File>
17.74 + <File
17.75 + RelativePath="..\testhookmangen.hxx"
17.76 + >
17.77 + </File>
17.78 </Filter>
17.79 </Filter>
17.80 <Filter
18.1 --- a/sourcehook/test/sourcehook_test.h Sat Nov 24 06:11:23 2007 +0000
18.2 +++ b/sourcehook/test/sourcehook_test.h Mon Nov 26 14:03:25 2007 +0000
18.3 @@ -17,6 +17,7 @@
18.4 CAutoPtrDestruction(T *p) : m_Ptr(p) { }
18.5 ~CAutoPtrDestruction() { if (m_Ptr) delete m_Ptr; }
18.6 void clear() { m_Ptr = NULL; }
18.7 + void set(T *ptr) { m_Ptr = ptr; }
18.8 };
18.9
18.10 struct CSHPtrAutoDestruction
18.11 @@ -33,3 +34,16 @@
18.12 void Test_UnloadPlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug);
18.13 void Test_PausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug);
18.14 void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug);
18.15 +
18.16 +SourceHook::IHookManagerAutoGen *Test_HMAG_Factory(SourceHook::ISourceHook *pSHPtr);
18.17 +void Test_HMAG_Delete(SourceHook::IHookManagerAutoGen *ptr);
18.18 +
18.19 +struct CHMAGAutoDestruction
18.20 +{
18.21 + SourceHook::IHookManagerAutoGen *m_Ptr;
18.22 + CHMAGAutoDestruction(SourceHook::IHookManagerAutoGen *ptr) : m_Ptr(ptr) {}
18.23 + ~CHMAGAutoDestruction() { Test_HMAG_Delete(m_Ptr); }
18.24 +};
18.25 +
18.26 +
18.27 +#define GET_HMAG(var, shptr) var = Test_HMAG_Factory(shptr); CHMAGAutoDestruction __hmagautodestruction(var);
19.1 --- a/sourcehook/test/test2.cpp Sat Nov 24 06:11:23 2007 +0000
19.2 +++ b/sourcehook/test/test2.cpp Mon Nov 26 14:03:25 2007 +0000
19.3 @@ -178,7 +178,7 @@
19.4 tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf,
19.5 tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf, tmpbuf);
19.6
19.7 - char refbuf[SourceHook::STRBUF_LEN];
19.8 + char refbuf[SourceHook::STRBUF_LEN];
19.9 for (int i = 0; i < (SourceHook::STRBUF_LEN - 1); ++i)
19.10 refbuf[i] = (i % 10) + '0';
19.11 refbuf[SourceHook::STRBUF_LEN - 1] = 0;
20.1 --- a/sourcehook/test/testevents.h Sat Nov 24 06:11:23 2007 +0000
20.2 +++ b/sourcehook/test/testevents.h Mon Nov 26 14:03:25 2007 +0000
20.3 @@ -19,6 +19,19 @@
20.4
20.5 extern bool g_Verbose;
20.6
20.7 +static unsigned int MakeHash(const char *name)
20.8 +{
20.9 + int a = 0;
20.10 + unsigned int res = 0xFFFFFFFF;
20.11 +
20.12 + while (*name)
20.13 + {
20.14 + res ^= ((unsigned int)*name << ((a++ % 4)*8));
20.15 + ++name;
20.16 + }
20.17 + return res;
20.18 +}
20.19 +
20.20 struct State
20.21 {
20.22 virtual ~State()
20.23 @@ -28,10 +41,27 @@
20.24
20.25 virtual bool IsEqual(State *other)
20.26 {
20.27 - return (typeid(other) == typeid(this)) ? true : false;
20.28 + return (MakeHash(GetName()) == MakeHash(other->GetName())) ? true : false;
20.29 + }
20.30 +
20.31 + virtual bool Ignore()
20.32 + {
20.33 + return false;
20.34 }
20.35
20.36 virtual void Dump() = 0;
20.37 + virtual const char *GetName() = 0;
20.38 +};
20.39 +
20.40 +struct IgnoreState : public State
20.41 +{
20.42 + virtual bool Ignore()
20.43 + {
20.44 + return true;
20.45 + }
20.46 + virtual void Dump()
20.47 + {
20.48 + }
20.49 };
20.50
20.51 typedef std::list<State*> StateList;
20.52 @@ -53,6 +83,8 @@
20.53 State *cs = va_arg(argptr, State*);
20.54 if (!cs)
20.55 break;
20.56 + if (cs->Ignore())
20.57 + continue;
20.58 requiredstates.push_back(cs);
20.59 }
20.60 va_end(argptr);
20.61 @@ -112,19 +144,21 @@
20.62 #define MAKE_STATE(name) struct name : State { \
20.63 virtual void Dump() { \
20.64 std::cout << " " << #name << std::endl; } \
20.65 + const char *GetName() { return #name; } \
20.66 };
20.67
20.68 #define MAKE_STATE_1(name, p1_type) struct name : State { \
20.69 p1_type m_Param1; \
20.70 name(p1_type param1) : m_Param1(param1) {} \
20.71 virtual bool IsEqual(State *other) { \
20.72 - name *other2 = dynamic_cast<name*>(other); \
20.73 - if (!other2) \
20.74 + if (MakeHash(GetName()) != MakeHash(other->GetName())) \
20.75 return false; \
20.76 + name *other2 = static_cast<name*>(other); \
20.77 return other2->m_Param1 == m_Param1;\
20.78 } \
20.79 virtual void Dump() { \
20.80 std::cout << " " << #name << "; Param1=" << m_Param1 << std::endl; } \
20.81 + const char *GetName() { return #name; } \
20.82 }
20.83
20.84 #define MAKE_STATE_2(name, p1_type, p2_type) struct name : State { \
20.85 @@ -132,13 +166,14 @@
20.86 p2_type m_Param2; \
20.87 name(p1_type param1, p2_type param2) : m_Param1(param1), m_Param2(param2) {} \
20.88 virtual bool IsEqual(State *other) { \
20.89 - name *other2 = dynamic_cast<name*>(other); \
20.90 - if (!other2) \
20.91 + if (MakeHash(GetName()) != MakeHash(other->GetName())) \
20.92 return false; \
20.93 + name *other2 = static_cast<name*>(other); \
20.94 return other2->m_Param1 == m_Param1 && other2->m_Param2 == m_Param2;\
20.95 } \
20.96 virtual void Dump() { \
20.97 std::cout << " " << #name << "; Param1=" << m_Param1 << "; Param2=" << m_Param2 << std::endl; } \
20.98 + const char *GetName() { return #name; } \
20.99 }
20.100
20.101 #define MAKE_STATE_3(name, p1_type, p2_type, p3_type) struct name : State { \
20.102 @@ -147,13 +182,31 @@
20.103 p3_type m_Param3; \
20.104 name(p1_type param1, p2_type param2, p3_type param3) : m_Param1(param1), m_Param2(param2), m_Param3(param3) {} \
20.105 virtual bool IsEqual(State *other) { \
20.106 - name *other2 = dynamic_cast<name*>(other); \
20.107 - if (!other2) \
20.108 + if (MakeHash(GetName()) != MakeHash(other->GetName())) \
20.109 return false; \
20.110 + name *other2 = static_cast<name*>(other); \
20.111 return other2->m_Param1 == m_Param1 && other2->m_Param2 == m_Param2 && other2->m_Param3 == m_Param3;\
20.112 } \
20.113 virtual void Dump() { \
20.114 std::cout << " " << #name << "; Param1=" << m_Param1 << "; Param2=" << m_Param2 << "; Param3=" << m_Param3 << std::endl; } \
20.115 + const char *GetName() { return #name; } \
20.116 + }
20.117 +
20.118 +#define MAKE_STATE_4(name, p1_type, p2_type, p3_type, p4_type) struct name : State { \
20.119 + p1_type m_Param1; \
20.120 + p2_type m_Param2; \
20.121 + p3_type m_Param3; \
20.122 + p4_type m_Param4; \
20.123 + name(p1_type param1, p2_type param2, p3_type param3, p4_type param4) : m_Param1(param1), m_Param2(param2), m_Param3(param3), m_Param4(param4) {} \
20.124 + virtual bool IsEqual(State *other) { \
20.125 + if (MakeHash(GetName()) != MakeHash(other->GetName())) \
20.126 + return false; \
20.127 + name *other2 = static_cast<name*>(other); \
20.128 + return other2->m_Param1 == m_Param1 && other2->m_Param2 == m_Param2 && other2->m_Param3 == m_Param3 && other2->m_Param4 == m_Param4;\
20.129 + } \
20.130 + virtual void Dump() { \
20.131 + std::cout << " " << #name << "; Param1=" << m_Param1 << "; Param2=" << m_Param2 << "; Param3=" << m_Param3 << "; Param4=" << m_Param4 << std::endl; } \
20.132 + const char *GetName() { return #name; } \
20.133 }
20.134
20.135 #define CHECK_COND(c, err) if (!(c)) { error = err; return false; }
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
21.2 +++ b/sourcehook/test/testhookmangen.cpp Mon Nov 26 14:03:25 2007 +0000
21.3 @@ -0,0 +1,1229 @@
21.4 +#include <string>
21.5 +#include "sourcehook.h"
21.6 +#include "sourcehook_test.h"
21.7 +#include "testevents.h"
21.8 +#include "sh_memory.h"
21.9 +#include "sh_pagealloc.h"
21.10 +#include "sourcehook_pibuilder.h"
21.11 +
21.12 +// TESTHOOKMANGEN
21.13 +// Test automatic hookman generation
21.14 +// Tests void and non-void functions
21.15 +// 0 to 6 params:
21.16 +// integer-type, float-type, plain-old-data struct and objects with ctors/dtors
21.17 +// both byval and byref
21.18 +// also tests ignore/supercede
21.19 +// also tests recalls
21.20 +
21.21 +// :TODO: test override as well
21.22 +
21.23 +namespace
21.24 +{
21.25 + StateList g_States;
21.26 + SourceHook::ISourceHook *g_SHPtr;
21.27 + SourceHook::Plugin g_PLID;
21.28 +
21.29 + SourceHook::IHookManagerAutoGen *g_HMAGPtr;
21.30 +
21.31 + // PtrBuf(ptr) gives ptrs unique numbers
21.32 + // in the order they appear
21.33 + SourceHook::List<const void*> g_PtrHash;
21.34 +
21.35 + bool g_Inside_LeafFunc = false; // inside a hook or a func
21.36 + bool g_Silent_CtorDtor = false; // inside a hook or a func
21.37 +
21.38 +
21.39 + // POD / Object types
21.40 + template <int MYSIZE>
21.41 + struct POD
21.42 + {
21.43 + char x[MYSIZE];
21.44 +
21.45 + bool operator==(const POD<MYSIZE> &other)
21.46 + {
21.47 + return memcmp(reinterpret_cast<void*>(x), reinterpret_cast<const void*>(other.x), MYSIZE) == 0;
21.48 + }
21.49 +
21.50 + bool operator==(char other)
21.51 + {
21.52 + for (int i = 0; i < MYSIZE; ++i)
21.53 + {
21.54 + if (x[i] != other)
21.55 + return false;
21.56 + }
21.57 + return true;
21.58 + }
21.59 + };
21.60 +
21.61 + template <int MYSIZE>
21.62 + std::ostream& operator <<(std::ostream &os, const POD<MYSIZE> &obj)
21.63 + {
21.64 + os << "Some POD!";
21.65 + return os;
21.66 + }
21.67 +
21.68 + MAKE_STATE_1(State_ObjOCtor_Called, int /*MYSIZE*/);
21.69 + MAKE_STATE_1(State_ObjCCtor_Called, int /*MYSIZE*/);
21.70 + MAKE_STATE_1(State_ObjODtor_Called, int /*MYSIZE*/);
21.71 + MAKE_STATE_1(State_ObjAssignOp_Called, int /*MYSIZE*/);
21.72 +
21.73 + template <int MYSIZE>
21.74 + struct Object
21.75 + {
21.76 + char x[MYSIZE];
21.77 +
21.78 + Object(char initch)
21.79 + {
21.80 + memset(reinterpret_cast<void*>(x), initch, MYSIZE);
21.81 + if (!g_Inside_LeafFunc && !g_Silent_CtorDtor)
21.82 + ADD_STATE(State_ObjOCtor_Called(MYSIZE));
21.83 + }
21.84 +
21.85 + Object()
21.86 + {
21.87 + if (!g_Inside_LeafFunc && !g_Silent_CtorDtor)
21.88 + ADD_STATE(State_ObjOCtor_Called(MYSIZE));
21.89 + }
21.90 +
21.91 + Object(const Object<MYSIZE> & other)
21.92 + {
21.93 + memcpy(reinterpret_cast<void*>(x), reinterpret_cast<const void*>(other.x), MYSIZE);
21.94 + if (!g_Inside_LeafFunc && !g_Silent_CtorDtor)
21.95 + ADD_STATE(State_ObjCCtor_Called(MYSIZE));
21.96 + }
21.97 +
21.98 + ~Object()
21.99 + {
21.100 + if (!g_Inside_LeafFunc && !g_Silent_CtorDtor)
21.101 + ADD_STATE(State_ObjODtor_Called(MYSIZE));
21.102 + }
21.103 +
21.104 + Object & operator = (const Object &other)
21.105 + {
21.106 + if (!g_Inside_LeafFunc && !g_Silent_CtorDtor)
21.107 + ADD_STATE(State_ObjAssignOp_Called(MYSIZE));
21.108 +
21.109 + memcpy(reinterpret_cast<void*>(x), reinterpret_cast<const void*>(other.x), MYSIZE);
21.110 +
21.111 + return *this;
21.112 + }
21.113 +
21.114 + bool operator==(const Object<MYSIZE> &other)
21.115 + {
21.116 + return memcmp(reinterpret_cast<void*>(x), reinterpret_cast<const void*>(other.x), MYSIZE) == 0;
21.117 + }
21.118 + };
21.119 +
21.120 + template <int MYSIZE>
21.121 + std::ostream& operator <<(std::ostream &os, const Object<MYSIZE> &obj)
21.122 + {
21.123 + os << "Some Obj" << static_cast<int>(obj.x[0]);
21.124 + return os;
21.125 + }
21.126 +
21.127 + // Because of some weird bug in MSVC < 1400
21.128 +#define MAKE_PODRET(size) \
21.129 + struct PodRet##size \
21.130 + { \
21.131 + POD<size> actPod; \
21.132 + bool operator==(const PodRet##size &other) { return actPod == other.actPod; } \
21.133 + bool operator==(char other) { return actPod == other; } \
21.134 + }; \
21.135 + std::ostream& operator <<(std::ostream &os, const PodRet##size &obj) \
21.136 + { \
21.137 + os << obj.actPod; \
21.138 + return os; \
21.139 + } \
21.140 + template <> struct MakeRet< PodRet##size > \
21.141 + { \
21.142 + static PodRet##size Do(int a) \
21.143 + { \
21.144 + PodRet##size x; \
21.145 + memset(reinterpret_cast<void*>(x.actPod.x), a, size); \
21.146 + return x; \
21.147 + } \
21.148 + };
21.149 +
21.150 +#define MAKE_OBJRET(size) \
21.151 + struct ObjRet##size \
21.152 + { \
21.153 + Object<size> actObj; \
21.154 + bool operator==(const ObjRet##size &other) { return actObj == other.actObj; } \
21.155 + bool operator==(char other) { return actObj == other; } \
21.156 + }; \
21.157 + std::ostream& operator <<(std::ostream &os, const ObjRet##size &obj) \
21.158 + { \
21.159 + os << obj.actObj; \
21.160 + return os; \
21.161 + } \
21.162 + template <> struct MakeRet< ObjRet##size > \
21.163 + { \
21.164 + static ObjRet##size Do(int a) NO_OPTIMIZE \
21.165 + { \
21.166 + ObjRet##size *x = new ObjRet##size; /* ptr: otherwise gcc optimizes away the temp obj */ \
21.167 + CAutoPtrDestruction< ObjRet##size > apd(x); \
21.168 + memset(reinterpret_cast<void*>(x->actObj.x), a, size); \
21.169 + return *x; \
21.170 + } \
21.171 + };
21.172 +
21.173 +
21.174 +
21.175 + // "Increment" something: (reproducible change for recall tests)
21.176 + // integer: ++
21.177 + // float: += 1.3
21.178 + // pod/object: x[i]++, 0 <= i < MYSIZE
21.179 + template <class T>
21.180 + struct Increment
21.181 + {
21.182 + static void Incr(T &what)
21.183 + {
21.184 + ++what;
21.185 + }
21.186 + };
21.187 +
21.188 + template<>
21.189 + struct Increment<float>
21.190 + {
21.191 + static void Incr(float &what)
21.192 + {
21.193 + what += 1.3f;
21.194 + }
21.195 + };
21.196 +
21.197 + template<>
21.198 + struct Increment<double>
21.199 + {
21.200 + static void Incr(double &what)
21.201 + {
21.202 + what += 1.3;
21.203 + }
21.204 + };
21.205 +
21.206 + template<int MYSIZE>
21.207 + struct Increment< POD<MYSIZE> >
21.208 + {
21.209 + static void Incr(POD<MYSIZE> &what)
21.210 + {
21.211 + for (int i = 0; i < MYSIZE; ++i)
21.212 + ++ what.x[i];
21.213 + }
21.214 + };
21.215 +
21.216 + template<int MYSIZE>
21.217 + struct Increment< Object<MYSIZE> >
21.218 + {
21.219 + static void Incr(Object<MYSIZE> &what)
21.220 + {
21.221 + for (int i = 0; i < MYSIZE; ++i)
21.222 + ++ what.x[i];
21.223 + }
21.224 + };
21.225 +
21.226 + template<>
21.227 + struct Increment<std::string>
21.228 + {
21.229 + static void Incr(std::string &what)
21.230 + {
21.231 + what += "!";
21.232 + }
21.233 + };
21.234 +
21.235 + #include "testhookmangen.h"
21.236 +
21.237 + template <class T>
21.238 + int PtrBuf(T ptr)
21.239 + {
21.240 + int a = 0;
21.241 +
21.242 + const void *vptr = reinterpret_cast<const void*>(ptr);
21.243 + for (SourceHook::List<const void*>::iterator iter = g_PtrHash.begin(); iter != g_PtrHash.end(); ++iter)
21.244 + {
21.245 + if (*iter == vptr)
21.246 + return a;
21.247 + else
21.248 + ++a;
21.249 + }
21.250 + g_PtrHash.push_back(vptr);
21.251 + return static_cast<int>(g_PtrHash.size()) - 1;
21.252 + }
21.253 +
21.254 + template <class T>
21.255 + T PtrBufPtr(T ptr)
21.256 + {
21.257 + PtrBuf(ptr);
21.258 + return ptr;
21.259 + }
21.260 +
21.261 + void PtrBuf_Clear(int leave_in = 0)
21.262 + {
21.263 + for (SourceHook::List<const void*>::iterator iter = g_PtrHash.begin(); iter != g_PtrHash.end();)
21.264 + {
21.265 + if (--leave_in < 0)
21.266 + iter = g_PtrHash.erase(iter);
21.267 + else
21.268 + ++iter;
21.269 + }
21.270 + }
21.271 +
21.272 + // MyDelegate base class for other delegates
21.273 + class MyDelegate : public SourceHook::ISHDelegate
21.274 + {
21.275 + // Unneeded
21.276 + // because we don't use old SH_REMOVE_HOOK syntax
21.277 + virtual bool IsEqual(SourceHook::ISHDelegate *pOtherDeleg)
21.278 + {
21.279 + return false;
21.280 + }
21.281 +
21.282 + virtual void DeleteThis()
21.283 + {
21.284 + delete this;
21.285 + }
21.286 + };
21.287 +
21.288 + THGM_MAKE_TEST0_void(0);
21.289 + THGM_SETUP_PI0(0);
21.290 +
21.291 + THGM_MAKE_TEST1_void(1, char);
21.292 + THGM_SETUP_PI1(1, char, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal);
21.293 +
21.294 + THGM_MAKE_TEST1_void(2, short);
21.295 + THGM_SETUP_PI1(2, short, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal);
21.296 +
21.297 + THGM_MAKE_TEST1_void(3, int);
21.298 + THGM_SETUP_PI1(3, int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal);
21.299 +
21.300 + THGM_MAKE_TEST1_void(4, float);
21.301 + THGM_SETUP_PI1(4, float, SourceHook::PassInfo::PassType_Float, SourceHook::PassInfo::PassFlag_ByVal);
21.302 +
21.303 + THGM_MAKE_TEST1_void(5, double);
21.304 + THGM_SETUP_PI1(5, double, SourceHook::PassInfo::PassType_Float, SourceHook::PassInfo::PassFlag_ByVal);
21.305 +
21.306 + THGM_MAKE_TEST5_void(6, char, short, int, float, double);
21.307 + THGM_SETUP_PI5(6,
21.308 + char, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal,
21.309 + short, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal,
21.310 + int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal,
21.311 + float, SourceHook::PassInfo::PassType_Float, SourceHook::PassInfo::PassFlag_ByVal,
21.312 + double, SourceHook::PassInfo::PassType_Float, SourceHook::PassInfo::PassFlag_ByVal
21.313 + );
21.314 +
21.315 + THGM_MAKE_TEST2_void(7, char&, double&);
21.316 + THGM_SETUP_PI2(7,
21.317 + char&, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByRef,
21.318 + double&, SourceHook::PassInfo::PassType_Float, SourceHook::PassInfo::PassFlag_ByRef
21.319 + );
21.320 +
21.321 + THGM_MAKE_TEST1_void(8, POD<7>);
21.322 + THGM_SETUP_PI1(8, POD<7>, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByVal);
21.323 +
21.324 + THGM_MAKE_TEST1_void(9, POD<600>);
21.325 + THGM_SETUP_PI1(9, POD<600>, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByVal);
21.326 +
21.327 + THGM_MAKE_TEST1_void(10, POD<600> &);
21.328 + THGM_SETUP_PI1(10, POD<600> &, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByRef);
21.329 +
21.330 + THGM_MAKE_TEST2_void(11, Object<3>, Object<600>&);
21.331 + THGM_SETUP_PI2(11,
21.332 + Object<3>, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByVal | SourceHook::PassInfo::PassFlag_OCtor | SourceHook::PassInfo::PassFlag_ODtor | SourceHook::PassInfo::PassFlag_CCtor,
21.333 + Object<600> &, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByRef | SourceHook::PassInfo::PassFlag_OCtor | SourceHook::PassInfo::PassFlag_ODtor | SourceHook::PassInfo::PassFlag_CCtor
21.334 + );
21.335 +
21.336 + THGM_MAKE_TEST0(101, char);
21.337 + THGM_SETUP_PI0(101);
21.338 + THGM_SETUP_RI(101, char, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal);
21.339 +
21.340 + THGM_MAKE_TEST0(102, short);
21.341 + THGM_SETUP_PI0(102);
21.342 + THGM_SETUP_RI(102, short, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal);
21.343 +
21.344 + THGM_MAKE_TEST0(103, int);
21.345 + THGM_SETUP_PI0(103);
21.346 + THGM_SETUP_RI(103, int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal);
21.347 +
21.348 + THGM_MAKE_TEST0(104, float);
21.349 + THGM_SETUP_PI0(104);
21.350 + THGM_SETUP_RI(104, float, SourceHook::PassInfo::PassType_Float, SourceHook::PassInfo::PassFlag_ByVal);
21.351 +
21.352 + THGM_MAKE_TEST0(105, double);
21.353 + THGM_SETUP_PI0(105);
21.354 + THGM_SETUP_RI(105, double, SourceHook::PassInfo::PassType_Float, SourceHook::PassInfo::PassFlag_ByVal);
21.355 +
21.356 + // pod 1-13
21.357 + MAKE_PODRET(1);
21.358 + THGM_MAKE_TEST1(106, PodRet1, int);
21.359 + THGM_SETUP_PI1(106,
21.360 + int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal
21.361 + );
21.362 + THGM_SETUP_RI(106, PodRet1, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByVal);
21.363 +
21.364 + MAKE_PODRET(4);
21.365 + THGM_MAKE_TEST1(107, PodRet4, int);
21.366 + THGM_SETUP_PI1(107,
21.367 + int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal
21.368 + );
21.369 + THGM_SETUP_RI(107, PodRet4, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByVal);
21.370 +
21.371 + MAKE_PODRET(8);
21.372 + THGM_MAKE_TEST1(108, PodRet8, int);
21.373 + THGM_SETUP_PI1(108,
21.374 + int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal
21.375 + );
21.376 + THGM_SETUP_RI(108, PodRet8, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByVal);
21.377 +
21.378 + MAKE_PODRET(13);
21.379 + THGM_MAKE_TEST1(109, PodRet13, int);
21.380 + THGM_SETUP_PI1(109,
21.381 + int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal
21.382 + );
21.383 + THGM_SETUP_RI(109, PodRet13, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByVal);
21.384 +
21.385 + MAKE_OBJRET(13);
21.386 + THGM_MAKE_TEST1(110, ObjRet13, int);
21.387 + THGM_SETUP_PI1(110,
21.388 + int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal
21.389 + );
21.390 + THGM_SETUP_RI(110, ObjRet13, SourceHook::PassInfo::PassType_Object,
21.391 + SourceHook::PassInfo::PassFlag_ByVal | SourceHook::PassInfo::PassFlag_OCtor | SourceHook::PassInfo::PassFlag_ODtor |
21.392 + SourceHook::PassInfo::PassFlag_CCtor | SourceHook::PassInfo::PassFlag_AssignOp);
21.393 +
21.394 + MAKE_OBJRET(111);
21.395 + ObjRet111 g_O111_0;
21.396 + ObjRet111 g_O111_1;
21.397 + ObjRet111 g_O111_2;
21.398 + ObjRet111 g_O111_3;
21.399 + ObjRet111 g_O111_4;
21.400 +
21.401 + template <>
21.402 + struct MakeRet< ObjRet111& >
21.403 + {
21.404 + static ObjRet111 &Do(int a)
21.405 + {
21.406 + switch (a)
21.407 + {
21.408 + case 0:
21.409 + return g_O111_0;
21.410 + case 1:
21.411 + return g_O111_1;
21.412 + case 2:
21.413 + return g_O111_2;
21.414 + case 3:
21.415 + return g_O111_3;
21.416 + default:
21.417 + return g_O111_4;
21.418 + }
21.419 + }
21.420 + };
21.421 +
21.422 + THGM_MAKE_TEST0(111, ObjRet111& );
21.423 + THGM_SETUP_PI0(111);
21.424 + THGM_SETUP_RI(111, ObjRet111& , SourceHook::PassInfo::PassType_Object,
21.425 + SourceHook::PassInfo::PassFlag_ByRef | SourceHook::PassInfo::PassFlag_OCtor | SourceHook::PassInfo::PassFlag_ODtor |
21.426 + SourceHook::PassInfo::PassFlag_CCtor | SourceHook::PassInfo::PassFlag_AssignOp);
21.427 +
21.428 +
21.429 + THGM_MAKE_TEST3_void(150, int, double, int);
21.430 + THGM_SETUP_PI3(150,
21.431 + int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal,
21.432 + double, SourceHook::PassInfo::PassType_Float, SourceHook::PassInfo::PassFlag_ByVal,
21.433 + int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal);
21.434 +
21.435 + // vafmt tests
21.436 + THGM_MAKE_TEST0_vafmt_void(200);
21.437 + THGM_SETUP_PI0(200);
21.438 +
21.439 + THGM_MAKE_TEST1_vafmt_void(201, char);
21.440 + THGM_SETUP_PI1(201, char, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal);
21.441 +
21.442 + THGM_MAKE_TEST1_vafmt_void(203, int);
21.443 + THGM_SETUP_PI1(203, int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal);
21.444 +
21.445 + THGM_MAKE_TEST5_vafmt_void(206, char, short, int, float, double);
21.446 + THGM_SETUP_PI5(206,
21.447 + char, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal,
21.448 + short, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal,
21.449 + int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal,
21.450 + float, SourceHook::PassInfo::PassType_Float, SourceHook::PassInfo::PassFlag_ByVal,
21.451 + double, SourceHook::PassInfo::PassType_Float, SourceHook::PassInfo::PassFlag_ByVal
21.452 + );
21.453 +
21.454 + THGM_MAKE_TEST2_vafmt_void(207, char&, double&);
21.455 + THGM_SETUP_PI2(207,
21.456 + char&, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByRef,
21.457 + double&, SourceHook::PassInfo::PassType_Float, SourceHook::PassInfo::PassFlag_ByRef
21.458 + );
21.459 +
21.460 + THGM_MAKE_TEST1_vafmt_void(208, POD<7>);
21.461 + THGM_SETUP_PI1(208, POD<7>, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByVal);
21.462 +
21.463 + THGM_MAKE_TEST1_vafmt_void(210, POD<600> &);
21.464 + THGM_SETUP_PI1(210, POD<600> &, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByRef)
21.465 +
21.466 + THGM_MAKE_TEST1_vafmt(211, int, int);
21.467 + THGM_SETUP_PI1(211,
21.468 + int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal
21.469 + );
21.470 + THGM_SETUP_RI(211, int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal);
21.471 +
21.472 + THGM_MAKE_TEST1_vafmt(212, double, int);
21.473 + THGM_SETUP_PI1(212,
21.474 + int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal
21.475 + );
21.476 + THGM_SETUP_RI(212, double, SourceHook::PassInfo::PassType_Float, SourceHook::PassInfo::PassFlag_ByVal);
21.477 +
21.478 + THGM_MAKE_TEST1_vafmt(213, PodRet8, int);
21.479 + THGM_SETUP_PI1(213,
21.480 + int, SourceHook::PassInfo::PassType_Basic, SourceHook::PassInfo::PassFlag_ByVal
21.481 + );
21.482 + THGM_SETUP_RI(213, PodRet8, SourceHook::PassInfo::PassType_Object, SourceHook::PassInfo::PassFlag_ByVal);
21.483 +
21.484 + THGM_MAKE_TEST1_vafmt_void(214, Object<133>);
21.485 + THGM_SETUP_PI1(214, Object<133>, SourceHook::PassInfo::PassType_Object,
21.486 + SourceHook::PassInfo::PassFlag_ByVal | SourceHook::PassInfo::PassFlag_OCtor | SourceHook::PassInfo::PassFlag_ODtor |
21.487 + SourceHook::PassInfo::PassFlag_CCtor | SourceHook::PassInfo::PassFlag_AssignOp);
21.488 +
21.489 +
21.490 + MAKE_STATE(State_Hello_Func4_Called);
21.491 + MAKE_STATE(State_Hello_Func79_Called);
21.492 +
21.493 + MAKE_STATE(State_Hello_Func4_PreHook);
21.494 + MAKE_STATE(State_Hello_Func79_PreHook);
21.495 +
21.496 + // Test for larger vtable indices
21.497 + class Hello
21.498 + {
21.499 + public:
21.500 + virtual void Func0() {}
21.501 + virtual void Func1() {}
21.502 + virtual void Func2() {}
21.503 + virtual void Func3() {}
21.504 + virtual void Func4()
21.505 + {
21.506 + ADD_STATE(State_Hello_Func4_Called);
21.507 + }
21.508 + virtual void Func5() {}
21.509 + virtual void Func6() {}
21.510 + virtual void Func7() {}
21.511 + virtual void Func8() {}
21.512 + virtual void Func9() {}
21.513 + virtual void Func10() {}
21.514 + virtual void Func11() {}
21.515 + virtual void Func12() {}
21.516 + virtual void Func13() {}
21.517 + virtual void Func14() {}
21.518 + virtual void Func15() {}
21.519 + virtual void Func16() {}
21.520 + virtual void Func17() {}
21.521 + virtual void Func18() {}
21.522 + virtual void Func19() {}
21.523 + virtual void Func20() {}
21.524 + virtual void Func21() {}
21.525 + virtual void Func22() {}
21.526 + virtual void Func23() {}
21.527 + virtual void Func24() {}
21.528 + virtual void Func25() {}
21.529 + virtual void Func26() {}
21.530 + virtual void Func27() {}
21.531 + virtual void Func28() {}
21.532 + virtual void Func29() {}
21.533 + virtual void Func30() {}
21.534 + virtual void Func31() {}
21.535 + virtual void Func32() {}
21.536 + virtual void Func33() {}
21.537 + virtual void Func34() {}
21.538 + virtual void Func35() {}
21.539 + virtual void Func36() {}
21.540 + virtual void Func37() {}
21.541 + virtual void Func38() {}
21.542 + virtual void Func39() {}
21.543 + virtual void Func40() {}
21.544 + virtual void Func41() {}
21.545 + virtual void Func42() {}
21.546 + virtual void Func43() {}
21.547 + virtual void Func44() {}
21.548 + virtual void Func45() {}
21.549 + virtual void Func46() {}
21.550 + virtual void Func47() {}
21.551 + virtual void Func48() {}
21.552 + virtual void Func49() {}
21.553 + virtual void Func50() {}
21.554 + virtual void Func51() {}
21.555 + virtual void Func52() {}
21.556 + virtual void Func53() {}
21.557 + virtual void Func54() {}
21.558 + virtual void Func55() {}
21.559 + virtual void Func56() {}
21.560 + virtual void Func57() {}
21.561 + virtual void Func58() {}
21.562 + virtual void Func59() {}
21.563 + virtual void Func60() {}
21.564 + virtual void Func61() {}
21.565 + virtual void Func62() {}
21.566 + virtual void Func63() {}
21.567 + virtual void Func64() {}
21.568 + virtual void Func65() {}
21.569 + virtual void Func66() {}
21.570 + virtual void Func67() {}
21.571 + virtual void Func68() {}
21.572 + virtual void Func69() {}
21.573 + virtual void Func70() {}
21.574 + virtual void Func71() {}
21.575 + virtual void Func72() {}
21.576 + virtual void Func73() {}
21.577 + virtual void Func74() {}
21.578 + virtual void Func75() {}
21.579 + virtual void Func76() {}
21.580 + virtual void Func77() {}
21.581 + virtual void Func78() {}
21.582 + virtual void Func79()
21.583 + {
21.584 + ADD_STATE(State_Hello_Func79_Called);
21.585 + }
21.586 + };
21.587 + class Hello_Func4_Deleg : public MyDelegate
21.588 + {
21.589 + virtual void Func()
21.590 + {
21.591 + ADD_STATE(State_Hello_Func4_PreHook);
21.592 + }
21.593 + };
21.594 + class Hello_Func79_Deleg : public MyDelegate
21.595 + {
21.596 + int a;
21.597 + virtual void Func()
21.598 + {
21.599 + ADD_STATE(State_Hello_Func79_PreHook);
21.600 + }
21.601 + };
21.602 +
21.603 + bool Tests1(std::string &error)
21.604 + {
21.605 + THGM_DO_TEST_void(0, ());
21.606 +
21.607 + THGM_DO_TEST_void(1, (100));
21.608 +
21.609 + THGM_DO_TEST_void(2, (0x1F00));
21.610 +
21.611 + THGM_DO_TEST_void(3, (0x1F000000));
21.612 +
21.613 + THGM_DO_TEST_void(4, (0.5f));
21.614 +
21.615 + THGM_DO_TEST_void(5, (5.5));
21.616 +
21.617 + THGM_DO_TEST_void(6, (100, 0x1f00, 0x1f000000, 0.5f, 5.5));
21.618 +
21.619 + return true;
21.620 + }
21.621 +
21.622 + bool Tests2(std::string &error)
21.623 + {
21.624 + char a = 5;
21.625 + double b = 233.33;
21.626 + THGM_DO_TEST_void(7, (a, b));
21.627 +
21.628 + POD<7> pod7 = MakeRet< POD<7> >::Do(78);
21.629 + THGM_DO_TEST_void(8, (pod7));
21.630 +
21.631 + POD<600> pod600 = MakeRet< POD<600> >::Do(34);
21.632 + THGM_DO_TEST_void(9, (pod600));
21.633 +
21.634 + THGM_DO_TEST_void(10, (pod600));
21.635 +
21.636 + // Test11: Special: constructors/destructors
21.637 + PtrBuf_Clear();
21.638 + Object<3> *obj3_real = new Object<3>(33);
21.639 + Object<600> *obj600_real = new Object<600>(21);
21.640 +
21.641 + Object<3> & obj3 = *obj3_real;
21.642 + Object<600> & obj600 = *obj600_real;
21.643 +
21.644 + CHECK_STATES((&g_States,
21.645 + new State_ObjOCtor_Called(3),
21.646 + new State_ObjOCtor_Called(600),
21.647 + NULL), "Test11 Part0");
21.648 +
21.649 + setuppi_11();
21.650 + SourceHook::HookManagerPubFunc myhookman11 = g_HMAGPtr->MakeHookMan(protoinfo_11, 0, 0); \
21.651 + CAutoReleaseHookMan arhm_11(myhookman11); \
21.652 + int hook1_11, hook2_11, hook3_11, hook4_11;
21.653 +
21.654 + TestClass11 *pTest11 = new TestClass11;
21.655 + CAutoPtrDestruction<TestClass11> apd11(pTest11);
21.656 +
21.657 + /* no hooks - no hooks */
21.658 + PtrBuf_Clear();
21.659 + pTest11->Func(obj3, obj600);
21.660 +
21.661 + g_Inside_LeafFunc = true;
21.662 + CHECK_STATES((&g_States,
21.663 + new State_ObjCCtor_Called(3),
21.664 + new State_Func11(pTest11, ParamState_m11 (obj3, obj600)),
21.665 + new State_ObjODtor_Called(3),
21.666 + NULL), "Test" "11" " Part1");
21.667 + g_Inside_LeafFunc = false;
21.668 +
21.669 + /* hook1 - no hooks */
21.670 + THGM_ADD_HOOK(11, 1);
21.671 +
21.672 + PtrBuf_Clear();
21.673 + pTest11->Func(obj3, obj600);
21.674 + g_Inside_LeafFunc = true;
21.675 + CHECK_STATES((&g_States,
21.676 + new State_ObjCCtor_Called(3),
21.677 +
21.678 + new State_ObjCCtor_Called(3),
21.679 + new State_Deleg_11(1, pTest11, 0, ParamState_m11 (obj3, obj600)),
21.680 + new State_ObjODtor_Called(3),
21.681 +
21.682 + new State_ObjCCtor_Called(3),
21.683 + new State_Func11(pTest11, ParamState_m11 (obj3, obj600)),
21.684 + new State_ObjODtor_Called(3),
21.685 +
21.686 + new State_ObjODtor_Called(3),
21.687 + NULL), "Test" "11" " Part2");
21.688 + g_Inside_LeafFunc = false;
21.689 +
21.690 + THGM_REMOVE_HOOK(11, 1);
21.691 +
21.692 + /* hook1, hook2 - hook3, hook4 */
21.693 + THGM_ADD_HOOK(11, 1);
21.694 + THGM_ADD_HOOK(11, 2);
21.695 + THGM_ADD_HOOK(11, 3);
21.696 + THGM_ADD_HOOK(11, 4);
21.697 + PtrBuf_Clear();
21.698 + pTest11->Func(obj3, obj600);
21.699 + g_Inside_LeafFunc = true;
21.700 + CHECK_STATES((&g_States,
21.701 + new State_ObjCCtor_Called(3),
21.702 +
21.703 + new State_ObjCCtor_Called(3),
21.704 + new State_Deleg_11(1, pTest11, 0, ParamState_m11 (obj3, obj600)),
21.705 + new State_ObjODtor_Called(3),
21.706 +
21.707 + new State_ObjCCtor_Called(3),
21.708 + new State_Deleg_11(2, pTest11, 1, ParamState_m11 (obj3, obj600)),
21.709 + new State_ObjODtor_Called(3),
21.710 +
21.711 + new State_ObjCCtor_Called(3),
21.712 + new State_Deleg_11(3, pTest11, 2, ParamState_m11 (obj3, obj600)),
21.713 + new State_ObjODtor_Called(3),
21.714 +
21.715 + new State_ObjCCtor_Called(3),
21.716 + new State_Deleg_11(4, pTest11, 3, ParamState_m11 (obj3, obj600)),
21.717 + new State_ObjODtor_Called(3),
21.718 +
21.719 + new State_ObjODtor_Called(3),
21.720 + NULL), "Test" "11" " Part3");
21.721 + g_Inside_LeafFunc = false;
21.722 +
21.723 + /* hook1 - hook3, hook4 WITH RECALLS */
21.724 + THGM_REMOVE_HOOK(11, 2);
21.725 + PtrBuf_Clear();
21.726 + TestClass11::ms_DoRecall = true;
21.727 + pTest11->Func(obj3, obj600);
21.728 + g_Inside_LeafFunc = true;
21.729 + CHECK_STATES((&g_States,
21.730 + new State_ObjCCtor_Called(3),
21.731 +
21.732 + new State_ObjCCtor_Called(3),
21.733 + new State_Deleg_11(1, pTest11, 0 /* first deleg ptr */, ParamState_m11 (obj3, obj600)),
21.734 +
21.735 + // recall !
21.736 + // second hookfunc -> new copy
21.737 + new State_ObjCCtor_Called(3),
21.738 +
21.739 + // in second hookfunc now
21.740 + // -> calls orig func
21.741 +
21.742 + new State_ObjCCtor_Called(3),
21.743 + new State_Func11(pTest11, ParamState_m11 (obj3, obj600)(1)),
21.744 + new State_ObjODtor_Called(3),
21.745 +
21.746 + // calls first posthook
21.747 + new State_ObjCCtor_Called(3),
21.748 + new State_Deleg_11(3, pTest11, 1 /* second deleg ptr */, ParamState_m11 (obj3, obj600)(1)),
21.749 +
21.750 + // recall!
21.751 + // third hookfunc -> new copy
21.752 + new State_ObjCCtor_Called(3),
21.753 +
21.754 + // calls second posthook
21.755 +
21.756 + new State_ObjCCtor_Called(3),
21.757 + new State_Deleg_11(4, pTest11, 2 /* third deleg ptr */, ParamState_m11 (obj3, obj600)(2)),
21.758 +
21.759 + // recall!
21.760 + // fourth hookfunc -> new copy
21.761 + new State_ObjCCtor_Called(3),
21.762 +
21.763 + // has nothing to do though!
21.764 +
21.765 + // fourth hookfunc done -> ret
21.766 + new State_ObjODtor_Called(3),
21.767 +
21.768 + // third hookfunc done -> ret
21.769 + new State_ObjODtor_Called(3),
21.770 + // ret from hookhandler which did the recall
21.771 + new State_ObjODtor_Called(3),
21.772 +
21.773 + // second hookfunc done -> ret
21.774 + new State_ObjODtor_Called(3),
21.775 + // ret from hookhandler which did the recall
21.776 + new State_ObjODtor_Called(3),
21.777 +
21.778 + // deleg1's instance
21.779 + new State_ObjODtor_Called(3),
21.780 + // first hookfunc done -> ret
21.781 + new State_ObjODtor_Called(3),
21.782 + NULL), "Test" "11" " Part4");
21.783 + g_Inside_LeafFunc = false;
21.784 +
21.785 + THGM_REMOVE_HOOK(11, 1);
21.786 + THGM_REMOVE_HOOK(11, 3);
21.787 + THGM_REMOVE_HOOK(11, 4);
21.788 +
21.789 + delete obj3_real;
21.790 + delete obj600_real;
21.791 +
21.792 + CHECK_STATES((&g_States,
21.793 + new State_ObjODtor_Called(3),
21.794 + new State_ObjODtor_Called(600),
21.795 + NULL), "Test11 Part100");
21.796 +
21.797 + return true;
21.798 + }
21.799 +
21.800 + bool Tests3(std::string &error)
21.801 + {
21.802 + THGM_DO_TEST(101, ());
21.803 +
21.804 + THGM_DO_TEST(102, ());
21.805 +
21.806 + THGM_DO_TEST(103, ());
21.807 +
21.808 + THGM_DO_TEST(104, ());
21.809 +
21.810 + THGM_DO_TEST(105, ());
21.811 +
21.812 + // pod returns
21.813 + THGM_DO_TEST(106, (5));
21.814 + THGM_DO_TEST(107, (5));
21.815 + THGM_DO_TEST(108, (5));
21.816 + THGM_DO_TEST(109, (5));
21.817 +
21.818 + return true;
21.819 + }
21.820 +
21.821 + bool Tests4(std::string &error)
21.822 + {
21.823 + // Test110: Special: constructors/destructors on return
21.824 + PtrBuf_Clear();
21.825 + ObjRet13 *obj13_real = new ObjRet13;
21.826 + ObjRet13 &obj13 = *obj13_real;
21.827 +
21.828 + CHECK_STATES((&g_States,
21.829 + new State_ObjOCtor_Called(13),
21.830 + NULL), "Test110 Part0");
21.831 +
21.832 + setuppi_110();
21.833 + setupri_110();
21.834 +
21.835 + SourceHook::HookManagerPubFunc myhookman110 = g_HMAGPtr->MakeHookMan(protoinfo_110, 0, 0); \
21.836 + CAutoReleaseHookMan arhm_110(myhookman110); \
21.837 + int hook1_110, hook2_110, hook3_110, hook4_110;
21.838 +
21.839 + TestClass110 *pTest110 = new TestClass110;
21.840 + CAutoPtrDestruction<TestClass110> apd110(pTest110);
21.841 +
21.842 + /* no hooks - no hooks */
21.843 + PtrBuf_Clear();
21.844 + obj13 = pTest110->Func(5);
21.845 +
21.846 + g_Inside_LeafFunc = true;
21.847 + CHECK_STATES((&g_States,
21.848 + new State_Func110(pTest110, ParamState_m110 (5)),
21.849 + new State_ObjOCtor_Called(13), // MakeRet: Construction of x
21.850 + new State_ObjCCtor_Called(13), // Return from MakeRet -> construct temporary object in our stack
21.851 + new State_ObjODtor_Called(13), // MakeRet: Destruction of x
21.852 +
21.853 + new State_ObjAssignOp_Called(13), // assign: obj13 = temporary object in our stack
21.854 + new State_ObjODtor_Called(13), // Func110: destruction of temporary object
21.855 + NULL), "Test" "110" " Part1");
21.856 + g_Inside_LeafFunc = false;
21.857 +
21.858 + /* hook1 - no hooks */
21.859 + THGM_ADD_HOOK(110, 1);
21.860 +
21.861 + PtrBuf_Clear();
21.862 + obj13 = pTest110->Func(5);
21.863 + g_Inside_LeafFunc = true;
21.864 + CHECK_STATES((&g_States,
21.865 + // HookFunc: construct orig_ret/override_ret/plugin_ret objects
21.866 + new State_ObjOCtor_Called(13),
21.867 + new State_ObjOCtor_Called(13),
21.868 + new State_ObjOCtor_Called(13),
21.869 +
21.870 + // Calling delegate
21.871 + new State_Deleg_110(1, pTest110, 0, ParamState_m110 (5)),
21.872 +
21.873 + new State_ObjOCtor_Called(13), // MakeRet: Construction of x
21.874 + new State_ObjCCtor_Called(13), // Return from MakeRet -> construct temporary object in HookFunc's stack
21.875 + new State_ObjODtor_Called(13), // MakeRet: Destruction of x
21.876 +
21.877 + // back in hookfunc
21.878 + new State_ObjAssignOp_Called(13), // assign: plugin_ret = temporary object in HookFunc's stack
21.879 + new State_ObjODtor_Called(13), // destruction of temporary object in HookFunc's stack
21.880 +
21.881 + // Calling orig function Func110
21.882 + new State_Func110(pTest110, ParamState_m110 (5)),
21.883 + new State_ObjOCtor_Called(13), // MakeRet: Construction of x
21.884 + new State_ObjCCtor_Called(13), // Return from MakeRet -> construct temporary object in HookFunc's stack
21.885 + new State_ObjODtor_Called(13), // MakeRet: Destruction of x
21.886 +
21.887 + // back in hookfunc
21.888 + new State_ObjAssignOp_Called(13), // assign: orig_ret = temporary object in HookFunc's stack
21.889 + new State_ObjODtor_Called(13), // destruction of temporary object in HookFunc's stack
21.890 +
21.891 + // hookfunc is returning:
21.892 + new State_ObjCCtor_Called(13), // copy to temp object in our stack
21.893 +
21.894 + // hookfunc cleans up its stack -> destroys plugin_ret/override_ret/orig_ret
21.895 + new State_ObjODtor_Called(13),
21.896 + new State_ObjODtor_Called(13),
21.897 + new State_ObjODtor_Called(13),
21.898 +
21.899 + // we are in our function: assign
21.900 + new State_ObjAssignOp_Called(13), // assign: obj13 = temporary object in our stack
21.901 + new State_ObjODtor_Called(13), // Func110: destruction of temporary object
21.902 +
21.903 + NULL), "Test" "11" " Part2");
21.904 +
21.905 + CHECK_COND(obj13 == 0, "Test" "11" " Part 2.1");
21.906 + g_Inside_LeafFunc = false;
21.907 +
21.908 + THGM_REMOVE_HOOK(110, 1);
21.909 +
21.910 + /* hook1, hook2 - hook3, hook4 */
21.911 + THGM_ADD_HOOK(110, 1);
21.912 + THGM_ADD_HOOK(110, 2);
21.913 + THGM_ADD_HOOK(110, 3);
21.914 + THGM_ADD_HOOK(110, 4);
21.915 +
21.916 + PtrBuf_Clear();
21.917 + obj13 = pTest110->Func(5);
21.918 + g_Inside_LeafFunc = true;
21.919 + CHECK_STATES((&g_States,
21.920 + // HookFunc: construct orig_ret/override_ret/plugin_ret objects
21.921 + new State_ObjOCtor_Called(13),
21.922 + new State_ObjOCtor_Called(13),
21.923 + new State_ObjOCtor_Called(13),
21.924 +
21.925 + // Calling delegate1
21.926 + new State_Deleg_110(1, pTest110, 0, ParamState_m110 (5)),
21.927 +
21.928 + new State_ObjOCtor_Called(13), // MakeRet: Construction of x
21.929 + new State_ObjCCtor_Called(13), // Return from MakeRet -> construct temporary object in HookFunc's stack
21.930 + new State_ObjODtor_Called(13), // MakeRet: Destruction of x
21.931 +
21.932 + // back in hookfunc
21.933 + new State_ObjAssignOp_Called(13), // assign: plugin_ret = temporary object in HookFunc's stack
21.934 + new State_ObjODtor_Called(13), // destruction of temporary object in HookFunc's stack
21.935 +
21.936 +
21.937 + // Calling delegate2
21.938 + new State_Deleg_110(2, pTest110, 1, ParamState_m110 (5)),
21.939 +
21.940 + new State_ObjOCtor_Called(13), // MakeRet: Construction of x
21.941 + new State_ObjCCtor_Called(13), // Return from MakeRet -> construct temporary object in HookFunc's stack
21.942 + new State_ObjODtor_Called(13), // MakeRet: Destruction of x
21.943 +
21.944 + // back in hookfunc
21.945 + new State_ObjAssignOp_Called(13), // assign: plugin_ret = temporary object in HookFunc's stack
21.946 + new State_ObjODtor_Called(13), // destruction of temporary object in HookFunc's stack
21.947 +
21.948 + // hookfunc finds out that the hook wanted to SUPERCEDE --> copy to override_Ret
21.949 + new State_ObjAssignOp_Called(13),
21.950 +
21.951 + // SUPERCEDE -> orig function is not called
21.952 + // instead: orig_ret = override_ret
21.953 + new State_ObjAssignOp_Called(13),
21.954 +
21.955 + // Calling delegate3
21.956 + new State_Deleg_110(3, pTest110, 2, ParamState_m110 (5)),
21.957 +
21.958 + new State_ObjOCtor_Called(13), // MakeRet: Construction of x
21.959 + new State_ObjCCtor_Called(13), // Return from MakeRet -> construct temporary object in HookFunc's stack
21.960 + new State_ObjODtor_Called(13), // MakeRet: Destruction of x
21.961 +
21.962 + // back in hookfunc
21.963 + new State_ObjAssignOp_Called(13), // assign: plugin_ret = temporary object in HookFunc's stack
21.964 + new State_ObjODtor_Called(13), // destruction of temporary object in HookFunc's stack
21.965 +
21.966 + // Calling delegate4
21.967 + new State_Deleg_110(4, pTest110, 3, ParamState_m110 (5)),
21.968 +
21.969 + new State_ObjOCtor_Called(13), // MakeRet: Construction of x
21.970 + new State_ObjCCtor_Called(13), // Return from MakeRet -> construct temporary object in HookFunc's stack
21.971 + new State_ObjODtor_Called(13), // MakeRet: Destruction of x
21.972 +
21.973 + // back in hookfunc
21.974 + new State_ObjAssignOp_Called(13), // assign: plugin_ret = temporary object in HookFunc's stack
21.975 + new State_ObjODtor_Called(13), // destruction of temporary object in HookFunc's stack
21.976 +
21.977 + // hookfunc finds out that the hook wanted to SUPERCEDE --> copy to override_Ret (yes really, we overwrite the old value!)
21.978 + new State_ObjAssignOp_Called(13),
21.979 +
21.980 + // hookfunc is returning:
21.981 + new State_ObjCCtor_Called(13), // copy to temp object in our stack
21.982 +
21.983 + // hookfunc cleans up its stack -> destroys plugin_ret/override_ret/orig_ret
21.984 + new State_ObjODtor_Called(13),
21.985 + new State_ObjODtor_Called(13),
21.986 + new State_ObjODtor_Called(13),
21.987 +
21.988 + // we are in our function: assign
21.989 + new State_ObjAssignOp_Called(13), // assign: obj13 = temporary object in our stack
21.990 + new State_ObjODtor_Called(13), // Func110: destruction of temporary object
21.991 +
21.992 + NULL), "Test" "11" " Part3");
21.993 +
21.994 + CHECK_COND(obj13 == 4, "Test" "11" " Part 3.1");
21.995 + g_Inside_LeafFunc = false;
21.996 +
21.997 + THGM_REMOVE_HOOK(110, 1);
21.998 + THGM_REMOVE_HOOK(110, 2);
21.999 + THGM_REMOVE_HOOK(110, 3);
21.1000 + THGM_REMOVE_HOOK(110, 4);
21.1001 +
21.1002 + delete obj13_real;
21.1003 +
21.1004 + CHECK_STATES((&g_States,
21.1005 + new State_ObjODtor_Called(13),
21.1006 + NULL), "Test110 Part100");
21.1007 +
21.1008 +
21.1009 + THGM_DO_TEST_void(150, (5, 5.5, 6));
21.1010 +
21.1011 + return true;
21.1012 + }
21.1013 +
21.1014 + bool Tests5(std::string &error)
21.1015 + {
21.1016 + // RefRet
21.1017 + THGM_DO_TEST(111, ());
21.1018 +
21.1019 + // Vafmt
21.1020 +
21.1021 + THGM_DO_TEST_void(200, ("Hello %s%d%s", "BA", 1, "L!"));
21.1022 +
21.1023 + THGM_DO_TEST_void(201, (100, "Hello %s%d%s", "BA", 1, "L!"));
21.1024 +
21.1025 + THGM_DO_TEST_void(203, (0x1F000000, "Hello %s%d%s", "BA", 1, "L!"));
21.1026 +
21.1027 + THGM_DO_TEST_void(206, (100, 0x1f00, 0x1f000000, 0.5f, 5.5, "Hello %s%d%s", "BA", 1, "L!"));
21.1028 +
21.1029 + char a = 5;
21.1030 + double b = 233.33;
21.1031 + THGM_DO_TEST_void(207, (a, b, "Hello %s%d%s", "BA", 1, "L!"));
21.1032 +
21.1033 + POD<7> pod7 = MakeRet< POD<7> >::Do(78);
21.1034 + THGM_DO_TEST_void(208, (pod7, "Hello %s%d%s", "BA", 1, "L!"));
21.1035 +
21.1036 + POD<600> pod600 = MakeRet< POD<600> >::Do(34);
21.1037 + THGM_DO_TEST_void(210, (pod600, "Hello %s%d%s", "BA", 1, "L!"));
21.1038 +
21.1039 +
21.1040 + THGM_DO_TEST(211, (5, "Hello %s%d%s", "BA", 1, "L!"));
21.1041 + THGM_DO_TEST(212, (5, "Hello %s%d%s", "BA", 1, "L!"));
21.1042 + THGM_DO_TEST(213, (5, "Hello %s%d%s", "BA", 1, "L!"));
21.1043 +
21.1044 + // Silence Object's ctors/dtors: we only want a forced byref param
21.1045 + g_Silent_CtorDtor = true;
21.1046 + Object<133> *myobj133 = new Object<133>;
21.1047 + THGM_DO_TEST_void(214, (*myobj133, "Hello %s%d%s", "BA", 1, "L!"));
21.1048 + delete myobj133;
21.1049 + g_Silent_CtorDtor = false;
21.1050 +
21.1051 + // Test for high vtable indices
21.1052 + Hello *pHello = new Hello;
21.1053 + SourceHook::CProtoInfoBuilder helloPi(SourceHook::ProtoInfo::CallConv_ThisCall);
21.1054 + SourceHook::HookManagerPubFunc helloHM_4 = g_HMAGPtr->MakeHookMan(helloPi, 0, 4);
21.1055 + SourceHook::HookManagerPubFunc helloHM_79 = g_HMAGPtr->MakeHookMan(helloPi, 0, 79);
21.1056 +
21.1057 + pHello->Func4();
21.1058 + pHello->Func79();
21.1059 + SH_CALL(pHello, &Hello::Func4)();
21.1060 + SH_CALL(pHello, &Hello::Func79)();
21.1061 + CHECK_STATES((&g_States,
21.1062 + new State_Hello_Func4_Called,
21.1063 + new State_Hello_Func79_Called,
21.1064 + new State_Hello_Func4_Called,
21.1065 + new State_Hello_Func79_Called,
21.1066 + NULL), "Test" "Hello" " Part1");
21.1067 +
21.1068 + int helloHook4 = g_SHPtr->AddHook(g_PLID, SourceHook::ISourceHook::Hook_Normal, reinterpret_cast<void*>(pHello),
21.1069 + 0, helloHM_4, new Hello_Func4_Deleg, false);
21.1070 +
21.1071 + int helloHook79 = g_SHPtr->AddHook(g_PLID, SourceHook::ISourceHook::Hook_Normal, reinterpret_cast<void*>(pHello),
21.1072 + 0, helloHM_79, new Hello_Func79_Deleg, false);
21.1073 +
21.1074 + pHello->Func4();
21.1075 + pHello->Func79();
21.1076 + SH_CALL(pHello, &Hello::Func4)();
21.1077 + SH_CALL(pHello, &Hello::Func79)();
21.1078 +
21.1079 + CHECK_STATES((&g_States,
21.1080 + new State_Hello_Func4_PreHook,
21.1081 + new State_Hello_Func4_Called,
21.1082 + new State_Hello_Func79_PreHook,
21.1083 + new State_Hello_Func79_Called,
21.1084 + new State_Hello_Func4_Called,
21.1085 + new State_Hello_Func79_Called,
21.1086 + NULL), "Test" "Hello" " Part2");
21.1087 +
21.1088 + g_SHPtr->RemoveHookByID(helloHook4);
21.1089 + g_SHPtr->RemoveHookByID(helloHook79);
21.1090 +
21.1091 + g_HMAGPtr->ReleaseHookMan(helloHM_4);
21.1092 + g_HMAGPtr->ReleaseHookMan(helloHM_79);
21.1093 +
21.1094 + return true;
21.1095 + }
21.1096 +}
21.1097 +
21.1098 +
21.1099 +bool TestHookManGen(std::string &error)
21.1100 +{
21.1101 + GET_SHPTR(g_SHPtr);
21.1102 + GET_HMAG(g_HMAGPtr, g_SHPtr);
21.1103 + g_PLID = 1337;
21.1104 +
21.1105 + // 5 Global constructors (g_O111_*)
21.1106 + CHECK_STATES((&g_States,
21.1107 + new State_ObjOCtor_Called(111),
21.1108 + new State_ObjOCtor_Called(111),
21.1109 + new State_ObjOCtor_Called(111),
21.1110 + new State_ObjOCtor_Called(111),
21.1111 + new State_ObjOCtor_Called(111),
21.1112 + NULL), "GlobCtors");
21.1113 +
21.1114 + if (!Tests1(error))
21.1115 + return false;
21.1116 + if (!Tests2(error))
21.1117 + return false;
21.1118 + if (!Tests3(error))
21.1119 + return false;
21.1120 + if (!Tests4(error))
21.1121 + return false;
21.1122 + if (!Tests5(error))
21.1123 + return false;
21.1124 +
21.1125 + // Shutdown now!
21.1126 + // If we don't SH will auto-shutdown _after_ genc's destructor is called
21.1127 + // -> crash
21.1128 +
21.1129 + Test_CompleteShutdown(g_SHPtr);
21.1130 +
21.1131 + CHECK_COND(sizeof(PodRet1) == 1, "WTF!");
21.1132 + CHECK_COND(sizeof(PodRet4) == 4, "WTF!");
21.1133 + CHECK_COND(sizeof(PodRet8) == 8, "WTF!");
21.1134 + CHECK_COND(sizeof(PodRet13) == 13, "WTF!");
21.1135 +
21.1136 + return true;
21.1137 +}
21.1138 +
21.1139 +bool TestCPageAlloc(std::string &error)
21.1140 +{
21.1141 + using namespace SourceHook;
21.1142 +
21.1143 + CPageAlloc alloc;
21.1144 + int i;
21.1145 + size_t ps = alloc.GetPageSize();
21.1146 +
21.1147 + char *test1[8];
21.1148 +
21.1149 + for (i = 0; i < 8; ++i)
21.1150 + test1[i] = (char*) alloc.Alloc(ps / 4);
21.1151 +
21.1152 + CHECK_COND(test1[1] == test1[0] + ps/4, "Part 1.1");
21.1153 + CHECK_COND(test1[2] == test1[1] + ps/4, "Part 1.2");
21.1154 + CHECK_COND(test1[3] == test1[2] + ps/4, "Part 1.3");
21.1155 +
21.1156 + CHECK_COND(test1[5] == test1[4] + ps/4, "Part 1.4");
21.1157 + CHECK_COND(test1[6] == test1[5] + ps/4, "Part 1.5");
21.1158 + CHECK_COND(test1[7] == test1[6] + ps/4, "Part 1.6");
21.1159 +
21.1160 + void *test2 = alloc.Alloc(ps * 3);
21.1161 +
21.1162 + alloc.SetRW(test2);
21.1163 + memset(test2, 0, ps * 3); // should not crash :)
21.1164 + alloc.SetRE(test2);
21.1165 +
21.1166 + alloc.Free(test2);
21.1167 +
21.1168 + // Dealloc a ps/4 block and place two ps/8 blocks into it
21.1169 + alloc.Free(test1[2]);
21.1170 +
21.1171 + char *test3[2];
21.1172 + test3[0] = (char*) alloc.Alloc(ps / 8);
21.1173 + test3[1] = (char*) alloc.Alloc(ps / 8);
21.1174 +
21.1175 + CHECK_COND(test3[0] == test1[2], "Part 2.1");
21.1176 + CHECK_COND(test3[1] == test1[2] + ps/8, "Part 2.2");
21.1177 +
21.1178 + // Isolated
21.1179 + char *test4[8];
21.1180 + for (i = 0; i < 8; ++i)
21.1181 + test4[i] = (char*) alloc.AllocIsolated(ps / 4);
21.1182 +
21.1183 + // -> The difference is at least one page
21.1184 + CHECK_COND(static_cast<size_t>(abs(test4[1] - test4[0])) >= ps, "Part 3.1");
21.1185 + CHECK_COND(static_cast<size_t>(abs(test4[2] - test4[1])) >= ps, "Part 3.2");
21.1186 + CHECK_COND(static_cast<size_t>(abs(test4[3] - test4[2])) >= ps, "Part 3.3");
21.1187 +
21.1188 + CHECK_COND(static_cast<size_t>(abs(test4[5] - test4[4])) >= ps, "Part 3.4");
21.1189 + CHECK_COND(static_cast<size_t>(abs(test4[6] - test4[5])) >= ps, "Part 3.5");
21.1190 + CHECK_COND(static_cast<size_t>(abs(test4[7] - test4[6])) >= ps, "Part 3.6");
21.1191 +
21.1192 + // Thus i can set everything except for test4[2] to RE and still write to test4[2]
21.1193 +
21.1194 + alloc.SetRW(test4[2]);
21.1195 +
21.1196 + alloc.SetRE(test4[0]);
21.1197 + alloc.SetRE(test4[1]);
21.1198 + alloc.SetRE(test4[3]);
21.1199 + alloc.SetRE(test4[4]);
21.1200 + alloc.SetRE(test4[5]);
21.1201 + alloc.SetRE(test4[6]);
21.1202 + alloc.SetRE(test4[7]);
21.1203 +
21.1204 + memset((void*)test4[2], 0, ps / 4);
21.1205 +
21.1206 + // alignement tests
21.1207 + CPageAlloc alloc1(1);
21.1208 + CPageAlloc alloc4(4);
21.1209 + CPageAlloc alloc16(16);
21.1210 +
21.1211 + void *last1 = alloc1.Alloc(1);
21.1212 + void *last4 = alloc4.Alloc(4);
21.1213 + void *last16 = alloc16.Alloc(16);
21.1214 + void *cur;
21.1215 + for (int i = 0; i < 20; ++i)
21.1216 + {
21.1217 + cur = alloc1.Alloc(1);
21.1218 + CHECK_COND(reinterpret_cast<intptr_t>(cur) == reinterpret_cast<intptr_t>(last1) + 1, "Part 4.1");
21.1219 + last1 = cur;
21.1220 +
21.1221 + cur = alloc4.Alloc(1);
21.1222 + CHECK_COND(reinterpret_cast<intptr_t>(cur) == reinterpret_cast<intptr_t>(last4) + 4, "Part 4.2");
21.1223 + last4 = cur;
21.1224 +
21.1225 + cur = alloc16.Alloc(1);
21.1226 + CHECK_COND(reinterpret_cast<intptr_t>(cur) == reinterpret_cast<intptr_t>(last16) + 16, "Part 4.3");
21.1227 + last16 = cur;
21.1228 + }
21.1229 +
21.1230 + alloc16.Free(alloc16.Alloc(1));
21.1231 + return true;
21.1232 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
22.2 +++ b/sourcehook/test/testhookmangen.h Mon Nov 26 14:03:25 2007 +0000
22.3 @@ -0,0 +1,2192 @@
22.4 +struct CAutoReleaseHookMan
22.5 +{
22.6 + SourceHook::HookManagerPubFunc m_Ptr;
22.7 + CAutoReleaseHookMan(SourceHook::HookManagerPubFunc ptr) : m_Ptr(ptr)
22.8 + {
22.9 + }
22.10 + ~CAutoReleaseHookMan()
22.11 + {
22.12 + g_HMAGPtr->ReleaseHookMan(m_Ptr);
22.13 + }
22.14 +};
22.15 +
22.16 +// Strip &
22.17 +template <class T> struct StripRef
22.18 +{
22.19 + typedef T type;
22.20 +};
22.21 +
22.22 +template <class T> struct StripRef<T&>
22.23 +{
22.24 + typedef T type;
22.25 +};
22.26 +
22.27 +// Address of constructor/destructor
22.28 +// (using wrappers)
22.29 +template <class T>
22.30 +class Ctor_Thunk
22.31 +{
22.32 +public:
22.33 + void NormalConstructor()
22.34 + {
22.35 + new(this) T;
22.36 + }
22.37 +
22.38 + void CopyConstructor(const T &other)
22.39 + {
22.40 + new(this) T(other);
22.41 + }
22.42 +
22.43 + void Destructor()
22.44 + {
22.45 + reinterpret_cast<T*>(this)->~T();
22.46 + }
22.47 +
22.48 + const T& AssignOp(const T &other)
22.49 + {
22.50 + return (*reinterpret_cast<T*>(this) = other);
22.51 + }
22.52 +};
22.53 +
22.54 +
22.55 +template <class T>
22.56 +void *FindFuncAddr(T mfp)
22.57 +{
22.58 + union
22.59 + {
22.60 + T a;
22.61 + void *b;
22.62 + } u;
22.63 + u.a = mfp;
22.64 + return u.b;
22.65 +}
22.66 +
22.67 +// Reference carrier
22.68 +template <class T> struct MyRefCarrier
22.69 +{
22.70 + typedef T type;
22.71 +};
22.72 +
22.73 +template <class T> struct MyRefCarrier<T&>
22.74 +{
22.75 + class type
22.76 + {
22.77 + T *m_StoredRef;
22.78 + public:
22.79 + type() : m_StoredRef(NULL)
22.80 + {
22.81 + }
22.82 + type(T& ref) : m_StoredRef(&ref)
22.83 + {
22.84 + }
22.85 +
22.86 + T& operator= (T& ref)
22.87 + {
22.88 + m_StoredRef = &ref;
22.89 + return ref;
22.90 + }
22.91 +
22.92 + operator T& () const
22.93 + {
22.94 + return *m_StoredRef;
22.95 + }
22.96 +
22.97 + bool operator== (const typename MyRefCarrier<T&>::type &other)
22.98 + {
22.99 + return m_StoredRef == other.m_StoredRef;
22.100 + }
22.101 +
22.102 + friend std::ostream& operator <<(std::ostream &os,const typename MyRefCarrier<T&>::type &obj)
22.103 + {
22.104 + os << *obj.m_StoredRef;
22.105 + return os;
22.106 + }
22.107 + };
22.108 +};
22.109 +
22.110 +#if SH_COMP==SH_COMP_GCC
22.111 +#define NO_OPTIMIZE __attribute__((noinline))
22.112 +#else
22.113 +#define NO_OPTIMIZE
22.114 +#endif
22.115 +
22.116 +// Return value maker
22.117 +template <class T>
22.118 +struct MakeRet
22.119 +{
22.120 + static T Do(int a)
22.121 + {
22.122 + return a;
22.123 + }
22.124 +};
22.125 +
22.126 +template <int SIZE>
22.127 +struct MakeRet< POD<SIZE> >
22.128 +{
22.129 + static POD<SIZE> Do(int a)
22.130 + {
22.131 + POD<SIZE> x;
22.132 + memset(reinterpret_cast<void*>(x.x), a, SIZE);
22.133 + return x;
22.134 + }
22.135 +};
22.136 +
22.137 +// Stores parameter status
22.138 +template <class T>
22.139 +bool EqualToMyFmtString(T sth)
22.140 +{
22.141 + return false;
22.142 +}
22.143 +
22.144 +bool EqualToMyFmtString(std::string &sth)
22.145 +{
22.146 + if (sth == "Hello %s%d%s")
22.147 + sth = "Hello BA1L!";
22.148 + return true;
22.149 +}
22.150 +
22.151 +
22.152 +
22.153 +
22.154 +template<int dummy>
22.155 +struct ParamState0
22.156 +{
22.157 +
22.158 +
22.159 + bool operator==(const ParamState0<dummy> &other)
22.160 + {
22.161 + return true
22.162 +
22.163 + ;
22.164 + }
22.165 + ParamState0(...)
22.166 + {
22.167 +
22.168 + }
22.169 +
22.170 + ParamState0<dummy> & operator() (int incrsteps)
22.171 + {
22.172 +
22.173 +
22.174 +
22.175 + return *this;
22.176 + }
22.177 +};
22.178 +
22.179 +
22.180 +std::ostream& operator <<(std::ostream &os,const ParamState0<0> &obj)
22.181 +{
22.182 + ;
22.183 + return os;
22.184 +}
22.185 +
22.186 +
22.187 +
22.188 +template<int dummy, class p1>
22.189 +struct ParamState1
22.190 +{
22.191 + typename MyRefCarrier<p1>::type m_1;
22.192 +
22.193 + bool operator==(const ParamState1<dummy, p1> &other)
22.194 + {
22.195 + return true
22.196 + && m_1 == other.m_1
22.197 + ;
22.198 + }
22.199 + ParamState1(p1 a1, ...) : m_1(a1)
22.200 + {
22.201 +
22.202 + EqualToMyFmtString(m_1);
22.203 +
22.204 + }
22.205 +
22.206 + ParamState1<dummy, p1> & operator() (int incrsteps)
22.207 + {
22.208 + int i;
22.209 +
22.210 + for (i = 0; i < incrsteps; ++i)
22.211 + Increment<typename StripRef< p1 >::type >::Incr(m_1);
22.212 +
22.213 +
22.214 + return *this;
22.215 + }
22.216 +};
22.217 +
22.218 +template<class p1>
22.219 +std::ostream& operator <<(std::ostream &os,const ParamState1<0, p1> &obj)
22.220 +{
22.221 + os << obj.m_1;
22.222 + return os;
22.223 +}
22.224 +
22.225 +
22.226 +
22.227 +template<int dummy, class p1, class p2>
22.228 +struct ParamState2
22.229 +{
22.230 + typename MyRefCarrier<p1>::type m_1; typename MyRefCarrier<p2>::type m_2;
22.231 +
22.232 + bool operator==(const ParamState2<dummy, p1, p2> &other)
22.233 + {
22.234 + return true
22.235 + && m_2 == other.m_2 && m_2 == other.m_2
22.236 + ;
22.237 + }
22.238 + ParamState2(p1 a1, p2 a2, ...) : m_1(a1), m_2(a2)
22.239 + {
22.240 +
22.241 + EqualToMyFmtString(m_1);
22.242 +
22.243 + EqualToMyFmtString(m_2);
22.244 +
22.245 + }
22.246 +
22.247 + ParamState2<dummy, p1, p2> & operator() (int incrsteps)
22.248 + {
22.249 + int i;
22.250 +
22.251 + for (i = 0; i < incrsteps; ++i)
22.252 + Increment<typename StripRef< p1 >::type >::Incr(m_1);
22.253 +
22.254 + for (i = 0; i < incrsteps; ++i)
22.255 + Increment<typename StripRef< p2 >::type >::Incr(m_2);
22.256 +
22.257 +
22.258 + return *this;
22.259 + }
22.260 +};
22.261 +
22.262 +template<class p1, class p2>
22.263 +std::ostream& operator <<(std::ostream &os,const ParamState2<0, p1, p2> &obj)
22.264 +{
22.265 + os << obj.m_1<< obj.m_2;
22.266 + return os;
22.267 +}
22.268 +
22.269 +
22.270 +
22.271 +template<int dummy, class p1, class p2, class p3>
22.272 +struct ParamState3
22.273 +{
22.274 + typename MyRefCarrier<p1>::type m_1; typename MyRefCarrier<p2>::type m_2; typename MyRefCarrier<p3>::type m_3;
22.275 +
22.276 + bool operator==(const ParamState3<dummy, p1, p2, p3> &other)
22.277 + {
22.278 + return true
22.279 + && m_3 == other.m_3 && m_3 == other.m_3 && m_3 == other.m_3
22.280 + ;
22.281 + }
22.282 + ParamState3(p1 a1, p2 a2, p3 a3, ...) : m_1(a1), m_2(a2), m_3(a3)
22.283 + {
22.284 +
22.285 + EqualToMyFmtString(m_1);
22.286 +
22.287 + EqualToMyFmtString(m_2);
22.288 +
22.289 + EqualToMyFmtString(m_3);
22.290 +
22.291 + }
22.292 +
22.293 + ParamState3<dummy, p1, p2, p3> & operator() (int incrsteps)
22.294 + {
22.295 + int i;
22.296 +
22.297 + for (i = 0; i < incrsteps; ++i)
22.298 + Increment<typename StripRef< p1 >::type >::Incr(m_1);
22.299 +
22.300 + for (i = 0; i < incrsteps; ++i)
22.301 + Increment<typename StripRef< p2 >::type >::Incr(m_2);
22.302 +
22.303 + for (i = 0; i < incrsteps; ++i)
22.304 + Increment<typename StripRef< p3 >::type >::Incr(m_3);
22.305 +
22.306 +
22.307 + return *this;
22.308 + }
22.309 +};
22.310 +
22.311 +template<class p1, class p2, class p3>
22.312 +std::ostream& operator <<(std::ostream &os,const ParamState3<0, p1, p2, p3> &obj)
22.313 +{
22.314 + os << obj.m_1<< obj.m_2<< obj.m_3;
22.315 + return os;
22.316 +}
22.317 +
22.318 +
22.319 +
22.320 +template<int dummy, class p1, class p2, class p3, class p4>
22.321 +struct ParamState4
22.322 +{
22.323 + typename MyRefCarrier<p1>::type m_1; typename MyRefCarrier<p2>::type m_2; typename MyRefCarrier<p3>::type m_3; typename MyRefCarrier<p4>::type m_4;
22.324 +
22.325 + bool operator==(const ParamState4<dummy, p1, p2, p3, p4> &other)
22.326 + {
22.327 + return true
22.328 + && m_4 == other.m_4 && m_4 == other.m_4 && m_4 == other.m_4 && m_4 == other.m_4
22.329 + ;
22.330 + }
22.331 + ParamState4(p1 a1, p2 a2, p3 a3, p4 a4, ...) : m_1(a1), m_2(a2), m_3(a3), m_4(a4)
22.332 + {
22.333 +
22.334 + EqualToMyFmtString(m_1);
22.335 +
22.336 + EqualToMyFmtString(m_2);
22.337 +
22.338 + EqualToMyFmtString(m_3);
22.339 +
22.340 + EqualToMyFmtString(m_4);
22.341 +
22.342 + }
22.343 +
22.344 + ParamState4<dummy, p1, p2, p3, p4> & operator() (int incrsteps)
22.345 + {
22.346 + int i;
22.347 +
22.348 + for (i = 0; i < incrsteps; ++i)
22.349 + Increment<typename StripRef< p1 >::type >::Incr(m_1);
22.350 +
22.351 + for (i = 0; i < incrsteps; ++i)
22.352 + Increment<typename StripRef< p2 >::type >::Incr(m_2);
22.353 +
22.354 + for (i = 0; i < incrsteps; ++i)
22.355 + Increment<typename StripRef< p3 >::type >::Incr(m_3);
22.356 +
22.357 + for (i = 0; i < incrsteps; ++i)
22.358 + Increment<typename StripRef< p4 >::type >::Incr(m_4);
22.359 +
22.360 +
22.361 + return *this;
22.362 + }
22.363 +};
22.364 +
22.365 +template<class p1, class p2, class p3, class p4>
22.366 +std::ostream& operator <<(std::ostream &os,const ParamState4<0, p1, p2, p3, p4> &obj)
22.367 +{
22.368 + os << obj.m_1<< obj.m_2<< obj.m_3<< obj.m_4;
22.369 + return os;
22.370 +}
22.371 +
22.372 +
22.373 +
22.374 +template<int dummy, class p1, class p2, class p3, class p4, class p5>
22.375 +struct ParamState5
22.376 +{
22.377 + typename MyRefCarrier<p1>::type m_1; typename MyRefCarrier<p2>::type m_2; typename MyRefCarrier<p3>::type m_3; typename MyRefCarrier<p4>::type m_4; typename MyRefCarrier<p5>::type m_5;
22.378 +
22.379 + bool operator==(const ParamState5<dummy, p1, p2, p3, p4, p5> &other)
22.380 + {
22.381 + return true
22.382 + && m_5 == other.m_5 && m_5 == other.m_5 && m_5 == other.m_5 && m_5 == other.m_5 && m_5 == other.m_5
22.383 + ;
22.384 + }
22.385 + ParamState5(p1 a1, p2 a2, p3 a3, p4 a4, p5 a5, ...) : m_1(a1), m_2(a2), m_3(a3), m_4(a4), m_5(a5)
22.386 + {
22.387 +
22.388 + EqualToMyFmtString(m_1);
22.389 +
22.390 + EqualToMyFmtString(m_2);
22.391 +
22.392 + EqualToMyFmtString(m_3);
22.393 +
22.394 + EqualToMyFmtString(m_4);
22.395 +
22.396 + EqualToMyFmtString(m_5);
22.397 +
22.398 + }
22.399 +
22.400 + ParamState5<dummy, p1, p2, p3, p4, p5> & operator() (int incrsteps)
22.401 + {
22.402 + int i;
22.403 +
22.404 + for (i = 0; i < incrsteps; ++i)
22.405 + Increment<typename StripRef< p1 >::type >::Incr(m_1);
22.406 +
22.407 + for (i = 0; i < incrsteps; ++i)
22.408 + Increment<typename StripRef< p2 >::type >::Incr(m_2);
22.409 +
22.410 + for (i = 0; i < incrsteps; ++i)
22.411 + Increment<typename StripRef< p3 >::type >::Incr(m_3);
22.412 +
22.413 + for (i = 0; i < incrsteps; ++i)
22.414 + Increment<typename StripRef< p4 >::type >::Incr(m_4);
22.415 +
22.416 + for (i = 0; i < incrsteps; ++i)
22.417 + Increment<typename StripRef< p5 >::type >::Incr(m_5);
22.418 +
22.419 +
22.420 + return *this;
22.421 + }
22.422 +};
22.423 +
22.424 +template<class p1, class p2, class p3, class p4, class p5>
22.425 +std::ostream& operator <<(std::ostream &os,const ParamState5<0, p1, p2, p3, p4, p5> &obj)
22.426 +{
22.427 + os << obj.m_1<< obj.m_2<< obj.m_3<< obj.m_4<< obj.m_5;
22.428 + return os;
22.429 +}
22.430 +
22.431 +
22.432 +
22.433 +template<int dummy, class p1, class p2, class p3, class p4, class p5, class p6>
22.434 +struct ParamState6
22.435 +{
22.436 + typename MyRefCarrier<p1>::type m_1; typename MyRefCarrier<p2>::type m_2; typename MyRefCarrier<p3>::type m_3; typename MyRefCarrier<p4>::type m_4; typename MyRefCarrier<p5>::type m_5; typename MyRefCarrier<p6>::type m_6;
22.437 +
22.438 + bool operator==(const ParamState6<dummy, p1, p2, p3, p4, p5, p6> &other)
22.439 + {
22.440 + return true
22.441 + && m_6 == other.m_6 && m_6 == other.m_6 && m_6 == other.m_6 && m_6 == other.m_6 && m_6 == other.m_6 && m_6 == other.m_6
22.442 + ;
22.443 + }
22.444 + ParamState6(p1 a1, p2 a2, p3 a3, p4 a4, p5 a5, p6 a6, ...) : m_1(a1), m_2(a2), m_3(a3), m_4(a4), m_5(a5), m_6(a6)
22.445 + {
22.446 +
22.447 + EqualToMyFmtString(m_1);
22.448 +
22.449 + EqualToMyFmtString(m_2);
22.450 +
22.451 + EqualToMyFmtString(m_3);
22.452 +
22.453 + EqualToMyFmtString(m_4);
22.454 +
22.455 + EqualToMyFmtString(m_5);
22.456 +
22.457 + EqualToMyFmtString(m_6);
22.458 +
22.459 + }
22.460 +
22.461 + ParamState6<dummy, p1, p2, p3, p4, p5, p6> & operator() (int incrsteps)
22.462 + {
22.463 + int i;
22.464 +
22.465 + for (i = 0; i < incrsteps; ++i)
22.466 + Increment<typename StripRef< p1 >::type >::Incr(m_1);
22.467 +
22.468 + for (i = 0; i < incrsteps; ++i)
22.469 + Increment<typename StripRef< p2 >::type >::Incr(m_2);
22.470 +
22.471 + for (i = 0; i < incrsteps; ++i)
22.472 + Increment<typename StripRef< p3 >::type >::Incr(m_3);
22.473 +
22.474 + for (i = 0; i < incrsteps; ++i)
22.475 + Increment<typename StripRef< p4 >::type >::Incr(m_4);
22.476 +
22.477 + for (i = 0; i < incrsteps; ++i)
22.478 + Increment<typename StripRef< p5 >::type >::Incr(m_5);
22.479 +
22.480 + for (i = 0; i < incrsteps; ++i)
22.481 + Increment<typename StripRef< p6 >::type >::Incr(m_6);
22.482 +
22.483 +
22.484 + return *this;
22.485 + }
22.486 +};
22.487 +
22.488 +template<class p1, class p2, class p3, class p4, class p5, class p6>
22.489 +std::ostream& operator <<(std::ostream &os,const ParamState6<0, p1, p2, p3, p4, p5, p6> &obj)
22.490 +{
22.491 + os << obj.m_1<< obj.m_2<< obj.m_3<< obj.m_4<< obj.m_5<< obj.m_6;
22.492 + return os;
22.493 +}
22.494 +
22.495 +
22.496 +
22.497 +#define CAT2(a, b) a##b
22.498 +#define CAT3(a, b, c) a##b##c
22.499 +#define CAT4(a, b, c, d) a##b##c##d
22.500 +
22.501 +// hook1: pre ignore
22.502 +// hook2: pre supercede
22.503 +// hook3: post ignore
22.504 +// hook4: post supercede
22.505 +
22.506 +
22.507 +
22.508 +
22.509 +#define THGM_MAKE_TEST0_void(id) \
22.510 + struct TestClass##id; \
22.511 + typedef ParamState0<0 > ParamState_m##id; \
22.512 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.513 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.514 + \
22.515 + struct TestClass##id \
22.516 + { \
22.517 + static bool ms_DoRecall; \
22.518 + \
22.519 + virtual void Func() \
22.520 + { \
22.521 + g_Inside_LeafFunc = true; \
22.522 + ADD_STATE(State_Func##id(this, ParamState_m##id())); \
22.523 + g_Inside_LeafFunc = false; \
22.524 + } \
22.525 + \
22.526 + struct Delegate : public MyDelegate \
22.527 + { \
22.528 + int m_DelegNumber; \
22.529 + Delegate(int num) : m_DelegNumber(num) { } \
22.530 + \
22.531 + virtual void Call() \
22.532 + { \
22.533 + g_Inside_LeafFunc = true; \
22.534 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id())); \
22.535 + g_Inside_LeafFunc = false; \
22.536 + if (ms_DoRecall) \
22.537 + { \
22.538 + \
22.539 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, ()); \
22.540 + } \
22.541 + else \
22.542 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.543 + } \
22.544 + }; \
22.545 + }; \
22.546 + \
22.547 + bool TestClass##id::ms_DoRecall = false; \
22.548 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.549 +
22.550 +
22.551 +#define THGM_MAKE_TEST0(id, ret_type) \
22.552 + struct TestClass##id; \
22.553 + typedef ret_type RetType##id; \
22.554 + typedef ParamState0<0 > ParamState_m##id; \
22.555 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.556 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.557 + \
22.558 + struct TestClass##id \
22.559 + { \
22.560 + static bool ms_DoRecall; \
22.561 + \
22.562 + virtual ret_type Func() \
22.563 + { \
22.564 + g_Inside_LeafFunc = true; \
22.565 + ADD_STATE(State_Func##id(this, ParamState_m##id())); \
22.566 + g_Inside_LeafFunc = false; \
22.567 + \
22.568 + return MakeRet< ret_type >::Do(0); \
22.569 + } \
22.570 + \
22.571 + struct Delegate : public MyDelegate \
22.572 + { \
22.573 + int m_DelegNumber; \
22.574 + Delegate(int num) : m_DelegNumber(num) { } \
22.575 + \
22.576 + virtual ret_type Call() \
22.577 + { \
22.578 + g_Inside_LeafFunc = true; \
22.579 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id())); \
22.580 + g_Inside_LeafFunc = false; \
22.581 + if (ms_DoRecall) \
22.582 + { \
22.583 + \
22.584 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, ()); \
22.585 + } \
22.586 + else \
22.587 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.588 + } \
22.589 + }; \
22.590 + }; \
22.591 + \
22.592 + bool TestClass##id::ms_DoRecall = false; \
22.593 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.594 +
22.595 +#define THGM_MAKE_TEST0_vafmt_void(id) \
22.596 + struct TestClass##id; \
22.597 + typedef ParamState1<0, std::string > ParamState_m##id; \
22.598 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.599 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.600 + \
22.601 + struct TestClass##id \
22.602 + { \
22.603 + static bool ms_DoRecall; \
22.604 + \
22.605 + virtual void Func(const char *fmt, ...) \
22.606 + { \
22.607 + g_Inside_LeafFunc = true; \
22.608 + \
22.609 + char buf[9999]; \
22.610 + va_list ap; \
22.611 + va_start(ap, fmt); \
22.612 + vsnprintf(buf, 9998, fmt, ap); \
22.613 + buf[9998] = 0; \
22.614 + va_end(ap); \
22.615 + \
22.616 + ADD_STATE(State_Func##id(this, ParamState_m##id(std::string(buf)))); \
22.617 + g_Inside_LeafFunc = false; \
22.618 + } \
22.619 + \
22.620 + struct Delegate : public MyDelegate \
22.621 + { \
22.622 + int m_DelegNumber; \
22.623 + Delegate(int num) : m_DelegNumber(num) { } \
22.624 + \
22.625 + virtual void Call(const char *buf) \
22.626 + { \
22.627 + g_Inside_LeafFunc = true; \
22.628 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(buf))); \
22.629 + g_Inside_LeafFunc = false; \
22.630 + if (ms_DoRecall) \
22.631 + { \
22.632 + \
22.633 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, ("%s!", buf)); \
22.634 + } \
22.635 + else \
22.636 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.637 + } \
22.638 + }; \
22.639 + }; \
22.640 + \
22.641 + bool TestClass##id::ms_DoRecall = false; \
22.642 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.643 +
22.644 +#define THGM_MAKE_TEST0_vafmt(id, ret_type) \
22.645 + struct TestClass##id; \
22.646 + typedef ret_type RetType##id; \
22.647 + typedef ParamState1<0, std::string > ParamState_m##id; \
22.648 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.649 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.650 + \
22.651 + struct TestClass##id \
22.652 + { \
22.653 + static bool ms_DoRecall; \
22.654 + \
22.655 + virtual ret_type Func(const char *fmt, ...) \
22.656 + { \
22.657 + g_Inside_LeafFunc = true; \
22.658 + \
22.659 + char buf[9999]; \
22.660 + va_list ap; \
22.661 + va_start(ap, fmt); \
22.662 + vsnprintf(buf, 9998, fmt, ap); \
22.663 + buf[9998] = 0; \
22.664 + va_end(ap); \
22.665 + \
22.666 + ADD_STATE(State_Func##id(this, ParamState_m##id(std::string(buf)))); \
22.667 + \
22.668 + return MakeRet< ret_type >::Do(0); \
22.669 + } \
22.670 + \
22.671 + struct Delegate : public MyDelegate \
22.672 + { \
22.673 + int m_DelegNumber; \
22.674 + Delegate(int num) : m_DelegNumber(num) { } \
22.675 + \
22.676 + virtual ret_type Call(const char *buf) \
22.677 + { \
22.678 + g_Inside_LeafFunc = true; \
22.679 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(buf))); \
22.680 + g_Inside_LeafFunc = false; \
22.681 + if (ms_DoRecall) \
22.682 + { \
22.683 + \
22.684 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, ("%s!", buf)); \
22.685 + } \
22.686 + else \
22.687 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.688 + } \
22.689 + }; \
22.690 + }; \
22.691 + \
22.692 + bool TestClass##id::ms_DoRecall = false; \
22.693 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.694 +
22.695 +#define THGM_SETUP_PI0(id) \
22.696 + void setuppi_##id() \
22.697 + { \
22.698 + \
22.699 + }
22.700 +
22.701 +
22.702 +
22.703 +#define THGM_MAKE_TEST1_void(id, param1) \
22.704 + struct TestClass##id; \
22.705 + typedef ParamState1<0, param1 > ParamState_m##id; \
22.706 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.707 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.708 + \
22.709 + struct TestClass##id \
22.710 + { \
22.711 + static bool ms_DoRecall; \
22.712 + \
22.713 + virtual void Func(param1 p1) \
22.714 + { \
22.715 + g_Inside_LeafFunc = true; \
22.716 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1))); \
22.717 + g_Inside_LeafFunc = false; \
22.718 + } \
22.719 + \
22.720 + struct Delegate : public MyDelegate \
22.721 + { \
22.722 + int m_DelegNumber; \
22.723 + Delegate(int num) : m_DelegNumber(num) { } \
22.724 + \
22.725 + virtual void Call(param1 p1) \
22.726 + { \
22.727 + g_Inside_LeafFunc = true; \
22.728 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1))); \
22.729 + g_Inside_LeafFunc = false; \
22.730 + if (ms_DoRecall) \
22.731 + { \
22.732 + Increment<StripRef< param1 >::type>::Incr(p1); \
22.733 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (p1)); \
22.734 + } \
22.735 + else \
22.736 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.737 + } \
22.738 + }; \
22.739 + }; \
22.740 + \
22.741 + bool TestClass##id::ms_DoRecall = false; \
22.742 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.743 +
22.744 +
22.745 +#define THGM_MAKE_TEST1(id, ret_type, param1) \
22.746 + struct TestClass##id; \
22.747 + typedef ret_type RetType##id; \
22.748 + typedef ParamState1<0, param1 > ParamState_m##id; \
22.749 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.750 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.751 + \
22.752 + struct TestClass##id \
22.753 + { \
22.754 + static bool ms_DoRecall; \
22.755 + \
22.756 + virtual ret_type Func(param1 p1) \
22.757 + { \
22.758 + g_Inside_LeafFunc = true; \
22.759 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1))); \
22.760 + g_Inside_LeafFunc = false; \
22.761 + \
22.762 + return MakeRet< ret_type >::Do(0); \
22.763 + } \
22.764 + \
22.765 + struct Delegate : public MyDelegate \
22.766 + { \
22.767 + int m_DelegNumber; \
22.768 + Delegate(int num) : m_DelegNumber(num) { } \
22.769 + \
22.770 + virtual ret_type Call(param1 p1) \
22.771 + { \
22.772 + g_Inside_LeafFunc = true; \
22.773 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1))); \
22.774 + g_Inside_LeafFunc = false; \
22.775 + if (ms_DoRecall) \
22.776 + { \
22.777 + Increment<StripRef< param1 >::type>::Incr(p1); \
22.778 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (p1)); \
22.779 + } \
22.780 + else \
22.781 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.782 + } \
22.783 + }; \
22.784 + }; \
22.785 + \
22.786 + bool TestClass##id::ms_DoRecall = false; \
22.787 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.788 +
22.789 +#define THGM_MAKE_TEST1_vafmt_void(id, param1) \
22.790 + struct TestClass##id; \
22.791 + typedef ParamState2<0, param1, std::string > ParamState_m##id; \
22.792 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.793 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.794 + \
22.795 + struct TestClass##id \
22.796 + { \
22.797 + static bool ms_DoRecall; \
22.798 + \
22.799 + virtual void Func(param1 p1, const char *fmt, ...) \
22.800 + { \
22.801 + g_Inside_LeafFunc = true; \
22.802 + \
22.803 + char buf[9999]; \
22.804 + va_list ap; \
22.805 + va_start(ap, fmt); \
22.806 + vsnprintf(buf, 9998, fmt, ap); \
22.807 + buf[9998] = 0; \
22.808 + va_end(ap); \
22.809 + \
22.810 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, std::string(buf)))); \
22.811 + g_Inside_LeafFunc = false; \
22.812 + } \
22.813 + \
22.814 + struct Delegate : public MyDelegate \
22.815 + { \
22.816 + int m_DelegNumber; \
22.817 + Delegate(int num) : m_DelegNumber(num) { } \
22.818 + \
22.819 + virtual void Call(param1 p1, const char *buf) \
22.820 + { \
22.821 + g_Inside_LeafFunc = true; \
22.822 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, buf))); \
22.823 + g_Inside_LeafFunc = false; \
22.824 + if (ms_DoRecall) \
22.825 + { \
22.826 + Increment<StripRef< param1 >::type>::Incr(p1); \
22.827 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (p1, "%s!", buf)); \
22.828 + } \
22.829 + else \
22.830 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.831 + } \
22.832 + }; \
22.833 + }; \
22.834 + \
22.835 + bool TestClass##id::ms_DoRecall = false; \
22.836 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.837 +
22.838 +#define THGM_MAKE_TEST1_vafmt(id, ret_type, param1) \
22.839 + struct TestClass##id; \
22.840 + typedef ret_type RetType##id; \
22.841 + typedef ParamState2<0, param1, std::string > ParamState_m##id; \
22.842 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.843 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.844 + \
22.845 + struct TestClass##id \
22.846 + { \
22.847 + static bool ms_DoRecall; \
22.848 + \
22.849 + virtual ret_type Func(param1 p1, const char *fmt, ...) \
22.850 + { \
22.851 + g_Inside_LeafFunc = true; \
22.852 + \
22.853 + char buf[9999]; \
22.854 + va_list ap; \
22.855 + va_start(ap, fmt); \
22.856 + vsnprintf(buf, 9998, fmt, ap); \
22.857 + buf[9998] = 0; \
22.858 + va_end(ap); \
22.859 + \
22.860 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, std::string(buf)))); \
22.861 + \
22.862 + return MakeRet< ret_type >::Do(0); \
22.863 + } \
22.864 + \
22.865 + struct Delegate : public MyDelegate \
22.866 + { \
22.867 + int m_DelegNumber; \
22.868 + Delegate(int num) : m_DelegNumber(num) { } \
22.869 + \
22.870 + virtual ret_type Call(param1 p1, const char *buf) \
22.871 + { \
22.872 + g_Inside_LeafFunc = true; \
22.873 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, buf))); \
22.874 + g_Inside_LeafFunc = false; \
22.875 + if (ms_DoRecall) \
22.876 + { \
22.877 + Increment<StripRef< param1 >::type>::Incr(p1); \
22.878 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (p1, "%s!", buf)); \
22.879 + } \
22.880 + else \
22.881 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.882 + } \
22.883 + }; \
22.884 + }; \
22.885 + \
22.886 + bool TestClass##id::ms_DoRecall = false; \
22.887 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.888 +
22.889 +#define THGM_SETUP_PI1(id, p1_type, p1_passtype, p1_flags) \
22.890 + void setuppi_##id() \
22.891 + { \
22.892 + \
22.893 + protoinfo_##id.AddParam(sizeof(p1_type), p1_passtype, p1_flags, \
22.894 + (p1_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::NormalConstructor) : NULL, \
22.895 + (p1_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::CopyConstructor) : NULL, \
22.896 + (p1_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::Destructor) : NULL, \
22.897 + (p1_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::AssignOp) : NULL \
22.898 + ); \
22.899 + \
22.900 + }
22.901 +
22.902 +
22.903 +
22.904 +#define THGM_MAKE_TEST2_void(id, param1, param2) \
22.905 + struct TestClass##id; \
22.906 + typedef ParamState2<0, param1, param2 > ParamState_m##id; \
22.907 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.908 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.909 + \
22.910 + struct TestClass##id \
22.911 + { \
22.912 + static bool ms_DoRecall; \
22.913 + \
22.914 + virtual void Func(param1 p1, param2 p2) \
22.915 + { \
22.916 + g_Inside_LeafFunc = true; \
22.917 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2))); \
22.918 + g_Inside_LeafFunc = false; \
22.919 + } \
22.920 + \
22.921 + struct Delegate : public MyDelegate \
22.922 + { \
22.923 + int m_DelegNumber; \
22.924 + Delegate(int num) : m_DelegNumber(num) { } \
22.925 + \
22.926 + virtual void Call(param1 p1, param2 p2) \
22.927 + { \
22.928 + g_Inside_LeafFunc = true; \
22.929 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2))); \
22.930 + g_Inside_LeafFunc = false; \
22.931 + if (ms_DoRecall) \
22.932 + { \
22.933 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2); \
22.934 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2)); \
22.935 + } \
22.936 + else \
22.937 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.938 + } \
22.939 + }; \
22.940 + }; \
22.941 + \
22.942 + bool TestClass##id::ms_DoRecall = false; \
22.943 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.944 +
22.945 +
22.946 +#define THGM_MAKE_TEST2(id, ret_type, param1, param2) \
22.947 + struct TestClass##id; \
22.948 + typedef ret_type RetType##id; \
22.949 + typedef ParamState2<0, param1, param2 > ParamState_m##id; \
22.950 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.951 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.952 + \
22.953 + struct TestClass##id \
22.954 + { \
22.955 + static bool ms_DoRecall; \
22.956 + \
22.957 + virtual ret_type Func(param1 p1, param2 p2) \
22.958 + { \
22.959 + g_Inside_LeafFunc = true; \
22.960 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2))); \
22.961 + g_Inside_LeafFunc = false; \
22.962 + \
22.963 + return MakeRet< ret_type >::Do(0); \
22.964 + } \
22.965 + \
22.966 + struct Delegate : public MyDelegate \
22.967 + { \
22.968 + int m_DelegNumber; \
22.969 + Delegate(int num) : m_DelegNumber(num) { } \
22.970 + \
22.971 + virtual ret_type Call(param1 p1, param2 p2) \
22.972 + { \
22.973 + g_Inside_LeafFunc = true; \
22.974 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2))); \
22.975 + g_Inside_LeafFunc = false; \
22.976 + if (ms_DoRecall) \
22.977 + { \
22.978 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2); \
22.979 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (p1, p2)); \
22.980 + } \
22.981 + else \
22.982 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.983 + } \
22.984 + }; \
22.985 + }; \
22.986 + \
22.987 + bool TestClass##id::ms_DoRecall = false; \
22.988 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.989 +
22.990 +#define THGM_MAKE_TEST2_vafmt_void(id, param1, param2) \
22.991 + struct TestClass##id; \
22.992 + typedef ParamState3<0, param1, param2, std::string > ParamState_m##id; \
22.993 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.994 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.995 + \
22.996 + struct TestClass##id \
22.997 + { \
22.998 + static bool ms_DoRecall; \
22.999 + \
22.1000 + virtual void Func(param1 p1, param2 p2, const char *fmt, ...) \
22.1001 + { \
22.1002 + g_Inside_LeafFunc = true; \
22.1003 + \
22.1004 + char buf[9999]; \
22.1005 + va_list ap; \
22.1006 + va_start(ap, fmt); \
22.1007 + vsnprintf(buf, 9998, fmt, ap); \
22.1008 + buf[9998] = 0; \
22.1009 + va_end(ap); \
22.1010 + \
22.1011 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, std::string(buf)))); \
22.1012 + g_Inside_LeafFunc = false; \
22.1013 + } \
22.1014 + \
22.1015 + struct Delegate : public MyDelegate \
22.1016 + { \
22.1017 + int m_DelegNumber; \
22.1018 + Delegate(int num) : m_DelegNumber(num) { } \
22.1019 + \
22.1020 + virtual void Call(param1 p1, param2 p2, const char *buf) \
22.1021 + { \
22.1022 + g_Inside_LeafFunc = true; \
22.1023 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, buf))); \
22.1024 + g_Inside_LeafFunc = false; \
22.1025 + if (ms_DoRecall) \
22.1026 + { \
22.1027 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2); \
22.1028 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, "%s!", buf)); \
22.1029 + } \
22.1030 + else \
22.1031 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.1032 + } \
22.1033 + }; \
22.1034 + }; \
22.1035 + \
22.1036 + bool TestClass##id::ms_DoRecall = false; \
22.1037 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.1038 +
22.1039 +#define THGM_MAKE_TEST2_vafmt(id, ret_type, param1, param2) \
22.1040 + struct TestClass##id; \
22.1041 + typedef ret_type RetType##id; \
22.1042 + typedef ParamState3<0, param1, param2, std::string > ParamState_m##id; \
22.1043 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1044 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1045 + \
22.1046 + struct TestClass##id \
22.1047 + { \
22.1048 + static bool ms_DoRecall; \
22.1049 + \
22.1050 + virtual ret_type Func(param1 p1, param2 p2, const char *fmt, ...) \
22.1051 + { \
22.1052 + g_Inside_LeafFunc = true; \
22.1053 + \
22.1054 + char buf[9999]; \
22.1055 + va_list ap; \
22.1056 + va_start(ap, fmt); \
22.1057 + vsnprintf(buf, 9998, fmt, ap); \
22.1058 + buf[9998] = 0; \
22.1059 + va_end(ap); \
22.1060 + \
22.1061 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, std::string(buf)))); \
22.1062 + \
22.1063 + return MakeRet< ret_type >::Do(0); \
22.1064 + } \
22.1065 + \
22.1066 + struct Delegate : public MyDelegate \
22.1067 + { \
22.1068 + int m_DelegNumber; \
22.1069 + Delegate(int num) : m_DelegNumber(num) { } \
22.1070 + \
22.1071 + virtual ret_type Call(param1 p1, param2 p2, const char *buf) \
22.1072 + { \
22.1073 + g_Inside_LeafFunc = true; \
22.1074 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, buf))); \
22.1075 + g_Inside_LeafFunc = false; \
22.1076 + if (ms_DoRecall) \
22.1077 + { \
22.1078 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2); \
22.1079 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (p1, p2, "%s!", buf)); \
22.1080 + } \
22.1081 + else \
22.1082 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.1083 + } \
22.1084 + }; \
22.1085 + }; \
22.1086 + \
22.1087 + bool TestClass##id::ms_DoRecall = false; \
22.1088 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.1089 +
22.1090 +#define THGM_SETUP_PI2(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags) \
22.1091 + void setuppi_##id() \
22.1092 + { \
22.1093 + \
22.1094 + protoinfo_##id.AddParam(sizeof(p1_type), p1_passtype, p1_flags, \
22.1095 + (p1_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::NormalConstructor) : NULL, \
22.1096 + (p1_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::CopyConstructor) : NULL, \
22.1097 + (p1_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::Destructor) : NULL, \
22.1098 + (p1_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::AssignOp) : NULL \
22.1099 + ); \
22.1100 + \
22.1101 + protoinfo_##id.AddParam(sizeof(p2_type), p2_passtype, p2_flags, \
22.1102 + (p2_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::NormalConstructor) : NULL, \
22.1103 + (p2_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::CopyConstructor) : NULL, \
22.1104 + (p2_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::Destructor) : NULL, \
22.1105 + (p2_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::AssignOp) : NULL \
22.1106 + ); \
22.1107 + \
22.1108 + }
22.1109 +
22.1110 +
22.1111 +
22.1112 +#define THGM_MAKE_TEST3_void(id, param1, param2, param3) \
22.1113 + struct TestClass##id; \
22.1114 + typedef ParamState3<0, param1, param2, param3 > ParamState_m##id; \
22.1115 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1116 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1117 + \
22.1118 + struct TestClass##id \
22.1119 + { \
22.1120 + static bool ms_DoRecall; \
22.1121 + \
22.1122 + virtual void Func(param1 p1, param2 p2, param3 p3) \
22.1123 + { \
22.1124 + g_Inside_LeafFunc = true; \
22.1125 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3))); \
22.1126 + g_Inside_LeafFunc = false; \
22.1127 + } \
22.1128 + \
22.1129 + struct Delegate : public MyDelegate \
22.1130 + { \
22.1131 + int m_DelegNumber; \
22.1132 + Delegate(int num) : m_DelegNumber(num) { } \
22.1133 + \
22.1134 + virtual void Call(param1 p1, param2 p2, param3 p3) \
22.1135 + { \
22.1136 + g_Inside_LeafFunc = true; \
22.1137 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3))); \
22.1138 + g_Inside_LeafFunc = false; \
22.1139 + if (ms_DoRecall) \
22.1140 + { \
22.1141 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3); \
22.1142 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3)); \
22.1143 + } \
22.1144 + else \
22.1145 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.1146 + } \
22.1147 + }; \
22.1148 + }; \
22.1149 + \
22.1150 + bool TestClass##id::ms_DoRecall = false; \
22.1151 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.1152 +
22.1153 +
22.1154 +#define THGM_MAKE_TEST3(id, ret_type, param1, param2, param3) \
22.1155 + struct TestClass##id; \
22.1156 + typedef ret_type RetType##id; \
22.1157 + typedef ParamState3<0, param1, param2, param3 > ParamState_m##id; \
22.1158 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1159 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1160 + \
22.1161 + struct TestClass##id \
22.1162 + { \
22.1163 + static bool ms_DoRecall; \
22.1164 + \
22.1165 + virtual ret_type Func(param1 p1, param2 p2, param3 p3) \
22.1166 + { \
22.1167 + g_Inside_LeafFunc = true; \
22.1168 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3))); \
22.1169 + g_Inside_LeafFunc = false; \
22.1170 + \
22.1171 + return MakeRet< ret_type >::Do(0); \
22.1172 + } \
22.1173 + \
22.1174 + struct Delegate : public MyDelegate \
22.1175 + { \
22.1176 + int m_DelegNumber; \
22.1177 + Delegate(int num) : m_DelegNumber(num) { } \
22.1178 + \
22.1179 + virtual ret_type Call(param1 p1, param2 p2, param3 p3) \
22.1180 + { \
22.1181 + g_Inside_LeafFunc = true; \
22.1182 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3))); \
22.1183 + g_Inside_LeafFunc = false; \
22.1184 + if (ms_DoRecall) \
22.1185 + { \
22.1186 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3); \
22.1187 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (p1, p2, p3)); \
22.1188 + } \
22.1189 + else \
22.1190 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.1191 + } \
22.1192 + }; \
22.1193 + }; \
22.1194 + \
22.1195 + bool TestClass##id::ms_DoRecall = false; \
22.1196 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.1197 +
22.1198 +#define THGM_MAKE_TEST3_vafmt_void(id, param1, param2, param3) \
22.1199 + struct TestClass##id; \
22.1200 + typedef ParamState4<0, param1, param2, param3, std::string > ParamState_m##id; \
22.1201 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1202 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1203 + \
22.1204 + struct TestClass##id \
22.1205 + { \
22.1206 + static bool ms_DoRecall; \
22.1207 + \
22.1208 + virtual void Func(param1 p1, param2 p2, param3 p3, const char *fmt, ...) \
22.1209 + { \
22.1210 + g_Inside_LeafFunc = true; \
22.1211 + \
22.1212 + char buf[9999]; \
22.1213 + va_list ap; \
22.1214 + va_start(ap, fmt); \
22.1215 + vsnprintf(buf, 9998, fmt, ap); \
22.1216 + buf[9998] = 0; \
22.1217 + va_end(ap); \
22.1218 + \
22.1219 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, std::string(buf)))); \
22.1220 + g_Inside_LeafFunc = false; \
22.1221 + } \
22.1222 + \
22.1223 + struct Delegate : public MyDelegate \
22.1224 + { \
22.1225 + int m_DelegNumber; \
22.1226 + Delegate(int num) : m_DelegNumber(num) { } \
22.1227 + \
22.1228 + virtual void Call(param1 p1, param2 p2, param3 p3, const char *buf) \
22.1229 + { \
22.1230 + g_Inside_LeafFunc = true; \
22.1231 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, buf))); \
22.1232 + g_Inside_LeafFunc = false; \
22.1233 + if (ms_DoRecall) \
22.1234 + { \
22.1235 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3); \
22.1236 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3, "%s!", buf)); \
22.1237 + } \
22.1238 + else \
22.1239 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.1240 + } \
22.1241 + }; \
22.1242 + }; \
22.1243 + \
22.1244 + bool TestClass##id::ms_DoRecall = false; \
22.1245 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.1246 +
22.1247 +#define THGM_MAKE_TEST3_vafmt(id, ret_type, param1, param2, param3) \
22.1248 + struct TestClass##id; \
22.1249 + typedef ret_type RetType##id; \
22.1250 + typedef ParamState4<0, param1, param2, param3, std::string > ParamState_m##id; \
22.1251 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1252 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1253 + \
22.1254 + struct TestClass##id \
22.1255 + { \
22.1256 + static bool ms_DoRecall; \
22.1257 + \
22.1258 + virtual ret_type Func(param1 p1, param2 p2, param3 p3, const char *fmt, ...) \
22.1259 + { \
22.1260 + g_Inside_LeafFunc = true; \
22.1261 + \
22.1262 + char buf[9999]; \
22.1263 + va_list ap; \
22.1264 + va_start(ap, fmt); \
22.1265 + vsnprintf(buf, 9998, fmt, ap); \
22.1266 + buf[9998] = 0; \
22.1267 + va_end(ap); \
22.1268 + \
22.1269 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, std::string(buf)))); \
22.1270 + \
22.1271 + return MakeRet< ret_type >::Do(0); \
22.1272 + } \
22.1273 + \
22.1274 + struct Delegate : public MyDelegate \
22.1275 + { \
22.1276 + int m_DelegNumber; \
22.1277 + Delegate(int num) : m_DelegNumber(num) { } \
22.1278 + \
22.1279 + virtual ret_type Call(param1 p1, param2 p2, param3 p3, const char *buf) \
22.1280 + { \
22.1281 + g_Inside_LeafFunc = true; \
22.1282 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, buf))); \
22.1283 + g_Inside_LeafFunc = false; \
22.1284 + if (ms_DoRecall) \
22.1285 + { \
22.1286 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3); \
22.1287 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (p1, p2, p3, "%s!", buf)); \
22.1288 + } \
22.1289 + else \
22.1290 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.1291 + } \
22.1292 + }; \
22.1293 + }; \
22.1294 + \
22.1295 + bool TestClass##id::ms_DoRecall = false; \
22.1296 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.1297 +
22.1298 +#define THGM_SETUP_PI3(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags, p3_type, p3_passtype, p3_flags) \
22.1299 + void setuppi_##id() \
22.1300 + { \
22.1301 + \
22.1302 + protoinfo_##id.AddParam(sizeof(p1_type), p1_passtype, p1_flags, \
22.1303 + (p1_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::NormalConstructor) : NULL, \
22.1304 + (p1_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::CopyConstructor) : NULL, \
22.1305 + (p1_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::Destructor) : NULL, \
22.1306 + (p1_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::AssignOp) : NULL \
22.1307 + ); \
22.1308 + \
22.1309 + protoinfo_##id.AddParam(sizeof(p2_type), p2_passtype, p2_flags, \
22.1310 + (p2_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::NormalConstructor) : NULL, \
22.1311 + (p2_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::CopyConstructor) : NULL, \
22.1312 + (p2_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::Destructor) : NULL, \
22.1313 + (p2_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::AssignOp) : NULL \
22.1314 + ); \
22.1315 + \
22.1316 + protoinfo_##id.AddParam(sizeof(p3_type), p3_passtype, p3_flags, \
22.1317 + (p3_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::NormalConstructor) : NULL, \
22.1318 + (p3_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::CopyConstructor) : NULL, \
22.1319 + (p3_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::Destructor) : NULL, \
22.1320 + (p3_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::AssignOp) : NULL \
22.1321 + ); \
22.1322 + \
22.1323 + }
22.1324 +
22.1325 +
22.1326 +
22.1327 +#define THGM_MAKE_TEST4_void(id, param1, param2, param3, param4) \
22.1328 + struct TestClass##id; \
22.1329 + typedef ParamState4<0, param1, param2, param3, param4 > ParamState_m##id; \
22.1330 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1331 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1332 + \
22.1333 + struct TestClass##id \
22.1334 + { \
22.1335 + static bool ms_DoRecall; \
22.1336 + \
22.1337 + virtual void Func(param1 p1, param2 p2, param3 p3, param4 p4) \
22.1338 + { \
22.1339 + g_Inside_LeafFunc = true; \
22.1340 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4))); \
22.1341 + g_Inside_LeafFunc = false; \
22.1342 + } \
22.1343 + \
22.1344 + struct Delegate : public MyDelegate \
22.1345 + { \
22.1346 + int m_DelegNumber; \
22.1347 + Delegate(int num) : m_DelegNumber(num) { } \
22.1348 + \
22.1349 + virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4) \
22.1350 + { \
22.1351 + g_Inside_LeafFunc = true; \
22.1352 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4))); \
22.1353 + g_Inside_LeafFunc = false; \
22.1354 + if (ms_DoRecall) \
22.1355 + { \
22.1356 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4); \
22.1357 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3, p4)); \
22.1358 + } \
22.1359 + else \
22.1360 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.1361 + } \
22.1362 + }; \
22.1363 + }; \
22.1364 + \
22.1365 + bool TestClass##id::ms_DoRecall = false; \
22.1366 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.1367 +
22.1368 +
22.1369 +#define THGM_MAKE_TEST4(id, ret_type, param1, param2, param3, param4) \
22.1370 + struct TestClass##id; \
22.1371 + typedef ret_type RetType##id; \
22.1372 + typedef ParamState4<0, param1, param2, param3, param4 > ParamState_m##id; \
22.1373 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1374 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1375 + \
22.1376 + struct TestClass##id \
22.1377 + { \
22.1378 + static bool ms_DoRecall; \
22.1379 + \
22.1380 + virtual ret_type Func(param1 p1, param2 p2, param3 p3, param4 p4) \
22.1381 + { \
22.1382 + g_Inside_LeafFunc = true; \
22.1383 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4))); \
22.1384 + g_Inside_LeafFunc = false; \
22.1385 + \
22.1386 + return MakeRet< ret_type >::Do(0); \
22.1387 + } \
22.1388 + \
22.1389 + struct Delegate : public MyDelegate \
22.1390 + { \
22.1391 + int m_DelegNumber; \
22.1392 + Delegate(int num) : m_DelegNumber(num) { } \
22.1393 + \
22.1394 + virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4) \
22.1395 + { \
22.1396 + g_Inside_LeafFunc = true; \
22.1397 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4))); \
22.1398 + g_Inside_LeafFunc = false; \
22.1399 + if (ms_DoRecall) \
22.1400 + { \
22.1401 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4); \
22.1402 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (p1, p2, p3, p4)); \
22.1403 + } \
22.1404 + else \
22.1405 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.1406 + } \
22.1407 + }; \
22.1408 + }; \
22.1409 + \
22.1410 + bool TestClass##id::ms_DoRecall = false; \
22.1411 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.1412 +
22.1413 +#define THGM_MAKE_TEST4_vafmt_void(id, param1, param2, param3, param4) \
22.1414 + struct TestClass##id; \
22.1415 + typedef ParamState5<0, param1, param2, param3, param4, std::string > ParamState_m##id; \
22.1416 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1417 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1418 + \
22.1419 + struct TestClass##id \
22.1420 + { \
22.1421 + static bool ms_DoRecall; \
22.1422 + \
22.1423 + virtual void Func(param1 p1, param2 p2, param3 p3, param4 p4, const char *fmt, ...) \
22.1424 + { \
22.1425 + g_Inside_LeafFunc = true; \
22.1426 + \
22.1427 + char buf[9999]; \
22.1428 + va_list ap; \
22.1429 + va_start(ap, fmt); \
22.1430 + vsnprintf(buf, 9998, fmt, ap); \
22.1431 + buf[9998] = 0; \
22.1432 + va_end(ap); \
22.1433 + \
22.1434 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, std::string(buf)))); \
22.1435 + g_Inside_LeafFunc = false; \
22.1436 + } \
22.1437 + \
22.1438 + struct Delegate : public MyDelegate \
22.1439 + { \
22.1440 + int m_DelegNumber; \
22.1441 + Delegate(int num) : m_DelegNumber(num) { } \
22.1442 + \
22.1443 + virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4, const char *buf) \
22.1444 + { \
22.1445 + g_Inside_LeafFunc = true; \
22.1446 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, buf))); \
22.1447 + g_Inside_LeafFunc = false; \
22.1448 + if (ms_DoRecall) \
22.1449 + { \
22.1450 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4); \
22.1451 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3, p4, "%s!", buf)); \
22.1452 + } \
22.1453 + else \
22.1454 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.1455 + } \
22.1456 + }; \
22.1457 + }; \
22.1458 + \
22.1459 + bool TestClass##id::ms_DoRecall = false; \
22.1460 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.1461 +
22.1462 +#define THGM_MAKE_TEST4_vafmt(id, ret_type, param1, param2, param3, param4) \
22.1463 + struct TestClass##id; \
22.1464 + typedef ret_type RetType##id; \
22.1465 + typedef ParamState5<0, param1, param2, param3, param4, std::string > ParamState_m##id; \
22.1466 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1467 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1468 + \
22.1469 + struct TestClass##id \
22.1470 + { \
22.1471 + static bool ms_DoRecall; \
22.1472 + \
22.1473 + virtual ret_type Func(param1 p1, param2 p2, param3 p3, param4 p4, const char *fmt, ...) \
22.1474 + { \
22.1475 + g_Inside_LeafFunc = true; \
22.1476 + \
22.1477 + char buf[9999]; \
22.1478 + va_list ap; \
22.1479 + va_start(ap, fmt); \
22.1480 + vsnprintf(buf, 9998, fmt, ap); \
22.1481 + buf[9998] = 0; \
22.1482 + va_end(ap); \
22.1483 + \
22.1484 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, std::string(buf)))); \
22.1485 + \
22.1486 + return MakeRet< ret_type >::Do(0); \
22.1487 + } \
22.1488 + \
22.1489 + struct Delegate : public MyDelegate \
22.1490 + { \
22.1491 + int m_DelegNumber; \
22.1492 + Delegate(int num) : m_DelegNumber(num) { } \
22.1493 + \
22.1494 + virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4, const char *buf) \
22.1495 + { \
22.1496 + g_Inside_LeafFunc = true; \
22.1497 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, buf))); \
22.1498 + g_Inside_LeafFunc = false; \
22.1499 + if (ms_DoRecall) \
22.1500 + { \
22.1501 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4); \
22.1502 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (p1, p2, p3, p4, "%s!", buf)); \
22.1503 + } \
22.1504 + else \
22.1505 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.1506 + } \
22.1507 + }; \
22.1508 + }; \
22.1509 + \
22.1510 + bool TestClass##id::ms_DoRecall = false; \
22.1511 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.1512 +
22.1513 +#define THGM_SETUP_PI4(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags, p3_type, p3_passtype, p3_flags, p4_type, p4_passtype, p4_flags) \
22.1514 + void setuppi_##id() \
22.1515 + { \
22.1516 + \
22.1517 + protoinfo_##id.AddParam(sizeof(p1_type), p1_passtype, p1_flags, \
22.1518 + (p1_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::NormalConstructor) : NULL, \
22.1519 + (p1_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::CopyConstructor) : NULL, \
22.1520 + (p1_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::Destructor) : NULL, \
22.1521 + (p1_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::AssignOp) : NULL \
22.1522 + ); \
22.1523 + \
22.1524 + protoinfo_##id.AddParam(sizeof(p2_type), p2_passtype, p2_flags, \
22.1525 + (p2_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::NormalConstructor) : NULL, \
22.1526 + (p2_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::CopyConstructor) : NULL, \
22.1527 + (p2_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::Destructor) : NULL, \
22.1528 + (p2_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::AssignOp) : NULL \
22.1529 + ); \
22.1530 + \
22.1531 + protoinfo_##id.AddParam(sizeof(p3_type), p3_passtype, p3_flags, \
22.1532 + (p3_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::NormalConstructor) : NULL, \
22.1533 + (p3_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::CopyConstructor) : NULL, \
22.1534 + (p3_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::Destructor) : NULL, \
22.1535 + (p3_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::AssignOp) : NULL \
22.1536 + ); \
22.1537 + \
22.1538 + protoinfo_##id.AddParam(sizeof(p4_type), p4_passtype, p4_flags, \
22.1539 + (p4_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::NormalConstructor) : NULL, \
22.1540 + (p4_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::CopyConstructor) : NULL, \
22.1541 + (p4_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::Destructor) : NULL, \
22.1542 + (p4_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::AssignOp) : NULL \
22.1543 + ); \
22.1544 + \
22.1545 + }
22.1546 +
22.1547 +
22.1548 +
22.1549 +#define THGM_MAKE_TEST5_void(id, param1, param2, param3, param4, param5) \
22.1550 + struct TestClass##id; \
22.1551 + typedef ParamState5<0, param1, param2, param3, param4, param5 > ParamState_m##id; \
22.1552 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1553 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1554 + \
22.1555 + struct TestClass##id \
22.1556 + { \
22.1557 + static bool ms_DoRecall; \
22.1558 + \
22.1559 + virtual void Func(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
22.1560 + { \
22.1561 + g_Inside_LeafFunc = true; \
22.1562 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, p5))); \
22.1563 + g_Inside_LeafFunc = false; \
22.1564 + } \
22.1565 + \
22.1566 + struct Delegate : public MyDelegate \
22.1567 + { \
22.1568 + int m_DelegNumber; \
22.1569 + Delegate(int num) : m_DelegNumber(num) { } \
22.1570 + \
22.1571 + virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
22.1572 + { \
22.1573 + g_Inside_LeafFunc = true; \
22.1574 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5))); \
22.1575 + g_Inside_LeafFunc = false; \
22.1576 + if (ms_DoRecall) \
22.1577 + { \
22.1578 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5); \
22.1579 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3, p4, p5)); \
22.1580 + } \
22.1581 + else \
22.1582 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.1583 + } \
22.1584 + }; \
22.1585 + }; \
22.1586 + \
22.1587 + bool TestClass##id::ms_DoRecall = false; \
22.1588 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.1589 +
22.1590 +
22.1591 +#define THGM_MAKE_TEST5(id, ret_type, param1, param2, param3, param4, param5) \
22.1592 + struct TestClass##id; \
22.1593 + typedef ret_type RetType##id; \
22.1594 + typedef ParamState5<0, param1, param2, param3, param4, param5 > ParamState_m##id; \
22.1595 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1596 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1597 + \
22.1598 + struct TestClass##id \
22.1599 + { \
22.1600 + static bool ms_DoRecall; \
22.1601 + \
22.1602 + virtual ret_type Func(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
22.1603 + { \
22.1604 + g_Inside_LeafFunc = true; \
22.1605 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, p5))); \
22.1606 + g_Inside_LeafFunc = false; \
22.1607 + \
22.1608 + return MakeRet< ret_type >::Do(0); \
22.1609 + } \
22.1610 + \
22.1611 + struct Delegate : public MyDelegate \
22.1612 + { \
22.1613 + int m_DelegNumber; \
22.1614 + Delegate(int num) : m_DelegNumber(num) { } \
22.1615 + \
22.1616 + virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5) \
22.1617 + { \
22.1618 + g_Inside_LeafFunc = true; \
22.1619 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5))); \
22.1620 + g_Inside_LeafFunc = false; \
22.1621 + if (ms_DoRecall) \
22.1622 + { \
22.1623 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5); \
22.1624 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (p1, p2, p3, p4, p5)); \
22.1625 + } \
22.1626 + else \
22.1627 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.1628 + } \
22.1629 + }; \
22.1630 + }; \
22.1631 + \
22.1632 + bool TestClass##id::ms_DoRecall = false; \
22.1633 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.1634 +
22.1635 +#define THGM_MAKE_TEST5_vafmt_void(id, param1, param2, param3, param4, param5) \
22.1636 + struct TestClass##id; \
22.1637 + typedef ParamState6<0, param1, param2, param3, param4, param5, std::string > ParamState_m##id; \
22.1638 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1639 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1640 + \
22.1641 + struct TestClass##id \
22.1642 + { \
22.1643 + static bool ms_DoRecall; \
22.1644 + \
22.1645 + virtual void Func(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, const char *fmt, ...) \
22.1646 + { \
22.1647 + g_Inside_LeafFunc = true; \
22.1648 + \
22.1649 + char buf[9999]; \
22.1650 + va_list ap; \
22.1651 + va_start(ap, fmt); \
22.1652 + vsnprintf(buf, 9998, fmt, ap); \
22.1653 + buf[9998] = 0; \
22.1654 + va_end(ap); \
22.1655 + \
22.1656 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, p5, std::string(buf)))); \
22.1657 + g_Inside_LeafFunc = false; \
22.1658 + } \
22.1659 + \
22.1660 + struct Delegate : public MyDelegate \
22.1661 + { \
22.1662 + int m_DelegNumber; \
22.1663 + Delegate(int num) : m_DelegNumber(num) { } \
22.1664 + \
22.1665 + virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, const char *buf) \
22.1666 + { \
22.1667 + g_Inside_LeafFunc = true; \
22.1668 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, buf))); \
22.1669 + g_Inside_LeafFunc = false; \
22.1670 + if (ms_DoRecall) \
22.1671 + { \
22.1672 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5); \
22.1673 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3, p4, p5, "%s!", buf)); \
22.1674 + } \
22.1675 + else \
22.1676 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.1677 + } \
22.1678 + }; \
22.1679 + }; \
22.1680 + \
22.1681 + bool TestClass##id::ms_DoRecall = false; \
22.1682 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.1683 +
22.1684 +#define THGM_MAKE_TEST5_vafmt(id, ret_type, param1, param2, param3, param4, param5) \
22.1685 + struct TestClass##id; \
22.1686 + typedef ret_type RetType##id; \
22.1687 + typedef ParamState6<0, param1, param2, param3, param4, param5, std::string > ParamState_m##id; \
22.1688 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1689 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1690 + \
22.1691 + struct TestClass##id \
22.1692 + { \
22.1693 + static bool ms_DoRecall; \
22.1694 + \
22.1695 + virtual ret_type Func(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, const char *fmt, ...) \
22.1696 + { \
22.1697 + g_Inside_LeafFunc = true; \
22.1698 + \
22.1699 + char buf[9999]; \
22.1700 + va_list ap; \
22.1701 + va_start(ap, fmt); \
22.1702 + vsnprintf(buf, 9998, fmt, ap); \
22.1703 + buf[9998] = 0; \
22.1704 + va_end(ap); \
22.1705 + \
22.1706 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, p5, std::string(buf)))); \
22.1707 + \
22.1708 + return MakeRet< ret_type >::Do(0); \
22.1709 + } \
22.1710 + \
22.1711 + struct Delegate : public MyDelegate \
22.1712 + { \
22.1713 + int m_DelegNumber; \
22.1714 + Delegate(int num) : m_DelegNumber(num) { } \
22.1715 + \
22.1716 + virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, const char *buf) \
22.1717 + { \
22.1718 + g_Inside_LeafFunc = true; \
22.1719 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, buf))); \
22.1720 + g_Inside_LeafFunc = false; \
22.1721 + if (ms_DoRecall) \
22.1722 + { \
22.1723 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5); \
22.1724 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (p1, p2, p3, p4, p5, "%s!", buf)); \
22.1725 + } \
22.1726 + else \
22.1727 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.1728 + } \
22.1729 + }; \
22.1730 + }; \
22.1731 + \
22.1732 + bool TestClass##id::ms_DoRecall = false; \
22.1733 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.1734 +
22.1735 +#define THGM_SETUP_PI5(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags, p3_type, p3_passtype, p3_flags, p4_type, p4_passtype, p4_flags, p5_type, p5_passtype, p5_flags) \
22.1736 + void setuppi_##id() \
22.1737 + { \
22.1738 + \
22.1739 + protoinfo_##id.AddParam(sizeof(p1_type), p1_passtype, p1_flags, \
22.1740 + (p1_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::NormalConstructor) : NULL, \
22.1741 + (p1_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::CopyConstructor) : NULL, \
22.1742 + (p1_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::Destructor) : NULL, \
22.1743 + (p1_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::AssignOp) : NULL \
22.1744 + ); \
22.1745 + \
22.1746 + protoinfo_##id.AddParam(sizeof(p2_type), p2_passtype, p2_flags, \
22.1747 + (p2_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::NormalConstructor) : NULL, \
22.1748 + (p2_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::CopyConstructor) : NULL, \
22.1749 + (p2_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::Destructor) : NULL, \
22.1750 + (p2_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::AssignOp) : NULL \
22.1751 + ); \
22.1752 + \
22.1753 + protoinfo_##id.AddParam(sizeof(p3_type), p3_passtype, p3_flags, \
22.1754 + (p3_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::NormalConstructor) : NULL, \
22.1755 + (p3_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::CopyConstructor) : NULL, \
22.1756 + (p3_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::Destructor) : NULL, \
22.1757 + (p3_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::AssignOp) : NULL \
22.1758 + ); \
22.1759 + \
22.1760 + protoinfo_##id.AddParam(sizeof(p4_type), p4_passtype, p4_flags, \
22.1761 + (p4_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::NormalConstructor) : NULL, \
22.1762 + (p4_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::CopyConstructor) : NULL, \
22.1763 + (p4_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::Destructor) : NULL, \
22.1764 + (p4_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::AssignOp) : NULL \
22.1765 + ); \
22.1766 + \
22.1767 + protoinfo_##id.AddParam(sizeof(p5_type), p5_passtype, p5_flags, \
22.1768 + (p5_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::NormalConstructor) : NULL, \
22.1769 + (p5_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::CopyConstructor) : NULL, \
22.1770 + (p5_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::Destructor) : NULL, \
22.1771 + (p5_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::AssignOp) : NULL \
22.1772 + ); \
22.1773 + \
22.1774 + }
22.1775 +
22.1776 +
22.1777 +
22.1778 +#define THGM_MAKE_TEST6_void(id, param1, param2, param3, param4, param5, param6) \
22.1779 + struct TestClass##id; \
22.1780 + typedef ParamState6<0, param1, param2, param3, param4, param5, param6 > ParamState_m##id; \
22.1781 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1782 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1783 + \
22.1784 + struct TestClass##id \
22.1785 + { \
22.1786 + static bool ms_DoRecall; \
22.1787 + \
22.1788 + virtual void Func(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
22.1789 + { \
22.1790 + g_Inside_LeafFunc = true; \
22.1791 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
22.1792 + g_Inside_LeafFunc = false; \
22.1793 + } \
22.1794 + \
22.1795 + struct Delegate : public MyDelegate \
22.1796 + { \
22.1797 + int m_DelegNumber; \
22.1798 + Delegate(int num) : m_DelegNumber(num) { } \
22.1799 + \
22.1800 + virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
22.1801 + { \
22.1802 + g_Inside_LeafFunc = true; \
22.1803 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
22.1804 + g_Inside_LeafFunc = false; \
22.1805 + if (ms_DoRecall) \
22.1806 + { \
22.1807 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5);Increment<StripRef< param6 >::type>::Incr(p6); \
22.1808 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3, p4, p5, p6)); \
22.1809 + } \
22.1810 + else \
22.1811 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.1812 + } \
22.1813 + }; \
22.1814 + }; \
22.1815 + \
22.1816 + bool TestClass##id::ms_DoRecall = false; \
22.1817 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.1818 +
22.1819 +
22.1820 +#define THGM_MAKE_TEST6(id, ret_type, param1, param2, param3, param4, param5, param6) \
22.1821 + struct TestClass##id; \
22.1822 + typedef ret_type RetType##id; \
22.1823 + typedef ParamState6<0, param1, param2, param3, param4, param5, param6 > ParamState_m##id; \
22.1824 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1825 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1826 + \
22.1827 + struct TestClass##id \
22.1828 + { \
22.1829 + static bool ms_DoRecall; \
22.1830 + \
22.1831 + virtual ret_type Func(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
22.1832 + { \
22.1833 + g_Inside_LeafFunc = true; \
22.1834 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
22.1835 + g_Inside_LeafFunc = false; \
22.1836 + \
22.1837 + return MakeRet< ret_type >::Do(0); \
22.1838 + } \
22.1839 + \
22.1840 + struct Delegate : public MyDelegate \
22.1841 + { \
22.1842 + int m_DelegNumber; \
22.1843 + Delegate(int num) : m_DelegNumber(num) { } \
22.1844 + \
22.1845 + virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6) \
22.1846 + { \
22.1847 + g_Inside_LeafFunc = true; \
22.1848 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, p6))); \
22.1849 + g_Inside_LeafFunc = false; \
22.1850 + if (ms_DoRecall) \
22.1851 + { \
22.1852 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5);Increment<StripRef< param6 >::type>::Incr(p6); \
22.1853 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (p1, p2, p3, p4, p5, p6)); \
22.1854 + } \
22.1855 + else \
22.1856 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.1857 + } \
22.1858 + }; \
22.1859 + }; \
22.1860 + \
22.1861 + bool TestClass##id::ms_DoRecall = false; \
22.1862 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
22.1863 +
22.1864 +#define THGM_MAKE_TEST6_vafmt_void(id, param1, param2, param3, param4, param5, param6) \
22.1865 + struct TestClass##id; \
22.1866 + typedef ParamState7<0, param1, param2, param3, param4, param5, param6, std::string > ParamState_m##id; \
22.1867 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1868 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1869 + \
22.1870 + struct TestClass##id \
22.1871 + { \
22.1872 + static bool ms_DoRecall; \
22.1873 + \
22.1874 + virtual void Func(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6, const char *fmt, ...) \
22.1875 + { \
22.1876 + g_Inside_LeafFunc = true; \
22.1877 + \
22.1878 + char buf[9999]; \
22.1879 + va_list ap; \
22.1880 + va_start(ap, fmt); \
22.1881 + vsnprintf(buf, 9998, fmt, ap); \
22.1882 + buf[9998] = 0; \
22.1883 + va_end(ap); \
22.1884 + \
22.1885 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, p5, p6, std::string(buf)))); \
22.1886 + g_Inside_LeafFunc = false; \
22.1887 + } \
22.1888 + \
22.1889 + struct Delegate : public MyDelegate \
22.1890 + { \
22.1891 + int m_DelegNumber; \
22.1892 + Delegate(int num) : m_DelegNumber(num) { } \
22.1893 + \
22.1894 + virtual void Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6, const char *buf) \
22.1895 + { \
22.1896 + g_Inside_LeafFunc = true; \
22.1897 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, p6, buf))); \
22.1898 + g_Inside_LeafFunc = false; \
22.1899 + if (ms_DoRecall) \
22.1900 + { \
22.1901 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5);Increment<StripRef< param6 >::type>::Incr(p6); \
22.1902 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (p1, p2, p3, p4, p5, p6, "%s!", buf)); \
22.1903 + } \
22.1904 + else \
22.1905 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
22.1906 + } \
22.1907 + }; \
22.1908 + }; \
22.1909 + \
22.1910 + bool TestClass##id::ms_DoRecall = false; \
22.1911 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.1912 +
22.1913 +#define THGM_MAKE_TEST6_vafmt(id, ret_type, param1, param2, param3, param4, param5, param6) \
22.1914 + struct TestClass##id; \
22.1915 + typedef ret_type RetType##id; \
22.1916 + typedef ParamState7<0, param1, param2, param3, param4, param5, param6, std::string > ParamState_m##id; \
22.1917 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
22.1918 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
22.1919 + \
22.1920 + struct TestClass##id \
22.1921 + { \
22.1922 + static bool ms_DoRecall; \
22.1923 + \
22.1924 + virtual ret_type Func(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6, const char *fmt, ...) \
22.1925 + { \
22.1926 + g_Inside_LeafFunc = true; \
22.1927 + \
22.1928 + char buf[9999]; \
22.1929 + va_list ap; \
22.1930 + va_start(ap, fmt); \
22.1931 + vsnprintf(buf, 9998, fmt, ap); \
22.1932 + buf[9998] = 0; \
22.1933 + va_end(ap); \
22.1934 + \
22.1935 + ADD_STATE(State_Func##id(this, ParamState_m##id(p1, p2, p3, p4, p5, p6, std::string(buf)))); \
22.1936 + \
22.1937 + return MakeRet< ret_type >::Do(0); \
22.1938 + } \
22.1939 + \
22.1940 + struct Delegate : public MyDelegate \
22.1941 + { \
22.1942 + int m_DelegNumber; \
22.1943 + Delegate(int num) : m_DelegNumber(num) { } \
22.1944 + \
22.1945 + virtual ret_type Call(param1 p1, param2 p2, param3 p3, param4 p4, param5 p5, param6 p6, const char *buf) \
22.1946 + { \
22.1947 + g_Inside_LeafFunc = true; \
22.1948 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(p1, p2, p3, p4, p5, p6, buf))); \
22.1949 + g_Inside_LeafFunc = false; \
22.1950 + if (ms_DoRecall) \
22.1951 + { \
22.1952 + Increment<StripRef< param1 >::type>::Incr(p1);Increment<StripRef< param2 >::type>::Incr(p2);Increment<StripRef< param3 >::type>::Incr(p3);Increment<StripRef< param4 >::type>::Incr(p4);Increment<StripRef< param5 >::type>::Incr(p5);Increment<StripRef< param6 >::type>::Incr(p6); \
22.1953 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (p1, p2, p3, p4, p5, p6, "%s!", buf)); \
22.1954 + } \
22.1955 + else \
22.1956 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
22.1957 + } \
22.1958 + }; \
22.1959 + }; \
22.1960 + \
22.1961 + bool TestClass##id::ms_DoRecall = false; \
22.1962 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
22.1963 +
22.1964 +#define THGM_SETUP_PI6(id, p1_type, p1_passtype, p1_flags, p2_type, p2_passtype, p2_flags, p3_type, p3_passtype, p3_flags, p4_type, p4_passtype, p4_flags, p5_type, p5_passtype, p5_flags, p6_type, p6_passtype, p6_flags) \
22.1965 + void setuppi_##id() \
22.1966 + { \
22.1967 + \
22.1968 + protoinfo_##id.AddParam(sizeof(p1_type), p1_passtype, p1_flags, \
22.1969 + (p1_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::NormalConstructor) : NULL, \
22.1970 + (p1_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::CopyConstructor) : NULL, \
22.1971 + (p1_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::Destructor) : NULL, \
22.1972 + (p1_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p1_type >::type>::AssignOp) : NULL \
22.1973 + ); \
22.1974 + \
22.1975 + protoinfo_##id.AddParam(sizeof(p2_type), p2_passtype, p2_flags, \
22.1976 + (p2_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::NormalConstructor) : NULL, \
22.1977 + (p2_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::CopyConstructor) : NULL, \
22.1978 + (p2_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::Destructor) : NULL, \
22.1979 + (p2_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p2_type >::type>::AssignOp) : NULL \
22.1980 + ); \
22.1981 + \
22.1982 + protoinfo_##id.AddParam(sizeof(p3_type), p3_passtype, p3_flags, \
22.1983 + (p3_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::NormalConstructor) : NULL, \
22.1984 + (p3_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::CopyConstructor) : NULL, \
22.1985 + (p3_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::Destructor) : NULL, \
22.1986 + (p3_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p3_type >::type>::AssignOp) : NULL \
22.1987 + ); \
22.1988 + \
22.1989 + protoinfo_##id.AddParam(sizeof(p4_type), p4_passtype, p4_flags, \
22.1990 + (p4_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::NormalConstructor) : NULL, \
22.1991 + (p4_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::CopyConstructor) : NULL, \
22.1992 + (p4_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::Destructor) : NULL, \
22.1993 + (p4_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p4_type >::type>::AssignOp) : NULL \
22.1994 + ); \
22.1995 + \
22.1996 + protoinfo_##id.AddParam(sizeof(p5_type), p5_passtype, p5_flags, \
22.1997 + (p5_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::NormalConstructor) : NULL, \
22.1998 + (p5_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::CopyConstructor) : NULL, \
22.1999 + (p5_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::Destructor) : NULL, \
22.2000 + (p5_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p5_type >::type>::AssignOp) : NULL \
22.2001 + ); \
22.2002 + \
22.2003 + protoinfo_##id.AddParam(sizeof(p6_type), p6_passtype, p6_flags, \
22.2004 + (p6_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p6_type >::type>::NormalConstructor) : NULL, \
22.2005 + (p6_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p6_type >::type>::CopyConstructor) : NULL, \
22.2006 + (p6_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p6_type >::type>::Destructor) : NULL, \
22.2007 + (p6_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p6_type >::type>::AssignOp) : NULL \
22.2008 + ); \
22.2009 + \
22.2010 + }
22.2011 +
22.2012 +
22.2013 +
22.2014 +#define THGM_SETUP_RI(id, ret_type, ret_passtype, ret_flags) \
22.2015 + void setupri_##id() \
22.2016 + { \
22.2017 + protoinfo_##id.SetReturnType(sizeof(ret_type), ret_passtype, ret_flags, \
22.2018 + (ret_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::NormalConstructor) : NULL, \
22.2019 + (ret_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::CopyConstructor) : NULL, \
22.2020 + (ret_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::Destructor) : NULL, \
22.2021 + (ret_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::AssignOp) : NULL \
22.2022 + ); \
22.2023 + }
22.2024 +
22.2025 +#define THGM_ADD_HOOK(id, num) \
22.2026 + CAT4(hook, num, _, id) = g_SHPtr->AddHook(g_PLID, SourceHook::ISourceHook::Hook_Normal, reinterpret_cast<void*>(pTest##id), \
22.2027 + 0, myhookman##id, PtrBufPtr(new TestClass##id::Delegate(num)), num >= 3);
22.2028 +
22.2029 +#define THGM_REMOVE_HOOK(id, num) \
22.2030 + g_SHPtr->RemoveHookByID(CAT4(hook, num, _, id));
22.2031 +
22.2032 +#define THGM_CALLS_void(id, call_params) \
22.2033 + pTest##id->Func call_params; \
22.2034 + SH_CALL(pTest##id, &TestClass##id::Func) call_params;
22.2035 +
22.2036 +#define THGM_DO_TEST_void(id, call_params) \
22.2037 + setuppi_##id(); \
22.2038 + SourceHook::HookManagerPubFunc myhookman##id = g_HMAGPtr->MakeHookMan(protoinfo_##id, 0, 0); \
22.2039 + CAutoReleaseHookMan arhm_##id(myhookman##id); \
22.2040 + int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
22.2041 + \
22.2042 + TestClass##id::ms_DoRecall = false; \
22.2043 + TestClass##id *pTest##id = new TestClass##id; \
22.2044 + CAutoPtrDestruction<TestClass##id> apd##id(pTest##id); \
22.2045 + \
22.2046 + /* no hooks - no hooks */ \
22.2047 + PtrBuf_Clear(); \
22.2048 + THGM_CALLS_void(id, call_params); \
22.2049 + CHECK_STATES((&g_States, \
22.2050 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2051 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2052 + NULL), "Test" #id " Part1"); \
22.2053 + \
22.2054 + /* hook1 - hook3 */ \
22.2055 + PtrBuf_Clear(); \
22.2056 + THGM_ADD_HOOK(id, 1); \
22.2057 + THGM_ADD_HOOK(id, 3); \
22.2058 + THGM_CALLS_void(id, call_params); \
22.2059 + CHECK_STATES((&g_States, \
22.2060 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
22.2061 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2062 + new State_Deleg_##id(3, pTest##id, 1, ParamState_m##id call_params), \
22.2063 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2064 + NULL), "Test" #id " Part4"); \
22.2065 + THGM_REMOVE_HOOK(id, 1); \
22.2066 + THGM_REMOVE_HOOK(id, 3); \
22.2067 + \
22.2068 + /* hook1, hook2 - hook3 */ \
22.2069 + PtrBuf_Clear(); \
22.2070 + THGM_ADD_HOOK(id, 1); \
22.2071 + THGM_ADD_HOOK(id, 2); \
22.2072 + THGM_ADD_HOOK(id, 3); \
22.2073 + THGM_CALLS_void(id, call_params); \
22.2074 + CHECK_STATES((&g_States, \
22.2075 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
22.2076 + new State_Deleg_##id(2, pTest##id, 1, ParamState_m##id call_params), \
22.2077 + new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params), \
22.2078 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2079 + NULL), "Test" #id " Part5"); \
22.2080 + /* hook1, hook2 - hook3, hook4 */ \
22.2081 + THGM_ADD_HOOK(id, 4); \
22.2082 + THGM_CALLS_void(id, call_params); \
22.2083 + CHECK_STATES((&g_States, \
22.2084 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
22.2085 + new State_Deleg_##id(2, pTest##id, 1, ParamState_m##id call_params), \
22.2086 + new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params), \
22.2087 + new State_Deleg_##id(4, pTest##id, 3, ParamState_m##id call_params), \
22.2088 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2089 + NULL), "Test" #id " Part6"); \
22.2090 + \
22.2091 + /* hook1 - hook3, hook4, with recalls! */ \
22.2092 + \
22.2093 + TestClass##id::ms_DoRecall = true; \
22.2094 + THGM_REMOVE_HOOK(id, 2); \
22.2095 + THGM_CALLS_void(id, call_params); \
22.2096 + CHECK_STATES((&g_States, \
22.2097 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params(0)), \
22.2098 + new State_Func##id(pTest##id, ParamState_m##id call_params(1)), \
22.2099 + new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params(1)), \
22.2100 + new State_Deleg_##id(4, pTest##id, 3, ParamState_m##id call_params(2)), \
22.2101 + /* sh_call one */ \
22.2102 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2103 + NULL), "Test" #id " Part7"); \
22.2104 + THGM_REMOVE_HOOK(id, 1); \
22.2105 + THGM_REMOVE_HOOK(id, 3); \
22.2106 + THGM_REMOVE_HOOK(id, 4);
22.2107 +
22.2108 +template<class T>
22.2109 +T ComparableRef(T x)
22.2110 +{
22.2111 + return x;
22.2112 +}
22.2113 +
22.2114 +template <class T>
22.2115 +T* ComparableRef(T& x)
22.2116 +{
22.2117 + return &x;
22.2118 +}
22.2119 +
22.2120 +#define THGM_CALLS(id, call_params, exp_ret_norm, exp_ret_shcall, err) \
22.2121 + CHECK_COND(ComparableRef<RetType##id>(pTest##id->Func call_params) == ComparableRef<RetType##id>(MakeRet< RetType##id >::Do(exp_ret_norm)), err " /retcallnorm"); \
22.2122 + CHECK_COND(ComparableRef<RetType##id>(SH_CALL(pTest##id, &TestClass##id::Func) call_params) == ComparableRef<RetType##id>(MakeRet< RetType##id >::Do(exp_ret_shcall)), err " /retcallshcall");
22.2123 +
22.2124 +#define THGM_DO_TEST(id, call_params) \
22.2125 + setuppi_##id(); \
22.2126 + setupri_##id(); \
22.2127 + SourceHook::HookManagerPubFunc myhookman##id = g_HMAGPtr->MakeHookMan(protoinfo_##id, 0, 0); \
22.2128 + CAutoReleaseHookMan arhm_##id(myhookman##id); \
22.2129 + int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
22.2130 + \
22.2131 + TestClass##id::ms_DoRecall = false; \
22.2132 + TestClass##id *pTest##id = new TestClass##id; \
22.2133 + CAutoPtrDestruction<TestClass##id> apd##id(pTest##id); \
22.2134 + \
22.2135 + /* no hooks - no hooks */ \
22.2136 + PtrBuf_Clear(); \
22.2137 + THGM_CALLS(id, call_params, 0, 0, "Part1"); \
22.2138 + CHECK_STATES((&g_States, \
22.2139 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2140 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2141 + NULL), "Test" #id " Part1"); \
22.2142 + \
22.2143 + /* hook1 - hook3 */ \
22.2144 + PtrBuf_Clear(); \
22.2145 + THGM_ADD_HOOK(id, 1); \
22.2146 + THGM_ADD_HOOK(id, 3); \
22.2147 + THGM_CALLS(id, call_params, 0, 0, "Part4"); \
22.2148 + CHECK_STATES((&g_States, \
22.2149 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
22.2150 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2151 + new State_Deleg_##id(3, pTest##id, 1, ParamState_m##id call_params), \
22.2152 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2153 + NULL), "Test" #id " Part4"); \
22.2154 + THGM_REMOVE_HOOK(id, 1); \
22.2155 + THGM_REMOVE_HOOK(id, 3); \
22.2156 + \
22.2157 + /* hook1, hook2 - hook3 */ \
22.2158 + PtrBuf_Clear(); \
22.2159 + THGM_ADD_HOOK(id, 1); \
22.2160 + THGM_ADD_HOOK(id, 2); \
22.2161 + THGM_ADD_HOOK(id, 3); \
22.2162 + THGM_CALLS(id, call_params, 2, 0, "Part5"); \
22.2163 + CHECK_STATES((&g_States, \
22.2164 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
22.2165 + new State_Deleg_##id(2, pTest##id, 1, ParamState_m##id call_params), \
22.2166 + new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params), \
22.2167 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2168 + NULL), "Test" #id " Part5"); \
22.2169 + /* hook1, hook2 - hook3, hook4 */ \
22.2170 + THGM_ADD_HOOK(id, 4); \
22.2171 + THGM_CALLS(id, call_params, 4, 0, "Part6"); \
22.2172 + CHECK_STATES((&g_States, \
22.2173 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
22.2174 + new State_Deleg_##id(2, pTest##id, 1, ParamState_m##id call_params), \
22.2175 + new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params), \
22.2176 + new State_Deleg_##id(4, pTest##id, 3, ParamState_m##id call_params), \
22.2177 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2178 + NULL), "Test" #id " Part6"); \
22.2179 + \
22.2180 + /* hook1 - hook3, hook4, with recalls! */ \
22.2181 + \
22.2182 + TestClass##id::ms_DoRecall = true; \
22.2183 + THGM_REMOVE_HOOK(id, 2); \
22.2184 + THGM_CALLS(id, call_params, 4, 0, "Part7"); \
22.2185 + CHECK_STATES((&g_States, \
22.2186 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params(0)), \
22.2187 + new State_Func##id(pTest##id, ParamState_m##id call_params(1)), \
22.2188 + new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params(1)), \
22.2189 + new State_Deleg_##id(4, pTest##id, 3, ParamState_m##id call_params(2)), \
22.2190 + /* sh_call one */ \
22.2191 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
22.2192 + NULL), "Test" #id " Part7"); \
22.2193 + THGM_REMOVE_HOOK(id, 1); \
22.2194 + THGM_REMOVE_HOOK(id, 3); \
22.2195 + THGM_REMOVE_HOOK(id, 4);
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
23.2 +++ b/sourcehook/test/testhookmangen.hxx Mon Nov 26 14:03:25 2007 +0000
23.3 @@ -0,0 +1,584 @@
23.4 +struct CAutoReleaseHookMan
23.5 +{
23.6 + SourceHook::HookManagerPubFunc m_Ptr;
23.7 + CAutoReleaseHookMan(SourceHook::HookManagerPubFunc ptr) : m_Ptr(ptr)
23.8 + {
23.9 + }
23.10 + ~CAutoReleaseHookMan()
23.11 + {
23.12 + g_HMAGPtr->ReleaseHookMan(m_Ptr);
23.13 + }
23.14 +};
23.15 +
23.16 +// Strip &
23.17 +template <class T> struct StripRef
23.18 +{
23.19 + typedef T type;
23.20 +};
23.21 +
23.22 +template <class T> struct StripRef<T&>
23.23 +{
23.24 + typedef T type;
23.25 +};
23.26 +
23.27 +// Address of constructor/destructor
23.28 +// (using wrappers)
23.29 +template <class T>
23.30 +class Ctor_Thunk
23.31 +{
23.32 +public:
23.33 + void NormalConstructor()
23.34 + {
23.35 + new(this) T;
23.36 + }
23.37 +
23.38 + void CopyConstructor(const T &other)
23.39 + {
23.40 + new(this) T(other);
23.41 + }
23.42 +
23.43 + void Destructor()
23.44 + {
23.45 + reinterpret_cast<T*>(this)->~T();
23.46 + }
23.47 +
23.48 + const T& AssignOp(const T &other)
23.49 + {
23.50 + return (*reinterpret_cast<T*>(this) = other);
23.51 + }
23.52 +};
23.53 +
23.54 +
23.55 +template <class T>
23.56 +void *FindFuncAddr(T mfp)
23.57 +{
23.58 + union
23.59 + {
23.60 + T a;
23.61 + void *b;
23.62 + } u;
23.63 + u.a = mfp;
23.64 + return u.b;
23.65 +}
23.66 +
23.67 +// Reference carrier
23.68 +template <class T> struct MyRefCarrier
23.69 +{
23.70 + typedef T type;
23.71 +};
23.72 +
23.73 +template <class T> struct MyRefCarrier<T&>
23.74 +{
23.75 + class type
23.76 + {
23.77 + T *m_StoredRef;
23.78 + public:
23.79 + type() : m_StoredRef(NULL)
23.80 + {
23.81 + }
23.82 + type(T& ref) : m_StoredRef(&ref)
23.83 + {
23.84 + }
23.85 +
23.86 + T& operator= (T& ref)
23.87 + {
23.88 + m_StoredRef = &ref;
23.89 + return ref;
23.90 + }
23.91 +
23.92 + operator T& () const
23.93 + {
23.94 + return *m_StoredRef;
23.95 + }
23.96 +
23.97 + bool operator== (const typename MyRefCarrier<T&>::type &other)
23.98 + {
23.99 + return m_StoredRef == other.m_StoredRef;
23.100 + }
23.101 +
23.102 + friend std::ostream& operator <<(std::ostream &os,const typename MyRefCarrier<T&>::type &obj)
23.103 + {
23.104 + os << *obj.m_StoredRef;
23.105 + return os;
23.106 + }
23.107 + };
23.108 +};
23.109 +
23.110 +#if SH_COMP==SH_COMP_GCC
23.111 +#define NO_OPTIMIZE __attribute__((noinline))
23.112 +#else
23.113 +#define NO_OPTIMIZE
23.114 +#endif
23.115 +
23.116 +// Return value maker
23.117 +template <class T>
23.118 +struct MakeRet
23.119 +{
23.120 + static T Do(int a)
23.121 + {
23.122 + return a;
23.123 + }
23.124 +};
23.125 +
23.126 +template <int SIZE>
23.127 +struct MakeRet< POD<SIZE> >
23.128 +{
23.129 + static POD<SIZE> Do(int a)
23.130 + {
23.131 + POD<SIZE> x;
23.132 + memset(reinterpret_cast<void*>(x.x), a, SIZE);
23.133 + return x;
23.134 + }
23.135 +};
23.136 +
23.137 +// Stores parameter status
23.138 +template <class T>
23.139 +bool EqualToMyFmtString(T sth)
23.140 +{
23.141 + return false;
23.142 +}
23.143 +
23.144 +bool EqualToMyFmtString(std::string &sth)
23.145 +{
23.146 + if (sth == "Hello %s%d%s")
23.147 + sth = "Hello BA1L!";
23.148 + return true;
23.149 +}
23.150 +
23.151 +
23.152 +@[$1,0,$a:
23.153 +
23.154 +template<int dummy@[$2,1,$1:, class p$2@]>
23.155 +struct ParamState$1
23.156 +{
23.157 + @[$2,1,$1:typename MyRefCarrier<p$2>::type m_$2; @]
23.158 +
23.159 + bool operator==(const ParamState$1<dummy@[$2,1,$1:, p$2@]> &other)
23.160 + {
23.161 + return true
23.162 + @[$2,1,$1: && m_$1 == other.m_$1@]
23.163 + ;
23.164 + }
23.165 + ParamState$1(@[$2,1,$1:p$2 a$2, @]...) @[$1!=0::@] @[$2,1,$1|, :m_$2(a$2)@]
23.166 + {
23.167 + @[$2,1,$1:
23.168 + EqualToMyFmtString(m_$2);
23.169 + @]
23.170 + }
23.171 +
23.172 + ParamState$1<dummy@[$2,1,$1:, p$2@]> & operator() (int incrsteps)
23.173 + {
23.174 + @[$1!=0:int i;@]
23.175 + @[$2,1,$1:
23.176 + for (i = 0; i < incrsteps; ++i)
23.177 + Increment<typename StripRef< p$2 >::type >::Incr(m_$2);
23.178 + @]
23.179 +
23.180 + return *this;
23.181 + }
23.182 +};
23.183 +
23.184 +@[$1!=0:template<@[$2,1,$1|, :class p$2@]>@]
23.185 +std::ostream& operator <<(std::ostream &os,const ParamState$1<0@[$2,1,$1:, p$2@]> &obj)
23.186 +{
23.187 + @[$1!=0:os@] @[$2,1,$1:<< obj.m_$2@];
23.188 + return os;
23.189 +}
23.190 +
23.191 +@]
23.192 +
23.193 +#define CAT2(a, b) a##b
23.194 +#define CAT3(a, b, c) a##b##c
23.195 +#define CAT4(a, b, c, d) a##b##c##d
23.196 +
23.197 +// hook1: pre ignore
23.198 +// hook2: pre supercede
23.199 +// hook3: post ignore
23.200 +// hook4: post supercede
23.201 +
23.202 +
23.203 +@[$1,0,$a:
23.204 +
23.205 +#define THGM_MAKE_TEST$1_void(id@[$2,1,$1:, param$2@]) \
23.206 + struct TestClass##id; \
23.207 + typedef ParamState$1<0@[$2,1,$1:, param$2@] > ParamState_m##id; \
23.208 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
23.209 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
23.210 + \
23.211 + struct TestClass##id \
23.212 + { \
23.213 + static bool ms_DoRecall; \
23.214 + \
23.215 + virtual void Func(@[$2,1,$1|, :param$2 p$2@]) \
23.216 + { \
23.217 + g_Inside_LeafFunc = true; \
23.218 + ADD_STATE(State_Func##id(this, ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
23.219 + g_Inside_LeafFunc = false; \
23.220 + } \
23.221 + \
23.222 + struct Delegate : public MyDelegate \
23.223 + { \
23.224 + int m_DelegNumber; \
23.225 + Delegate(int num) : m_DelegNumber(num) { } \
23.226 + \
23.227 + virtual void Call(@[$2,1,$1|, :param$2 p$2@]) \
23.228 + { \
23.229 + g_Inside_LeafFunc = true; \
23.230 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
23.231 + g_Inside_LeafFunc = false; \
23.232 + if (ms_DoRecall) \
23.233 + { \
23.234 + @[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
23.235 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (@[$2,1,$1|, :p$2@])); \
23.236 + } \
23.237 + else \
23.238 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
23.239 + } \
23.240 + }; \
23.241 + }; \
23.242 + \
23.243 + bool TestClass##id::ms_DoRecall = false; \
23.244 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
23.245 +
23.246 +
23.247 +#define THGM_MAKE_TEST$1(id, ret_type@[$2,1,$1:, param$2@]) \
23.248 + struct TestClass##id; \
23.249 + typedef ret_type RetType##id; \
23.250 + typedef ParamState$1<0@[$2,1,$1:, param$2@] > ParamState_m##id; \
23.251 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
23.252 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
23.253 + \
23.254 + struct TestClass##id \
23.255 + { \
23.256 + static bool ms_DoRecall; \
23.257 + \
23.258 + virtual ret_type Func(@[$2,1,$1|, :param$2 p$2@]) \
23.259 + { \
23.260 + g_Inside_LeafFunc = true; \
23.261 + ADD_STATE(State_Func##id(this, ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
23.262 + g_Inside_LeafFunc = false; \
23.263 + \
23.264 + return MakeRet< ret_type >::Do(0); \
23.265 + } \
23.266 + \
23.267 + struct Delegate : public MyDelegate \
23.268 + { \
23.269 + int m_DelegNumber; \
23.270 + Delegate(int num) : m_DelegNumber(num) { } \
23.271 + \
23.272 + virtual ret_type Call(@[$2,1,$1|, :param$2 p$2@]) \
23.273 + { \
23.274 + g_Inside_LeafFunc = true; \
23.275 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1|, :p$2@]))); \
23.276 + g_Inside_LeafFunc = false; \
23.277 + if (ms_DoRecall) \
23.278 + { \
23.279 + @[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
23.280 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (@[$2,1,$1|, :p$2@])); \
23.281 + } \
23.282 + else \
23.283 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
23.284 + } \
23.285 + }; \
23.286 + }; \
23.287 + \
23.288 + bool TestClass##id::ms_DoRecall = false; \
23.289 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall);
23.290 +
23.291 +#define THGM_MAKE_TEST$1_vafmt_void(id@[$2,1,$1:, param$2@]) \
23.292 + struct TestClass##id; \
23.293 + typedef ParamState@($1+1)<0@[$2,1,$1:, param$2@], std::string > ParamState_m##id; \
23.294 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
23.295 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
23.296 + \
23.297 + struct TestClass##id \
23.298 + { \
23.299 + static bool ms_DoRecall; \
23.300 + \
23.301 + virtual void Func(@[$2,1,$1:param$2 p$2, @]const char *fmt, ...) \
23.302 + { \
23.303 + g_Inside_LeafFunc = true; \
23.304 + \
23.305 + char buf[9999]; \
23.306 + va_list ap; \
23.307 + va_start(ap, fmt); \
23.308 + vsnprintf(buf, 9998, fmt, ap); \
23.309 + buf[9998] = 0; \
23.310 + va_end(ap); \
23.311 + \
23.312 + ADD_STATE(State_Func##id(this, ParamState_m##id(@[$2,1,$1:p$2, @]std::string(buf)))); \
23.313 + g_Inside_LeafFunc = false; \
23.314 + } \
23.315 + \
23.316 + struct Delegate : public MyDelegate \
23.317 + { \
23.318 + int m_DelegNumber; \
23.319 + Delegate(int num) : m_DelegNumber(num) { } \
23.320 + \
23.321 + virtual void Call(@[$2,1,$1:param$2 p$2, @]const char *buf) \
23.322 + { \
23.323 + g_Inside_LeafFunc = true; \
23.324 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1:p$2, @]buf))); \
23.325 + g_Inside_LeafFunc = false; \
23.326 + if (ms_DoRecall) \
23.327 + { \
23.328 + @[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
23.329 + RETURN_META_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, &TestClass##id::Func, (@[$2,1,$1:p$2, @]"%s!", buf)); \
23.330 + } \
23.331 + else \
23.332 + RETURN_META((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE); \
23.333 + } \
23.334 + }; \
23.335 + }; \
23.336 + \
23.337 + bool TestClass##id::ms_DoRecall = false; \
23.338 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
23.339 +
23.340 +#define THGM_MAKE_TEST$1_vafmt(id, ret_type@[$2,1,$1:, param$2@]) \
23.341 + struct TestClass##id; \
23.342 + typedef ret_type RetType##id; \
23.343 + typedef ParamState@($1+1)<0@[$2,1,$1:, param$2@], std::string > ParamState_m##id; \
23.344 + MAKE_STATE_2(State_Func##id, TestClass##id* /*thisptr*/, ParamState_m##id ); \
23.345 + MAKE_STATE_4(State_Deleg_##id, int /*delegnumber*/, TestClass##id* /*ifptr*/, int /*deleg thisptr*/, ParamState_m##id ); \
23.346 + \
23.347 + struct TestClass##id \
23.348 + { \
23.349 + static bool ms_DoRecall; \
23.350 + \
23.351 + virtual ret_type Func(@[$2,1,$1:param$2 p$2, @]const char *fmt, ...) \
23.352 + { \
23.353 + g_Inside_LeafFunc = true; \
23.354 + \
23.355 + char buf[9999]; \
23.356 + va_list ap; \
23.357 + va_start(ap, fmt); \
23.358 + vsnprintf(buf, 9998, fmt, ap); \
23.359 + buf[9998] = 0; \
23.360 + va_end(ap); \
23.361 + \
23.362 + ADD_STATE(State_Func##id(this, ParamState_m##id(@[$2,1,$1:p$2, @]std::string(buf)))); \
23.363 + \
23.364 + return MakeRet< ret_type >::Do(0); \
23.365 + } \
23.366 + \
23.367 + struct Delegate : public MyDelegate \
23.368 + { \
23.369 + int m_DelegNumber; \
23.370 + Delegate(int num) : m_DelegNumber(num) { } \
23.371 + \
23.372 + virtual ret_type Call(@[$2,1,$1:param$2 p$2, @]const char *buf) \
23.373 + { \
23.374 + g_Inside_LeafFunc = true; \
23.375 + ADD_STATE(State_Deleg_##id(m_DelegNumber, META_IFACEPTR(TestClass##id), PtrBuf(this), ParamState_m##id(@[$2,1,$1:p$2, @]buf))); \
23.376 + g_Inside_LeafFunc = false; \
23.377 + if (ms_DoRecall) \
23.378 + { \
23.379 + @[$2,1,$1:Increment<StripRef< param$2 >::type>::Incr(p$2);@] \
23.380 + RETURN_META_VALUE_NEWPARAMS((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber), &TestClass##id::Func, (@[$2,1,$1:p$2, @]"%s!", buf)); \
23.381 + } \
23.382 + else \
23.383 + RETURN_META_VALUE((m_DelegNumber & 1) ? MRES_IGNORED : MRES_SUPERCEDE, MakeRet< ret_type >::Do(m_DelegNumber)); \
23.384 + } \
23.385 + }; \
23.386 + }; \
23.387 + \
23.388 + bool TestClass##id::ms_DoRecall = false; \
23.389 + SourceHook::CProtoInfoBuilder protoinfo_##id(SourceHook::ProtoInfo::CallConv_ThisCall | SourceHook::ProtoInfo::CallConv_HasVafmt);
23.390 +
23.391 +#define THGM_SETUP_PI$1(id@[$2,1,$1:, p$2_type, p$2_passtype, p$2_flags@]) \
23.392 + void setuppi_##id() \
23.393 + { \
23.394 + @[$2,1,$1: \
23.395 + protoinfo_##id.AddParam(sizeof(p$2_type), p$2_passtype, p$2_flags, \
23.396 + (p$2_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p$2_type >::type>::NormalConstructor) : NULL, \
23.397 + (p$2_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p$2_type >::type>::CopyConstructor) : NULL, \
23.398 + (p$2_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< p$2_type >::type>::Destructor) : NULL, \
23.399 + (p$2_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< p$2_type >::type>::AssignOp) : NULL \
23.400 + ); \
23.401 + @] \
23.402 + }
23.403 +
23.404 +@]
23.405 +
23.406 +#define THGM_SETUP_RI(id, ret_type, ret_passtype, ret_flags) \
23.407 + void setupri_##id() \
23.408 + { \
23.409 + protoinfo_##id.SetReturnType(sizeof(ret_type), ret_passtype, ret_flags, \
23.410 + (ret_flags & SourceHook::PassInfo::PassFlag_OCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::NormalConstructor) : NULL, \
23.411 + (ret_flags & SourceHook::PassInfo::PassFlag_CCtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::CopyConstructor) : NULL, \
23.412 + (ret_flags & SourceHook::PassInfo::PassFlag_ODtor) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::Destructor) : NULL, \
23.413 + (ret_flags & SourceHook::PassInfo::PassFlag_AssignOp) ? FindFuncAddr(&Ctor_Thunk<StripRef< ret_type >::type>::AssignOp) : NULL \
23.414 + ); \
23.415 + }
23.416 +
23.417 +#define THGM_ADD_HOOK(id, num) \
23.418 + CAT4(hook, num, _, id) = g_SHPtr->AddHook(g_PLID, SourceHook::ISourceHook::Hook_Normal, reinterpret_cast<void*>(pTest##id), \
23.419 + 0, myhookman##id, PtrBufPtr(new TestClass##id::Delegate(num)), num >= 3);
23.420 +
23.421 +#define THGM_REMOVE_HOOK(id, num) \
23.422 + g_SHPtr->RemoveHookByID(CAT4(hook, num, _, id));
23.423 +
23.424 +#define THGM_CALLS_void(id, call_params) \
23.425 + pTest##id->Func call_params; \
23.426 + SH_CALL(pTest##id, &TestClass##id::Func) call_params;
23.427 +
23.428 +#define THGM_DO_TEST_void(id, call_params) \
23.429 + setuppi_##id(); \
23.430 + SourceHook::HookManagerPubFunc myhookman##id = g_HMAGPtr->MakeHookMan(protoinfo_##id, 0, 0); \
23.431 + CAutoReleaseHookMan arhm_##id(myhookman##id); \
23.432 + int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
23.433 + \
23.434 + TestClass##id::ms_DoRecall = false; \
23.435 + TestClass##id *pTest##id = new TestClass##id; \
23.436 + CAutoPtrDestruction<TestClass##id> apd##id(pTest##id); \
23.437 + \
23.438 + /* no hooks - no hooks */ \
23.439 + PtrBuf_Clear(); \
23.440 + THGM_CALLS_void(id, call_params); \
23.441 + CHECK_STATES((&g_States, \
23.442 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.443 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.444 + NULL), "Test" #id " Part1"); \
23.445 + \
23.446 + /* hook1 - hook3 */ \
23.447 + PtrBuf_Clear(); \
23.448 + THGM_ADD_HOOK(id, 1); \
23.449 + THGM_ADD_HOOK(id, 3); \
23.450 + THGM_CALLS_void(id, call_params); \
23.451 + CHECK_STATES((&g_States, \
23.452 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
23.453 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.454 + new State_Deleg_##id(3, pTest##id, 1, ParamState_m##id call_params), \
23.455 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.456 + NULL), "Test" #id " Part4"); \
23.457 + THGM_REMOVE_HOOK(id, 1); \
23.458 + THGM_REMOVE_HOOK(id, 3); \
23.459 + \
23.460 + /* hook1, hook2 - hook3 */ \
23.461 + PtrBuf_Clear(); \
23.462 + THGM_ADD_HOOK(id, 1); \
23.463 + THGM_ADD_HOOK(id, 2); \
23.464 + THGM_ADD_HOOK(id, 3); \
23.465 + THGM_CALLS_void(id, call_params); \
23.466 + CHECK_STATES((&g_States, \
23.467 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
23.468 + new State_Deleg_##id(2, pTest##id, 1, ParamState_m##id call_params), \
23.469 + new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params), \
23.470 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.471 + NULL), "Test" #id " Part5"); \
23.472 + /* hook1, hook2 - hook3, hook4 */ \
23.473 + THGM_ADD_HOOK(id, 4); \
23.474 + THGM_CALLS_void(id, call_params); \
23.475 + CHECK_STATES((&g_States, \
23.476 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
23.477 + new State_Deleg_##id(2, pTest##id, 1, ParamState_m##id call_params), \
23.478 + new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params), \
23.479 + new State_Deleg_##id(4, pTest##id, 3, ParamState_m##id call_params), \
23.480 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.481 + NULL), "Test" #id " Part6"); \
23.482 + \
23.483 + /* hook1 - hook3, hook4, with recalls! */ \
23.484 + \
23.485 + TestClass##id::ms_DoRecall = true; \
23.486 + THGM_REMOVE_HOOK(id, 2); \
23.487 + THGM_CALLS_void(id, call_params); \
23.488 + CHECK_STATES((&g_States, \
23.489 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params(0)), \
23.490 + new State_Func##id(pTest##id, ParamState_m##id call_params(1)), \
23.491 + new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params(1)), \
23.492 + new State_Deleg_##id(4, pTest##id, 3, ParamState_m##id call_params(2)), \
23.493 + /* sh_call one */ \
23.494 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.495 + NULL), "Test" #id " Part7"); \
23.496 + THGM_REMOVE_HOOK(id, 1); \
23.497 + THGM_REMOVE_HOOK(id, 3); \
23.498 + THGM_REMOVE_HOOK(id, 4);
23.499 +
23.500 +template<class T>
23.501 +T ComparableRef(T x)
23.502 +{
23.503 + return x;
23.504 +}
23.505 +
23.506 +template <class T>
23.507 +T* ComparableRef(T& x)
23.508 +{
23.509 + return &x;
23.510 +}
23.511 +
23.512 +#define THGM_CALLS(id, call_params, exp_ret_norm, exp_ret_shcall, err) \
23.513 + CHECK_COND(ComparableRef<RetType##id>(pTest##id->Func call_params) == ComparableRef<RetType##id>(MakeRet< RetType##id >::Do(exp_ret_norm)), err " /retcallnorm"); \
23.514 + CHECK_COND(ComparableRef<RetType##id>(SH_CALL(pTest##id, &TestClass##id::Func) call_params) == ComparableRef<RetType##id>(MakeRet< RetType##id >::Do(exp_ret_shcall)), err " /retcallshcall");
23.515 +
23.516 +#define THGM_DO_TEST(id, call_params) \
23.517 + setuppi_##id(); \
23.518 + setupri_##id(); \
23.519 + SourceHook::HookManagerPubFunc myhookman##id = g_HMAGPtr->MakeHookMan(protoinfo_##id, 0, 0); \
23.520 + CAutoReleaseHookMan arhm_##id(myhookman##id); \
23.521 + int hook1_##id, hook2_##id, hook3_##id, hook4_##id; \
23.522 + \
23.523 + TestClass##id::ms_DoRecall = false; \
23.524 + TestClass##id *pTest##id = new TestClass##id; \
23.525 + CAutoPtrDestruction<TestClass##id> apd##id(pTest##id); \
23.526 + \
23.527 + /* no hooks - no hooks */ \
23.528 + PtrBuf_Clear(); \
23.529 + THGM_CALLS(id, call_params, 0, 0, "Part1"); \
23.530 + CHECK_STATES((&g_States, \
23.531 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.532 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.533 + NULL), "Test" #id " Part1"); \
23.534 + \
23.535 + /* hook1 - hook3 */ \
23.536 + PtrBuf_Clear(); \
23.537 + THGM_ADD_HOOK(id, 1); \
23.538 + THGM_ADD_HOOK(id, 3); \
23.539 + THGM_CALLS(id, call_params, 0, 0, "Part4"); \
23.540 + CHECK_STATES((&g_States, \
23.541 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
23.542 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.543 + new State_Deleg_##id(3, pTest##id, 1, ParamState_m##id call_params), \
23.544 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.545 + NULL), "Test" #id " Part4"); \
23.546 + THGM_REMOVE_HOOK(id, 1); \
23.547 + THGM_REMOVE_HOOK(id, 3); \
23.548 + \
23.549 + /* hook1, hook2 - hook3 */ \
23.550 + PtrBuf_Clear(); \
23.551 + THGM_ADD_HOOK(id, 1); \
23.552 + THGM_ADD_HOOK(id, 2); \
23.553 + THGM_ADD_HOOK(id, 3); \
23.554 + THGM_CALLS(id, call_params, 2, 0, "Part5"); \
23.555 + CHECK_STATES((&g_States, \
23.556 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
23.557 + new State_Deleg_##id(2, pTest##id, 1, ParamState_m##id call_params), \
23.558 + new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params), \
23.559 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.560 + NULL), "Test" #id " Part5"); \
23.561 + /* hook1, hook2 - hook3, hook4 */ \
23.562 + THGM_ADD_HOOK(id, 4); \
23.563 + THGM_CALLS(id, call_params, 4, 0, "Part6"); \
23.564 + CHECK_STATES((&g_States, \
23.565 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params), \
23.566 + new State_Deleg_##id(2, pTest##id, 1, ParamState_m##id call_params), \
23.567 + new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params), \
23.568 + new State_Deleg_##id(4, pTest##id, 3, ParamState_m##id call_params), \
23.569 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.570 + NULL), "Test" #id " Part6"); \
23.571 + \
23.572 + /* hook1 - hook3, hook4, with recalls! */ \
23.573 + \
23.574 + TestClass##id::ms_DoRecall = true; \
23.575 + THGM_REMOVE_HOOK(id, 2); \
23.576 + THGM_CALLS(id, call_params, 4, 0, "Part7"); \
23.577 + CHECK_STATES((&g_States, \
23.578 + new State_Deleg_##id(1, pTest##id, 0, ParamState_m##id call_params(0)), \
23.579 + new State_Func##id(pTest##id, ParamState_m##id call_params(1)), \
23.580 + new State_Deleg_##id(3, pTest##id, 2, ParamState_m##id call_params(1)), \
23.581 + new State_Deleg_##id(4, pTest##id, 3, ParamState_m##id call_params(2)), \
23.582 + /* sh_call one */ \
23.583 + new State_Func##id(pTest##id, ParamState_m##id call_params), \
23.584 + NULL), "Test" #id " Part7"); \
23.585 + THGM_REMOVE_HOOK(id, 1); \
23.586 + THGM_REMOVE_HOOK(id, 3); \
23.587 + THGM_REMOVE_HOOK(id, 4);
24.1 --- a/sourcemm/ISmmAPI.h Sat Nov 24 06:11:23 2007 +0000
24.2 +++ b/sourcemm/ISmmAPI.h Mon Nov 26 14:03:25 2007 +0000
24.3 @@ -49,6 +49,7 @@
24.4
24.5 #define MMIFACE_SOURCEHOOK "ISourceHook" /**< ISourceHook Pointer */
24.6 #define MMIFACE_PLMANAGER "IPluginManager" /**< SourceMM Plugin Functions */
24.7 +#define MMIFACE_SH_HOOKMANAUTOGEN "IHookManagerAutoGen" /**< SourceHook::IHookManagerAutoGen Pointer */
24.8 #define IFACE_MAXNUM 999 /**< Maximum interface version */
24.9
24.10 namespace SourceMM
25.1 --- a/sourcemm/Makefile.ep1 Sat Nov 24 06:11:23 2007 +0000
25.2 +++ b/sourcemm/Makefile.ep1 Mon Nov 26 14:03:25 2007 +0000
25.3 @@ -17,7 +17,7 @@
25.4 HL2LIB = $(HL2SDK)/linux_sdk
25.5
25.6 OBJECTS = metamod.cpp metamod_util.cpp metamod_console.cpp metamod_oslink.cpp metamod_plugins.cpp \
25.7 - sourcehook.cpp episode1/console.cpp episode1/provider_ep1.cpp episode1/vsp_listener.cpp
25.8 + sourcehook.cpp sourcehook_hookmangen.cpp episode1/console.cpp episode1/provider_ep1.cpp episode1/vsp_listener.cpp
25.9
25.10 LINK = $(HL2LIB)/tier1_i486.a vstdlib_i486.so tier0_i486.so -static-libgcc
25.11
25.12 @@ -56,6 +56,7 @@
25.13 ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so
25.14 ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so
25.15 ln -sf $(SMM_ROOT)/sourcehook/sourcehook.cpp sourcehook.cpp
25.16 + ln -sf $(SMM_ROOT)/sourcehook/sourcehook_hookmangen.cpp sourcehook_hookmangen.cpp
25.17 $(MAKE) -f Makefile.ep1 sourcemm
25.18 rm -rf $(BINARY)
25.19 ln -sf $(BIN_DIR)/$(BINARY) $(BINARY)
26.1 --- a/sourcemm/Makefile.ep2 Sat Nov 24 06:11:23 2007 +0000
26.2 +++ b/sourcemm/Makefile.ep2 Mon Nov 26 14:03:25 2007 +0000
26.3 @@ -17,7 +17,7 @@
26.4 HL2LIB = $(HL2SDK)/linux_sdk
26.5
26.6 OBJECTS = metamod.cpp metamod_util.cpp metamod_console.cpp metamod_oslink.cpp metamod_plugins.cpp \
26.7 - sourcehook.cpp episode2/console.cpp episode2/provider_ep2.cpp episode2/vsp_listener.cpp
26.8 + sourcehook.cpp sourcehook_hookmangen.cpp episode2/console.cpp episode2/provider_ep2.cpp episode2/vsp_listener.cpp
26.9
26.10 LINK = $(HL2SDK)/linux_sdk/tier1_i486.a vstdlib_i486.so tier0_i486.so -static-libgcc
26.11
26.12 @@ -56,6 +56,7 @@
26.13 ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so
26.14 ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so
26.15 ln -sf $(SMM_ROOT)/sourcehook/sourcehook.cpp sourcehook.cpp
26.16 + ln -sf $(SMM_ROOT)/sourcehook/sourcehook_hookmangen.cpp sourcehook_hookmangen.cpp
26.17 $(MAKE) -f Makefile.ep2 sourcemm
26.18 rm -rf $(BINARY)
26.19 ln -sf $(BIN_DIR)/$(BINARY) $(BINARY)
27.1 --- a/sourcemm/episode1/msvc8/sourcemm.vcproj Sat Nov 24 06:11:23 2007 +0000
27.2 +++ b/sourcemm/episode1/msvc8/sourcemm.vcproj Mon Nov 26 14:03:25 2007 +0000
27.3 @@ -331,6 +331,11 @@
27.4 RelativePath="..\..\..\sourcehook\sourcehook.cpp"
27.5 >
27.6 </File>
27.7 + <File
27.8 + RelativePath="..\..\..\sourcehook\sourcehook_hookmangen.cpp"
27.9 + >
27.10 + </File>
27.11 +
27.12 </Filter>
27.13 </Files>
27.14 <Globals>
28.1 --- a/sourcemm/episode2/msvc8/sourcemm.vcproj Sat Nov 24 06:11:23 2007 +0000
28.2 +++ b/sourcemm/episode2/msvc8/sourcemm.vcproj Mon Nov 26 14:03:25 2007 +0000
28.3 @@ -327,6 +327,10 @@
28.4 RelativePath="..\..\..\sourcehook\sourcehook.cpp"
28.5 >
28.6 </File>
28.7 + <File
28.8 + RelativePath="..\..\..\sourcehook\sourcehook_hookmangen.cpp"
28.9 + >
28.10 + </File>
28.11 </Filter>
28.12 </Files>
28.13 <Globals>
29.1 --- a/sourcemm/metamod.cpp Sat Nov 24 06:11:23 2007 +0000
29.2 +++ b/sourcemm/metamod.cpp Mon Nov 26 14:03:25 2007 +0000
29.3 @@ -94,6 +94,7 @@
29.4 CreateInterfaceFn filesystem_factory = NULL;
29.5 CGlobalVars *gpGlobals = NULL;
29.6 CSourceHookImpl g_SourceHook;
29.7 +CHookManagerAutoGen g_SH_HookManagerAutoGen(&g_SourceHook);
29.8 ISourceHook *g_SHPtr = &g_SourceHook;
29.9 PluginId g_PLID = Pl_Console;
29.10 META_RES last_meta_res;
29.11 @@ -1090,6 +1091,14 @@
29.12 }
29.13 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
29.14 }
29.15 + else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
29.16 + {
29.17 + if (ret)
29.18 + {
29.19 + *ret = IFACE_OK;
29.20 + }
29.21 + return static_cast<void *>(static_cast<SourceHook::IHookManagerAutoGen *>(&g_SH_HookManagerAutoGen));
29.22 + }
29.23
29.24 CPluginManager::CPlugin *pl;
29.25 List<IMetamodListener *>::iterator event;
30.1 --- a/sourcemm/metamod.h Sat Nov 24 06:11:23 2007 +0000
30.2 +++ b/sourcemm/metamod.h Mon Nov 26 14:03:25 2007 +0000
30.3 @@ -37,6 +37,7 @@
30.4 #include <interface.h>
30.5 #include <eiface.h>
30.6 #include <sourcehook/sourcehook_impl.h>
30.7 +#include <sourcehook/sourcehook_hookmangen.h>
30.8 #include <sourcehook/sourcehook.h>
30.9 #include <ISmmPlugin.h>
30.10 #include "metamod_provider.h"