1+ /* *
2+ * =============================================================================
3+ * DynamicHooks
4+ * Copyright (C) 2015 Robin Gohmert. All rights reserved.
5+ * =============================================================================
6+ *
7+ * This software is provided 'as-is', without any express or implied warranty.
8+ * In no event will the authors be held liable for any damages arising from
9+ * the use of this software.
10+ *
11+ * Permission is granted to anyone to use this software for any purpose,
12+ * including commercial applications, and to alter it and redistribute it
13+ * freely, subject to the following restrictions:
14+ *
15+ * 1. The origin of this software must not be misrepresented; you must not
16+ * claim that you wrote the original software. If you use this software in a
17+ * product, an acknowledgment in the product documentation would be
18+ * appreciated but is not required.
19+ *
20+ * 2. Altered source versions must be plainly marked as such, and must not be
21+ * misrepresented as being the original software.
22+ *
23+ * 3. This notice may not be removed or altered from any source distribution.
24+ *
25+ * asm.h/cpp from devmaster.net (thanks cybermind) edited by pRED* to handle gcc
26+ * -fPIC thunks correctly
27+ *
28+ * Idea and trampoline code taken from DynDetours (thanks your-name-here).
29+ */
30+
31+ #ifndef _X86_MS_FASTCALL_H
32+ #define _X86_MS_FASTCALL_H
33+
34+ // ============================================================================
35+ // >> INCLUDES
36+ // ============================================================================
37+ #include " ../convention.h"
38+
39+
40+ // ============================================================================
41+ // >> CLASSES
42+ // ============================================================================
43+ /*
44+ Source: DynCall manual and Windows docs
45+
46+ Registers:
47+ - eax = return value
48+ - ecx = parameter 0
49+ - edx = parameter 1, return value
50+ - esp = stack pointer
51+ - st0 = floating point return value
52+
53+ Parameter passing:
54+ - stack parameter order: right-to-left
55+ - callee cleans up the stack
56+ - all other arguments are pushed onto the stack
57+ - alignment: 4 bytes
58+
59+ Return values:
60+ - return values of pointer or intergral type (<= 32 bits) are returned via the eax register
61+ - integers > 32 bits are returned via the eax and edx registers
62+ - floating pointer types are returned via the st0 register
63+ */
64+ class x86MsFastcall : public ICallingConvention
65+ {
66+ public:
67+ x86MsFastcall (std::vector<DataType_t> vecArgTypes, DataType_t returnType, int iAlignment=4 );
68+ ~x86MsFastcall ();
69+
70+ virtual std::list<Register_t> GetRegisters ();
71+ virtual int GetPopSize ();
72+
73+ virtual void * GetArgumentPtr (int iIndex, CRegisters* pRegisters);
74+ virtual void ArgumentPtrChanged (int iIndex, CRegisters* pRegisters, void * pArgumentPtr);
75+
76+ virtual void * GetReturnPtr (CRegisters* pRegisters);
77+ virtual void ReturnPtrChanged (CRegisters* pRegisters, void * pReturnPtr);
78+
79+ private:
80+ void * m_pReturnBuffer;
81+ };
82+
83+ #endif // _X86_MS_FASTCALL_H
0 commit comments