Executable memory is now provided by MM:S's allocator, this should reduce virtual memory usage.
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401900
This commit is contained in:
parent
0e547df447
commit
45860880ef
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="Windows-1252"?>
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
<VisualStudioProject
|
<VisualStudioProject
|
||||||
ProjectType="Visual C++"
|
ProjectType="Visual C++"
|
||||||
Version="8.00"
|
Version="8,00"
|
||||||
Name="sourcemod_mm"
|
Name="sourcemod_mm"
|
||||||
ProjectGUID="{E39527CD-7CAB-4420-97CC-DA1B93B260BC}"
|
ProjectGUID="{E39527CD-7CAB-4420-97CC-DA1B93B260BC}"
|
||||||
RootNamespace="sourcemod_mm"
|
RootNamespace="sourcemod_mm"
|
||||||
@ -1154,6 +1154,46 @@
|
|||||||
<File
|
<File
|
||||||
RelativePath="..\vm\sp_vm_engine.cpp"
|
RelativePath="..\vm\sp_vm_engine.cpp"
|
||||||
>
|
>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release - Episode 1|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories=""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug - Episode 1|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories=""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="CrazyDebug|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories=""$(SOURCEMM16)\sourcehook""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug - Old Metamod|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories=""$(SOURCEMM16)\sourcehook""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release - Old Metamod|Win32"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories=""$(SOURCEMM16)\sourcehook""
|
||||||
|
/>
|
||||||
|
</FileConfiguration>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\vm\sp_vm_function.cpp"
|
RelativePath="..\vm\sp_vm_function.cpp"
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include "TimerSys.h"
|
#include "TimerSys.h"
|
||||||
#include "PluginSys.h"
|
#include "PluginSys.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "DebugReporter.h"
|
||||||
|
|
||||||
#define TIMER_HNDL_CLOSE (1<<9)
|
#define TIMER_HNDL_CLOSE (1<<9)
|
||||||
|
|
||||||
@ -150,19 +151,23 @@ void TimerNatives::OnTimerEnd(ITimer *pTimer, void *pData)
|
|||||||
{
|
{
|
||||||
if ((herr=g_HandleSys.FreeHandle(usrhndl, &sec)) != HandleError_None)
|
if ((herr=g_HandleSys.FreeHandle(usrhndl, &sec)) != HandleError_None)
|
||||||
{
|
{
|
||||||
g_Logger.LogError("Invalid data handle %x (error %d) passed during timer end on plugin %s",
|
g_DbgReporter.GenerateError(pInfo->pContext,
|
||||||
usrhndl,
|
pInfo->Hook->GetFunctionID(),
|
||||||
herr,
|
SP_ERROR_NATIVE,
|
||||||
g_PluginSys.FindPluginByContext(pInfo->pContext->GetContext())->GetFilename());
|
"Invalid data handle %x (error %d) passed during timer end",
|
||||||
|
usrhndl,
|
||||||
|
herr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((herr=g_HandleSys.FreeHandle(pInfo->TimerHandle, &sec)) != HandleError_None)
|
if ((herr=g_HandleSys.FreeHandle(pInfo->TimerHandle, &sec)) != HandleError_None)
|
||||||
{
|
{
|
||||||
g_Logger.LogError("Invalid timer handle %x (error %d) on plugin %s during timer end",
|
g_DbgReporter.GenerateError(pInfo->pContext,
|
||||||
pInfo->TimerHandle,
|
pInfo->Hook->GetFunctionID(),
|
||||||
herr,
|
SP_ERROR_NATIVE,
|
||||||
g_PluginSys.FindPluginByContext(pInfo->pContext->GetContext())->GetFilename());
|
"Invalid timer handle %x (error %d) during timer end, displayed function is timer callback, not the stack trace",
|
||||||
|
pInfo->TimerHandle,
|
||||||
|
herr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DeleteTimerInfo(pInfo);
|
DeleteTimerInfo(pInfo);
|
||||||
@ -332,4 +337,3 @@ REGISTER_NATIVES(timernatives)
|
|||||||
{"IsServerProcessing", smn_IsServerProcessing},
|
{"IsServerProcessing", smn_IsServerProcessing},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ const char *GetSourcePawnErrorMessage(int error)
|
|||||||
return g_ErrorMsgTable[error];
|
return g_ErrorMsgTable[error];
|
||||||
}
|
}
|
||||||
|
|
||||||
SourcePawnEngine::SourcePawnEngine()
|
SourcePawnEngine::SourcePawnEngine() : m_ExeMemory(16)
|
||||||
{
|
{
|
||||||
m_pDebugHook = NULL;
|
m_pDebugHook = NULL;
|
||||||
m_CallStack = NULL;
|
m_CallStack = NULL;
|
||||||
@ -137,6 +137,26 @@ void *SourcePawnEngine::ExecAlloc(size_t size)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *SourcePawnEngine::AllocatePageMemory(size_t size)
|
||||||
|
{
|
||||||
|
return m_ExeMemory.Alloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SourcePawnEngine::SetReadExecute(void *ptr)
|
||||||
|
{
|
||||||
|
m_ExeMemory.SetRE(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SourcePawnEngine::SetReadWrite(void *ptr)
|
||||||
|
{
|
||||||
|
m_ExeMemory.SetRW(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SourcePawnEngine::FreePageMemory(void *ptr)
|
||||||
|
{
|
||||||
|
m_ExeMemory.Free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
void SourcePawnEngine::ExecFree(void *address)
|
void SourcePawnEngine::ExecFree(void *address)
|
||||||
{
|
{
|
||||||
#if defined WIN32
|
#if defined WIN32
|
||||||
|
@ -32,6 +32,15 @@
|
|||||||
#ifndef _INCLUDE_SOURCEPAWN_VM_ENGINE_H_
|
#ifndef _INCLUDE_SOURCEPAWN_VM_ENGINE_H_
|
||||||
#define _INCLUDE_SOURCEPAWN_VM_ENGINE_H_
|
#define _INCLUDE_SOURCEPAWN_VM_ENGINE_H_
|
||||||
|
|
||||||
|
#include <sh_memory.h>
|
||||||
|
/* HACK to avoid including sourcehook.h for just the SH_ASSERT definition */
|
||||||
|
#if !defined SH_ASSERT
|
||||||
|
#define SH_ASSERT(x, info)
|
||||||
|
#include <sh_pagealloc.h>
|
||||||
|
#undef SH_ASSERT
|
||||||
|
#else
|
||||||
|
#include <sh_pagealloc.h>
|
||||||
|
#endif
|
||||||
#include "sp_vm_api.h"
|
#include "sp_vm_api.h"
|
||||||
#include "sp_vm_function.h"
|
#include "sp_vm_function.h"
|
||||||
|
|
||||||
@ -82,6 +91,10 @@ public: //ISourcePawnEngine
|
|||||||
IDebugListener *SetDebugListener(IDebugListener *pListener);
|
IDebugListener *SetDebugListener(IDebugListener *pListener);
|
||||||
unsigned int GetContextCallCount();
|
unsigned int GetContextCallCount();
|
||||||
unsigned int GetEngineAPIVersion();
|
unsigned int GetEngineAPIVersion();
|
||||||
|
void *AllocatePageMemory(size_t size);
|
||||||
|
void SetReadWrite(void *ptr);
|
||||||
|
void SetReadExecute(void *ptr);
|
||||||
|
void FreePageMemory(void *ptr);
|
||||||
public: //Debugger Stuff
|
public: //Debugger Stuff
|
||||||
/**
|
/**
|
||||||
* @brief Pushes a context onto the top of the call tracer.
|
* @brief Pushes a context onto the top of the call tracer.
|
||||||
@ -110,6 +123,7 @@ private:
|
|||||||
TracedCall *m_FreedCalls;
|
TracedCall *m_FreedCalls;
|
||||||
TracedCall *m_CallStack;
|
TracedCall *m_CallStack;
|
||||||
unsigned int m_CurChain;
|
unsigned int m_CurChain;
|
||||||
|
SourceHook::CPageAlloc m_ExeMemory;
|
||||||
//CFunction *m_pFreeFuncs;
|
//CFunction *m_pFreeFuncs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ CallWrapper::~CallWrapper()
|
|||||||
{
|
{
|
||||||
delete [] m_Params;
|
delete [] m_Params;
|
||||||
delete m_RetParam;
|
delete m_RetParam;
|
||||||
g_SPEngine->ExecFree(m_Addrs[ADDR_CODEBASE]);
|
g_SPEngine->FreePageMemory(m_Addrs[ADDR_CODEBASE]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallWrapper::Destroy()
|
void CallWrapper::Destroy()
|
||||||
|
@ -637,7 +637,8 @@ skip_retbuffer:
|
|||||||
if (writer.outbase == NULL)
|
if (writer.outbase == NULL)
|
||||||
{
|
{
|
||||||
CodeSize = writer.get_outputpos();
|
CodeSize = writer.get_outputpos();
|
||||||
writer.outbase = (jitcode_t)g_SPEngine->ExecAlloc(CodeSize);
|
writer.outbase = (jitcode_t)g_SPEngine->AllocatePageMemory(CodeSize);
|
||||||
|
g_SPEngine->SetReadWrite(writer.outbase);
|
||||||
writer.outptr = writer.outbase;
|
writer.outptr = writer.outbase;
|
||||||
pWrapper->m_Addrs[ADDR_CODEBASE] = writer.outbase;
|
pWrapper->m_Addrs[ADDR_CODEBASE] = writer.outbase;
|
||||||
g_StackAlign = (g_StackUsage) ? ((g_StackUsage & 0xFFFFFFF0) + 16) - g_StackUsage : 0;
|
g_StackAlign = (g_StackUsage) ? ((g_StackUsage & 0xFFFFFFF0) + 16) - g_StackUsage : 0;
|
||||||
@ -646,4 +647,5 @@ skip_retbuffer:
|
|||||||
Needs_Retbuf = false;
|
Needs_Retbuf = false;
|
||||||
goto jit_rewind;
|
goto jit_rewind;
|
||||||
}
|
}
|
||||||
|
g_SPEngine->SetReadExecute(writer.outbase);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define SMINTERFACE_SOURCEMOD_NAME "ISourceMod"
|
#define SMINTERFACE_SOURCEMOD_NAME "ISourceMod"
|
||||||
#define SMINTERFACE_SOURCEMOD_VERSION 4
|
#define SMINTERFACE_SOURCEMOD_VERSION 5
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Forward declaration of the KeyValues class.
|
* @brief Forward declaration of the KeyValues class.
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
#include "sp_vm_types.h"
|
#include "sp_vm_types.h"
|
||||||
|
|
||||||
/** SourcePawn Engine API Version */
|
/** SourcePawn Engine API Version */
|
||||||
#define SOURCEPAWN_ENGINE_API_VERSION 1
|
#define SOURCEPAWN_ENGINE_API_VERSION 2
|
||||||
|
|
||||||
/** SourcePawn VM API Version */
|
/** SourcePawn VM API Version */
|
||||||
#define SOURCEPAWN_VM_API_VERSION 5
|
#define SOURCEPAWN_VM_API_VERSION 5
|
||||||
@ -740,6 +740,7 @@ namespace SourcePawn
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Allocates executable memory.
|
* @brief Allocates executable memory.
|
||||||
|
* @deprecated Use AllocPageMemory()
|
||||||
*
|
*
|
||||||
* @param size Size of memory to allocate.
|
* @param size Size of memory to allocate.
|
||||||
* @return Pointer to memory, NULL if allocation failed.
|
* @return Pointer to memory, NULL if allocation failed.
|
||||||
@ -748,6 +749,7 @@ namespace SourcePawn
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Frees executable memory.
|
* @brief Frees executable memory.
|
||||||
|
* @deprecated Use FreePageMemory()
|
||||||
*
|
*
|
||||||
* @param address Address to free.
|
* @param address Address to free.
|
||||||
*/
|
*/
|
||||||
@ -777,6 +779,35 @@ namespace SourcePawn
|
|||||||
* @return Engine API version.
|
* @return Engine API version.
|
||||||
*/
|
*/
|
||||||
virtual unsigned int GetEngineAPIVersion() =0;
|
virtual unsigned int GetEngineAPIVersion() =0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Allocates executable memory.
|
||||||
|
*
|
||||||
|
* @param size Size of memory to allocate.
|
||||||
|
* @return Pointer to memory, NULL if allocation failed.
|
||||||
|
*/
|
||||||
|
virtual void *AllocatePageMemory(size_t size) =0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the input memory permissions to read+write.
|
||||||
|
*
|
||||||
|
* @param ptr Memory block.
|
||||||
|
*/
|
||||||
|
virtual void SetReadWrite(void *ptr) =0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the input memory permissions to read+execute.
|
||||||
|
*
|
||||||
|
* @param ptr Memory block.
|
||||||
|
*/
|
||||||
|
virtual void SetReadExecute(void *ptr) =0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Frees executable memory.
|
||||||
|
*
|
||||||
|
* @param ptr Address to free.
|
||||||
|
*/
|
||||||
|
virtual void FreePageMemory(void *ptr) =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -2380,7 +2380,8 @@ jit_rewind:
|
|||||||
|
|
||||||
/* the total codesize is now known! */
|
/* the total codesize is now known! */
|
||||||
codemem = writer.get_outputpos();
|
codemem = writer.get_outputpos();
|
||||||
writer.outbase = (jitcode_t)engine->ExecAlloc(codemem);
|
writer.outbase = (jitcode_t)engine->AllocatePageMemory(codemem);
|
||||||
|
engine->SetReadWrite(writer.outbase);
|
||||||
writer.outptr = writer.outbase;
|
writer.outptr = writer.outbase;
|
||||||
/* go back for third pass */
|
/* go back for third pass */
|
||||||
goto jit_rewind;
|
goto jit_rewind;
|
||||||
@ -2398,6 +2399,8 @@ jit_rewind:
|
|||||||
}
|
}
|
||||||
/* Write these last because error jumps should be unpredicted, and thus forward */
|
/* Write these last because error jumps should be unpredicted, and thus forward */
|
||||||
WriteErrorRoutines(data, jit);
|
WriteErrorRoutines(data, jit);
|
||||||
|
|
||||||
|
engine->SetReadExecute(writer.outbase);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************
|
/*************
|
||||||
@ -2605,22 +2608,25 @@ rewind:
|
|||||||
if (jw.outbase == NULL)
|
if (jw.outbase == NULL)
|
||||||
{
|
{
|
||||||
/* Second pass: Actually write */
|
/* Second pass: Actually write */
|
||||||
jw.outbase = (jitcode_t)engine->ExecAlloc(jw.get_outputpos());
|
jw.outbase = (jitcode_t)engine->AllocatePageMemory(jw.get_outputpos());
|
||||||
if (!jw.outbase)
|
if (!jw.outbase)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
engine->SetReadWrite(jw.outbase);
|
||||||
jw.outptr = jw.outbase;
|
jw.outptr = jw.outbase;
|
||||||
|
|
||||||
goto rewind;
|
goto rewind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
engine->SetReadExecute(jw.outbase);
|
||||||
|
|
||||||
return (SPVM_NATIVE_FUNC)jw.outbase;
|
return (SPVM_NATIVE_FUNC)jw.outbase;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JITX86::DestroyFakeNative(SPVM_NATIVE_FUNC func)
|
void JITX86::DestroyFakeNative(SPVM_NATIVE_FUNC func)
|
||||||
{
|
{
|
||||||
engine->ExecFree((void *)func);
|
engine->FreePageMemory(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *JITX86::GetVMName()
|
const char *JITX86::GetVMName()
|
||||||
@ -2637,7 +2643,7 @@ int JITX86::ContextExecute(sp_context_t *ctx, uint32_t code_idx, cell_t *result)
|
|||||||
|
|
||||||
void JITX86::FreeContext(sp_context_t *ctx)
|
void JITX86::FreeContext(sp_context_t *ctx)
|
||||||
{
|
{
|
||||||
engine->ExecFree(ctx->codebase);
|
engine->FreePageMemory(ctx->codebase);
|
||||||
delete [] ctx->memory;
|
delete [] ctx->memory;
|
||||||
delete [] ctx->files;
|
delete [] ctx->files;
|
||||||
delete [] ctx->lines;
|
delete [] ctx->lines;
|
||||||
|
Loading…
Reference in New Issue
Block a user