core/vm/sp_vm_engine.h
author Matt Woodrow <pred@alliedmods.net>
Tue Mar 11 23:52:56 2008 +0000 (2008-03-11)
changeset 1921 f993e100e5a3
parent 1896 6617f850dede
child 1947 e73a1e51833b
permissions -rw-r--r--
Fixed bug in GetAdjustedTime()
dvander@371
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourcePawn
dvander@1231
     5
 * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@371
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1231
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@371
    28
 *
dvander@371
    29
 * Version: $Id$
dvander@371
    30
 */
dvander@371
    31
dvander@159
    32
#ifndef _INCLUDE_SOURCEPAWN_VM_ENGINE_H_
dvander@159
    33
#define _INCLUDE_SOURCEPAWN_VM_ENGINE_H_
dvander@159
    34
dvander@159
    35
#include "sp_vm_api.h"
dvander@327
    36
#include "sp_vm_function.h"
dvander@159
    37
dvander@327
    38
struct TracedCall
dvander@159
    39
{
dvander@327
    40
	uint32_t cip;
dvander@327
    41
	uint32_t frm;
dvander@327
    42
	sp_context_t *ctx;
dvander@327
    43
	TracedCall *next;
dvander@327
    44
	unsigned int chain;
dvander@327
    45
};
dvander@240
    46
dvander@327
    47
class CContextTrace : public IContextTrace
dvander@327
    48
{
dvander@327
    49
public:
dvander@327
    50
	CContextTrace(TracedCall *pStart, int error, const char *msg, uint32_t native);
dvander@327
    51
public:
faluco@641
    52
	int GetErrorCode();
faluco@641
    53
	const char *GetErrorString();
faluco@641
    54
	bool DebugInfoAvailable();
faluco@641
    55
	const char *GetCustomErrorString();
faluco@641
    56
	bool GetTraceInfo(CallStackInfo *trace);
faluco@641
    57
	void ResetTrace();
faluco@641
    58
	const char *GetLastNative(uint32_t *index);
dvander@327
    59
private:
dvander@351
    60
	int m_Error;
dvander@351
    61
	const char *m_pMsg;
dvander@327
    62
	TracedCall *m_pStart;
dvander@327
    63
	TracedCall *m_pIterator;
dvander@327
    64
	uint32_t m_Native;
dvander@327
    65
};
dvander@240
    66
dvander@327
    67
class SourcePawnEngine : public ISourcePawnEngine
dvander@327
    68
{
dvander@327
    69
public:
dvander@327
    70
	SourcePawnEngine();
dvander@327
    71
	~SourcePawnEngine();
dvander@327
    72
public: //ISourcePawnEngine
dvander@327
    73
	sp_plugin_t *LoadFromFilePointer(FILE *fp, int *err);
dvander@327
    74
	sp_plugin_t *LoadFromMemory(void *base, sp_plugin_t *plugin, int *err);
dvander@327
    75
	int FreeFromMemory(sp_plugin_t *plugin);
dvander@327
    76
	IPluginContext *CreateBaseContext(sp_context_t *ctx);
dvander@327
    77
	void FreeBaseContext(IPluginContext *ctx);
dvander@327
    78
	void *BaseAlloc(size_t size);
dvander@327
    79
	void BaseFree(void *memory);
dvander@327
    80
	void *ExecAlloc(size_t size);
dvander@327
    81
	void ExecFree(void *address);
dvander@327
    82
	IDebugListener *SetDebugListener(IDebugListener *pListener);
dvander@327
    83
	unsigned int GetContextCallCount();
dvander@1147
    84
	unsigned int GetEngineAPIVersion();
faluco@1894
    85
	void *AllocatePageMemory(size_t size);
faluco@1894
    86
	void SetReadWrite(void *ptr);
faluco@1894
    87
	void SetReadExecute(void *ptr);
faluco@1894
    88
	void FreePageMemory(void *ptr);
dvander@327
    89
public: //Debugger Stuff
dvander@327
    90
	/**
dvander@327
    91
	 * @brief Pushes a context onto the top of the call tracer.
dvander@327
    92
	 * 
dvander@327
    93
	 * @param ctx		Plugin context.
dvander@327
    94
	 */
dvander@327
    95
	void PushTracer(sp_context_t *ctx);
dvander@159
    96
dvander@327
    97
	/**
dvander@327
    98
	 * @brief Pops a plugin off the call tracer.
dvander@327
    99
	 */
dvander@327
   100
	void PopTracer(int error, const char *msg);
dvander@159
   101
dvander@327
   102
	/**
dvander@327
   103
	 * @brief Runs tracer from a debug break.
dvander@327
   104
	 */
dvander@327
   105
	void RunTracer(sp_context_t *ctx, uint32_t frame, uint32_t codeip);
dvander@327
   106
public: //Plugin function stuff
dvander@327
   107
	CFunction *GetFunctionFromPool(funcid_t f, IPluginContext  *plugin);
dvander@327
   108
	void ReleaseFunctionToPool(CFunction *func);
dvander@327
   109
private:
dvander@327
   110
	TracedCall *MakeTracedCall(bool new_chain);
dvander@327
   111
	void FreeTracedCall(TracedCall *pCall);
dvander@327
   112
private:
dvander@327
   113
	IDebugListener *m_pDebugHook;
dvander@327
   114
	TracedCall *m_FreedCalls;
dvander@327
   115
	TracedCall *m_CallStack;
dvander@327
   116
	unsigned int m_CurChain;
dvander@327
   117
	//CFunction *m_pFreeFuncs;
dvander@159
   118
};
dvander@159
   119
dvander@159
   120
#endif //_INCLUDE_SOURCEPAWN_VM_ENGINE_H_