2015-02-24 07:36:10 +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/.
|
|
|
|
//
|
|
|
|
#ifndef _include_sourcepawn_vm_api_h_
|
|
|
|
#define _include_sourcepawn_vm_api_h_
|
|
|
|
|
|
|
|
#include <sp_vm_api.h>
|
|
|
|
#include <am-utility.h> // Replace with am-cxx later.
|
|
|
|
|
|
|
|
namespace sp {
|
|
|
|
|
|
|
|
using namespace SourcePawn;
|
|
|
|
|
|
|
|
class SourcePawnEngine : public ISourcePawnEngine
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SourcePawnEngine();
|
|
|
|
|
|
|
|
sp_plugin_t *LoadFromFilePointer(FILE *fp, int *err) KE_OVERRIDE;
|
|
|
|
sp_plugin_t *LoadFromMemory(void *base, sp_plugin_t *plugin, int *err) KE_OVERRIDE;
|
|
|
|
int FreeFromMemory(sp_plugin_t *plugin) KE_OVERRIDE;
|
|
|
|
void *BaseAlloc(size_t size) KE_OVERRIDE;
|
|
|
|
void BaseFree(void *memory) KE_OVERRIDE;
|
|
|
|
void *ExecAlloc(size_t size) KE_OVERRIDE;
|
|
|
|
void ExecFree(void *address) KE_OVERRIDE;
|
|
|
|
IDebugListener *SetDebugListener(IDebugListener *pListener) KE_OVERRIDE;
|
|
|
|
unsigned int GetContextCallCount() KE_OVERRIDE;
|
|
|
|
unsigned int GetEngineAPIVersion() KE_OVERRIDE;
|
|
|
|
void *AllocatePageMemory(size_t size) KE_OVERRIDE;
|
|
|
|
void SetReadWrite(void *ptr) KE_OVERRIDE;
|
|
|
|
void SetReadExecute(void *ptr) KE_OVERRIDE;
|
|
|
|
void FreePageMemory(void *ptr) KE_OVERRIDE;
|
|
|
|
void SetReadWriteExecute(void *ptr);
|
|
|
|
const char *GetErrorString(int err);
|
|
|
|
};
|
|
|
|
|
|
|
|
class SourcePawnEngine2 : public ISourcePawnEngine2
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SourcePawnEngine2();
|
|
|
|
|
|
|
|
unsigned int GetAPIVersion() KE_OVERRIDE;
|
|
|
|
const char *GetEngineName() KE_OVERRIDE;
|
|
|
|
const char *GetVersionString() KE_OVERRIDE;
|
|
|
|
IPluginRuntime *LoadPlugin(ICompilation *co, const char *file, int *err) KE_OVERRIDE;
|
|
|
|
SPVM_NATIVE_FUNC CreateFakeNative(SPVM_FAKENATIVE_FUNC callback, void *pData) KE_OVERRIDE;
|
|
|
|
void DestroyFakeNative(SPVM_NATIVE_FUNC func) KE_OVERRIDE;
|
|
|
|
IDebugListener *SetDebugListener(IDebugListener *listener) KE_OVERRIDE;
|
|
|
|
ICompilation *StartCompilation() KE_OVERRIDE;
|
|
|
|
const char *GetErrorString(int err) KE_OVERRIDE;
|
|
|
|
bool Initialize() KE_OVERRIDE;
|
|
|
|
void Shutdown() KE_OVERRIDE;
|
|
|
|
IPluginRuntime *CreateEmptyRuntime(const char *name, uint32_t memory) KE_OVERRIDE;
|
|
|
|
bool InstallWatchdogTimer(size_t timeout_ms) KE_OVERRIDE;
|
|
|
|
bool SetJitEnabled(bool enabled) KE_OVERRIDE;
|
|
|
|
bool IsJitEnabled() KE_OVERRIDE;
|
|
|
|
void SetProfiler(IProfiler *profiler) KE_OVERRIDE;
|
|
|
|
void EnableProfiling() KE_OVERRIDE;
|
|
|
|
void DisableProfiling() KE_OVERRIDE;
|
|
|
|
void SetProfilingTool(IProfilingTool *tool) KE_OVERRIDE;
|
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
|
|
|
IPluginRuntime *LoadBinaryFromFile(const char *file, char *error, size_t maxlength) KE_OVERRIDE;
|
2015-02-24 07:36:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace SourcePawn
|
|
|
|
|
|
|
|
#endif // _include_sourcepawn_vm_api_h_
|