2015-02-24 01:40:36 +01:00
|
|
|
// 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/.
|
|
|
|
//
|
2008-07-11 10:18:43 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-08-15 07:22:26 +02:00
|
|
|
#include <assert.h>
|
2015-02-24 01:44:15 +01:00
|
|
|
#include "plugin-runtime.h"
|
2008-07-11 10:18:43 +02:00
|
|
|
#include "x86/jit_x86.h"
|
2015-02-24 21:55:00 +01:00
|
|
|
#include "plugin-context.h"
|
2015-02-24 08:49:39 +01:00
|
|
|
#include "environment.h"
|
2008-07-11 10:18:43 +02:00
|
|
|
|
2012-08-09 02:54:43 +02:00
|
|
|
#include "md5/md5.h"
|
|
|
|
|
2014-08-22 07:16:07 +02:00
|
|
|
using namespace sp;
|
2008-07-11 10:18:43 +02:00
|
|
|
using namespace SourcePawn;
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
static inline bool
|
|
|
|
IsPointerCellAligned(void *p)
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
2013-08-08 18:41:24 +02:00
|
|
|
return uintptr_t(p) % 4 == 0;
|
|
|
|
}
|
2008-07-11 10:18:43 +02:00
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
PluginRuntime::PluginRuntime(LegacyImage *image)
|
|
|
|
: image_(image),
|
|
|
|
paused_(false),
|
|
|
|
computed_code_hash_(false),
|
|
|
|
computed_data_hash_(false)
|
2013-08-08 18:41:24 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
code_ = image_->DescribeCode();
|
|
|
|
data_ = image_->DescribeData();
|
|
|
|
memset(code_hash_, 0, sizeof(code_hash_));
|
|
|
|
memset(data_hash_, 0, sizeof(data_hash_));
|
2013-08-15 08:54:25 +02:00
|
|
|
|
2015-02-24 08:49:39 +01:00
|
|
|
ke::AutoLock lock(Environment::get()->lock());
|
|
|
|
Environment::get()->RegisterRuntime(this);
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::~PluginRuntime()
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
2013-08-15 08:54:25 +02:00
|
|
|
// The watchdog thread takes the global JIT lock while it patches all
|
|
|
|
// runtimes. It is not enough to ensure that the unlinking of the runtime is
|
|
|
|
// protected; we cannot delete functions or code while the watchdog might be
|
|
|
|
// executing. Therefore, the entire destructor is guarded.
|
2015-02-24 08:49:39 +01:00
|
|
|
ke::AutoLock lock(Environment::get()->lock());
|
2013-08-15 08:54:25 +02:00
|
|
|
|
2015-02-24 08:49:39 +01:00
|
|
|
Environment::get()->DeregisterRuntime(this);
|
2013-08-15 08:54:25 +02:00
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
for (uint32_t i = 0; i < image_->NumPublics(); i++)
|
|
|
|
delete entrypoints_[i];
|
2013-08-08 18:41:24 +02:00
|
|
|
|
|
|
|
for (size_t i = 0; i < m_JitFunctions.length(); i++)
|
|
|
|
delete m_JitFunctions[i];
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginRuntime::Initialize()
|
|
|
|
{
|
|
|
|
if (!ke::IsAligned(code_.bytes, sizeof(cell_t))) {
|
|
|
|
// Align the code section.
|
|
|
|
aligned_code_ = new uint8_t[code_.length];
|
|
|
|
if (!aligned_code_)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
memcpy(aligned_code_, code_.bytes, code_.length);
|
|
|
|
code_.bytes = aligned_code_;
|
|
|
|
}
|
|
|
|
|
|
|
|
natives_ = new sp_native_t[image_->NumNatives()];
|
|
|
|
if (!natives_)
|
|
|
|
return false;
|
|
|
|
memset(natives_, 0, sizeof(sp_native_t) * image_->NumNatives());
|
|
|
|
|
|
|
|
publics_ = new sp_public_t[image_->NumPublics()];
|
|
|
|
if (!publics_)
|
|
|
|
return false;
|
|
|
|
memset(publics_, 0, sizeof(sp_public_t) * image_->NumPublics());
|
|
|
|
|
|
|
|
pubvars_ = new sp_pubvar_t[image_->NumPubvars()];
|
|
|
|
if (!pubvars_)
|
|
|
|
return false;
|
|
|
|
memset(pubvars_, 0, sizeof(sp_pubvar_t) * image_->NumPubvars());
|
|
|
|
|
|
|
|
entrypoints_ = new ScriptedInvoker *[image_->NumPublics()];
|
|
|
|
if (!entrypoints_)
|
|
|
|
return false;
|
|
|
|
memset(entrypoints_, 0, sizeof(ScriptedInvoker *) * image_->NumPublics());
|
|
|
|
|
|
|
|
context_ = new PluginContext(this);
|
|
|
|
if (!context_->Initialize())
|
|
|
|
return false;
|
2013-08-08 18:41:24 +02:00
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
SetupFloatNativeRemapping();
|
|
|
|
|
|
|
|
if (!function_map_.init(32))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2013-08-08 18:41:24 +02:00
|
|
|
}
|
|
|
|
|
2014-04-23 04:40:45 +02:00
|
|
|
struct NativeMapping {
|
|
|
|
const char *name;
|
|
|
|
unsigned opcode;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const NativeMapping sNativeMap[] = {
|
|
|
|
{ "FloatAbs", OP_FABS },
|
|
|
|
{ "FloatAdd", OP_FLOATADD },
|
|
|
|
{ "FloatSub", OP_FLOATSUB },
|
|
|
|
{ "FloatMul", OP_FLOATMUL },
|
|
|
|
{ "FloatDiv", OP_FLOATDIV },
|
|
|
|
{ "float", OP_FLOAT },
|
|
|
|
{ "FloatCompare", OP_FLOATCMP },
|
|
|
|
{ "RoundToCeil", OP_RND_TO_CEIL },
|
|
|
|
{ "RoundToZero", OP_RND_TO_ZERO },
|
|
|
|
{ "RoundToFloor", OP_RND_TO_FLOOR },
|
|
|
|
{ "RoundToNearest", OP_RND_TO_NEAREST },
|
|
|
|
{ "__FLOAT_GT__", OP_FLOAT_GT },
|
|
|
|
{ "__FLOAT_GE__", OP_FLOAT_GE },
|
|
|
|
{ "__FLOAT_LT__", OP_FLOAT_LT },
|
|
|
|
{ "__FLOAT_LE__", OP_FLOAT_LE },
|
|
|
|
{ "__FLOAT_EQ__", OP_FLOAT_EQ },
|
|
|
|
{ "__FLOAT_NE__", OP_FLOAT_NE },
|
|
|
|
{ "__FLOAT_NOT__", OP_FLOAT_NOT },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
void
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::SetupFloatNativeRemapping()
|
2013-08-08 18:41:24 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
float_table_ = new floattbl_t[image_->NumNatives()];
|
|
|
|
for (size_t i = 0; i < image_->NumNatives(); i++) {
|
|
|
|
const char *name = image_->GetNative(i);
|
2014-04-23 04:40:45 +02:00
|
|
|
const NativeMapping *iter = sNativeMap;
|
|
|
|
while (iter->name) {
|
|
|
|
if (strcmp(name, iter->name) == 0) {
|
|
|
|
float_table_[i].found = true;
|
|
|
|
float_table_[i].index = iter->opcode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
iter++;
|
2013-08-08 18:41:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::GetNativeReplacement(size_t index)
|
2013-08-08 18:41:24 +02:00
|
|
|
{
|
|
|
|
if (!float_table_[index].found)
|
|
|
|
return OP_NOP;
|
|
|
|
return float_table_[index].index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::SetName(const char *name)
|
2013-08-08 18:41:24 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
size_t len = strlen(name);
|
|
|
|
name_ = new char[len + 1];
|
|
|
|
strcpy(name_, name);
|
2008-08-15 07:22:26 +02:00
|
|
|
}
|
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
static cell_t
|
|
|
|
InvalidNative(IPluginContext *pCtx, const cell_t *params)
|
2008-08-15 07:22:26 +02:00
|
|
|
{
|
2013-08-08 18:41:24 +02:00
|
|
|
return pCtx->ThrowNativeErrorEx(SP_ERROR_INVALID_NATIVE, "Invalid native");
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
void
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::AddJittedFunction(CompiledFunction *fn)
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
2013-08-08 18:41:24 +02:00
|
|
|
m_JitFunctions.append(fn);
|
2008-07-11 10:18:43 +02:00
|
|
|
|
2015-02-25 08:37:23 +01:00
|
|
|
ucell_t pcode_offset = fn->GetCodeOffset();
|
|
|
|
FunctionMap::Insert p = function_map_.findForAdd(pcode_offset);
|
|
|
|
assert(!p.found());
|
2008-07-11 10:18:43 +02:00
|
|
|
|
2015-02-25 08:37:23 +01:00
|
|
|
function_map_.add(p, pcode_offset, fn);
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
2015-02-24 01:27:57 +01:00
|
|
|
CompiledFunction *
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::GetJittedFunctionByOffset(cell_t pcode_offset)
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
2015-02-25 08:37:23 +01:00
|
|
|
FunctionMap::Result r = function_map_.find(pcode_offset);
|
|
|
|
if (r.found())
|
|
|
|
return r->value;
|
|
|
|
return nullptr;
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
int
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::FindNativeByName(const char *name, uint32_t *index)
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
size_t idx;
|
|
|
|
if (!image_->FindNative(name, &idx))
|
|
|
|
return SP_ERROR_NOT_FOUND;
|
|
|
|
|
|
|
|
if (index)
|
|
|
|
*index = idx;
|
2013-08-08 18:41:24 +02:00
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
return SP_ERROR_NONE;
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
int
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::GetNativeByIndex(uint32_t index, sp_native_t **native)
|
2015-02-25 07:58:31 +01:00
|
|
|
{
|
|
|
|
return SP_ERROR_PARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
PluginRuntime::UpdateNativeBinding(uint32_t index, SPVM_NATIVE_FUNC pfn, uint32_t flags, void *data)
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (index >= image_->NumNatives())
|
2013-08-08 18:41:24 +02:00
|
|
|
return SP_ERROR_INDEX;
|
2008-07-11 10:18:43 +02:00
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
sp_native_t *native = &natives_[index];
|
2008-07-11 10:18:43 +02:00
|
|
|
|
2015-02-25 07:58:31 +01:00
|
|
|
native->pfn = pfn;
|
|
|
|
native->status = pfn
|
|
|
|
? SP_NATIVE_BOUND
|
|
|
|
: SP_NATIVE_UNBOUND;
|
|
|
|
native->flags = flags;
|
|
|
|
native->user = data;
|
2013-08-08 18:41:24 +02:00
|
|
|
return SP_ERROR_NONE;
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
2015-02-25 07:58:31 +01:00
|
|
|
const sp_native_t *
|
|
|
|
PluginRuntime::GetNative(uint32_t index)
|
2014-05-11 23:36:32 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (index >= image_->NumNatives())
|
2015-02-25 07:58:31 +01:00
|
|
|
return nullptr;
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
|
|
|
|
if (!natives_[index].name)
|
|
|
|
natives_[index].name = image_->GetNative(index);
|
|
|
|
|
|
|
|
return &natives_[index];
|
2014-05-11 23:36:32 +02:00
|
|
|
}
|
2013-08-08 18:41:24 +02:00
|
|
|
|
|
|
|
uint32_t
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::GetNativesNum()
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
return image_->NumNatives();
|
2013-08-08 18:41:24 +02:00
|
|
|
}
|
2008-07-11 10:18:43 +02:00
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
int
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::FindPublicByName(const char *name, uint32_t *index)
|
2013-08-08 18:41:24 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
size_t idx;
|
|
|
|
if (!image_->FindPublic(name, &idx))
|
|
|
|
return SP_ERROR_NOT_FOUND;
|
2013-08-08 18:41:24 +02:00
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (index)
|
|
|
|
*index = idx;
|
|
|
|
return SP_ERROR_NONE;
|
2013-08-08 18:41:24 +02:00
|
|
|
}
|
2008-07-11 10:18:43 +02:00
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
int
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
PluginRuntime::GetPublicByIndex(uint32_t index, sp_public_t **out)
|
2013-08-08 18:41:24 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (index >= image_->NumPublics())
|
2013-08-08 18:41:24 +02:00
|
|
|
return SP_ERROR_INDEX;
|
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
sp_public_t &entry = publics_[index];
|
|
|
|
if (!entry.name) {
|
|
|
|
uint32_t offset;
|
|
|
|
image_->GetPublic(index, &offset, &entry.name);
|
|
|
|
entry.code_offs = offset;
|
|
|
|
entry.funcid = (index << 1) | 1;
|
|
|
|
}
|
2008-07-11 10:18:43 +02:00
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (out)
|
|
|
|
*out = &entry;
|
2013-08-08 18:41:24 +02:00
|
|
|
return SP_ERROR_NONE;
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
uint32_t
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::GetPublicsNum()
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
return image_->NumPublics();
|
2013-08-08 18:41:24 +02:00
|
|
|
}
|
2008-07-11 10:18:43 +02:00
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
int
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
PluginRuntime::GetPubvarByIndex(uint32_t index, sp_pubvar_t **out)
|
2013-08-08 18:41:24 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (index >= image_->NumPubvars())
|
2013-08-08 18:41:24 +02:00
|
|
|
return SP_ERROR_INDEX;
|
2008-07-11 10:18:43 +02:00
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
sp_pubvar_t *pubvar = &pubvars_[index];
|
|
|
|
if (!pubvar->name) {
|
|
|
|
uint32_t offset;
|
|
|
|
image_->GetPubvar(index, &offset, &pubvar->name);
|
|
|
|
if (int err = context_->LocalToPhysAddr(offset, &pubvar->offs))
|
|
|
|
return err;
|
|
|
|
}
|
2013-08-08 18:41:24 +02:00
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (out)
|
|
|
|
*out = pubvar;
|
2013-08-08 18:41:24 +02:00
|
|
|
return SP_ERROR_NONE;
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
int
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::FindPubvarByName(const char *name, uint32_t *index)
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
size_t idx;
|
|
|
|
if (!image_->FindPubvar(name, &idx))
|
|
|
|
return SP_ERROR_NOT_FOUND;
|
2013-08-08 18:41:24 +02:00
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (index)
|
|
|
|
*index = idx;
|
|
|
|
return SP_ERROR_NONE;
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
int
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr)
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (index >= image_->NumPubvars())
|
2013-08-08 18:41:24 +02:00
|
|
|
return SP_ERROR_INDEX;
|
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
uint32_t offset;
|
|
|
|
image_->GetPubvar(index, &offset, nullptr);
|
2013-08-08 18:41:24 +02:00
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (int err = context_->LocalToPhysAddr(offset, phys_addr))
|
|
|
|
return err;
|
|
|
|
*local_addr = offset;
|
2013-08-08 18:41:24 +02:00
|
|
|
return SP_ERROR_NONE;
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
uint32_t
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::GetPubVarsNum()
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
return image_->NumPubvars();
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
IPluginContext *
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::GetDefaultContext()
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
return context_;
|
2013-08-08 18:41:24 +02:00
|
|
|
}
|
2008-07-11 10:18:43 +02:00
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
IPluginDebugInfo *
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::GetDebugInfo()
|
2013-08-08 18:41:24 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
return this;
|
2013-08-08 18:41:24 +02:00
|
|
|
}
|
2008-07-11 10:18:43 +02:00
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
IPluginFunction *
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::GetFunctionById(funcid_t func_id)
|
2013-08-08 18:41:24 +02:00
|
|
|
{
|
2015-02-24 00:47:47 +01:00
|
|
|
ScriptedInvoker *pFunc = NULL;
|
2013-08-08 18:41:24 +02:00
|
|
|
|
|
|
|
if (func_id & 1) {
|
|
|
|
func_id >>= 1;
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (func_id >= image_->NumPublics())
|
2013-08-08 18:41:24 +02:00
|
|
|
return NULL;
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
pFunc = entrypoints_[func_id];
|
2013-08-08 18:41:24 +02:00
|
|
|
if (!pFunc) {
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
entrypoints_[func_id] = new ScriptedInvoker(this, (func_id << 1) | 1, func_id);
|
|
|
|
pFunc = entrypoints_[func_id];
|
2013-08-08 18:41:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pFunc;
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
2015-02-24 00:47:47 +01:00
|
|
|
ScriptedInvoker *
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::GetPublicFunction(size_t index)
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
assert(index < image_->NumPublics());
|
|
|
|
ScriptedInvoker *pFunc = entrypoints_[index];
|
2013-08-08 18:41:24 +02:00
|
|
|
if (!pFunc) {
|
|
|
|
sp_public_t *pub = NULL;
|
|
|
|
GetPublicByIndex(index, &pub);
|
|
|
|
if (pub)
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
entrypoints_[index] = new ScriptedInvoker(this, (index << 1) | 1, index);
|
|
|
|
pFunc = entrypoints_[index];
|
2013-08-08 18:41:24 +02:00
|
|
|
}
|
2008-07-11 10:18:43 +02:00
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
return pFunc;
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
2014-06-24 10:04:13 +02:00
|
|
|
IPluginFunction *
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::GetFunctionByName(const char *public_name)
|
2014-06-24 10:04:13 +02:00
|
|
|
{
|
|
|
|
uint32_t index;
|
|
|
|
|
|
|
|
if (FindPublicByName(public_name, &index) != SP_ERROR_NONE)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return GetPublicFunction(index);
|
|
|
|
}
|
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
bool
|
|
|
|
PluginRuntime::IsDebugging()
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
2013-08-08 18:41:24 +02:00
|
|
|
return true;
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
void
|
|
|
|
PluginRuntime::SetPauseState(bool paused)
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
paused_ = paused;
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
bool
|
|
|
|
PluginRuntime::IsPaused()
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
return paused_;
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
size_t
|
|
|
|
PluginRuntime::GetMemUsage()
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
return sizeof(*this) +
|
|
|
|
sizeof(PluginContext) +
|
|
|
|
image_->ImageSize() +
|
|
|
|
(aligned_code_ ? code_.length : 0) +
|
|
|
|
context_->HeapSize();
|
2008-07-11 10:18:43 +02:00
|
|
|
}
|
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
unsigned char *
|
|
|
|
PluginRuntime::GetCodeHash()
|
2012-08-09 02:54:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (!computed_code_hash_) {
|
|
|
|
MD5 md5_pcode;
|
|
|
|
md5_pcode.update((const unsigned char *)code_.bytes, code_.length);
|
|
|
|
md5_pcode.finalize();
|
|
|
|
md5_pcode.raw_digest(code_hash_);
|
|
|
|
computed_code_hash_ = true;
|
|
|
|
}
|
|
|
|
return code_hash_;
|
2012-08-09 02:54:43 +02:00
|
|
|
}
|
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
unsigned char *
|
|
|
|
PluginRuntime::GetDataHash()
|
2012-08-09 02:54:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (!computed_data_hash_) {
|
|
|
|
MD5 md5_data;
|
|
|
|
md5_data.update((const unsigned char *)data_.bytes, data_.length);
|
|
|
|
md5_data.finalize();
|
|
|
|
md5_data.raw_digest(data_hash_);
|
|
|
|
computed_data_hash_ = true;
|
|
|
|
}
|
|
|
|
return data_hash_;
|
2012-08-09 02:54:43 +02:00
|
|
|
}
|
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
PluginContext *
|
|
|
|
PluginRuntime::GetBaseContext()
|
2008-07-11 10:18:43 +02:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
return context_;
|
2008-08-15 07:22:26 +02:00
|
|
|
}
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
int
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime::ApplyCompilationOptions(ICompilation *co)
|
2008-08-15 07:22:26 +02:00
|
|
|
{
|
2013-08-08 18:41:24 +02:00
|
|
|
return SP_ERROR_NONE;
|
2008-08-15 07:22:26 +02:00
|
|
|
}
|
2009-02-01 08:03:03 +01:00
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
int
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
PluginRuntime::LookupLine(ucell_t addr, uint32_t *line)
|
2009-02-01 08:03:03 +01:00
|
|
|
{
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
if (!image_->LookupLine(addr, line))
|
|
|
|
return SP_ERROR_NOT_FOUND;
|
|
|
|
return SP_ERROR_NONE;
|
|
|
|
}
|
2009-02-01 08:03:03 +01:00
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
int
|
|
|
|
PluginRuntime::LookupFunction(ucell_t addr, const char **out)
|
|
|
|
{
|
|
|
|
const char *name = image_->LookupFunction(addr);
|
|
|
|
if (!name)
|
|
|
|
return SP_ERROR_NOT_FOUND;
|
|
|
|
if (out)
|
|
|
|
*out = name;
|
|
|
|
return SP_ERROR_NONE;
|
|
|
|
}
|
2009-02-01 08:03:03 +01:00
|
|
|
|
Rewrite the .smx parser.
This removes one the last remnants of the SourceMod 1.0 VM implementation.
The new parser introduces a number of design changes in the VM. First, the VM now takes greater responsibility for validating and sanity checking the structure of the SMX container format. Previously, malformed SMX files could easily crash SourcePawn. The loader now rejects files that have out-of-bounds offsets or incomplete sections. Complex sections, like debug info or the code stream, are verified lazily.
Internally, the sp_plugin_t structure has been removed. It has been replaced by a new LegacyImage class, designed to be independent from the SPVM API. This potentially lets us load code streams from non-.smx containers. More importantly, it removes a lot of bookkeeping and pre-computed state from PluginRuntime. The LegacyImage class is now responsible for handling debug info as well.
PluginRuntime is now intended to hold only cached or immutable data, and PluginContext holds all VM state. As such PluginContext is now responsible for allocating a plugin's runtime memory, not PluginRuntime.
Finally, some aspects of the loading process have been cleaned up. The
decompression and image handoff logic should now be easier to
understand.
2015-02-25 11:19:38 +01:00
|
|
|
int
|
|
|
|
PluginRuntime::LookupFile(ucell_t addr, const char **out)
|
|
|
|
{
|
|
|
|
const char *name = image_->LookupFile(addr);
|
|
|
|
if (!name)
|
|
|
|
return SP_ERROR_NOT_FOUND;
|
|
|
|
if (out)
|
|
|
|
*out = name;
|
2013-08-08 18:41:24 +02:00
|
|
|
return SP_ERROR_NONE;
|
2009-02-01 08:03:03 +01:00
|
|
|
}
|