core/vm/sp_vm_function.h
author David Anderson <dvander@alliedmods.net>
Fri Feb 16 04:16:31 2007 +0000 (2007-02-16)
changeset 502 4530ea065a8b
parent 371 71b0caa3aaa8
child 525 d36c45088e36
permissions -rw-r--r--
fixed a serious potential bug with swapping plugins to debug mode, leaving stale function pointers without plugin removal
     1 /**
     2  * ================================================================
     3  * SourcePawn (C)2004-2007 AlliedModders LLC.  All rights reserved.
     4  * ================================================================
     5  *
     6  * This file is not open source and may not be copied without explicit
     7  * written permission of AlliedModders LLC.  This file may not be redistributed 
     8  * in whole or significant part.
     9  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    10  *
    11  * Version: $Id$
    12  */
    13 
    14 #ifndef _INCLUDE_SOURCEMOD_BASEFUNCTION_H_
    15 #define _INCLUDE_SOURCEMOD_BASEFUNCTION_H_
    16 
    17 #include "sm_globals.h"
    18 
    19 struct ParamInfo
    20 {
    21 	int flags;			/* Copy-back flags */
    22 	bool marked;		/* Whether this is marked as being used */
    23 	cell_t local_addr;	/* Local address to free */
    24 	cell_t *phys_addr;	/* Physical address of our copy */
    25 	cell_t *orig_addr;	/* Original address to copy back to */
    26 	ucell_t size;		/* Size of array in bytes */
    27 };
    28 
    29 class CPlugin;
    30 
    31 class CFunction : public IPluginFunction
    32 {
    33 	friend class SourcePawnEngine;
    34 public:
    35 	CFunction(uint32_t code_addr, IPluginContext *pContext);
    36 public:
    37 	virtual int PushCell(cell_t cell);
    38 	virtual int PushCellByRef(cell_t *cell, int flags);
    39 	virtual int PushFloat(float number);
    40 	virtual int PushFloatByRef(float *number, int flags);
    41 	virtual int PushArray(cell_t *inarray, unsigned int cells, cell_t **phys_addr, int copyback);
    42 	virtual int PushString(const char *string);
    43 	virtual int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags);
    44 	virtual cell_t *GetAddressOfPushedParam(unsigned int param);
    45 	virtual int Execute(cell_t *result);
    46 	virtual void Cancel();
    47 	virtual int CallFunction(const cell_t *params, unsigned int num_params, cell_t *result);
    48 	virtual IPluginContext *GetParentContext();
    49 	inline bool IsInvalidated()
    50 	{
    51 		return m_Invalid;
    52 	}
    53 	inline void Invalidate()
    54 	{
    55 		m_Invalid = true;
    56 	}
    57 public:
    58 	void Set(uint32_t code_addr, IPluginContext *plugin);
    59 private:
    60 	int _PushString(const char *string, int sz_flags, int cp_flags, size_t len);
    61 	inline int SetError(int err)
    62 	{
    63 		m_errorstate = err;
    64 		return err;
    65 	}
    66 private:
    67 	uint32_t m_codeaddr;
    68 	IPluginContext *m_pContext;
    69 	cell_t m_params[SP_MAX_EXEC_PARAMS];
    70 	ParamInfo m_info[SP_MAX_EXEC_PARAMS];
    71 	unsigned int m_curparam;
    72 	int m_errorstate;
    73 	CFunction *m_pNext;
    74 	bool m_Invalid;
    75 };
    76 
    77 #endif //_INCLUDE_SOURCEMOD_BASEFUNCTION_H_