began JIT integration
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40165
This commit is contained in:
parent
65026ef57e
commit
9141ae103e
@ -40,7 +40,7 @@
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\interfaces;..\"
|
||||
AdditionalIncludeDirectories="..\interfaces;..\;..\systems"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;SOURCEMOD_MM_EXPORTS;_CRT_SECURE_NO_DEPRECATE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
@ -186,6 +186,10 @@
|
||||
RelativePath="..\sourcemm_api.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\sourcemod.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
@ -196,6 +200,10 @@
|
||||
RelativePath="..\CTextParsers.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\sm_globals.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\sm_platform.h"
|
||||
>
|
||||
@ -213,12 +221,6 @@
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Interfaces"
|
||||
>
|
||||
@ -410,6 +412,12 @@
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
|
15
core/sm_globals.h
Normal file
15
core/sm_globals.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_GLOBALS_H_
|
||||
#define _INCLUDE_SOURCEMOD_GLOBALS_H_
|
||||
|
||||
#include <sp_vm_types.h>
|
||||
#include <sp_vm_api.h>
|
||||
#include "sm_platform.h"
|
||||
#include "interfaces/IShareSys.h"
|
||||
|
||||
using namespace SourcePawn;
|
||||
using namespace SourceMod;
|
||||
|
||||
extern ISourcePawnEngine *g_pSourcePawn;
|
||||
extern IVirtualMachine *g_pVM;
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_GLOBALS_H_
|
@ -11,6 +11,7 @@
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <direct.h>
|
||||
#define PLATFORM_LIB_EXT "dll"
|
||||
#define PLATFORM_MAX_PATH MAX_PATH
|
||||
#else if defined __linux__
|
||||
#define PLATFORM_LINUX
|
||||
@ -18,6 +19,7 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#define PLATFORM_MAX_PATH PATH_MAX
|
||||
#define PLATFORM_LIB_EXT "so"
|
||||
#endif
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_PLATFORM_H_
|
||||
|
@ -1,17 +1,17 @@
|
||||
#include <oslink.h>
|
||||
#include "sourcemm_api.h"
|
||||
#include "sm_version.h"
|
||||
#include "CTextParsers.h"
|
||||
#include "sourcemod.h"
|
||||
|
||||
SourceMod_Core g_SourceMod;
|
||||
SourceMod_Core g_SourceMod_Core;
|
||||
|
||||
PLUGIN_EXPOSE(SourceMod, g_SourceMod);
|
||||
PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
|
||||
|
||||
bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
|
||||
{
|
||||
PLUGIN_SAVEVARS();
|
||||
|
||||
return true;
|
||||
return g_SourceMod.InitializeSourceMod(error, maxlen, late);
|
||||
}
|
||||
|
||||
bool SourceMod_Core::Unload(char *error, size_t maxlen)
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
const char *GetLogTag();
|
||||
};
|
||||
|
||||
extern SourceMod_Core g_SourceMod;
|
||||
extern SourceMod_Core g_SourceMod_Core;
|
||||
|
||||
PLUGIN_GLOBALVARS();
|
||||
|
||||
|
103
core/sourcemod.cpp
Normal file
103
core/sourcemod.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
#include <stdio.h>
|
||||
#include "sourcemod.h"
|
||||
#include "sourcemm_api.h"
|
||||
#include "systems/LibrarySys.h"
|
||||
#include "vm/sp_vm_engine.h"
|
||||
#include <sh_string.h>
|
||||
|
||||
SourcePawnEngine g_SourcePawn;
|
||||
SourceModBase g_SourceMod;
|
||||
|
||||
ILibrary *g_pJIT = NULL;
|
||||
SourceHook::String g_BaseDir;
|
||||
ISourcePawnEngine *g_pSourcePawn = &g_SourcePawn;
|
||||
IVirtualMachine *g_pVM;
|
||||
|
||||
typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *);
|
||||
typedef unsigned int (*GETEXPORTCOUNT)();
|
||||
typedef IVirtualMachine *(*GETEXPORT)(unsigned int);
|
||||
typedef void (*NOTIFYSHUTDOWN)();
|
||||
|
||||
void ShutdownJIT()
|
||||
{
|
||||
NOTIFYSHUTDOWN notify = (NOTIFYSHUTDOWN)g_pJIT->GetSymbolAddress("NotifyShutdown");
|
||||
if (notify)
|
||||
{
|
||||
notify();
|
||||
}
|
||||
|
||||
g_pJIT->CloseLibrary();
|
||||
}
|
||||
|
||||
bool SourceModBase::InitializeSourceMod(char *error, size_t err_max, bool late)
|
||||
{
|
||||
//:TODO: we need a localinfo system!
|
||||
g_BaseDir.assign(g_SMAPI->GetBaseDir());
|
||||
|
||||
/* Attempt to load the JIT! */
|
||||
char file[PLATFORM_MAX_PATH];
|
||||
char myerror[255];
|
||||
g_SMAPI->PathFormat(file, sizeof(file), "%s/addons/sourcemod/bin/sourcepawn.jit.x86.%s",
|
||||
g_BaseDir.c_str(),
|
||||
PLATFORM_LIB_EXT
|
||||
);
|
||||
|
||||
g_pJIT = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror));
|
||||
if (!g_pJIT)
|
||||
{
|
||||
if (error && err_max)
|
||||
{
|
||||
snprintf(error, err_max, "%s (failed to load bin/sourcepawn.jit.x86.%s)",
|
||||
myerror,
|
||||
PLATFORM_LIB_EXT);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int err;
|
||||
GIVEENGINEPOINTER jit_init = (GIVEENGINEPOINTER)g_pJIT->GetSymbolAddress("GiveEnginePointer");
|
||||
if (!jit_init)
|
||||
{
|
||||
ShutdownJIT();
|
||||
if (error && err_max)
|
||||
{
|
||||
snprintf(error, err_max, "Failed to find GiveEnginePointer in JIT!");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((err=jit_init(g_pSourcePawn)) != 0)
|
||||
{
|
||||
ShutdownJIT();
|
||||
if (error && err_max)
|
||||
{
|
||||
snprintf(error, err_max, "GiveEnginePointer returned %d in the JIT", err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
GETEXPORTCOUNT jit_getnum = (GETEXPORTCOUNT)g_pJIT->GetSymbolAddress("GetExportCount");
|
||||
GETEXPORT jit_get = (GETEXPORT)g_pJIT->GetSymbolAddress("GetExport");
|
||||
if (!jit_get)
|
||||
{
|
||||
ShutdownJIT();
|
||||
if (error && err_max)
|
||||
{
|
||||
snprintf(error, err_max, "JIT is missing a necessary export!");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int num = jit_getnum();
|
||||
if (!num || ((g_pVM=jit_get(0)) == NULL))
|
||||
{
|
||||
ShutdownJIT();
|
||||
if (error && err_max)
|
||||
{
|
||||
snprintf(error, err_max, "JIT did not export any virtual machines!");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
@ -1,8 +1,17 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_GLOBALHEADER_H_
|
||||
#define _INCLUDE_SOURCEMOD_GLOBALHEADER_H_
|
||||
|
||||
#include <sp_vm_types.h>
|
||||
#include <sp_vm_context.h>
|
||||
#include "sm_globals.h"
|
||||
|
||||
class SourceModBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Initializes SourceMod, or returns an error on failure.
|
||||
*/
|
||||
bool InitializeSourceMod(char *error, size_t err_max, bool late);
|
||||
};
|
||||
|
||||
extern SourceModBase g_SourceMod;
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_GLOBALHEADER_H_
|
||||
|
Loading…
Reference in New Issue
Block a user