new jit api versioning scheme for amb398

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401153
This commit is contained in:
David Anderson 2007-07-23 19:12:54 +00:00
parent b4ba442d3c
commit 172b3e8ab8
5 changed files with 84 additions and 23 deletions

View File

@ -56,6 +56,7 @@ int g_StillFrames = 0;
float g_StillTime = 0.0f; float g_StillTime = 0.0f;
typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *); typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *);
typedef int (*GIVEENGINEPOINTER2)(ISourcePawnEngine *, unsigned int api_version);
typedef unsigned int (*GETEXPORTCOUNT)(); typedef unsigned int (*GETEXPORTCOUNT)();
typedef IVirtualMachine *(*GETEXPORT)(unsigned int); typedef IVirtualMachine *(*GETEXPORT)(unsigned int);
typedef void (*NOTIFYSHUTDOWN)(); typedef void (*NOTIFYSHUTDOWN)();
@ -157,25 +158,43 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late
} }
int err; int err;
GIVEENGINEPOINTER jit_init = (GIVEENGINEPOINTER)g_pJIT->GetSymbolAddress("GiveEnginePointer");
if (!jit_init) GIVEENGINEPOINTER2 jit_init2 = (GIVEENGINEPOINTER2)g_pJIT->GetSymbolAddress("GiveEnginePointer2");
if (!jit_init2)
{ {
ShutdownJIT(); GIVEENGINEPOINTER jit_init = (GIVEENGINEPOINTER)g_pJIT->GetSymbolAddress("GiveEnginePointer");
if (error && maxlength) if (!jit_init)
{ {
snprintf(error, maxlength, "Failed to find GiveEnginePointer in JIT!"); ShutdownJIT();
if (error && maxlength)
{
snprintf(error, maxlength, "Failed to find GiveEnginePointer in JIT!");
}
return false;
} }
return false;
}
if ((err=jit_init(g_pSourcePawn)) != 0) if ((err=jit_init(g_pSourcePawn)) != 0)
{
ShutdownJIT();
if (error && maxlength)
{ {
snprintf(error, maxlength, "GiveEnginePointer returned %d in the JIT", err); ShutdownJIT();
if (error && maxlength)
{
snprintf(error, maxlength, "GiveEnginePointer returned %d in the JIT", err);
}
return false;
}
} else {
/* On version bumps, we should check for older versions as well, if the new version fails.
* We can then check the exports to see if any VM versions will be sufficient.
*/
if ((err=jit_init2(g_pSourcePawn, SOURCEPAWN_ENGINE_API_VERSION)) != SP_ERROR_NONE)
{
ShutdownJIT();
if (error && maxlength)
{
snprintf(error, maxlength, "JIT incompatible with SourceMod version");
}
return false;
} }
return false;
} }
GETEXPORTCOUNT jit_getnum = (GETEXPORTCOUNT)g_pJIT->GetSymbolAddress("GetExportCount"); GETEXPORTCOUNT jit_getnum = (GETEXPORTCOUNT)g_pJIT->GetSymbolAddress("GetExportCount");
@ -191,7 +210,7 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late
} }
unsigned int num = jit_getnum(); unsigned int num = jit_getnum();
if (!num || ((g_pVM=jit_get(0)) == NULL)) if (!num)
{ {
ShutdownJIT(); ShutdownJIT();
if (error && maxlength) if (error && maxlength)
@ -201,15 +220,36 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late
return false; return false;
} }
unsigned int api = g_pVM->GetAPIVersion(); unsigned int api_version;
/* :TODO: clean this up (see amb398) */ for (unsigned int i=0; i<num; i++)
if (api > SOURCEPAWN_VM_API_VERSION || api < 2) {
if ((g_pVM=jit_get(i)) == NULL)
{
if (error && maxlength)
{
snprintf(error, maxlength, "JIT did not export any virtual machines!");
}
continue;
}
/* Refuse any API that we might not be able to deal with.
* Also refuse anything < 3 because we need fake natives.
*/
api_version = g_pVM->GetAPIVersion();
if (api_version < 3 || api_version > SOURCEPAWN_VM_API_VERSION)
{
if (error && maxlength)
{
snprintf(error, maxlength, "JIT is not a compatible version");
}
g_pVM = NULL;
continue;
}
break;
}
if (!g_pVM)
{ {
ShutdownJIT(); ShutdownJIT();
if (error && maxlength)
{
snprintf(error, maxlength, "JIT is not a compatible version");
}
return false; return false;
} }

View File

@ -536,6 +536,11 @@ void SourcePawnEngine::PopTracer(int error, const char *msg)
m_CurChain--; m_CurChain--;
} }
unsigned int SourcePawnEngine::GetEngineAPIVersion()
{
return SOURCEPAWN_ENGINE_API_VERSION;
}
CContextTrace::CContextTrace(TracedCall *pStart, int error, const char *msg, uint32_t native) : CContextTrace::CContextTrace(TracedCall *pStart, int error, const char *msg, uint32_t native) :
m_Error(error), m_pMsg(msg), m_pStart(pStart), m_pIterator(pStart), m_Native(native) m_Error(error), m_pMsg(msg), m_pStart(pStart), m_pIterator(pStart), m_Native(native)
{ {

View File

@ -65,6 +65,7 @@ public: //ISourcePawnEngine
void ExecFree(void *address); void ExecFree(void *address);
IDebugListener *SetDebugListener(IDebugListener *pListener); IDebugListener *SetDebugListener(IDebugListener *pListener);
unsigned int GetContextCallCount(); unsigned int GetContextCallCount();
unsigned int GetEngineAPIVersion();
public: //Debugger Stuff public: //Debugger Stuff
/** /**
* @brief Pushes a context onto the top of the call tracer. * @brief Pushes a context onto the top of the call tracer.

View File

@ -27,6 +27,9 @@
#include <stdio.h> #include <stdio.h>
#include "sp_vm_types.h" #include "sp_vm_types.h"
/** SourcePawn Engine API Version */
#define SOURCEPAWN_ENGINE_API_VERSION 1
/** SourcePawn VM API Version */ /** SourcePawn VM API Version */
#define SOURCEPAWN_VM_API_VERSION 3 #define SOURCEPAWN_VM_API_VERSION 3
@ -730,6 +733,13 @@ namespace SourcePawn
* @return Number of contexts in the call stack. * @return Number of contexts in the call stack.
*/ */
virtual unsigned int GetContextCallCount() =0; virtual unsigned int GetContextCallCount() =0;
/**
* @brief Returns the engine API version.
*
* @return Engine API version.
*/
virtual unsigned int GetEngineAPIVersion() =0;
}; };

View File

@ -20,11 +20,16 @@
SourcePawn::ISourcePawnEngine *engine = NULL; SourcePawn::ISourcePawnEngine *engine = NULL;
JITX86 g_jit; JITX86 g_jit;
EXPORTFUNC int GiveEnginePointer(SourcePawn::ISourcePawnEngine *engine_p) EXPORTFUNC int GiveEnginePointer2(SourcePawn::ISourcePawnEngine *engine_p, unsigned int api_version)
{ {
engine = engine_p; engine = engine_p;
return 0; if (api_version > SOURCEPAWN_ENGINE_API_VERSION)
{
return SP_ERROR_PARAM;
}
return SP_ERROR_NONE;
} }
EXPORTFUNC unsigned int GetExportCount() EXPORTFUNC unsigned int GetExportCount()