MCPcopy Create free account
hub / github.com/ZDoom/Raze / AddJitFunction

Function AddJitFunction

source/common/scripting/jit/jit_runtime.cpp:256–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256void *AddJitFunction(asmjit::CodeHolder* code, JitCompiler *compiler)
257{
258 using namespace asmjit;
259
260 CCFunc *func = compiler->Codegen();
261
262 size_t codeSize = code->getCodeSize();
263 if (codeSize == 0)
264 return nullptr;
265
266#ifdef _WIN64
267 TArray<uint16_t> unwindInfo = CreateUnwindInfoWindows(func);
268 size_t unwindInfoSize = unwindInfo.Size() * sizeof(uint16_t);
269 size_t functionTableSize = sizeof(RUNTIME_FUNCTION);
270#else
271 size_t unwindInfoSize = 0;
272 size_t functionTableSize = 0;
273#endif
274
275 codeSize = (codeSize + 15) / 16 * 16;
276
277 uint8_t *p = (uint8_t *)AllocJitMemory(codeSize + unwindInfoSize + functionTableSize);
278 if (!p)
279 return nullptr;
280
281 size_t relocSize = code->relocate(p);
282 if (relocSize == 0)
283 return nullptr;
284
285 size_t unwindStart = relocSize;
286 unwindStart = (unwindStart + 15) / 16 * 16;
287 JitBlockPos -= codeSize - unwindStart;
288
289#ifdef _WIN64
290 uint8_t *baseaddr = JitBlocks.Last();
291 uint8_t *startaddr = p;
292 uint8_t *endaddr = p + relocSize;
293 uint8_t *unwindptr = p + unwindStart;
294 memcpy(unwindptr, &unwindInfo[0], unwindInfoSize);
295
296 RUNTIME_FUNCTION *table = (RUNTIME_FUNCTION*)(unwindptr + unwindInfoSize);
297 table[0].BeginAddress = (DWORD)(ptrdiff_t)(startaddr - baseaddr);
298 table[0].EndAddress = (DWORD)(ptrdiff_t)(endaddr - baseaddr);
299#ifndef __MINGW64__
300 table[0].UnwindInfoAddress = (DWORD)(ptrdiff_t)(unwindptr - baseaddr);
301#else
302 table[0].UnwindData = (DWORD)(ptrdiff_t)(unwindptr - baseaddr);
303#endif
304 BOOLEAN result = RtlAddFunctionTable(table, 1, (DWORD64)baseaddr);
305 JitFrames.Push((uint8_t*)table);
306 if (result == 0)
307 I_Error("RtlAddFunctionTable failed");
308
309 JitDebugInfo.Push({ FString(compiler->GetScriptFunction()->PrintableName), compiler->GetScriptFunction()->SourceFileName, compiler->LineInfo, startaddr, endaddr });
310#endif
311
312 return p;
313}

Callers 1

JitCompileFunction · 0.85

Calls 11

CreateUnwindInfoWindowsFunction · 0.85
AllocJitMemoryFunction · 0.85
I_ErrorFunction · 0.85
CreateUnwindInfoUnixFunction · 0.85
CodegenMethod · 0.80
getCodeSizeMethod · 0.80
relocateMethod · 0.80
GetScriptFunctionMethod · 0.80
FStringClass · 0.50
SizeMethod · 0.45
PushMethod · 0.45

Tested by

no test coverage detected