From 2e77155b4e8d6b3be74e359a2e6302e38478f2a9 Mon Sep 17 00:00:00 2001 From: "dvander@alliedmods.net" Date: Tue, 24 Feb 2015 12:50:09 -0800 Subject: [PATCH 1/2] Rename BaseContext to PluginContext. --- sourcepawn/jit/jit_shared.h | 8 +-- sourcepawn/jit/plugin-runtime.cpp | 8 +-- sourcepawn/jit/plugin-runtime.h | 6 +- sourcepawn/jit/sp_vm_basecontext.cpp | 102 +++++++++++++-------------- sourcepawn/jit/sp_vm_basecontext.h | 10 +-- 5 files changed, 65 insertions(+), 69 deletions(-) diff --git a/sourcepawn/jit/jit_shared.h b/sourcepawn/jit/jit_shared.h index 4e06b61e..8c615bf4 100644 --- a/sourcepawn/jit/jit_shared.h +++ b/sourcepawn/jit/jit_shared.h @@ -25,7 +25,7 @@ typedef struct sp_plugin_debug_s bool unpacked; /**< Whether debug structures are unpacked */ } sp_plugin_debug_t; -class BaseContext; +class PluginContext; /** * Breaks into a debugger @@ -34,7 +34,7 @@ class BaseContext; * [1] - frm * [2] - cip */ -typedef int (*SPVM_DEBUGBREAK)(BaseContext *, uint32_t, uint32_t); +typedef int (*SPVM_DEBUGBREAK)(PluginContext *, uint32_t, uint32_t); /** * @brief The rebased memory format of a plugin. This differs from the on-disk structure @@ -69,7 +69,7 @@ namespace SourcePawn } struct tracker_t; -class BaseContext; +class PluginContext; typedef struct sp_context_s { @@ -83,7 +83,7 @@ typedef struct sp_context_s uint32_t n_idx; /**< Current native index being executed */ tracker_t *tracker; sp_plugin_t *plugin; - BaseContext *basecx; + PluginContext *basecx; void * vm[8]; /**< VM-specific pointers */ cell_t rp; /**< Return stack pointer */ cell_t rstk_cips[SP_MAX_RETURN_STACK]; diff --git a/sourcepawn/jit/plugin-runtime.cpp b/sourcepawn/jit/plugin-runtime.cpp index 029d952a..9ce3fd14 100644 --- a/sourcepawn/jit/plugin-runtime.cpp +++ b/sourcepawn/jit/plugin-runtime.cpp @@ -300,7 +300,7 @@ int PluginRuntime::CreateFromMemory(sp_file_hdr_t *hdr, uint8_t *base) md5_data.finalize(); md5_data.raw_digest(m_DataHash); - m_pCtx = new BaseContext(this); + m_pCtx = new PluginContext(this); SetupFloatNativeRemapping(); function_map_size_ = m_plugin.pcode_size / sizeof(cell_t) + 1; @@ -559,7 +559,7 @@ size_t PluginRuntime::GetMemUsage() mem += sizeof(this); mem += sizeof(sp_plugin_t); - mem += sizeof(BaseContext); + mem += sizeof(PluginContext); mem += m_plugin.base_size; return mem; @@ -575,7 +575,7 @@ unsigned char *PluginRuntime::GetDataHash() return m_DataHash; } -BaseContext *PluginRuntime::GetBaseContext() +PluginContext *PluginRuntime::GetBaseContext() { return m_pCtx; } @@ -598,7 +598,7 @@ PluginRuntime::CreateBlank(uint32_t heastk) m_plugin.mem_size = heastk; m_plugin.memory = new uint8_t[heastk]; - m_pCtx = new BaseContext(this); + m_pCtx = new PluginContext(this); return SP_ERROR_NONE; } diff --git a/sourcepawn/jit/plugin-runtime.h b/sourcepawn/jit/plugin-runtime.h index f08c5342..9f0706a0 100644 --- a/sourcepawn/jit/plugin-runtime.h +++ b/sourcepawn/jit/plugin-runtime.h @@ -20,7 +20,7 @@ #include "compiled-function.h" #include "scripted-invoker.h" -class BaseContext; +class PluginContext; class DebugInfo : public IPluginDebugInfo { @@ -84,7 +84,7 @@ class PluginRuntime unsigned GetNativeReplacement(size_t index); ScriptedInvoker *GetPublicFunction(size_t index); - BaseContext *GetBaseContext(); + PluginContext *GetBaseContext(); const sp_plugin_t *plugin() const { return &m_plugin; } @@ -111,7 +111,7 @@ class PluginRuntime public: DebugInfo m_Debug; - BaseContext *m_pCtx; + PluginContext *m_pCtx; ScriptedInvoker **m_PubFuncs; CompiledFunction **m_PubJitFuncs; diff --git a/sourcepawn/jit/sp_vm_basecontext.cpp b/sourcepawn/jit/sp_vm_basecontext.cpp index 7861738f..56bfb1a3 100644 --- a/sourcepawn/jit/sp_vm_basecontext.cpp +++ b/sourcepawn/jit/sp_vm_basecontext.cpp @@ -26,7 +26,7 @@ using namespace SourcePawn; #define CELLBOUNDMAX (INT_MAX/sizeof(cell_t)) #define STACKMARGIN ((cell_t)(16*sizeof(cell_t))) -BaseContext::BaseContext(PluginRuntime *pRuntime) +PluginContext::PluginContext(PluginRuntime *pRuntime) { m_pRuntime = pRuntime; @@ -66,56 +66,56 @@ BaseContext::BaseContext(PluginRuntime *pRuntime) m_ctx.plugin = const_cast(pRuntime->plugin()); } -BaseContext::~BaseContext() +PluginContext::~PluginContext() { free(m_ctx.tracker->pBase); delete m_ctx.tracker; } IVirtualMachine * -BaseContext::GetVirtualMachine() +PluginContext::GetVirtualMachine() { return NULL; } sp_context_t * -BaseContext::GetContext() +PluginContext::GetContext() { return reinterpret_cast((IPluginContext * )this); } sp_context_t * -BaseContext::GetCtx() +PluginContext::GetCtx() { return &m_ctx; } bool -BaseContext::IsDebugging() +PluginContext::IsDebugging() { return true; } int -BaseContext::SetDebugBreak(void *newpfn, void *oldpfn) +PluginContext::SetDebugBreak(void *newpfn, void *oldpfn) { return SP_ERROR_ABORTED; } IPluginDebugInfo * -BaseContext::GetDebugInfo() +PluginContext::GetDebugInfo() { return NULL; } int -BaseContext::Execute(uint32_t code_addr, cell_t *result) +PluginContext::Execute(uint32_t code_addr, cell_t *result) { return SP_ERROR_ABORTED; } void -BaseContext::SetErrorMessage(const char *msg, va_list ap) +PluginContext::SetErrorMessage(const char *msg, va_list ap) { m_CustomMsg = true; @@ -123,7 +123,7 @@ BaseContext::SetErrorMessage(const char *msg, va_list ap) } void -BaseContext::_SetErrorMessage(const char *msg, ...) +PluginContext::_SetErrorMessage(const char *msg, ...) { va_list ap; va_start(ap, msg); @@ -132,7 +132,7 @@ BaseContext::_SetErrorMessage(const char *msg, ...) } cell_t -BaseContext::ThrowNativeErrorEx(int error, const char *msg, ...) +PluginContext::ThrowNativeErrorEx(int error, const char *msg, ...) { if (!m_InExec) return 0; @@ -150,7 +150,7 @@ BaseContext::ThrowNativeErrorEx(int error, const char *msg, ...) } cell_t -BaseContext::ThrowNativeError(const char *msg, ...) +PluginContext::ThrowNativeError(const char *msg, ...) { if (!m_InExec) return 0; @@ -168,7 +168,7 @@ BaseContext::ThrowNativeError(const char *msg, ...) } int -BaseContext::HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr) +PluginContext::HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr) { cell_t *addr; ucell_t realmem; @@ -207,7 +207,7 @@ BaseContext::HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_add } int -BaseContext::HeapPop(cell_t local_addr) +PluginContext::HeapPop(cell_t local_addr) { cell_t cellcount; cell_t *addr; @@ -230,7 +230,7 @@ BaseContext::HeapPop(cell_t local_addr) int -BaseContext::HeapRelease(cell_t local_addr) +PluginContext::HeapRelease(cell_t local_addr) { if (local_addr < (cell_t)m_pRuntime->plugin()->data_size) return SP_ERROR_INVALID_ADDRESS; @@ -241,91 +241,91 @@ BaseContext::HeapRelease(cell_t local_addr) } int -BaseContext::FindNativeByName(const char *name, uint32_t *index) +PluginContext::FindNativeByName(const char *name, uint32_t *index) { return m_pRuntime->FindNativeByName(name, index); } int -BaseContext::GetNativeByIndex(uint32_t index, sp_native_t **native) +PluginContext::GetNativeByIndex(uint32_t index, sp_native_t **native) { return m_pRuntime->GetNativeByIndex(index, native); } uint32_t -BaseContext::GetNativesNum() +PluginContext::GetNativesNum() { return m_pRuntime->GetNativesNum(); } int -BaseContext::FindPublicByName(const char *name, uint32_t *index) +PluginContext::FindPublicByName(const char *name, uint32_t *index) { return m_pRuntime->FindPublicByName(name, index); } int -BaseContext::GetPublicByIndex(uint32_t index, sp_public_t **pblic) +PluginContext::GetPublicByIndex(uint32_t index, sp_public_t **pblic) { return m_pRuntime->GetPublicByIndex(index, pblic); } uint32_t -BaseContext::GetPublicsNum() +PluginContext::GetPublicsNum() { return m_pRuntime->GetPublicsNum(); } int -BaseContext::GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar) +PluginContext::GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar) { return m_pRuntime->GetPubvarByIndex(index, pubvar); } int -BaseContext::FindPubvarByName(const char *name, uint32_t *index) +PluginContext::FindPubvarByName(const char *name, uint32_t *index) { return m_pRuntime->FindPubvarByName(name, index); } int -BaseContext::GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr) +PluginContext::GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr) { return m_pRuntime->GetPubvarAddrs(index, local_addr, phys_addr); } uint32_t -BaseContext::GetPubVarsNum() +PluginContext::GetPubVarsNum() { return m_pRuntime->GetPubVarsNum(); } int -BaseContext::BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite) +PluginContext::BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite) { return SP_ERROR_ABORTED; } int -BaseContext::BindNative(const sp_nativeinfo_t *native) +PluginContext::BindNative(const sp_nativeinfo_t *native) { return SP_ERROR_ABORTED; } int -BaseContext::BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC func) +PluginContext::BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC func) { return SP_ERROR_ABORTED; } int -BaseContext::BindNativeToAny(SPVM_NATIVE_FUNC native) +PluginContext::BindNativeToAny(SPVM_NATIVE_FUNC native) { return SP_ERROR_ABORTED; } int -BaseContext::LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr) +PluginContext::LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr) { if (((local_addr >= m_ctx.hp) && (local_addr < m_ctx.sp)) || (local_addr < 0) || ((ucell_t)local_addr >= m_pRuntime->plugin()->mem_size)) @@ -340,25 +340,25 @@ BaseContext::LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr) } int -BaseContext::PushCell(cell_t value) +PluginContext::PushCell(cell_t value) { return SP_ERROR_ABORTED; } int -BaseContext::PushCellsFromArray(cell_t array[], unsigned int numcells) +PluginContext::PushCellsFromArray(cell_t array[], unsigned int numcells) { return SP_ERROR_ABORTED; } int -BaseContext::PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t array[], unsigned int numcells) +PluginContext::PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t array[], unsigned int numcells) { return SP_ERROR_ABORTED; } int -BaseContext::LocalToString(cell_t local_addr, char **addr) +PluginContext::LocalToString(cell_t local_addr, char **addr) { if (((local_addr >= m_ctx.hp) && (local_addr < m_ctx.sp)) || (local_addr < 0) || ((ucell_t)local_addr >= m_pRuntime->plugin()->mem_size)) @@ -371,13 +371,13 @@ BaseContext::LocalToString(cell_t local_addr, char **addr) } int -BaseContext::PushString(cell_t *local_addr, char **phys_addr, const char *string) +PluginContext::PushString(cell_t *local_addr, char **phys_addr, const char *string) { return SP_ERROR_ABORTED; } int -BaseContext::StringToLocal(cell_t local_addr, size_t bytes, const char *source) +PluginContext::StringToLocal(cell_t local_addr, size_t bytes, const char *source) { char *dest; size_t len; @@ -439,7 +439,7 @@ __CheckValidChar(char *c) } int -BaseContext::StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes) +PluginContext::StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes) { char *dest; size_t len; @@ -475,19 +475,19 @@ BaseContext::StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *s } IPluginFunction * -BaseContext::GetFunctionById(funcid_t func_id) +PluginContext::GetFunctionById(funcid_t func_id) { return m_pRuntime->GetFunctionById(func_id); } IPluginFunction * -BaseContext::GetFunctionByName(const char *public_name) +PluginContext::GetFunctionByName(const char *public_name) { return m_pRuntime->GetFunctionByName(public_name); } int -BaseContext::LocalToStringNULL(cell_t local_addr, char **addr) +PluginContext::LocalToStringNULL(cell_t local_addr, char **addr) { int err; if ((err = LocalToString(local_addr, addr)) != SP_ERROR_NONE) @@ -500,7 +500,7 @@ BaseContext::LocalToStringNULL(cell_t local_addr, char **addr) } SourceMod::IdentityToken_t * -BaseContext::GetIdentity() +PluginContext::GetIdentity() { SourceMod::IdentityToken_t *tok; @@ -510,7 +510,7 @@ BaseContext::GetIdentity() } cell_t * -BaseContext::GetNullRef(SP_NULL_TYPE type) +PluginContext::GetNullRef(SP_NULL_TYPE type) { if (type == SP_NULL_VECTOR) return m_pNullVec; @@ -519,13 +519,13 @@ BaseContext::GetNullRef(SP_NULL_TYPE type) } bool -BaseContext::IsInExec() +PluginContext::IsInExec() { return m_InExec; } int -BaseContext::Execute2(IPluginFunction *function, const cell_t *params, unsigned int num_params, cell_t *result) +PluginContext::Execute2(IPluginFunction *function, const cell_t *params, unsigned int num_params, cell_t *result) { int ir; int serial; @@ -656,7 +656,7 @@ BaseContext::Execute2(IPluginFunction *function, const cell_t *params, unsigned } IPluginRuntime * -BaseContext::GetRuntime() +PluginContext::GetRuntime() { return m_pRuntime; } @@ -778,19 +778,19 @@ DebugInfo::LookupLine(ucell_t addr, uint32_t *line) #undef USHR int -BaseContext::GetLastNativeError() +PluginContext::GetLastNativeError() { return m_ctx.n_err; } cell_t * -BaseContext::GetLocalParams() +PluginContext::GetLocalParams() { return (cell_t *)(m_pRuntime->plugin()->memory + m_ctx.frm + (2 * sizeof(cell_t))); } void -BaseContext::SetKey(int k, void *value) +PluginContext::SetKey(int k, void *value) { if (k < 1 || k > 4) return; @@ -800,7 +800,7 @@ BaseContext::SetKey(int k, void *value) } bool -BaseContext::GetKey(int k, void **value) +PluginContext::GetKey(int k, void **value) { if (k < 1 || k > 4 || m_keys_set[k - 1] == false) return false; @@ -810,7 +810,7 @@ BaseContext::GetKey(int k, void **value) } void -BaseContext::ClearLastNativeError() +PluginContext::ClearLastNativeError() { m_ctx.n_err = SP_ERROR_NONE; } diff --git a/sourcepawn/jit/sp_vm_basecontext.h b/sourcepawn/jit/sp_vm_basecontext.h index 213e849c..a96da4a2 100644 --- a/sourcepawn/jit/sp_vm_basecontext.h +++ b/sourcepawn/jit/sp_vm_basecontext.h @@ -18,15 +18,11 @@ #include "plugin-runtime.h" #include "jit_shared.h" -/** - * :TODO: Make functions allocate as a lump instead of individual allocations! - */ - -class BaseContext : public IPluginContext +class PluginContext : public IPluginContext { public: - BaseContext(PluginRuntime *pRuntime); - ~BaseContext(); + PluginContext(PluginRuntime *pRuntime); + ~PluginContext(); public: //IPluginContext IVirtualMachine *GetVirtualMachine(); From 8eed58a467448060a96cf60ba334fd824e9b529b Mon Sep 17 00:00:00 2001 From: "dvander@alliedmods.net" Date: Tue, 24 Feb 2015 12:55:00 -0800 Subject: [PATCH 2/2] Rename sp_vm_basecontext to plugin-context. --- sourcepawn/jit/AMBuilder | 2 +- sourcepawn/jit/debug-trace.cpp | 2 +- sourcepawn/jit/interpreter.h | 2 +- sourcepawn/jit/{sp_vm_basecontext.cpp => plugin-context.cpp} | 4 ++-- sourcepawn/jit/{sp_vm_basecontext.h => plugin-context.h} | 0 sourcepawn/jit/plugin-runtime.cpp | 2 +- sourcepawn/jit/x86/jit_x86.cpp | 4 ++-- sourcepawn/jit/x86/jit_x86.h | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) rename sourcepawn/jit/{sp_vm_basecontext.cpp => plugin-context.cpp} (95%) rename sourcepawn/jit/{sp_vm_basecontext.h => plugin-context.h} (100%) diff --git a/sourcepawn/jit/AMBuilder b/sourcepawn/jit/AMBuilder index b96a3211..88ba7434 100644 --- a/sourcepawn/jit/AMBuilder +++ b/sourcepawn/jit/AMBuilder @@ -32,11 +32,11 @@ library.sources += [ 'api.cpp', 'code-allocator.cpp', 'code-stubs.cpp', + 'plugin-context.cpp', 'plugin-runtime.cpp', 'compiled-function.cpp', 'debug-trace.cpp', 'environment.cpp', - 'sp_vm_basecontext.cpp', 'scripted-invoker.cpp', 'opcodes.cpp', 'interpreter.cpp', diff --git a/sourcepawn/jit/debug-trace.cpp b/sourcepawn/jit/debug-trace.cpp index d6a0a104..c3a3e60d 100644 --- a/sourcepawn/jit/debug-trace.cpp +++ b/sourcepawn/jit/debug-trace.cpp @@ -11,7 +11,7 @@ // SourcePawn. If not, see http://www.gnu.org/licenses/. // #include "debug-trace.h" -#include "sp_vm_basecontext.h" +#include "plugin-context.h" #include "environment.h" using namespace ke; diff --git a/sourcepawn/jit/interpreter.h b/sourcepawn/jit/interpreter.h index bc698b5a..b4603c96 100644 --- a/sourcepawn/jit/interpreter.h +++ b/sourcepawn/jit/interpreter.h @@ -20,7 +20,7 @@ #include #include #include "plugin-runtime.h" -#include "sp_vm_basecontext.h" +#include "plugin-context.h" struct tracker_t { diff --git a/sourcepawn/jit/sp_vm_basecontext.cpp b/sourcepawn/jit/plugin-context.cpp similarity index 95% rename from sourcepawn/jit/sp_vm_basecontext.cpp rename to sourcepawn/jit/plugin-context.cpp index 56bfb1a3..79d0e451 100644 --- a/sourcepawn/jit/sp_vm_basecontext.cpp +++ b/sourcepawn/jit/plugin-context.cpp @@ -14,8 +14,8 @@ #include #include #include -#include "sp_vm_api.h" -#include "sp_vm_basecontext.h" +#include +#include "plugin-context.h" #include "watchdog_timer.h" #include "x86/jit_x86.h" #include "interpreter.h" diff --git a/sourcepawn/jit/sp_vm_basecontext.h b/sourcepawn/jit/plugin-context.h similarity index 100% rename from sourcepawn/jit/sp_vm_basecontext.h rename to sourcepawn/jit/plugin-context.h diff --git a/sourcepawn/jit/plugin-runtime.cpp b/sourcepawn/jit/plugin-runtime.cpp index 9ce3fd14..9f88feeb 100644 --- a/sourcepawn/jit/plugin-runtime.cpp +++ b/sourcepawn/jit/plugin-runtime.cpp @@ -16,7 +16,7 @@ #include #include "plugin-runtime.h" #include "x86/jit_x86.h" -#include "sp_vm_basecontext.h" +#include "plugin-context.h" #include "environment.h" #include "md5/md5.h" diff --git a/sourcepawn/jit/x86/jit_x86.cpp b/sourcepawn/jit/x86/jit_x86.cpp index 8a413f14..5c00bcac 100644 --- a/sourcepawn/jit/x86/jit_x86.cpp +++ b/sourcepawn/jit/x86/jit_x86.cpp @@ -33,8 +33,8 @@ #include #include #include "jit_x86.h" -#include "../plugin-runtime.h" -#include "../sp_vm_basecontext.h" +#include "plugin-runtime.h" +#include "plugin-context.h" #include "watchdog_timer.h" #include "interpreter.h" #include "environment.h" diff --git a/sourcepawn/jit/x86/jit_x86.h b/sourcepawn/jit/x86/jit_x86.h index 45e4aa0e..3af246b2 100644 --- a/sourcepawn/jit/x86/jit_x86.h +++ b/sourcepawn/jit/x86/jit_x86.h @@ -23,7 +23,7 @@ #include #include "jit_shared.h" #include "plugin-runtime.h" -#include "sp_vm_basecontext.h" +#include "plugin-context.h" #include "compiled-function.h" #include "opcodes.h"