Dynamic virtualscope checking. May yet be buggy.

This commit is contained in:
ZZYZX 2017-02-18 06:27:28 +02:00
commit e0ae0fdb2e
6 changed files with 92 additions and 20 deletions

View file

@ -648,13 +648,25 @@ begin:
VMReturn returns[MAX_RETURNS];
int numret;
// [ZZ] hax!
b = B;
if (call->BarrierSide == 3) // :( - this is Side_Virtual. Side_Virtual should receive special arguments.
{
PFunction* calledfunc = (PFunction*)(reg.param + f->NumParam - b)[0].a;
PFunction* callingfunc = (PFunction*)(reg.param + f->NumParam - b)[1].a;
DObject* dobj = (DObject*)(reg.param + f->NumParam - b)[2].a; // this is the self pointer. it should be in, since Side_Virtual functions are always non-static methods.
PClass* selftype = dobj->GetClass();
FScopeBarrier_ValidateCall(calledfunc, callingfunc, selftype);
b -= 2;
}
FillReturns(reg, f, returns, pc+1, C);
if (call->Native)
{
try
{
VMCycles[0].Unclock();
numret = static_cast<VMNativeFunction *>(call)->NativeCall(reg.param + f->NumParam - B, call->DefaultArgs, B, returns, C);
numret = static_cast<VMNativeFunction *>(call)->NativeCall(reg.param + f->NumParam - b, call->DefaultArgs, b, returns, C);
VMCycles[0].Clock();
}
catch (CVMAbortException &err)
@ -670,7 +682,7 @@ begin:
VMCalls[0]++;
VMScriptFunction *script = static_cast<VMScriptFunction *>(call);
VMFrame *newf = stack->AllocFrame(script);
VMFillParams(reg.param + f->NumParam - B, newf, B);
VMFillParams(reg.param + f->NumParam - b, newf, b);
try
{
numret = Exec(stack, script->Code, returns, C);
@ -801,6 +813,9 @@ begin:
if (!callingfunc || pcls != callingfunc->OwningClass)
ThrowAbortException(X_OTHER, "Cannot instantiate class %s directly", cls->TypeName.GetChars());
}
// [ZZ] validate readonly and between scope construction
if (callingfunc)
FScopeBarrier_ValidateNew(cls, callingfunc);
reg.a[a] = cls->CreateNew();
reg.atag[a] = ATAG_OBJECT;
NEXTOP;