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
+12 -2
View File
@@ -22,8 +22,8 @@
#include "sp_vm_types.h"
/** SourcePawn Engine API Versions */
#define SOURCEPAWN_ENGINE2_API_VERSION 8
#define SOURCEPAWN_API_VERSION 0x0208
#define SOURCEPAWN_ENGINE2_API_VERSION 9
#define SOURCEPAWN_API_VERSION 0x0209
namespace SourceMod {
struct IdentityToken_t;
@@ -1316,6 +1316,16 @@ namespace SourcePawn
* @param tool Profiling tool.
*/
virtual void SetProfilingTool(IProfilingTool *tool) =0;
/**
* @brief Loads a plugin from disk.
*
* @param file Path to the file to compile.
* @param errpr Buffer to store an error message (optional).
* @param maxlength Maximum length of the error buffer.
* @return New runtime pointer, or NULL on failure.
*/
virtual IPluginRuntime *LoadBinaryFromFile(const char *file, char *error, size_t maxlength) = 0;
};
// @brief This class is the v3 API for SourcePawn. It provides access to