diff -r 09508e46e362 -r b00ab8fec541 sourcepawn/vm/sp_vm_engine.cpp --- a/sourcepawn/vm/sp_vm_engine.cpp Sat Sep 23 23:37:40 2006 +0000 +++ b/sourcepawn/vm/sp_vm_engine.cpp Sun Sep 24 06:17:10 2006 +0000 @@ -6,8 +6,39 @@ #include "zlib/zlib.h" #include "sp_vm_basecontext.h" +#if defined WIN32 + #define WIN32_LEAN_AND_MEAN + #include +#else if defined __GNUC__ + #include +#endif + using namespace SourcePawn; +void *SourcePawnEngine::ExecAlloc(size_t size) +{ +#if defined WIN32 + return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); +#else if defined __GNUC__ + void *base = memalign(sysconf(_SC_PAGESIZE), size); + if (mprotect(base, size, PROT_READ|PROT_WRITE|PROT_EXEC) != 0) + { + free(base); + return NULL; + } + return base; +#endif +} + +void SourcePawnEngine::ExecFree(void *address) +{ +#if defined WIN32 + VirtualFree(address, 0, MEM_RELEASE); +#else if defined __GNUC__ + free(address); +#endif +} + void *SourcePawnEngine::BaseAlloc(size_t size) { return malloc(size); @@ -28,7 +59,7 @@ sp_context_t *_ctx = ctx->GetContext(); IVirtualMachine *vm = ctx->GetVirtualMachine(); - vm->FreeContextVars(_ctx); + vm->FreeContext(_ctx); delete ctx; }