sourcepawn/jit/sp_vm_function.h
author David Anderson <dvander@alliedmods.net>
Sun Oct 26 23:50:54 2008 -0500 (2008-10-26)
changeset 2377 6ee3bbd6fbdf
parent 2226 d10b38524be3
child 2825 811ec7a539c3
permissions -rw-r--r--
Fixed leaking relocation table memory in JIT.
dvander@2193
     1
/**
dvander@2193
     2
 * vim: set ts=4 :
dvander@2193
     3
 * =============================================================================
dvander@2193
     4
 * SourcePawn
dvander@2193
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
dvander@2193
     6
 * =============================================================================
dvander@2193
     7
 *
dvander@2193
     8
 * This program is free software; you can redistribute it and/or modify it under
dvander@2193
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
dvander@2193
    10
 * Free Software Foundation.
dvander@2193
    11
 * 
dvander@2193
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
dvander@2193
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
dvander@2193
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
dvander@2193
    15
 * details.
dvander@2193
    16
 *
dvander@2193
    17
 * You should have received a copy of the GNU General Public License along with
dvander@2193
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@2193
    19
 *
dvander@2193
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
dvander@2193
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
dvander@2193
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
dvander@2193
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
dvander@2193
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
dvander@2193
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
dvander@2193
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
dvander@2193
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@2193
    28
 *
dvander@2193
    29
 * Version: $Id$
dvander@2193
    30
 */
dvander@2193
    31
dvander@2193
    32
#ifndef _INCLUDE_SOURCEMOD_BASEFUNCTION_H_
dvander@2193
    33
#define _INCLUDE_SOURCEMOD_BASEFUNCTION_H_
dvander@2193
    34
dvander@2193
    35
#include <sp_vm_api.h>
dvander@2193
    36
dvander@2193
    37
class BaseRuntime;
dvander@2193
    38
dvander@2193
    39
using namespace SourcePawn;
dvander@2193
    40
dvander@2193
    41
struct ParamInfo
dvander@2193
    42
{
dvander@2193
    43
	int flags;			/* Copy-back flags */
dvander@2193
    44
	bool marked;		/* Whether this is marked as being used */
dvander@2193
    45
	cell_t local_addr;	/* Local address to free */
dvander@2193
    46
	cell_t *phys_addr;	/* Physical address of our copy */
dvander@2193
    47
	cell_t *orig_addr;	/* Original address to copy back to */
dvander@2193
    48
	ucell_t size;		/* Size of array in bytes */
dvander@2193
    49
	struct
dvander@2193
    50
	{
dvander@2193
    51
		bool is_sz;		/* is a string */
dvander@2193
    52
		int sz_flags;	/* has sz flags */
dvander@2193
    53
	} str;
dvander@2193
    54
};
dvander@2193
    55
dvander@2193
    56
class CPlugin;
dvander@2226
    57
class JitFunction;
dvander@2193
    58
dvander@2193
    59
class CFunction : public IPluginFunction
dvander@2193
    60
{
dvander@2193
    61
	friend class SourcePawnEngine;
dvander@2193
    62
public:
dvander@2226
    63
	CFunction(BaseRuntime *pRuntime, 
dvander@2193
    64
			  funcid_t fnid,
dvander@2193
    65
			  uint32_t pub_id);
dvander@2193
    66
public:
dvander@2193
    67
	virtual int PushCell(cell_t cell);
dvander@2193
    68
	virtual int PushCellByRef(cell_t *cell, int flags);
dvander@2193
    69
	virtual int PushFloat(float number);
dvander@2193
    70
	virtual int PushFloatByRef(float *number, int flags);
dvander@2193
    71
	virtual int PushArray(cell_t *inarray, unsigned int cells, int copyback);
dvander@2193
    72
	virtual int PushString(const char *string);
dvander@2193
    73
	virtual int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags);
dvander@2193
    74
	virtual int Execute(cell_t *result);
dvander@2193
    75
	virtual void Cancel();
dvander@2193
    76
	virtual int CallFunction(const cell_t *params, unsigned int num_params, cell_t *result);
dvander@2193
    77
	virtual IPluginContext *GetParentContext();
dvander@2193
    78
	bool IsRunnable();
dvander@2193
    79
	funcid_t GetFunctionID();
dvander@2193
    80
	int Execute2(IPluginContext *ctx, cell_t *result);
dvander@2193
    81
	int CallFunction2(IPluginContext *ctx, 
dvander@2193
    82
		const cell_t *params, 
dvander@2193
    83
		unsigned int num_params, 
dvander@2193
    84
		cell_t *result);
dvander@2193
    85
public:
dvander@2226
    86
	void Set(BaseRuntime *runtime, funcid_t fnid, uint32_t pub_id);
dvander@2193
    87
private:
dvander@2193
    88
	int _PushString(const char *string, int sz_flags, int cp_flags, size_t len);
dvander@2193
    89
	int SetError(int err);
dvander@2193
    90
private:
dvander@2193
    91
	BaseRuntime *m_pRuntime;
dvander@2193
    92
	cell_t m_params[SP_MAX_EXEC_PARAMS];
dvander@2193
    93
	ParamInfo m_info[SP_MAX_EXEC_PARAMS];
dvander@2193
    94
	unsigned int m_curparam;
dvander@2193
    95
	int m_errorstate;
dvander@2193
    96
	funcid_t m_FnId;
dvander@2193
    97
};
dvander@2193
    98
dvander@2193
    99
#endif //_INCLUDE_SOURCEMOD_BASEFUNCTION_H_