public/extensions/IBinTools.h
author Scott Ehlert <ds@alliedmods.net>
Sun Jul 15 08:00:26 2007 +0000 (2007-07-15)
changeset 1116 40cc5e9f0f1b
parent 942 5a930535b6d0
child 1226 478550a4d5ec
permissions -rw-r--r--
Removed strange debugging code
faluco@739
     1
/**
faluco@739
     2
 * vim: set ts=4 :
faluco@739
     3
 * ===============================================================
faluco@739
     4
 * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. 
faluco@739
     5
 * All rights reserved.
faluco@739
     6
 * ===============================================================
faluco@739
     7
 *
faluco@739
     8
 *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be 
faluco@739
     9
 * used or modified under the Terms and Conditions of its License Agreement, 
faluco@739
    10
 * which is found in public/licenses/LICENSE.txt.  As of this notice, derivative 
faluco@739
    11
 * works must be licensed under the GNU General Public License (version 2 or 
faluco@739
    12
 * greater).  A copy of the GPL is included under public/licenses/GPL.txt.
faluco@739
    13
 * 
faluco@739
    14
 * To view the latest information, see: http://www.sourcemod.net/license.php
faluco@739
    15
 *
faluco@739
    16
 * Version: $Id$
faluco@739
    17
 */
faluco@739
    18
faluco@739
    19
#ifndef _INCLUDE_SMEXT_BINTOOLS_H_
faluco@739
    20
#define _INCLUDE_SMEXT_BINTOOLS_H_
faluco@739
    21
faluco@739
    22
#include <IShareSys.h>
faluco@739
    23
faluco@739
    24
#define SMINTERFACE_BINTOOLS_NAME		"IBinTools"
dvander@942
    25
#define SMINTERFACE_BINTOOLS_VERSION	2
faluco@739
    26
faluco@739
    27
/**
faluco@739
    28
 * @brief Function calling encoding utilities
faluco@739
    29
 * @file IBinTools.h
faluco@739
    30
 */
faluco@739
    31
faluco@739
    32
