Non-public function addresses are no longer accepted
Added a new VM function for pcode addresses (unused right now) --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40349
This commit is contained in:
parent
dbf105cc71
commit
aeb512c444
@ -150,7 +150,11 @@ int BaseContext::Execute(funcid_t funcid, cell_t *result)
|
|||||||
}
|
}
|
||||||
code_addr = pubfunc->code_offs;
|
code_addr = pubfunc->code_offs;
|
||||||
} else {
|
} else {
|
||||||
|
#if 0
|
||||||
code_addr = funcid >> 1;
|
code_addr = funcid >> 1;
|
||||||
|
#endif
|
||||||
|
assert(false);
|
||||||
|
return SP_ERROR_INVALID_ADDRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
PushCell(pushcount++);
|
PushCell(pushcount++);
|
||||||
@ -875,6 +879,7 @@ IPluginFunction *BaseContext::GetFunctionById(funcid_t func_id)
|
|||||||
pFunc = m_pub_funcs[func_id];
|
pFunc = m_pub_funcs[func_id];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
#if 0
|
||||||
func_id >>= 1;
|
func_id >>= 1;
|
||||||
unsigned int index;
|
unsigned int index;
|
||||||
if (!g_pVM->FunctionLookup(ctx, func_id, &index))
|
if (!g_pVM->FunctionLookup(ctx, func_id, &index))
|
||||||
@ -887,6 +892,8 @@ IPluginFunction *BaseContext::GetFunctionById(funcid_t func_id)
|
|||||||
m_priv_funcs[func_id] = new CFunction(save, this);
|
m_priv_funcs[func_id] = new CFunction(save, this);
|
||||||
pFunc = m_priv_funcs[func_id];
|
pFunc = m_priv_funcs[func_id];
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pFunc;
|
return pFunc;
|
||||||
|
@ -794,6 +794,16 @@ namespace SourcePawn
|
|||||||
* @return String describing CPU specific optimizations.
|
* @return String describing CPU specific optimizations.
|
||||||
*/
|
*/
|
||||||
virtual const char *GetCPUOptimizations() =0;
|
virtual const char *GetCPUOptimizations() =0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Given a context and a p-code address, returns the index of the function.
|
||||||
|
*
|
||||||
|
* @param ctx Context to search.
|
||||||
|
* @param code_addr Index into the p-code section.
|
||||||
|
* @param result Pointer to store result into.
|
||||||
|
* @return True if code index is valid, false otherwise.
|
||||||
|
*/
|
||||||
|
virtual bool FunctionPLookup(const sp_context_t *ctx, uint32_t code_addr, unsigned int *result) =0;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2161,10 +2161,12 @@ jit_rewind:
|
|||||||
|
|
||||||
functracker_t *fnc = new functracker_t;
|
functracker_t *fnc = new functracker_t;
|
||||||
ctx->vm[JITVARS_FUNCINFO] = fnc;
|
ctx->vm[JITVARS_FUNCINFO] = fnc;
|
||||||
|
ctx->vm[JITVARS_REBASE] = data->rebase;
|
||||||
fnc->code_size = codemem;
|
fnc->code_size = codemem;
|
||||||
fnc->num_functions = data->func_idx;
|
fnc->num_functions = data->func_idx;
|
||||||
|
|
||||||
/* clean up relocation+compilation memory */
|
/* clean up relocation+compilation memory */
|
||||||
|
data->rebase = NULL;
|
||||||
AbortCompilation(co);
|
AbortCompilation(co);
|
||||||
|
|
||||||
*err = SP_ERROR_NONE;
|
*err = SP_ERROR_NONE;
|
||||||
@ -2194,6 +2196,7 @@ void JITX86::FreeContext(sp_context_t *ctx)
|
|||||||
delete [] ctx->publics;
|
delete [] ctx->publics;
|
||||||
delete [] ctx->pubvars;
|
delete [] ctx->pubvars;
|
||||||
delete [] ctx->symbols;
|
delete [] ctx->symbols;
|
||||||
|
engine->BaseFree(ctx->vm[JITVARS_REBASE]);
|
||||||
free(((tracker_t *)(ctx->vm[JITVARS_TRACKER]))->pBase);
|
free(((tracker_t *)(ctx->vm[JITVARS_TRACKER]))->pBase);
|
||||||
delete ctx->vm[JITVARS_TRACKER];
|
delete ctx->vm[JITVARS_TRACKER];
|
||||||
delete ctx;
|
delete ctx;
|
||||||
@ -2247,15 +2250,51 @@ unsigned int JITX86::GetAPIVersion()
|
|||||||
return SOURCEPAWN_VM_API_VERSION;
|
return SOURCEPAWN_VM_API_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JITX86::FunctionLookup(const sp_context_t *ctx, uint32_t code_addr, unsigned int *result)
|
bool JITX86::FunctionPLookup(const sp_context_t *ctx, uint32_t code_addr, unsigned int *result)
|
||||||
{
|
{
|
||||||
functracker_t *fnc = (functracker_t *)ctx->vm[JITVARS_FUNCINFO];
|
uint8_t *rebase = (uint8_t *)ctx->vm[JITVARS_REBASE];
|
||||||
|
|
||||||
|
/* Is this within the pcode bounds? */
|
||||||
|
if (code_addr >= ctx->plugin->pcode_size - sizeof(uint32_t))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Relocate this */
|
||||||
|
code_addr = *(jitoffs_t *)(rebase + code_addr);
|
||||||
|
|
||||||
|
/* Check if this is in the relocation bounds */
|
||||||
|
functracker_t *fnc = (functracker_t *)ctx->vm[JITVARS_FUNCINFO];
|
||||||
if (code_addr >= fnc->code_size)
|
if (code_addr >= fnc->code_size)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the function info and sanity check */
|
||||||
|
funcinfo_t *f = (funcinfo_t *)((char *)ctx->codebase + code_addr - sizeof(funcinfo_t));
|
||||||
|
if (f->magic != JIT_FUNCMAGIC || f->index >= fnc->num_functions)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
*result = f->index;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JITX86::FunctionLookup(const sp_context_t *ctx, uint32_t code_addr, unsigned int *result)
|
||||||
|
{
|
||||||
|
/* Check if this is in the relocation bounds */
|
||||||
|
functracker_t *fnc = (functracker_t *)ctx->vm[JITVARS_FUNCINFO];
|
||||||
|
if (code_addr >= fnc->code_size)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the function info and sanity check */
|
||||||
funcinfo_t *f = (funcinfo_t *)((char *)ctx->codebase + code_addr - sizeof(funcinfo_t));
|
funcinfo_t *f = (funcinfo_t *)((char *)ctx->codebase + code_addr - sizeof(funcinfo_t));
|
||||||
if (f->magic != JIT_FUNCMAGIC || f->index >= fnc->num_functions)
|
if (f->magic != JIT_FUNCMAGIC || f->index >= fnc->num_functions)
|
||||||
{
|
{
|
||||||
|
@ -14,6 +14,7 @@ using namespace SourcePawn;
|
|||||||
|
|
||||||
#define JITVARS_TRACKER 0 //important: don't change this to avoid trouble
|
#define JITVARS_TRACKER 0 //important: don't change this to avoid trouble
|
||||||
#define JITVARS_FUNCINFO 1 //important: don't change this aWOAWOGJQG I LIKE HAM
|
#define JITVARS_FUNCINFO 1 //important: don't change this aWOAWOGJQG I LIKE HAM
|
||||||
|
#define JITVARS_REBASE 2 //important: hi, i'm bail
|
||||||
|
|
||||||
typedef struct tracker_s
|
typedef struct tracker_s
|
||||||
{
|
{
|
||||||
@ -80,6 +81,7 @@ public:
|
|||||||
int ContextExecute(sp_context_t *ctx, uint32_t code_idx, cell_t *result);
|
int ContextExecute(sp_context_t *ctx, uint32_t code_idx, cell_t *result);
|
||||||
unsigned int GetAPIVersion();
|
unsigned int GetAPIVersion();
|
||||||
bool FunctionLookup(const sp_context_t *ctx, uint32_t code_addr, unsigned int *result);
|
bool FunctionLookup(const sp_context_t *ctx, uint32_t code_addr, unsigned int *result);
|
||||||
|
bool FunctionPLookup(const sp_context_t *ctx, uint32_t code_addr, unsigned int *result);
|
||||||
unsigned int FunctionCount(const sp_context_t *ctx);
|
unsigned int FunctionCount(const sp_context_t *ctx);
|
||||||
const char *GetVersionString();
|
const char *GetVersionString();
|
||||||
const char *GetCPUOptimizations();
|
const char *GetCPUOptimizations();
|
||||||
|
@ -247,19 +247,23 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\include\sp_file_headers.h"
|
RelativePath="..\..\..\..\public\sourcepawn\sp_file_headers.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\include\sp_vm_api.h"
|
RelativePath="..\..\..\..\public\sourcepawn\sp_typeutil.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\include\sp_vm_base.h"
|
RelativePath="..\..\..\..\public\sourcepawn\sp_vm_api.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\..\include\sp_vm_types.h"
|
RelativePath="..\..\..\..\public\sourcepawn\sp_vm_base.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\..\..\public\sourcepawn\sp_vm_types.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
Loading…
Reference in New Issue
Block a user