Fixed leaking relocation table memory in JIT.
5 #include "x86/jit_x86.h"
6 #include "jit_version.h"
8 #include "BaseRuntime.h"
9 #include "sp_vm_engine.h"
11 using namespace SourcePawn;
13 SourcePawnEngine2::SourcePawnEngine2()
18 IPluginRuntime *SourcePawnEngine2::LoadPlugin(ICompilation *co, const char *file, int *err)
24 BaseRuntime *pRuntime;
26 FILE *fp = fopen(file, "rb");
30 error = SP_ERROR_NOT_FOUND;
34 /* Rewind for safety */
35 fread(&hdr, sizeof(sp_file_hdr_t), 1, fp);
37 if (hdr.magic != SPFILE_MAGIC)
39 error = SP_ERROR_FILE_FORMAT;
43 switch (hdr.compression)
45 case SPFILE_COMPRESSION_GZ:
47 uint32_t uncompsize = hdr.imagesize - hdr.dataoffs;
48 uint32_t compsize = hdr.disksize - hdr.dataoffs;
49 uint32_t sectsize = hdr.dataoffs - sizeof(sp_file_hdr_t);
50 uLongf destlen = uncompsize;
52 char *tempbuf = (char *)malloc(compsize);
53 void *uncompdata = malloc(uncompsize);
54 void *sectheader = malloc(sectsize);
56 fread(sectheader, sectsize, 1, fp);
57 fread(tempbuf, compsize, 1, fp);
59 z_result = uncompress((Bytef *)uncompdata, &destlen, (Bytef *)tempbuf, compsize);
65 error = SP_ERROR_DECOMPRESSOR;
69 base = (uint8_t *)malloc(hdr.imagesize);
70 memcpy(base, &hdr, sizeof(sp_file_hdr_t));
71 memcpy(base + sizeof(sp_file_hdr_t), sectheader, sectsize);
73 memcpy(base + hdr.dataoffs, uncompdata, uncompsize);
77 case SPFILE_COMPRESSION_NONE:
79 base = (uint8_t *)malloc(hdr.imagesize);
81 fread(base, hdr.imagesize, 1, fp);
86 error = SP_ERROR_DECOMPRESSOR;
92 pRuntime = new BaseRuntime();
93 if ((error = pRuntime->CreateFromMemory(&hdr, base)) != SP_ERROR_NONE)
102 for (size_t i = len - 1; i >= 0 && i < len; i--)
110 pRuntime->m_pPlugin->name = strdup(&file[i+1]);
115 if (pRuntime->m_pPlugin->name == NULL)
117 pRuntime->m_pPlugin->name = strdup(file);
120 pRuntime->ApplyCompilationOptions(co);
136 SPVM_NATIVE_FUNC SourcePawnEngine2::CreateFakeNative(SPVM_FAKENATIVE_FUNC callback, void *pData)
138 return g_Jit.CreateFakeNative(callback, pData);
141 void SourcePawnEngine2::DestroyFakeNative(SPVM_NATIVE_FUNC func)
143 g_Jit.DestroyFakeNative(func);
146 const char *SourcePawnEngine2::GetEngineName()
148 return "SourcePawn 1.1, jit-x86";
151 const char *SourcePawnEngine2::GetVersionString()
153 return SVN_FULL_VERSION;
156 IProfiler *SourcePawnEngine2::GetProfiler()
161 void SourcePawnEngine2::SetProfiler(IProfiler *profiler)
163 m_Profiler = profiler;
166 IDebugListener *SourcePawnEngine2::SetDebugListener(IDebugListener *listener)
168 return g_engine1.SetDebugListener(listener);
171 unsigned int SourcePawnEngine2::GetAPIVersion()
173 return SOURCEPAWN_ENGINE2_API_VERSION;
176 ICompilation *SourcePawnEngine2::StartCompilation()
178 return g_Jit.StartCompilation();
181 const char *SourcePawnEngine2::GetErrorString(int err)
183 return g_engine1.GetErrorString(err);
186 bool SourcePawnEngine2::Initialize()
188 return g_Jit.InitializeJIT();
191 void SourcePawnEngine2::Shutdown()