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.
This commit is contained in:
David Anderson
2015-02-25 22:28:10 -08:00
parent afbcdc8a20
commit 04827466b0
29 changed files with 1570 additions and 768 deletions
+5 -5
View File
@@ -58,7 +58,7 @@ MD5::MD5(){
// operation, processing another message block, and updating the
// context.
void MD5::update (uint1 *input, uint4 input_length) {
void MD5::update (const uint1 *input, uint4 input_length) {
uint4 input_index, buffer_index;
uint4 buffer_space; // how much space is left in buffer
@@ -271,7 +271,7 @@ void MD5::init(){
// MD5 basic transformation. Transforms state based on block.
void MD5::transform (uint1 block[64]){
void MD5::transform (const uint1 block[64]){
uint4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
@@ -365,7 +365,7 @@ void MD5::transform (uint1 block[64]){
// Encodes input (UINT4) into output (unsigned char). Assumes len is
// a multiple of 4.
void MD5::encode (uint1 *output, uint4 *input, uint4 len) {
void MD5::encode (uint1 *output, const uint4 *input, uint4 len) {
unsigned int i, j;
@@ -382,7 +382,7 @@ void MD5::encode (uint1 *output, uint4 *input, uint4 len) {
// Decodes input (unsigned char) into output (UINT4). Assumes len is
// a multiple of 4.
void MD5::decode (uint4 *output, uint1 *input, uint4 len){
void MD5::decode (uint4 *output, const uint1 *input, uint4 len){
unsigned int i, j;
@@ -396,7 +396,7 @@ void MD5::decode (uint4 *output, uint1 *input, uint4 len){
// Note: Replace "for loop" with standard memcpy if possible.
void MD5::memcpy (uint1 *output, uint1 *input, uint4 len){
void MD5::memcpy (uint1 *output, const uint1 *input, uint4 len){
unsigned int i;
+5 -5
View File
@@ -48,7 +48,7 @@ class MD5 {
public:
// methods for controlled operation:
MD5 (); // simple initializer
void update (unsigned char *input, unsigned int input_length);
void update (const unsigned char *input, unsigned int input_length);
void update (FILE *file);
void finalize ();
@@ -81,12 +81,12 @@ private:
// last, the private methods, mostly static:
void init (); // called by all constructors
void transform (uint1 *buffer); // does the real update work. Note
void transform (const uint1 *buffer); // does the real update work. Note
// that length is implied to be 64.
static void encode (uint1 *dest, uint4 *src, uint4 length);
static void decode (uint4 *dest, uint1 *src, uint4 length);
static void memcpy (uint1 *dest, uint1 *src, uint4 length);
static void encode (uint1 *dest, const uint4 *src, uint4 length);
static void decode (uint4 *dest, const uint1 *src, uint4 length);
static void memcpy (uint1 *dest, const uint1 *src, uint4 length);
static void memset (uint1 *start, uint1 val, uint4 length);
static inline uint4 rotate_left (uint4 x, uint4 n);