Merge sp_vm_engine and engine2.
This commit is contained in:
parent
499f7b3929
commit
3cf3f6c3f8
@ -4,7 +4,6 @@ import os
|
|||||||
Includes = [
|
Includes = [
|
||||||
os.path.join(SM.mms_root, 'core', 'sourcehook'),
|
os.path.join(SM.mms_root, 'core', 'sourcehook'),
|
||||||
os.path.join(builder.sourcePath, 'sourcepawn', 'jit'),
|
os.path.join(builder.sourcePath, 'sourcepawn', 'jit'),
|
||||||
os.path.join(builder.sourcePath, 'sourcepawn', 'jit', 'x86'),
|
|
||||||
os.path.join(builder.sourcePath, 'public'),
|
os.path.join(builder.sourcePath, 'public'),
|
||||||
os.path.join(builder.sourcePath, 'public', 'sourcepawn'),
|
os.path.join(builder.sourcePath, 'public', 'sourcepawn'),
|
||||||
os.path.join(builder.sourcePath, 'public', 'amtl'),
|
os.path.join(builder.sourcePath, 'public', 'amtl'),
|
||||||
@ -31,13 +30,12 @@ def setup(binary):
|
|||||||
# Build the static library.
|
# Build the static library.
|
||||||
library = setup(builder.compiler.StaticLibrary('sourcepawn'))
|
library = setup(builder.compiler.StaticLibrary('sourcepawn'))
|
||||||
library.sources += [
|
library.sources += [
|
||||||
|
'api.cpp',
|
||||||
'plugin-runtime.cpp',
|
'plugin-runtime.cpp',
|
||||||
'compiled-function.cpp',
|
'compiled-function.cpp',
|
||||||
'debug-trace.cpp',
|
'debug-trace.cpp',
|
||||||
'engine2.cpp',
|
|
||||||
'environment.cpp',
|
'environment.cpp',
|
||||||
'sp_vm_basecontext.cpp',
|
'sp_vm_basecontext.cpp',
|
||||||
'sp_vm_engine.cpp',
|
|
||||||
'scripted-invoker.cpp',
|
'scripted-invoker.cpp',
|
||||||
'opcodes.cpp',
|
'opcodes.cpp',
|
||||||
'interpreter.cpp',
|
'interpreter.cpp',
|
||||||
|
@ -10,20 +10,168 @@
|
|||||||
// You should have received a copy of the GNU General Public License along with
|
// You should have received a copy of the GNU General Public License along with
|
||||||
// SourcePawn. If not, see http://www.gnu.org/licenses/.
|
// SourcePawn. If not, see http://www.gnu.org/licenses/.
|
||||||
//
|
//
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "engine2.h"
|
#include <assert.h>
|
||||||
|
#include <KeCodeAllocator.h>
|
||||||
#include "x86/jit_x86.h"
|
#include "x86/jit_x86.h"
|
||||||
#include "zlib/zlib.h"
|
|
||||||
#include "plugin-runtime.h"
|
|
||||||
#include "sp_vm_engine.h"
|
|
||||||
#include "watchdog_timer.h"
|
|
||||||
#include <sourcemod_version.h>
|
|
||||||
#include "environment.h"
|
#include "environment.h"
|
||||||
|
#include "api.h"
|
||||||
|
#include "zlib/zlib.h"
|
||||||
|
#if defined __GNUC__
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#elif defined __GNUC__
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined __linux__
|
||||||
|
#include <malloc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sourcemod_version.h>
|
||||||
|
|
||||||
|
using namespace sp;
|
||||||
using namespace SourcePawn;
|
using namespace SourcePawn;
|
||||||
|
|
||||||
|
// ////// //
|
||||||
|
// API v1
|
||||||
|
// ////// //
|
||||||
|
|
||||||
|
SourcePawnEngine::SourcePawnEngine()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
SourcePawnEngine::GetErrorString(int error)
|
||||||
|
{
|
||||||
|
return Environment::get()->GetErrorString(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
SourcePawnEngine::ExecAlloc(size_t size)
|
||||||
|
{
|
||||||
|
#if defined WIN32
|
||||||
|
return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
||||||
|
#elif defined __GNUC__
|
||||||
|
# if defined __APPLE__
|
||||||
|
void *base = valloc(size);
|
||||||
|
# else
|
||||||
|
void *base = memalign(sysconf(_SC_PAGESIZE), size);
|
||||||
|
# endif
|
||||||
|
if (mprotect(base, size, PROT_READ|PROT_WRITE|PROT_EXEC) != 0) {
|
||||||
|
free(base);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return base;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
SourcePawnEngine::AllocatePageMemory(size_t size)
|
||||||
|
{
|
||||||
|
return g_Jit.AllocCode(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SourcePawnEngine::SetReadExecute(void *ptr)
|
||||||
|
{
|
||||||
|
/* already re */
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SourcePawnEngine::SetReadWrite(void *ptr)
|
||||||
|
{
|
||||||
|
/* already rw */
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SourcePawnEngine::FreePageMemory(void *ptr)
|
||||||
|
{
|
||||||
|
g_Jit.FreeCode(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SourcePawnEngine::ExecFree(void *address)
|
||||||
|
{
|
||||||
|
#if defined WIN32
|
||||||
|
VirtualFree(address, 0, MEM_RELEASE);
|
||||||
|
#elif defined __GNUC__
|
||||||
|
free(address);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SourcePawnEngine::SetReadWriteExecute(void *ptr)
|
||||||
|
{
|
||||||
|
//:TODO: g_ExeMemory.SetRWE(ptr);
|
||||||
|
SetReadExecute(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
SourcePawnEngine::BaseAlloc(size_t size)
|
||||||
|
{
|
||||||
|
return malloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SourcePawnEngine::BaseFree(void *memory)
|
||||||
|
{
|
||||||
|
free(memory);
|
||||||
|
}
|
||||||
|
|
||||||
|
sp_plugin_t *
|
||||||
|
SourcePawnEngine::LoadFromFilePointer(FILE *fp, int *err)
|
||||||
|
{
|
||||||
|
if (err != NULL)
|
||||||
|
*err = SP_ERROR_ABORTED;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
sp_plugin_t *
|
||||||
|
SourcePawnEngine::LoadFromMemory(void *base, sp_plugin_t *plugin, int *err)
|
||||||
|
{
|
||||||
|
if (err != NULL)
|
||||||
|
*err = SP_ERROR_ABORTED;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
SourcePawnEngine::FreeFromMemory(sp_plugin_t *plugin)
|
||||||
|
{
|
||||||
|
return SP_ERROR_ABORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDebugListener *
|
||||||
|
SourcePawnEngine::SetDebugListener(IDebugListener *pListener)
|
||||||
|
{
|
||||||
|
IDebugListener *old = Environment::get()->debugger();
|
||||||
|
Environment::get()->SetDebugger(pListener);
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
SourcePawnEngine::GetEngineAPIVersion()
|
||||||
|
{
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
SourcePawnEngine::GetContextCallCount()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ////// //
|
||||||
|
// API v2
|
||||||
|
// ////// //
|
||||||
|
|
||||||
SourcePawnEngine2::SourcePawnEngine2()
|
SourcePawnEngine2::SourcePawnEngine2()
|
||||||
{
|
{
|
||||||
}
|
}
|
@ -10,22 +10,21 @@
|
|||||||
// You should have received a copy of the GNU General Public License along with
|
// You should have received a copy of the GNU General Public License along with
|
||||||
// SourcePawn. If not, see http://www.gnu.org/licenses/.
|
// SourcePawn. If not, see http://www.gnu.org/licenses/.
|
||||||
//
|
//
|
||||||
#ifndef _INCLUDE_SOURCEPAWN_VM_ENGINE_H_
|
#ifndef _include_sourcepawn_vm_api_h_
|
||||||
#define _INCLUDE_SOURCEPAWN_VM_ENGINE_H_
|
#define _include_sourcepawn_vm_api_h_
|
||||||
|
|
||||||
#include <sp_vm_api.h>
|
#include <sp_vm_api.h>
|
||||||
#include <am-utility.h> // Replace with am-cxx.h later.
|
#include <am-utility.h> // Replace with am-cxx later.
|
||||||
#include "scripted-invoker.h"
|
|
||||||
|
|
||||||
class BaseContext;
|
namespace sp {
|
||||||
|
|
||||||
|
using namespace SourcePawn;
|
||||||
|
|
||||||
class SourcePawnEngine : public ISourcePawnEngine
|
class SourcePawnEngine : public ISourcePawnEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SourcePawnEngine();
|
SourcePawnEngine();
|
||||||
~SourcePawnEngine();
|
|
||||||
|
|
||||||
public: //ISourcePawnEngine
|
|
||||||
sp_plugin_t *LoadFromFilePointer(FILE *fp, int *err) KE_OVERRIDE;
|
sp_plugin_t *LoadFromFilePointer(FILE *fp, int *err) KE_OVERRIDE;
|
||||||
sp_plugin_t *LoadFromMemory(void *base, sp_plugin_t *plugin, int *err) KE_OVERRIDE;
|
sp_plugin_t *LoadFromMemory(void *base, sp_plugin_t *plugin, int *err) KE_OVERRIDE;
|
||||||
int FreeFromMemory(sp_plugin_t *plugin) KE_OVERRIDE;
|
int FreeFromMemory(sp_plugin_t *plugin) KE_OVERRIDE;
|
||||||
@ -44,4 +43,33 @@ class SourcePawnEngine : public ISourcePawnEngine
|
|||||||
const char *GetErrorString(int err);
|
const char *GetErrorString(int err);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //_INCLUDE_SOURCEPAWN_VM_ENGINE_H_
|
class SourcePawnEngine2 : public ISourcePawnEngine2
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SourcePawnEngine2();
|
||||||
|
|
||||||
|
unsigned int GetAPIVersion() KE_OVERRIDE;
|
||||||
|
const char *GetEngineName() KE_OVERRIDE;
|
||||||
|
const char *GetVersionString() KE_OVERRIDE;
|
||||||
|
IPluginRuntime *LoadPlugin(ICompilation *co, const char *file, int *err) KE_OVERRIDE;
|
||||||
|
SPVM_NATIVE_FUNC CreateFakeNative(SPVM_FAKENATIVE_FUNC callback, void *pData) KE_OVERRIDE;
|
||||||
|
void DestroyFakeNative(SPVM_NATIVE_FUNC func) KE_OVERRIDE;
|
||||||
|
IDebugListener *SetDebugListener(IDebugListener *listener) KE_OVERRIDE;
|
||||||
|
ICompilation *StartCompilation() KE_OVERRIDE;
|
||||||
|
const char *GetErrorString(int err) KE_OVERRIDE;
|
||||||
|
bool Initialize() KE_OVERRIDE;
|
||||||
|
void Shutdown() KE_OVERRIDE;
|
||||||
|
IPluginRuntime *CreateEmptyRuntime(const char *name, uint32_t memory) KE_OVERRIDE;
|
||||||
|
bool InstallWatchdogTimer(size_t timeout_ms) KE_OVERRIDE;
|
||||||
|
|
||||||
|
bool SetJitEnabled(bool enabled) KE_OVERRIDE;
|
||||||
|
bool IsJitEnabled() KE_OVERRIDE;
|
||||||
|
void SetProfiler(IProfiler *profiler) KE_OVERRIDE;
|
||||||
|
void EnableProfiling() KE_OVERRIDE;
|
||||||
|
void DisableProfiling() KE_OVERRIDE;
|
||||||
|
void SetProfilingTool(IProfilingTool *tool) KE_OVERRIDE;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace SourcePawn
|
||||||
|
|
||||||
|
#endif // _include_sourcepawn_vm_api_h_
|
@ -11,8 +11,7 @@
|
|||||||
// SourcePawn. If not, see http://www.gnu.org/licenses/.
|
// SourcePawn. If not, see http://www.gnu.org/licenses/.
|
||||||
//
|
//
|
||||||
#include "compiled-function.h"
|
#include "compiled-function.h"
|
||||||
#include "sp_vm_engine.h"
|
#include "x86/jit_x86.h"
|
||||||
#include "jit_x86.h"
|
|
||||||
|
|
||||||
CompiledFunction::CompiledFunction(void *entry_addr, cell_t pcode_offs, FixedArray<LoopEdge> *edges)
|
CompiledFunction::CompiledFunction(void *entry_addr, cell_t pcode_offs, FixedArray<LoopEdge> *edges)
|
||||||
: entry_(entry_addr),
|
: entry_(entry_addr),
|
||||||
|
@ -34,16 +34,12 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <am-utility.h> // Replace with am-cxx later.
|
#include <am-utility.h> // Replace with am-cxx later.
|
||||||
#include "dll_exports.h"
|
#include "dll_exports.h"
|
||||||
#include "sp_vm_engine.h"
|
|
||||||
#include "engine2.h"
|
|
||||||
#include "environment.h"
|
#include "environment.h"
|
||||||
|
|
||||||
using namespace ke;
|
using namespace ke;
|
||||||
using namespace sp;
|
using namespace sp;
|
||||||
using namespace SourcePawn;
|
using namespace SourcePawn;
|
||||||
|
|
||||||
SourcePawnEngine2 g_engine2;
|
|
||||||
|
|
||||||
class SourcePawnFactory : public ISourcePawnFactory
|
class SourcePawnFactory : public ISourcePawnFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -192,14 +188,14 @@ static cell_t PrintFloat(IPluginContext *cx, const cell_t *params)
|
|||||||
|
|
||||||
static int Execute(const char *file)
|
static int Execute(const char *file)
|
||||||
{
|
{
|
||||||
ICompilation *co = g_engine2.StartCompilation();
|
ICompilation *co = sEnv->APIv2()->StartCompilation();
|
||||||
if (!co) {
|
if (!co) {
|
||||||
fprintf(stderr, "Could not create a compilation context\n");
|
fprintf(stderr, "Could not create a compilation context\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int err;
|
int err;
|
||||||
AutoT<IPluginRuntime> rt(g_engine2.LoadPlugin(co, file, &err));
|
AutoT<IPluginRuntime> rt(sEnv->APIv2()->LoadPlugin(co, file, &err));
|
||||||
if (!rt) {
|
if (!rt) {
|
||||||
fprintf(stderr, "Could not load plugin: %s\n", sEnv->GetErrorString(err));
|
fprintf(stderr, "Could not load plugin: %s\n", sEnv->GetErrorString(err));
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
// vim: set sts=2 ts=8 sw=2 tw=99 et:
|
|
||||||
//
|
|
||||||
// Copyright (C) 2006-2015 AlliedModders LLC
|
|
||||||
//
|
|
||||||
// This file is part of SourcePawn. SourcePawn is free software: you can
|
|
||||||
// redistribute it and/or modify it under the terms of the GNU General Public
|
|
||||||
// License as published by the Free Software Foundation, either version 3 of
|
|
||||||
// the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License along with
|
|
||||||
// SourcePawn. If not, see http://www.gnu.org/licenses/.
|
|
||||||
//
|
|
||||||
#ifndef _INCLUDE_SOURCEPAWN_ENGINE_2_H_
|
|
||||||
#define _INCLUDE_SOURCEPAWN_ENGINE_2_H_
|
|
||||||
|
|
||||||
#include <sp_vm_api.h>
|
|
||||||
#include <am-utility.h> // Replace with am-cxx later.
|
|
||||||
|
|
||||||
namespace SourcePawn {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Outlines the interface a Virtual Machine (JIT) must expose
|
|
||||||
*/
|
|
||||||
class SourcePawnEngine2 : public ISourcePawnEngine2
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SourcePawnEngine2();
|
|
||||||
|
|
||||||
public:
|
|
||||||
unsigned int GetAPIVersion();
|
|
||||||
const char *GetEngineName();
|
|
||||||
const char *GetVersionString();
|
|
||||||
IPluginRuntime *LoadPlugin(ICompilation *co, const char *file, int *err);
|
|
||||||
SPVM_NATIVE_FUNC CreateFakeNative(SPVM_FAKENATIVE_FUNC callback, void *pData);
|
|
||||||
void DestroyFakeNative(SPVM_NATIVE_FUNC func);
|
|
||||||
IDebugListener *SetDebugListener(IDebugListener *listener);
|
|
||||||
ICompilation *StartCompilation();
|
|
||||||
const char *GetErrorString(int err);
|
|
||||||
bool Initialize();
|
|
||||||
void Shutdown();
|
|
||||||
IPluginRuntime *CreateEmptyRuntime(const char *name, uint32_t memory);
|
|
||||||
bool InstallWatchdogTimer(size_t timeout_ms);
|
|
||||||
|
|
||||||
bool SetJitEnabled(bool enabled) KE_OVERRIDE;
|
|
||||||
bool IsJitEnabled() KE_OVERRIDE;
|
|
||||||
void SetProfiler(IProfiler *profiler) KE_OVERRIDE;
|
|
||||||
void EnableProfiling() KE_OVERRIDE;
|
|
||||||
void DisableProfiling() KE_OVERRIDE;
|
|
||||||
void SetProfilingTool(IProfilingTool *tool) KE_OVERRIDE;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace SourcePawn
|
|
||||||
|
|
||||||
#endif //_INCLUDE_SOURCEPAWN_ENGINE_2_H_
|
|
@ -11,11 +11,10 @@
|
|||||||
// SourcePawn. If not, see http://www.gnu.org/licenses/.
|
// SourcePawn. If not, see http://www.gnu.org/licenses/.
|
||||||
//
|
//
|
||||||
#include "environment.h"
|
#include "environment.h"
|
||||||
#include "sp_vm_engine.h"
|
|
||||||
#include "engine2.h"
|
|
||||||
#include "x86/jit_x86.h"
|
#include "x86/jit_x86.h"
|
||||||
#include "watchdog_timer.h"
|
#include "watchdog_timer.h"
|
||||||
#include "debug-trace.h"
|
#include "debug-trace.h"
|
||||||
|
#include "api.h"
|
||||||
|
|
||||||
using namespace sp;
|
using namespace sp;
|
||||||
using namespace SourcePawn;
|
using namespace SourcePawn;
|
||||||
|
@ -15,10 +15,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "plugin-runtime.h"
|
#include "plugin-runtime.h"
|
||||||
#include "sp_vm_engine.h"
|
|
||||||
#include "x86/jit_x86.h"
|
#include "x86/jit_x86.h"
|
||||||
#include "sp_vm_basecontext.h"
|
#include "sp_vm_basecontext.h"
|
||||||
#include "engine2.h"
|
|
||||||
|
|
||||||
#include "md5/md5.h"
|
#include "md5/md5.h"
|
||||||
|
|
||||||
|
@ -37,8 +37,6 @@ class CPlugin;
|
|||||||
|
|
||||||
class ScriptedInvoker : public IPluginFunction
|
class ScriptedInvoker : public IPluginFunction
|
||||||
{
|
{
|
||||||
friend class SourcePawnEngine;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ScriptedInvoker(PluginRuntime *pRuntime, funcid_t fnid, uint32_t pub_id);
|
ScriptedInvoker(PluginRuntime *pRuntime, funcid_t fnid, uint32_t pub_id);
|
||||||
~ScriptedInvoker();
|
~ScriptedInvoker();
|
||||||
|
@ -16,10 +16,8 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include "sp_vm_api.h"
|
#include "sp_vm_api.h"
|
||||||
#include "sp_vm_basecontext.h"
|
#include "sp_vm_basecontext.h"
|
||||||
#include "sp_vm_engine.h"
|
|
||||||
#include "watchdog_timer.h"
|
#include "watchdog_timer.h"
|
||||||
#include "x86/jit_x86.h"
|
#include "x86/jit_x86.h"
|
||||||
#include "engine2.h"
|
|
||||||
#include "interpreter.h"
|
#include "interpreter.h"
|
||||||
#include "environment.h"
|
#include "environment.h"
|
||||||
|
|
||||||
|
@ -10,159 +10,4 @@
|
|||||||
// You should have received a copy of the GNU General Public License along with
|
// You should have received a copy of the GNU General Public License along with
|
||||||
// SourcePawn. If not, see http://www.gnu.org/licenses/.
|
// SourcePawn. If not, see http://www.gnu.org/licenses/.
|
||||||
//
|
//
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include "sp_vm_types.h"
|
|
||||||
#include <KeCodeAllocator.h>
|
|
||||||
#include "sp_vm_engine.h"
|
|
||||||
#include "jit_x86.h"
|
|
||||||
#include "zlib/zlib.h"
|
|
||||||
#include "sp_vm_basecontext.h"
|
|
||||||
#include "environment.h"
|
|
||||||
#if defined __GNUC__
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined WIN32
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#include <windows.h>
|
|
||||||
#elif defined __GNUC__
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined __linux__
|
|
||||||
#include <malloc.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace SourcePawn;
|
|
||||||
|
|
||||||
const char *
|
|
||||||
SourcePawnEngine::GetErrorString(int error)
|
|
||||||
{
|
|
||||||
return Environment::get()->GetErrorString(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
SourcePawnEngine::SourcePawnEngine()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
SourcePawnEngine::~SourcePawnEngine()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
SourcePawnEngine::ExecAlloc(size_t size)
|
|
||||||
{
|
|
||||||
#if defined WIN32
|
|
||||||
return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
|
||||||
#elif defined __GNUC__
|
|
||||||
# if defined __APPLE__
|
|
||||||
void *base = valloc(size);
|
|
||||||
# else
|
|
||||||
void *base = memalign(sysconf(_SC_PAGESIZE), size);
|
|
||||||
# endif
|
|
||||||
if (mprotect(base, size, PROT_READ|PROT_WRITE|PROT_EXEC) != 0) {
|
|
||||||
free(base);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return base;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
SourcePawnEngine::AllocatePageMemory(size_t size)
|
|
||||||
{
|
|
||||||
return g_Jit.AllocCode(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
SourcePawnEngine::SetReadExecute(void *ptr)
|
|
||||||
{
|
|
||||||
/* already re */
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
SourcePawnEngine::SetReadWrite(void *ptr)
|
|
||||||
{
|
|
||||||
/* already rw */
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
SourcePawnEngine::FreePageMemory(void *ptr)
|
|
||||||
{
|
|
||||||
g_Jit.FreeCode(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
SourcePawnEngine::ExecFree(void *address)
|
|
||||||
{
|
|
||||||
#if defined WIN32
|
|
||||||
VirtualFree(address, 0, MEM_RELEASE);
|
|
||||||
#elif defined __GNUC__
|
|
||||||
free(address);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
SourcePawnEngine::SetReadWriteExecute(void *ptr)
|
|
||||||
{
|
|
||||||
//:TODO: g_ExeMemory.SetRWE(ptr);
|
|
||||||
SetReadExecute(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
SourcePawnEngine::BaseAlloc(size_t size)
|
|
||||||
{
|
|
||||||
return malloc(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
SourcePawnEngine::BaseFree(void *memory)
|
|
||||||
{
|
|
||||||
free(memory);
|
|
||||||
}
|
|
||||||
|
|
||||||
sp_plugin_t *
|
|
||||||
SourcePawnEngine::LoadFromFilePointer(FILE *fp, int *err)
|
|
||||||
{
|
|
||||||
if (err != NULL)
|
|
||||||
*err = SP_ERROR_ABORTED;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
sp_plugin_t *
|
|
||||||
SourcePawnEngine::LoadFromMemory(void *base, sp_plugin_t *plugin, int *err)
|
|
||||||
{
|
|
||||||
if (err != NULL)
|
|
||||||
*err = SP_ERROR_ABORTED;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
SourcePawnEngine::FreeFromMemory(sp_plugin_t *plugin)
|
|
||||||
{
|
|
||||||
return SP_ERROR_ABORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
IDebugListener *
|
|
||||||
SourcePawnEngine::SetDebugListener(IDebugListener *pListener)
|
|
||||||
{
|
|
||||||
IDebugListener *old = Environment::get()->debugger();
|
|
||||||
Environment::get()->SetDebugger(pListener);
|
|
||||||
return old;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
SourcePawnEngine::GetEngineAPIVersion()
|
|
||||||
{
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
SourcePawnEngine::GetContextCallCount()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
@ -33,8 +33,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "jit_x86.h"
|
#include "jit_x86.h"
|
||||||
#include "../sp_vm_engine.h"
|
|
||||||
#include "../engine2.h"
|
|
||||||
#include "../plugin-runtime.h"
|
#include "../plugin-runtime.h"
|
||||||
#include "../sp_vm_basecontext.h"
|
#include "../sp_vm_basecontext.h"
|
||||||
#include "watchdog_timer.h"
|
#include "watchdog_timer.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user