Modernize sp_vm_basecontext.
This commit is contained in:
parent
1b47aa10ca
commit
45c43f4aee
@ -1,34 +1,15 @@
|
||||
/**
|
||||
* vim: set ts=4 sw=4 tw=99 noet:
|
||||
* =============================================================================
|
||||
* SourcePawn
|
||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||
* this exception to all derivative works. AlliedModders LLC defines further
|
||||
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||
* or <http://www.sourcemod.net/license.php>.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
// 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/.
|
||||
//
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
@ -55,25 +36,19 @@ BaseContext::BaseContext(BaseRuntime *pRuntime)
|
||||
|
||||
/* Initialize the null references */
|
||||
uint32_t index;
|
||||
if (FindPubvarByName("NULL_VECTOR", &index) == SP_ERROR_NONE)
|
||||
{
|
||||
if (FindPubvarByName("NULL_VECTOR", &index) == SP_ERROR_NONE) {
|
||||
sp_pubvar_t *pubvar;
|
||||
GetPubvarByIndex(index, &pubvar);
|
||||
m_pNullVec = pubvar->offs;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
m_pNullVec = NULL;
|
||||
}
|
||||
|
||||
if (FindPubvarByName("NULL_STRING", &index) == SP_ERROR_NONE)
|
||||
{
|
||||
if (FindPubvarByName("NULL_STRING", &index) == SP_ERROR_NONE) {
|
||||
sp_pubvar_t *pubvar;
|
||||
GetPubvarByIndex(index, &pubvar);
|
||||
m_pNullString = pubvar->offs;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
m_pNullString = NULL;
|
||||
}
|
||||
|
||||
@ -92,49 +67,58 @@ BaseContext::~BaseContext()
|
||||
g_Jit.FreeContextVars(&m_ctx);
|
||||
}
|
||||
|
||||
IVirtualMachine *BaseContext::GetVirtualMachine()
|
||||
IVirtualMachine *
|
||||
BaseContext::GetVirtualMachine()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sp_context_t *BaseContext::GetContext()
|
||||
sp_context_t *
|
||||
BaseContext::GetContext()
|
||||
{
|
||||
return reinterpret_cast<sp_context_t *>((IPluginContext * )this);
|
||||
}
|
||||
|
||||
sp_context_t *BaseContext::GetCtx()
|
||||
sp_context_t *
|
||||
BaseContext::GetCtx()
|
||||
{
|
||||
return &m_ctx;
|
||||
}
|
||||
|
||||
bool BaseContext::IsDebugging()
|
||||
bool
|
||||
BaseContext::IsDebugging()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int BaseContext::SetDebugBreak(void *newpfn, void *oldpfn)
|
||||
int
|
||||
BaseContext::SetDebugBreak(void *newpfn, void *oldpfn)
|
||||
{
|
||||
return SP_ERROR_ABORTED;
|
||||
}
|
||||
|
||||
IPluginDebugInfo *BaseContext::GetDebugInfo()
|
||||
IPluginDebugInfo *
|
||||
BaseContext::GetDebugInfo()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int BaseContext::Execute(uint32_t code_addr, cell_t *result)
|
||||
int
|
||||
BaseContext::Execute(uint32_t code_addr, cell_t *result)
|
||||
{
|
||||
return SP_ERROR_ABORTED;
|
||||
}
|
||||
|
||||
void BaseContext::SetErrorMessage(const char *msg, va_list ap)
|
||||
void
|
||||
BaseContext::SetErrorMessage(const char *msg, va_list ap)
|
||||
{
|
||||
m_CustomMsg = true;
|
||||
|
||||
vsnprintf(m_MsgCache, sizeof(m_MsgCache), msg, ap);
|
||||
}
|
||||
|
||||
void BaseContext::_SetErrorMessage(const char *msg, ...)
|
||||
void
|
||||
BaseContext::_SetErrorMessage(const char *msg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
@ -142,17 +126,15 @@ void BaseContext::_SetErrorMessage(const char *msg, ...)
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
cell_t BaseContext::ThrowNativeErrorEx(int error, const char *msg, ...)
|
||||
cell_t
|
||||
BaseContext::ThrowNativeErrorEx(int error, const char *msg, ...)
|
||||
{
|
||||
if (!m_InExec)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_ctx.n_err = error;
|
||||
|
||||
if (msg)
|
||||
{
|
||||
if (msg) {
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
SetErrorMessage(msg, ap);
|
||||
@ -162,17 +144,15 @@ cell_t BaseContext::ThrowNativeErrorEx(int error, const char *msg, ...)
|
||||
return 0;
|
||||
}
|
||||
|
||||
cell_t BaseContext::ThrowNativeError(const char *msg, ...)
|
||||
cell_t
|
||||
BaseContext::ThrowNativeError(const char *msg, ...)
|
||||
{
|
||||
if (!m_InExec)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_ctx.n_err = SP_ERROR_NATIVE;
|
||||
|
||||
if (msg)
|
||||
{
|
||||
if (msg) {
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
SetErrorMessage(msg, ap);
|
||||
@ -182,7 +162,8 @@ cell_t BaseContext::ThrowNativeError(const char *msg, ...)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BaseContext::HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr)
|
||||
int
|
||||
BaseContext::HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr)
|
||||
{
|
||||
cell_t *addr;
|
||||
ucell_t realmem;
|
||||
@ -202,9 +183,7 @@ int BaseContext::HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys
|
||||
* Check if the space between the heap and stack is sufficient.
|
||||
*/
|
||||
if ((cell_t)(m_ctx.sp - m_ctx.hp - realmem) < STACKMARGIN)
|
||||
{
|
||||
return SP_ERROR_HEAPLOW;
|
||||
}
|
||||
|
||||
addr = (cell_t *)(m_pRuntime->plugin()->memory + m_ctx.hp);
|
||||
/* store size of allocation in cells */
|
||||
@ -215,16 +194,15 @@ int BaseContext::HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys
|
||||
*local_addr = m_ctx.hp;
|
||||
|
||||
if (phys_addr)
|
||||
{
|
||||
*phys_addr = addr;
|
||||
}
|
||||
|
||||
m_ctx.hp += realmem;
|
||||
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
int BaseContext::HeapPop(cell_t local_addr)
|
||||
int
|
||||
BaseContext::HeapPop(cell_t local_addr)
|
||||
{
|
||||
cell_t cellcount;
|
||||
cell_t *addr;
|
||||
@ -232,17 +210,13 @@ int BaseContext::HeapPop(cell_t local_addr)
|
||||
/* check the bounds of this address */
|
||||
local_addr -= sizeof(cell_t);
|
||||
if (local_addr < (cell_t)m_pRuntime->plugin()->data_size || local_addr >= m_ctx.sp)
|
||||
{
|
||||
return SP_ERROR_INVALID_ADDRESS;
|
||||
}
|
||||
|
||||
addr = (cell_t *)(m_pRuntime->plugin()->memory + local_addr);
|
||||
cellcount = (*addr) * sizeof(cell_t);
|
||||
/* check if this memory count looks valid */
|
||||
if ((signed)(m_ctx.hp - cellcount - sizeof(cell_t)) != local_addr)
|
||||
{
|
||||
return SP_ERROR_INVALID_ADDRESS;
|
||||
}
|
||||
|
||||
m_ctx.hp = local_addr;
|
||||
|
||||
@ -250,124 +224,139 @@ int BaseContext::HeapPop(cell_t local_addr)
|
||||
}
|
||||
|
||||
|
||||
int BaseContext::HeapRelease(cell_t local_addr)
|
||||
int
|
||||
BaseContext::HeapRelease(cell_t local_addr)
|
||||
{
|
||||
if (local_addr < (cell_t)m_pRuntime->plugin()->data_size)
|
||||
{
|
||||
return SP_ERROR_INVALID_ADDRESS;
|
||||
}
|
||||
|
||||
m_ctx.hp = local_addr - sizeof(cell_t);
|
||||
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
int BaseContext::FindNativeByName(const char *name, uint32_t *index)
|
||||
int
|
||||
BaseContext::FindNativeByName(const char *name, uint32_t *index)
|
||||
{
|
||||
return m_pRuntime->FindNativeByName(name, index);
|
||||
}
|
||||
|
||||
int BaseContext::GetNativeByIndex(uint32_t index, sp_native_t **native)
|
||||
int
|
||||
BaseContext::GetNativeByIndex(uint32_t index, sp_native_t **native)
|
||||
{
|
||||
return m_pRuntime->GetNativeByIndex(index, native);
|
||||
}
|
||||
|
||||
|
||||
uint32_t BaseContext::GetNativesNum()
|
||||
uint32_t
|
||||
BaseContext::GetNativesNum()
|
||||
{
|
||||
return m_pRuntime->GetNativesNum();
|
||||
}
|
||||
|
||||
int BaseContext::FindPublicByName(const char *name, uint32_t *index)
|
||||
int
|
||||
BaseContext::FindPublicByName(const char *name, uint32_t *index)
|
||||
{
|
||||
return m_pRuntime->FindPublicByName(name, index);
|
||||
}
|
||||
|
||||
int BaseContext::GetPublicByIndex(uint32_t index, sp_public_t **pblic)
|
||||
int
|
||||
BaseContext::GetPublicByIndex(uint32_t index, sp_public_t **pblic)
|
||||
{
|
||||
return m_pRuntime->GetPublicByIndex(index, pblic);
|
||||
}
|
||||
|
||||
uint32_t BaseContext::GetPublicsNum()
|
||||
uint32_t
|
||||
BaseContext::GetPublicsNum()
|
||||
{
|
||||
return m_pRuntime->GetPublicsNum();
|
||||
}
|
||||
|
||||
int BaseContext::GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar)
|
||||
int
|
||||
BaseContext::GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar)
|
||||
{
|
||||
return m_pRuntime->GetPubvarByIndex(index, pubvar);
|
||||
}
|
||||
|
||||
int BaseContext::FindPubvarByName(const char *name, uint32_t *index)
|
||||
int
|
||||
BaseContext::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)
|
||||
int
|
||||
BaseContext::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()
|
||||
uint32_t
|
||||
BaseContext::GetPubVarsNum()
|
||||
{
|
||||
return m_pRuntime->GetPubVarsNum();
|
||||
}
|
||||
|
||||
int BaseContext::BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite)
|
||||
int
|
||||
BaseContext::BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite)
|
||||
{
|
||||
return SP_ERROR_ABORTED;
|
||||
}
|
||||
|
||||
int BaseContext::BindNative(const sp_nativeinfo_t *native)
|
||||
int
|
||||
BaseContext::BindNative(const sp_nativeinfo_t *native)
|
||||
{
|
||||
return SP_ERROR_ABORTED;
|
||||
}
|
||||
|
||||
int BaseContext::BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC func)
|
||||
int
|
||||
BaseContext::BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC func)
|
||||
{
|
||||
return SP_ERROR_ABORTED;
|
||||
}
|
||||
|
||||
int BaseContext::BindNativeToAny(SPVM_NATIVE_FUNC native)
|
||||
int
|
||||
BaseContext::BindNativeToAny(SPVM_NATIVE_FUNC native)
|
||||
{
|
||||
return SP_ERROR_ABORTED;
|
||||
}
|
||||
|
||||
int BaseContext::LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr)
|
||||
int
|
||||
BaseContext::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))
|
||||
if (((local_addr >= m_ctx.hp) && (local_addr < m_ctx.sp)) ||
|
||||
(local_addr < 0) || ((ucell_t)local_addr >= m_pRuntime->plugin()->mem_size))
|
||||
{
|
||||
return SP_ERROR_INVALID_ADDRESS;
|
||||
}
|
||||
|
||||
if (phys_addr)
|
||||
{
|
||||
*phys_addr = (cell_t *)(m_pRuntime->plugin()->memory + local_addr);
|
||||
}
|
||||
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
int BaseContext::PushCell(cell_t value)
|
||||
int
|
||||
BaseContext::PushCell(cell_t value)
|
||||
{
|
||||
return SP_ERROR_ABORTED;
|
||||
}
|
||||
|
||||
int BaseContext::PushCellsFromArray(cell_t array[], unsigned int numcells)
|
||||
int
|
||||
BaseContext::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)
|
||||
int
|
||||
BaseContext::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)
|
||||
int
|
||||
BaseContext::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))
|
||||
if (((local_addr >= m_ctx.hp) && (local_addr < m_ctx.sp)) ||
|
||||
(local_addr < 0) || ((ucell_t)local_addr >= m_pRuntime->plugin()->mem_size))
|
||||
{
|
||||
return SP_ERROR_INVALID_ADDRESS;
|
||||
}
|
||||
@ -376,34 +365,32 @@ int BaseContext::LocalToString(cell_t local_addr, char **addr)
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
int BaseContext::PushString(cell_t *local_addr, char **phys_addr, const char *string)
|
||||
int
|
||||
BaseContext::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)
|
||||
int
|
||||
BaseContext::StringToLocal(cell_t local_addr, size_t bytes, const char *source)
|
||||
{
|
||||
char *dest;
|
||||
size_t len;
|
||||
|
||||
if (((local_addr >= m_ctx.hp) && (local_addr < m_ctx.sp))
|
||||
|| (local_addr < 0) || ((ucell_t)local_addr >= m_pRuntime->plugin()->mem_size))
|
||||
if (((local_addr >= m_ctx.hp) && (local_addr < m_ctx.sp)) ||
|
||||
(local_addr < 0) || ((ucell_t)local_addr >= m_pRuntime->plugin()->mem_size))
|
||||
{
|
||||
return SP_ERROR_INVALID_ADDRESS;
|
||||
}
|
||||
|
||||
if (bytes == 0)
|
||||
{
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
len = strlen(source);
|
||||
dest = (char *)(m_pRuntime->plugin()->memory + local_addr);
|
||||
|
||||
if (len >= bytes)
|
||||
{
|
||||
len = bytes - 1;
|
||||
}
|
||||
|
||||
memmove(dest, source, len);
|
||||
dest[len] = '\0';
|
||||
@ -411,15 +398,14 @@ int BaseContext::StringToLocal(cell_t local_addr, size_t bytes, const char *sour
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
inline int __CheckValidChar(char *c)
|
||||
static inline int
|
||||
__CheckValidChar(char *c)
|
||||
{
|
||||
int count;
|
||||
int bytecount = 0;
|
||||
|
||||
for (count=1; (*c & 0xC0) == 0x80; count++)
|
||||
{
|
||||
c--;
|
||||
}
|
||||
|
||||
switch (*c & 0xF0)
|
||||
{
|
||||
@ -442,109 +428,99 @@ inline int __CheckValidChar(char *c)
|
||||
}
|
||||
|
||||
if (bytecount != count)
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BaseContext::StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes)
|
||||
int
|
||||
BaseContext::StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes)
|
||||
{
|
||||
char *dest;
|
||||
size_t len;
|
||||
bool needtocheck = false;
|
||||
|
||||
if (((local_addr >= m_ctx.hp) && (local_addr < m_ctx.sp))
|
||||
|| (local_addr < 0)
|
||||
|| ((ucell_t)local_addr >= m_pRuntime->plugin()->mem_size))
|
||||
if (((local_addr >= m_ctx.hp) && (local_addr < m_ctx.sp)) ||
|
||||
(local_addr < 0) ||
|
||||
((ucell_t)local_addr >= m_pRuntime->plugin()->mem_size))
|
||||
{
|
||||
return SP_ERROR_INVALID_ADDRESS;
|
||||
}
|
||||
|
||||
if (maxbytes == 0)
|
||||
{
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
len = strlen(source);
|
||||
dest = (char *)(m_pRuntime->plugin()->memory + local_addr);
|
||||
|
||||
if ((size_t)len >= maxbytes)
|
||||
{
|
||||
if ((size_t)len >= maxbytes) {
|
||||
len = maxbytes - 1;
|
||||
needtocheck = true;
|
||||
}
|
||||
|
||||
memmove(dest, source, len);
|
||||
if ((dest[len-1] & 1<<7) && needtocheck)
|
||||
{
|
||||
len -= __CheckValidChar(dest+len-1);
|
||||
}
|
||||
dest[len] = '\0';
|
||||
|
||||
if (wrtnbytes)
|
||||
{
|
||||
*wrtnbytes = len;
|
||||
}
|
||||
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
IPluginFunction *BaseContext::GetFunctionById(funcid_t func_id)
|
||||
IPluginFunction *
|
||||
BaseContext::GetFunctionById(funcid_t func_id)
|
||||
{
|
||||
return m_pRuntime->GetFunctionById(func_id);
|
||||
}
|
||||
|
||||
IPluginFunction *BaseContext::GetFunctionByName(const char *public_name)
|
||||
IPluginFunction *
|
||||
BaseContext::GetFunctionByName(const char *public_name)
|
||||
{
|
||||
return m_pRuntime->GetFunctionByName(public_name);
|
||||
}
|
||||
|
||||
int BaseContext::LocalToStringNULL(cell_t local_addr, char **addr)
|
||||
int
|
||||
BaseContext::LocalToStringNULL(cell_t local_addr, char **addr)
|
||||
{
|
||||
int err;
|
||||
if ((err = LocalToString(local_addr, addr)) != SP_ERROR_NONE)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((cell_t *)*addr == m_pNullString)
|
||||
{
|
||||
*addr = NULL;
|
||||
}
|
||||
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
SourceMod::IdentityToken_t *BaseContext::GetIdentity()
|
||||
SourceMod::IdentityToken_t *
|
||||
BaseContext::GetIdentity()
|
||||
{
|
||||
SourceMod::IdentityToken_t *tok;
|
||||
|
||||
if (GetKey(1, (void **)&tok))
|
||||
{
|
||||
return tok;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cell_t *BaseContext::GetNullRef(SP_NULL_TYPE type)
|
||||
cell_t *
|
||||
BaseContext::GetNullRef(SP_NULL_TYPE type)
|
||||
{
|
||||
if (type == SP_NULL_VECTOR)
|
||||
{
|
||||
return m_pNullVec;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool BaseContext::IsInExec()
|
||||
bool
|
||||
BaseContext::IsInExec()
|
||||
{
|
||||
return m_InExec;
|
||||
}
|
||||
|
||||
int BaseContext::Execute2(IPluginFunction *function, const cell_t *params, unsigned int num_params, cell_t *result)
|
||||
int
|
||||
BaseContext::Execute2(IPluginFunction *function, const cell_t *params, unsigned int num_params, cell_t *result)
|
||||
{
|
||||
int ir;
|
||||
int serial;
|
||||
@ -579,20 +555,16 @@ int BaseContext::Execute2(IPluginFunction *function, const cell_t *params, unsig
|
||||
EnterProfileScope scriptScope("SourcePawn", cfun->FullName());
|
||||
|
||||
/* See if we have to compile the callee. */
|
||||
if (g_engine2.IsJitEnabled() && (fn = m_pRuntime->m_PubJitFuncs[public_id]) == NULL)
|
||||
if (g_engine2.IsJitEnabled() &&
|
||||
(fn = m_pRuntime->m_PubJitFuncs[public_id]) == NULL)
|
||||
{
|
||||
/* We might not have to - check pcode offset. */
|
||||
fn = m_pRuntime->GetJittedFunctionByOffset(cfun->Public()->code_offs);
|
||||
if (fn)
|
||||
{
|
||||
if (fn) {
|
||||
m_pRuntime->m_PubJitFuncs[public_id] = fn;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ((fn = g_Jit.CompileFunction(m_pRuntime, cfun->Public()->code_offs, &ir)) == NULL)
|
||||
{
|
||||
return ir;
|
||||
}
|
||||
m_pRuntime->m_PubJitFuncs[public_id] = fn;
|
||||
}
|
||||
}
|
||||
@ -617,9 +589,7 @@ int BaseContext::Execute2(IPluginFunction *function, const cell_t *params, unsig
|
||||
|
||||
sp[0] = num_params;
|
||||
for (unsigned int i = 0; i < num_params; i++)
|
||||
{
|
||||
sp[i + 1] = params[i];
|
||||
}
|
||||
|
||||
/* Clear internal state */
|
||||
m_ctx.n_err = SP_ERROR_NONE;
|
||||
@ -639,25 +609,21 @@ int BaseContext::Execute2(IPluginFunction *function, const cell_t *params, unsig
|
||||
|
||||
m_InExec = save_exec;
|
||||
|
||||
if (ir == SP_ERROR_NONE)
|
||||
{
|
||||
if (ir == SP_ERROR_NONE) {
|
||||
m_ctx.n_err = SP_ERROR_NONE;
|
||||
if (m_ctx.sp != save_sp)
|
||||
{
|
||||
if (m_ctx.sp != save_sp) {
|
||||
ir = SP_ERROR_STACKLEAK;
|
||||
_SetErrorMessage("Stack leak detected: sp:%d should be %d!",
|
||||
m_ctx.sp,
|
||||
save_sp);
|
||||
}
|
||||
if (m_ctx.hp != save_hp)
|
||||
{
|
||||
if (m_ctx.hp != save_hp) {
|
||||
ir = SP_ERROR_HEAPLEAK;
|
||||
_SetErrorMessage("Heap leak detected: hp:%d should be %d!",
|
||||
m_ctx.hp,
|
||||
save_hp);
|
||||
}
|
||||
if (m_ctx.rp != save_rp)
|
||||
{
|
||||
if (m_ctx.rp != save_rp) {
|
||||
ir = SP_ERROR_STACKLEAK;
|
||||
_SetErrorMessage("Return stack leak detected: rp:%d should be %d!",
|
||||
m_ctx.rp,
|
||||
@ -669,9 +635,7 @@ int BaseContext::Execute2(IPluginFunction *function, const cell_t *params, unsig
|
||||
g_WatchdogTimer.NotifyTimeoutReceived();
|
||||
|
||||
if (ir != SP_ERROR_NONE)
|
||||
{
|
||||
g_engine1.ReportError(m_pRuntime, ir, m_MsgCache, save_rp);
|
||||
}
|
||||
|
||||
m_ctx.sp = save_sp;
|
||||
m_ctx.hp = save_hp;
|
||||
@ -686,7 +650,8 @@ int BaseContext::Execute2(IPluginFunction *function, const cell_t *params, unsig
|
||||
return ir;
|
||||
}
|
||||
|
||||
IPluginRuntime *BaseContext::GetRuntime()
|
||||
IPluginRuntime *
|
||||
BaseContext::GetRuntime()
|
||||
{
|
||||
return m_pRuntime;
|
||||
}
|
||||
@ -697,57 +662,50 @@ DebugInfo::DebugInfo(sp_plugin_t *plugin) : m_pPlugin(plugin)
|
||||
|
||||
#define USHR(x) ((unsigned int)(x)>>1)
|
||||
|
||||
int DebugInfo::LookupFile(ucell_t addr, const char **filename)
|
||||
int
|
||||
DebugInfo::LookupFile(ucell_t addr, const char **filename)
|
||||
{
|
||||
int high, low, mid;
|
||||
|
||||
high = m_pPlugin->debug.files_num;
|
||||
low = -1;
|
||||
|
||||
while (high - low > 1)
|
||||
{
|
||||
while (high - low > 1) {
|
||||
mid = USHR(low + high);
|
||||
if (m_pPlugin->debug.files[mid].addr <= addr)
|
||||
{
|
||||
low = mid;
|
||||
} else {
|
||||
else
|
||||
high = mid;
|
||||
}
|
||||
}
|
||||
|
||||
if (low == -1)
|
||||
{
|
||||
return SP_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
*filename = m_pPlugin->debug.stringbase + m_pPlugin->debug.files[low].name;
|
||||
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
int DebugInfo::LookupFunction(ucell_t addr, const char **name)
|
||||
{
|
||||
if (!m_pPlugin->debug.unpacked)
|
||||
int
|
||||
DebugInfo::LookupFunction(ucell_t addr, const char **name)
|
||||
{
|
||||
if (!m_pPlugin->debug.unpacked) {
|
||||
uint32_t max, iter;
|
||||
sp_fdbg_symbol_t *sym;
|
||||
uint8_t *cursor = (uint8_t *)(m_pPlugin->debug.symbols);
|
||||
|
||||
max = m_pPlugin->debug.syms_num;
|
||||
for (iter = 0; iter < max; iter++)
|
||||
{
|
||||
for (iter = 0; iter < max; iter++) {
|
||||
sym = (sp_fdbg_symbol_t *)cursor;
|
||||
|
||||
if (sym->ident == sp::IDENT_FUNCTION
|
||||
&& sym->codestart <= addr
|
||||
&& sym->codeend > addr)
|
||||
if (sym->ident == sp::IDENT_FUNCTION &&
|
||||
sym->codestart <= addr &&
|
||||
sym->codeend > addr)
|
||||
{
|
||||
*name = m_pPlugin->debug.stringbase + sym->name;
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
if (sym->dimcount > 0)
|
||||
{
|
||||
if (sym->dimcount > 0) {
|
||||
cursor += sizeof(sp_fdbg_symbol_t);
|
||||
cursor += sizeof(sp_fdbg_arraydim_t) * sym->dimcount;
|
||||
continue;
|
||||
@ -757,28 +715,24 @@ int DebugInfo::LookupFunction(ucell_t addr, const char **name)
|
||||
}
|
||||
|
||||
return SP_ERROR_NOT_FOUND;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
uint32_t max, iter;
|
||||
sp_u_fdbg_symbol_t *sym;
|
||||
uint8_t *cursor = (uint8_t *)(m_pPlugin->debug.symbols);
|
||||
|
||||
max = m_pPlugin->debug.syms_num;
|
||||
for (iter = 0; iter < max; iter++)
|
||||
{
|
||||
for (iter = 0; iter < max; iter++) {
|
||||
sym = (sp_u_fdbg_symbol_t *)cursor;
|
||||
|
||||
if (sym->ident == sp::IDENT_FUNCTION
|
||||
&& sym->codestart <= addr
|
||||
&& sym->codeend > addr)
|
||||
if (sym->ident == sp::IDENT_FUNCTION &&
|
||||
sym->codestart <= addr &&
|
||||
sym->codeend > addr)
|
||||
{
|
||||
*name = m_pPlugin->debug.stringbase + sym->name;
|
||||
return SP_ERROR_NONE;
|
||||
}
|
||||
|
||||
if (sym->dimcount > 0)
|
||||
{
|
||||
if (sym->dimcount > 0) {
|
||||
cursor += sizeof(sp_u_fdbg_symbol_t);
|
||||
cursor += sizeof(sp_u_fdbg_arraydim_t) * sym->dimcount;
|
||||
continue;
|
||||
@ -791,28 +745,24 @@ int DebugInfo::LookupFunction(ucell_t addr, const char **name)
|
||||
}
|
||||
}
|
||||
|
||||
int DebugInfo::LookupLine(ucell_t addr, uint32_t *line)
|
||||
int
|
||||
DebugInfo::LookupLine(ucell_t addr, uint32_t *line)
|
||||
{
|
||||
int high, low, mid;
|
||||
|
||||
high = m_pPlugin->debug.lines_num;
|
||||
low = -1;
|
||||
|
||||
while (high - low > 1)
|
||||
{
|
||||
while (high - low > 1) {
|
||||
mid = USHR(low + high);
|
||||
if (m_pPlugin->debug.lines[mid].addr <= addr)
|
||||
{
|
||||
low = mid;
|
||||
} else {
|
||||
else
|
||||
high = mid;
|
||||
}
|
||||
}
|
||||
|
||||
if (low == -1)
|
||||
{
|
||||
return SP_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
/* Since the CIP occurs BEFORE the line, we have to add one */
|
||||
*line = m_pPlugin->debug.lines[low].line + 1;
|
||||
@ -822,40 +772,40 @@ int DebugInfo::LookupLine(ucell_t addr, uint32_t *line)
|
||||
|
||||
#undef USHR
|
||||
|
||||
int BaseContext::GetLastNativeError()
|
||||
int
|
||||
BaseContext::GetLastNativeError()
|
||||
{
|
||||
return m_ctx.n_err;
|
||||
}
|
||||
|
||||
cell_t *BaseContext::GetLocalParams()
|
||||
cell_t *
|
||||
BaseContext::GetLocalParams()
|
||||
{
|
||||
return (cell_t *)(m_pRuntime->plugin()->memory + m_ctx.frm + (2 * sizeof(cell_t)));
|
||||
}
|
||||
|
||||
void BaseContext::SetKey(int k, void *value)
|
||||
void
|
||||
BaseContext::SetKey(int k, void *value)
|
||||
{
|
||||
if (k < 1 || k > 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_keys[k - 1] = value;
|
||||
m_keys_set[k - 1] = true;
|
||||
}
|
||||
|
||||
bool BaseContext::GetKey(int k, void **value)
|
||||
bool
|
||||
BaseContext::GetKey(int k, void **value)
|
||||
{
|
||||
if (k < 1 || k > 4 || m_keys_set[k - 1] == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
*value = m_keys[k - 1];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BaseContext::ClearLastNativeError()
|
||||
void
|
||||
BaseContext::ClearLastNativeError()
|
||||
{
|
||||
m_ctx.n_err = SP_ERROR_NONE;
|
||||
}
|
||||
|
@ -1,34 +1,15 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* =============================================================================
|
||||
* SourcePawn
|
||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||
* =============================================================================
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||
* Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||
* this exception to all derivative works. AlliedModders LLC defines further
|
||||
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||
* or <http://www.sourcemod.net/license.php>.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
// 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_BASECONTEXT_H_
|
||||
#define _INCLUDE_SOURCEPAWN_BASECONTEXT_H_
|
||||
|
||||
@ -46,6 +27,7 @@ class BaseContext : public IPluginContext
|
||||
public:
|
||||
BaseContext(BaseRuntime *pRuntime);
|
||||
~BaseContext();
|
||||
|
||||
public: //IPluginContext
|
||||
IVirtualMachine *GetVirtualMachine();
|
||||
sp_context_t *GetContext();
|
||||
@ -94,11 +76,14 @@ public: //IPluginContext
|
||||
bool GetKey(int k, void **value);
|
||||
void Refresh();
|
||||
void ClearLastNativeError();
|
||||
|
||||
public:
|
||||
bool IsInExec();
|
||||
|
||||
private:
|
||||
void SetErrorMessage(const char *msg, va_list ap);
|
||||
void _SetErrorMessage(const char *msg, ...);
|
||||
|
||||
private:
|
||||
cell_t *m_pNullVec;
|
||||
cell_t *m_pNullString;
|
||||
|
Loading…
Reference in New Issue
Block a user