2013-08-15 08:54:25 +02:00
|
|
|
// vim: set ts=8 sts=2 sw=2 tw=99 et:
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// SourcePawn is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with SourcePawn. If not, see <http://www.gnu.org/licenses/>.
|
2008-03-30 09:00:22 +02:00
|
|
|
#ifndef _INCLUDE_SOURCEPAWN_JIT_X86_H_
|
|
|
|
#define _INCLUDE_SOURCEPAWN_JIT_X86_H_
|
|
|
|
|
|
|
|
#include <sp_vm_types.h>
|
|
|
|
#include <sp_vm_api.h>
|
2013-08-09 05:26:36 +02:00
|
|
|
#include <macro-assembler-x86.h>
|
2013-08-23 02:10:59 +02:00
|
|
|
#include <am-vector.h>
|
2015-02-24 01:44:15 +01:00
|
|
|
#include "plugin-runtime.h"
|
2015-02-24 21:55:00 +01:00
|
|
|
#include "plugin-context.h"
|
2015-02-24 01:04:57 +01:00
|
|
|
#include "compiled-function.h"
|
2013-08-08 18:41:24 +02:00
|
|
|
#include "opcodes.h"
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
using namespace SourcePawn;
|
|
|
|
|
2015-02-24 10:12:23 +01:00
|
|
|
namespace sp {
|
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
|
|
|
class LegacyImage;
|
2015-02-24 10:12:23 +01:00
|
|
|
class Environment;
|
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
|
|
|
class CompiledFunction;
|
2015-02-24 10:12:23 +01:00
|
|
|
|
Implement a new stack and error handling model for the SourcePawn VM.
This has three major changes to SourcePawn. First, the API now supports the concept of "exceptions". The exception state is a global property of an instance of the SourcePawn VM. Exceptions can be caught or suppressed. Many places in SourceMod have been updated to check exceptions instead of errors.
The new API obsoletes major parts of the embedder API - all but one method of invoking functions is obsoleted, and the debug interface has been scrapped. Extensions using the native API will not be affected, however, ThrowNativeError has been deprecated in favor of ReportError.
Second, the SourcePawn concept of a "stack" has been unified at the API level. A stack frame iterator now iterates over all SourcePawn invocations, rather than the topmost plugin. This makes error handling more consistent and removes another dependency on context-per-plugin.
Finally, the implementation of stack frames has been changed dramatically. Rather than maintain a complicated and expensive return pointer stack, we now rely on the implicit one provided by the CPU. The stack frame iterator now walks the JIT stack directly. This removes many unnecessary bookkeeping instructions from the generated code, in particular making the CALL instruction 40% faster.
These changes required some fair surgery to the JIT. Its error paths are now slightly more complicated, as they have to throw an exception rather than return an error code. In addition, any path that can throw an exception is now responsible for creating an "exit frame", which exists to tell the stack frame iterator about transitions from the JIT to the VM.
2015-02-27 09:32:44 +01:00
|
|
|
struct ErrorPath
|
|
|
|
{
|
|
|
|
SilentLabel label;
|
|
|
|
const cell_t *cip;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
ErrorPath(const cell_t *cip, int err)
|
|
|
|
: cip(cip),
|
|
|
|
err(err)
|
|
|
|
{}
|
|
|
|
ErrorPath()
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BackwardJump {
|
|
|
|
// The pc at the jump instruction (i.e. after it).
|
|
|
|
uint32_t pc;
|
|
|
|
// The cip of the jump.
|
|
|
|
const cell_t *cip;
|
|
|
|
// The offset of the timeout thunk. This is filled in at the end.
|
|
|
|
uint32_t timeout_offset;
|
|
|
|
|
|
|
|
BackwardJump()
|
|
|
|
{}
|
|
|
|
BackwardJump(uint32_t pc, const cell_t *cip)
|
|
|
|
: pc(pc),
|
|
|
|
cip(cip)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
#define JIT_INLINE_ERRORCHECKS (1<<0)
|
|
|
|
#define JIT_INLINE_NATIVES (1<<1)
|
|
|
|
#define STACK_MARGIN 64 //8 parameters of safety, I guess
|
|
|
|
#define JIT_FUNCMAGIC 0x214D4148 //magic function offset
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
#define JITVARS_PROFILER 2 //profiler
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
#define sDIMEN_MAX 5 //this must mirror what the compiler has.
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
struct CallThunk
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
Implement a new stack and error handling model for the SourcePawn VM.
This has three major changes to SourcePawn. First, the API now supports the concept of "exceptions". The exception state is a global property of an instance of the SourcePawn VM. Exceptions can be caught or suppressed. Many places in SourceMod have been updated to check exceptions instead of errors.
The new API obsoletes major parts of the embedder API - all but one method of invoking functions is obsoleted, and the debug interface has been scrapped. Extensions using the native API will not be affected, however, ThrowNativeError has been deprecated in favor of ReportError.
Second, the SourcePawn concept of a "stack" has been unified at the API level. A stack frame iterator now iterates over all SourcePawn invocations, rather than the topmost plugin. This makes error handling more consistent and removes another dependency on context-per-plugin.
Finally, the implementation of stack frames has been changed dramatically. Rather than maintain a complicated and expensive return pointer stack, we now rely on the implicit one provided by the CPU. The stack frame iterator now walks the JIT stack directly. This removes many unnecessary bookkeeping instructions from the generated code, in particular making the CALL instruction 40% faster.
These changes required some fair surgery to the JIT. Its error paths are now slightly more complicated, as they have to throw an exception rather than return an error code. In addition, any path that can throw an exception is now responsible for creating an "exit frame", which exists to tell the stack frame iterator about transitions from the JIT to the VM.
2015-02-27 09:32:44 +01:00
|
|
|
SilentLabel call;
|
2013-08-08 18:41:24 +02:00
|
|
|
cell_t pcode_offset;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
CallThunk(cell_t pcode_offset)
|
|
|
|
: pcode_offset(pcode_offset)
|
|
|
|
{
|
|
|
|
}
|
2008-08-15 07:22:26 +02:00
|
|
|
};
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
class Compiler
|
|
|
|
{
|
|
|
|
public:
|
2015-02-24 01:40:36 +01:00
|
|
|
Compiler(PluginRuntime *rt, cell_t pcode_offs);
|
2013-08-08 18:41:24 +02:00
|
|
|
~Compiler();
|
|
|
|
|
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::CompiledFunction *emit(int *errp);
|
2013-08-08 18:41:24 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool setup(cell_t pcode_offs);
|
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 emitOp(sp::OPCODE op);
|
2013-08-08 18:41:24 +02:00
|
|
|
cell_t readCell();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Label *labelAt(size_t offset);
|
|
|
|
bool emitCall();
|
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 emitNativeCall(sp::OPCODE op);
|
2013-08-08 18:41:24 +02:00
|
|
|
bool emitSwitch();
|
|
|
|
void emitGenArray(bool autozero);
|
|
|
|
void emitCallThunks();
|
|
|
|
void emitCheckAddress(Register reg);
|
|
|
|
void emitErrorPath(Label *dest, int code);
|
|
|
|
void emitErrorPaths();
|
2014-04-23 04:40:45 +02:00
|
|
|
void emitFloatCmp(ConditionCode cc);
|
Implement a new stack and error handling model for the SourcePawn VM.
This has three major changes to SourcePawn. First, the API now supports the concept of "exceptions". The exception state is a global property of an instance of the SourcePawn VM. Exceptions can be caught or suppressed. Many places in SourceMod have been updated to check exceptions instead of errors.
The new API obsoletes major parts of the embedder API - all but one method of invoking functions is obsoleted, and the debug interface has been scrapped. Extensions using the native API will not be affected, however, ThrowNativeError has been deprecated in favor of ReportError.
Second, the SourcePawn concept of a "stack" has been unified at the API level. A stack frame iterator now iterates over all SourcePawn invocations, rather than the topmost plugin. This makes error handling more consistent and removes another dependency on context-per-plugin.
Finally, the implementation of stack frames has been changed dramatically. Rather than maintain a complicated and expensive return pointer stack, we now rely on the implicit one provided by the CPU. The stack frame iterator now walks the JIT stack directly. This removes many unnecessary bookkeeping instructions from the generated code, in particular making the CALL instruction 40% faster.
These changes required some fair surgery to the JIT. Its error paths are now slightly more complicated, as they have to throw an exception rather than return an error code. In addition, any path that can throw an exception is now responsible for creating an "exit frame", which exists to tell the stack frame iterator about transitions from the JIT to the VM.
2015-02-27 09:32:44 +01:00
|
|
|
void jumpOnError(ConditionCode cc, int err = 0);
|
|
|
|
void emitThrowPathIfNeeded(int err);
|
2013-08-08 18:41:24 +02:00
|
|
|
|
2013-08-12 01:23:00 +02:00
|
|
|
ExternalAddress hpAddr() {
|
2015-02-25 06:18:34 +01:00
|
|
|
return ExternalAddress(context_->addressOfHp());
|
2013-08-12 01:23:00 +02:00
|
|
|
}
|
2013-08-12 01:23:54 +02:00
|
|
|
ExternalAddress frmAddr() {
|
2015-02-25 06:01:05 +01:00
|
|
|
return ExternalAddress(context_->addressOfFrm());
|
2013-08-12 01:23:54 +02:00
|
|
|
}
|
2013-08-12 01:22:54 +02:00
|
|
|
|
Implement a new stack and error handling model for the SourcePawn VM.
This has three major changes to SourcePawn. First, the API now supports the concept of "exceptions". The exception state is a global property of an instance of the SourcePawn VM. Exceptions can be caught or suppressed. Many places in SourceMod have been updated to check exceptions instead of errors.
The new API obsoletes major parts of the embedder API - all but one method of invoking functions is obsoleted, and the debug interface has been scrapped. Extensions using the native API will not be affected, however, ThrowNativeError has been deprecated in favor of ReportError.
Second, the SourcePawn concept of a "stack" has been unified at the API level. A stack frame iterator now iterates over all SourcePawn invocations, rather than the topmost plugin. This makes error handling more consistent and removes another dependency on context-per-plugin.
Finally, the implementation of stack frames has been changed dramatically. Rather than maintain a complicated and expensive return pointer stack, we now rely on the implicit one provided by the CPU. The stack frame iterator now walks the JIT stack directly. This removes many unnecessary bookkeeping instructions from the generated code, in particular making the CALL instruction 40% faster.
These changes required some fair surgery to the JIT. Its error paths are now slightly more complicated, as they have to throw an exception rather than return an error code. In addition, any path that can throw an exception is now responsible for creating an "exit frame", which exists to tell the stack frame iterator about transitions from the JIT to the VM.
2015-02-27 09:32:44 +01:00
|
|
|
// Map a return address (i.e. an exit point from a function) to its source
|
|
|
|
// cip. This lets us avoid tracking the cip during runtime. These are
|
|
|
|
// sorted by definition since we assemble and emit in forward order.
|
|
|
|
void emitCipMapping(const cell_t *cip) {
|
|
|
|
CipMapEntry entry;
|
|
|
|
entry.cipoffs = uintptr_t(cip) - uintptr_t(code_start_);
|
|
|
|
entry.pcoffs = masm.pc();
|
|
|
|
cip_map_.append(entry);
|
|
|
|
}
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
private:
|
|
|
|
AssemblerX86 masm;
|
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
|
|
|
Environment *env_;
|
2015-02-24 01:40:36 +01:00
|
|
|
PluginRuntime *rt_;
|
2015-02-25 05:53:44 +01:00
|
|
|
PluginContext *context_;
|
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
|
|
|
LegacyImage *image_;
|
2013-08-08 18:41:24 +02:00
|
|
|
int error_;
|
|
|
|
uint32_t pcode_start_;
|
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
|
|
|
const cell_t *code_start_;
|
|
|
|
const cell_t *cip_;
|
Implement a new stack and error handling model for the SourcePawn VM.
This has three major changes to SourcePawn. First, the API now supports the concept of "exceptions". The exception state is a global property of an instance of the SourcePawn VM. Exceptions can be caught or suppressed. Many places in SourceMod have been updated to check exceptions instead of errors.
The new API obsoletes major parts of the embedder API - all but one method of invoking functions is obsoleted, and the debug interface has been scrapped. Extensions using the native API will not be affected, however, ThrowNativeError has been deprecated in favor of ReportError.
Second, the SourcePawn concept of a "stack" has been unified at the API level. A stack frame iterator now iterates over all SourcePawn invocations, rather than the topmost plugin. This makes error handling more consistent and removes another dependency on context-per-plugin.
Finally, the implementation of stack frames has been changed dramatically. Rather than maintain a complicated and expensive return pointer stack, we now rely on the implicit one provided by the CPU. The stack frame iterator now walks the JIT stack directly. This removes many unnecessary bookkeeping instructions from the generated code, in particular making the CALL instruction 40% faster.
These changes required some fair surgery to the JIT. Its error paths are now slightly more complicated, as they have to throw an exception rather than return an error code. In addition, any path that can throw an exception is now responsible for creating an "exit frame", which exists to tell the stack frame iterator about transitions from the JIT to the VM.
2015-02-27 09:32:44 +01:00
|
|
|
const cell_t *op_cip_;
|
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
|
|
|
const cell_t *code_end_;
|
2013-08-08 18:41:24 +02:00
|
|
|
Label *jump_map_;
|
Implement a new stack and error handling model for the SourcePawn VM.
This has three major changes to SourcePawn. First, the API now supports the concept of "exceptions". The exception state is a global property of an instance of the SourcePawn VM. Exceptions can be caught or suppressed. Many places in SourceMod have been updated to check exceptions instead of errors.
The new API obsoletes major parts of the embedder API - all but one method of invoking functions is obsoleted, and the debug interface has been scrapped. Extensions using the native API will not be affected, however, ThrowNativeError has been deprecated in favor of ReportError.
Second, the SourcePawn concept of a "stack" has been unified at the API level. A stack frame iterator now iterates over all SourcePawn invocations, rather than the topmost plugin. This makes error handling more consistent and removes another dependency on context-per-plugin.
Finally, the implementation of stack frames has been changed dramatically. Rather than maintain a complicated and expensive return pointer stack, we now rely on the implicit one provided by the CPU. The stack frame iterator now walks the JIT stack directly. This removes many unnecessary bookkeeping instructions from the generated code, in particular making the CALL instruction 40% faster.
These changes required some fair surgery to the JIT. Its error paths are now slightly more complicated, as they have to throw an exception rather than return an error code. In addition, any path that can throw an exception is now responsible for creating an "exit frame", which exists to tell the stack frame iterator about transitions from the JIT to the VM.
2015-02-27 09:32:44 +01:00
|
|
|
ke::Vector<BackwardJump> backward_jumps_;
|
|
|
|
|
|
|
|
ke::Vector<CipMapEntry> cip_map_;
|
|
|
|
|
|
|
|
// Errors.
|
|
|
|
ke::Vector<ErrorPath> error_paths_;
|
|
|
|
Label throw_timeout_;
|
|
|
|
Label throw_error_code_[SP_MAX_ERROR_CODES];
|
|
|
|
Label report_error_;
|
|
|
|
Label return_reported_error_;
|
2013-08-08 18:41:24 +02:00
|
|
|
|
|
|
|
ke::Vector<CallThunk *> thunks_; //:TODO: free
|
2008-03-30 09:00:22 +02:00
|
|
|
};
|
|
|
|
|
2013-08-08 18:41:24 +02:00
|
|
|
const Register pri = eax;
|
|
|
|
const Register alt = edx;
|
|
|
|
const Register stk = edi;
|
2013-08-12 01:24:02 +02:00
|
|
|
const Register dat = esi;
|
2013-08-08 18:41:24 +02:00
|
|
|
const Register tmp = ecx;
|
|
|
|
const Register frm = ebx;
|
|
|
|
|
2015-02-24 10:19:16 +01:00
|
|
|
CompiledFunction *
|
|
|
|
CompileFunction(PluginRuntime *prt, cell_t pcode_offs, int *err);
|
2008-03-30 09:00:22 +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
|
|
|
}
|
|
|
|
|
2008-03-30 09:00:22 +02:00
|
|
|
#endif //_INCLUDE_SOURCEPAWN_JIT_X86_H_
|
2013-08-15 08:54:25 +02:00
|
|
|
|