sourcepawn/vm/sp_vm_engine.cpp
changeset 93 b00ab8fec541
parent 67 2fae86728e54
child 113 75b928da1ef1
     1.1 --- a/sourcepawn/vm/sp_vm_engine.cpp	Sat Sep 23 23:37:40 2006 +0000
     1.2 +++ b/sourcepawn/vm/sp_vm_engine.cpp	Sun Sep 24 06:17:10 2006 +0000
     1.3 @@ -6,8 +6,39 @@
     1.4  #include "zlib/zlib.h"
     1.5  #include "sp_vm_basecontext.h"
     1.6  
     1.7 +#if defined WIN32
     1.8 + #define WIN32_LEAN_AND_MEAN
     1.9 + #include <windows.h>
    1.10 +#else if defined __GNUC__
    1.11 + #include <sys/mman.h>
    1.12 +#endif
    1.13 +
    1.14  using namespace SourcePawn;
    1.15  
    1.16 +void *SourcePawnEngine::ExecAlloc(size_t size)
    1.17 +{
    1.18 +#if defined WIN32
    1.19 +	return VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    1.20 +#else if defined __GNUC__
    1.21 +	void *base = memalign(sysconf(_SC_PAGESIZE), size);
    1.22 +	if (mprotect(base, size, PROT_READ|PROT_WRITE|PROT_EXEC) != 0)
    1.23 +	{
    1.24 +		free(base);
    1.25 +		return NULL;
    1.26 +	}
    1.27 +	return base;
    1.28 +#endif
    1.29 +}
    1.30 +
    1.31 +void SourcePawnEngine::ExecFree(void *address)
    1.32 +{
    1.33 +#if defined WIN32
    1.34 +	VirtualFree(address, 0, MEM_RELEASE);
    1.35 +#else if defined __GNUC__
    1.36 +	free(address);
    1.37 +#endif
    1.38 +}
    1.39 +
    1.40  void *SourcePawnEngine::BaseAlloc(size_t size)
    1.41  {
    1.42  	return malloc(size);
    1.43 @@ -28,7 +59,7 @@
    1.44  	sp_context_t *_ctx = ctx->GetContext();
    1.45  	IVirtualMachine *vm = ctx->GetVirtualMachine();
    1.46  	
    1.47 -	vm->FreeContextVars(_ctx);
    1.48 +	vm->FreeContext(_ctx);
    1.49  
    1.50  	delete ctx;
    1.51  }