namespace SourceMod
faluco@739
    33
{
faluco@739
    34
	/**
faluco@739
    35
	 * @brief Supported calling conventions
faluco@739
    36
	 */
faluco@739
    37
	enum CallConvention
faluco@739
    38
	{
faluco@739
    39
		CallConv_ThisCall,		/**< This call (object pointer required) */
faluco@739
    40
		CallConv_Cdecl,			/**< Standard C call */
faluco@739
    41
	};
faluco@739
    42
faluco@739
    43
	/**
faluco@739
    44
	 * @brief Describes how a parameter should be passed
faluco@739
    45
	 */
faluco@739
    46
	enum PassType
faluco@739
    47
	{
faluco@739
    48
		PassType_Basic,			/**< Plain old register data (pointers, integers) */
faluco@739
    49
		PassType_Float,			/**< Floating point data */
faluco@739
    50
		PassType_Object,		/**< Object or structure */
faluco@739
    51
	};
faluco@739
    52
faluco@739
    53
	#define PASSFLAG_BYVAL		(1<<0)		/**< Passing by value */
faluco@739
    54
	#define PASSFLAG_BYREF		(1<<1)		/**< Passing by reference */
faluco@739
    55
	#define PASSFLAG_ODTOR		(1<<2)		/**< Object has a destructor */
faluco@739
    56
	#define PASSFLAG_OCTOR		(1<<3)		/**< Object has a constructor */
faluco@739
    57
	#define PASSFLAG_OASSIGNOP	(1<<4)		/**< Object has an assignment operator */
faluco@739
    58
faluco@739
    59
	/**
faluco@739
    60
	 * @brief Parameter passing information
faluco@739
    61
	 */
faluco@739
    62
	struct PassInfo
faluco@739
    63
	{
faluco@739
    64
		PassType type;			/**< PassType value */
faluco@739
    65
		unsigned int flags;		/**< Pass/return flags */
faluco@739
    66
		size_t size;			/**< Size of the data being passed */
faluco@739
    67
	};
faluco@739
    68
faluco@739
    69
	/**
faluco@739
    70
	 * @brief Parameter encoding information
faluco@739
    71
	 */
faluco@739
    72
	struct PassEncode
faluco@739
    73
	{
faluco@739
    74
		PassInfo info;			/**< Parameter information */
faluco@739
    75
		size_t offset;			/**< Offset into the virtual stack */
faluco@739
    76
	};
faluco@739
    77
faluco@739
    78
	/**
faluco@739
    79
	 * @brief Wraps a C/C++ call.
faluco@739
    80
	 */
faluco@739
    81
	class ICallWrapper
faluco@739
    82
	{
faluco@739
    83
	public:
faluco@739
    84
		/**
faluco@739
    85
		 * @brief Returns the calling convention.
faluco@739
    86
		 *
faluco@739
    87
		 * @return				CallConvention value.
faluco@739
    88
		 */
faluco@739
    89
		virtual CallConvention GetCallConvention() =0;
faluco@739
    90
faluco@739
    91
		/**
faluco@739
    92
		 * @brief Returns parameter info.
faluco@739
    93
		 *
faluco@739
    94
		 * @param num			Parameter number to get (starting from 0).
faluco@739
    95
		 * @return				A PassInfo pointer.
faluco@739
    96
		 */
faluco@739
    97
		virtual const PassEncode *GetParamInfo(unsigned int num) =0;
faluco@739
    98
faluco@739
    99
		/**
faluco@739
   100
		 * @brief Returns return type info.
faluco@739
   101
		 *
faluco@739
   102
		 * @return				A PassInfo pointer.
faluco@739
   103
		 */
faluco@739
   104
		virtual const PassInfo *GetReturnInfo() =0;
faluco@739
   105
faluco@739
   106
		/**
faluco@739
   107
		 * @brief Returns the number of parameters.
dvander@942
   108
		 *
dvander@942
   109
		 * @return				Number of parameters.
faluco@739
   110
		 */
faluco@739
   111
		virtual unsigned int GetParamCount() =0;
faluco@739
   112
faluco@739
   113
		/**
faluco@739
   114
		 * @brief Execute the contained function.
dvander@942
   115
		 *
dvander@942
   116
		 * @param vParamStack	A blob of memory containing stack data.
dvander@942
   117
		 * @param retBuffer		Buffer to store return value.
faluco@739
   118
		 */
faluco@739
   119
		virtual void Execute(void *vParamStack, void *retBuffer) =0;
dvander@942
   120
dvander@942
   121
		/**
dvander@942
   122
		 * @brief Destroys all resources used by this object.
dvander@942
   123
		 */
dvander@942
   124
		virtual void Destroy() =0;
faluco@739
   125
	};
faluco@739
   126
faluco@739
   127
	/**
faluco@739
   128
	 * @brief Binary tools interface.
faluco@739
   129
	 */
faluco@739
   130
	class IBinTools : public SMInterface
faluco@739
   131
	{
faluco@739
   132
	public:
faluco@739
   133
		virtual const char *GetInterfaceName()
faluco@739
   134
		{
faluco@739
   135
			return SMINTERFACE_BINTOOLS_NAME;
faluco@739
   136
		}
faluco@739
   137
		virtual unsigned int GetInterfaceVersion()
faluco@739
   138
		{
faluco@739
   139
			return SMINTERFACE_BINTOOLS_VERSION;
faluco@739
   140
		}
faluco@739
   141
	public:
faluco@739
   142
		/**
faluco@739
   143
		 * @brief Creates a call decoder.
faluco@739
   144
		 *
faluco@739
   145
		 * Note: CallConv_ThisCall requires an implicit first parameter
faluco@739
   146
		 * of PassType_Basic / PASSFLAG_BYVAL / sizeof(void *).  However,
faluco@739
   147
		 * this should only be given to the Execute() function, and never
faluco@739
   148
		 * listed in the paramInfo array.
faluco@739
   149
		 *
faluco@739
   150
		 * @param address			Address to use as a call.
faluco@739
   151
		 * @param cv				Calling convention.
faluco@739
   152
		 * @param retInfo			Return type information, or NULL for void.
faluco@739
   153
		 * @param paramInfo			Array of parameters.
faluco@739
   154
		 * @param numParams			Number of parameters in the array.
faluco@739
   155
		 * @return					A new ICallWrapper function.
faluco@739
   156
		 */
faluco@739
   157
		virtual ICallWrapper *CreateCall(void *address,
faluco@739
   158
											CallConvention cv,
faluco@739
   159
											const PassInfo *retInfo,
faluco@739
   160
											const PassInfo paramInfo[],
faluco@739
   161
											unsigned int numParams) =0;
faluco@739
   162
faluco@739
   163
		/**
faluco@739
   164
		 * @brief Creates a vtable call decoder.
faluco@739
   165
		 *
faluco@739
   166
		 * Note: CallConv_ThisCall requires an implicit first parameter
faluco@739
   167
		 * of PassType_Basic / PASSFLAG_BYVAL / sizeof(void *).  However,
faluco@739
   168
		 * this should only be given to the Execute() function, and never
faluco@739
   169
		 * listed in the paramInfo array.
faluco@739
   170
		 *
faluco@739
   171
		 * @param vtblIdx			Index into the virtual table.
faluco@739
   172
		 * @param vtblOffs			Offset of the virtual table.
faluco@739
   173
		 * @param thisOffs			Offset of the this pointer of the virtual table.
faluco@739
   174
		 * @param retInfo			Return type information, or NULL for void.
faluco@739
   175
		 * @param paramInfo			Array of parameters.
faluco@739
   176
		 * @param numParams			Number of parameters in the array.
faluco@739
   177
		 * @return					A new ICallWrapper function.
faluco@739
   178
		 */
faluco@739
   179
		virtual ICallWrapper *CreateVCall(unsigned int vtblIdx,
faluco@739
   180
											unsigned int vtblOffs,
faluco@739
   181
											unsigned int thisOffs,
faluco@739
   182
											const PassInfo *retInfo,
faluco@739
   183
											const PassInfo paramInfo[],
faluco@739
   184
											unsigned int numParams) =0;
faluco@739
   185
	};
faluco@739
   186
}
faluco@739
   187
faluco@739
   188
#endif //_INCLUDE_SMEXT_BINTOOLS_H_