Fixed horrendous crash in the JIT from packing change in the debug table (
bug 3334, r=me).
I accidentally changed the debug table packing in a commit a while ago. This explains the nonsense debug output and crashes people have been getting on the 1.1 branch. Fortunately this is (mostly) detectable via the "debug.natives" table and the JIT will unpack symbols based on that information.
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;
91 pRuntime = new BaseRuntime();
92 if ((error = pRuntime->CreateFromMemory(&hdr, base)) != SP_ERROR_NONE)
101 for (size_t i = len - 1; i >= 0 && i < len; i--)
109 pRuntime->m_pPlugin->name = strdup(&file[i+1]);
114 if (pRuntime->m_pPlugin->name == NULL)
116 pRuntime->m_pPlugin->name = strdup(file);
119 pRuntime->ApplyCompilationOptions(co);
135 SPVM_NATIVE_FUNC SourcePawnEngine2::CreateFakeNative(SPVM_FAKENATIVE_FUNC callback, void *pData)
137 return g_Jit.CreateFakeNative(callback, pData);
140 void SourcePawnEngine2::DestroyFakeNative(SPVM_NATIVE_FUNC func)
142 g_Jit.DestroyFakeNative(func);
145 const char *SourcePawnEngine2::GetEngineName()
147 return "SourcePawn 1.1, jit-x86";
150 const char *SourcePawnEngine2::GetVersionString()
152 return SVN_FULL_VERSION;
155 IProfiler *SourcePawnEngine2::GetProfiler()
160 void SourcePawnEngine2::SetProfiler(IProfiler *profiler)
162 m_Profiler = profiler;
165 IDebugListener *SourcePawnEngine2::SetDebugListener(IDebugListener *listener)
167 return g_engine1.SetDebugListener(listener);
170 unsigned int SourcePawnEngine2::GetAPIVersion()
172 return SOURCEPAWN_ENGINE2_API_VERSION;
175 ICompilation *SourcePawnEngine2::StartCompilation()
177 return g_Jit.StartCompilation();
180 const char *SourcePawnEngine2::GetErrorString(int err)
182 return g_engine1.GetErrorString(err);
185 bool SourcePawnEngine2::Initialize()
187 return g_Jit.InitializeJIT();
190 void SourcePawnEngine2::Shutdown()