MCPcopy Create free account
hub / github.com/WheretIB/nullc / InitExecution

Method InitExecution

NULLC/Executor.cpp:665–723  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

663#define RUNTIME_ERROR(test, desc) if(test){ fcallStack.push_back(cmdStream); cmdStream = NULL; strcpy(execError, desc); break; }
664
665void Executor::InitExecution()
666{
667 if(!exLinker->exCode.size())
668 {
669 strcpy(execError, "ERROR: no code to run");
670 return;
671 }
672 fcallStack.clear();
673 NULLC_UNWRAP(funcIDStack.clear());
674
675 CommonSetLinker(exLinker);
676
677 genParams.reserve(4096);
678 genParams.clear();
679 genParams.resize((exLinker->globalVarSize + 0xf) & ~0xf);
680
681 SetUnmanagableRange(genParams.data, genParams.max);
682
683 execError[0] = 0;
684 callContinue = true;
685
686 // Add return after the last instruction to end execution of code with no return at the end
687 exLinker->exCode.push_back(VMCmd(cmdReturn, bitRetError, 0, 1));
688
689 // General stack
690 if(!genStackBase)
691 {
692 genStackBase = (unsigned int*)NULLC::alloc(sizeof(unsigned int) * 8192 * 2); // Should be enough, but can grow
693 genStackTop = genStackBase + 8192 * 2;
694 }
695 genStackPtr = genStackTop - 1;
696
697 paramBase = 0;
698
699#if defined(_M_X64)
700 // Generate gateway code for all functions
701 gateCode.clear();
702 for(unsigned int i = 0; i < exFunctions.size(); i++)
703 {
704 if(!exFunctions[i].funcType)
705 {
706 exFunctions[i].startInByteCode = 0;
707 exFunctions[i].returnShift = 0;
708 }else{
709 exFunctions[i].startInByteCode = gateCode.size();
710 exFunctions[i].returnShift = (unsigned char)CreateFunctionGateway(gateCode, i);
711 }
712 }
713#ifdef _WIN64
714 DWORD old;
715 VirtualProtect(gateCode.data, gateCode.size(), PAGE_EXECUTE_READWRITE, &old);
716#else
717 char *p = (char*)((intptr_t)((char*)gateCode.data + PAGESIZE - 1) & ~(PAGESIZE - 1)) - PAGESIZE;
718 if(mprotect(p, ((gateCode.size() + PAGESIZE - 1) & ~(PAGESIZE - 1)) + PAGESIZE, PROT_READ | PROT_WRITE | PROT_EXEC))
719 asm("int $0x3");
720#endif
721
722#endif

Callers

nothing calls this directly

Calls 8

CommonSetLinkerFunction · 0.85
SetUnmanagableRangeFunction · 0.85
VMCmdClass · 0.85
sizeMethod · 0.45
clearMethod · 0.45
reserveMethod · 0.45
resizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected