Skip to content

Commit

Permalink
- added null check for self pointer before calling a native function
Browse files Browse the repository at this point in the history
With JIT enabled, an implicit test for null self pointer is added to generated code
This has no effect without JIT as VM verifies a pointer before calling a native method

https://forum.zdoom.org/viewtopic.php?t=64961
  • Loading branch information
alexey-lysiuk authored and madame-rachelle committed Jun 7, 2019
1 parent c222b24 commit d3e6ed3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/scripting/vm/jit_call.cpp
Expand Up @@ -323,6 +323,28 @@ void JitCompiler::EmitNativeCall(VMNativeFunction *target)
I_Error("Native direct member function calls not implemented\n");
}

if (target->ImplicitArgs > 0)
{
auto label = EmitThrowExceptionLabel(X_READ_NIL);

assert(ParamOpcodes.Size() > 0);
const VMOP *param = ParamOpcodes[0];
const int bc = param->i16u;
asmjit::X86Gp *reg = nullptr;

switch (param->a & REGT_TYPE)
{
case REGT_STRING: reg = &regS[bc]; break;
case REGT_POINTER: reg = &regA[bc]; break;
default:
I_Error("Unexpected register type for self pointer\n");
break;
}

cc.test(*reg, *reg);
cc.jz(label);
}

asmjit::CBNode *cursorBefore = cc.getCursor();
auto call = cc.call(imm_ptr(target->DirectNativeCall), CreateFuncSignature());
call->setInlineComment(target->PrintableName.GetChars());
Expand Down

0 comments on commit d3e6ed3

Please sign in to comment.