From 43d759782d136c77b4abf9be88415ed1f51b2ee3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 4 Feb 2017 16:23:14 +0100 Subject: [PATCH] - fixed: Stack based local VM object pointers should not be subjected to a read barrier. This isn't done for register based variables so for consistency it should not be done for stack based variables, too. This difference in handling made it impossible to check the target of a hitscan attack if it was destroyed by getting damaged. --- src/scripting/codegeneration/codegen.cpp | 4 +++- src/scripting/vm/vmexec.h | 12 ++++++++++++ src/scripting/vm/vmops.h | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/scripting/codegeneration/codegen.cpp b/src/scripting/codegeneration/codegen.cpp index e6cd1989cd..a23811390b 100644 --- a/src/scripting/codegeneration/codegen.cpp +++ b/src/scripting/codegeneration/codegen.cpp @@ -6553,7 +6553,9 @@ ExpEmit FxStackVariable::Emit(VMFunctionBuilder *build) if (membervar->BitValue == -1) { if (offsetreg == -1) offsetreg = build->GetConstantInt(0); - build->Emit(membervar->Type->GetLoadOp(), loc.RegNum, build->FramePointer.RegNum, offsetreg); + auto op = membervar->Type->GetLoadOp(); + if (op == OP_LO) op = OP_LOS; + build->Emit(op, loc.RegNum, build->FramePointer.RegNum, offsetreg); } else { diff --git a/src/scripting/vm/vmexec.h b/src/scripting/vm/vmexec.h index fc6a53bee1..0e34aa0315 100644 --- a/src/scripting/vm/vmexec.h +++ b/src/scripting/vm/vmexec.h @@ -209,6 +209,18 @@ begin: reg.a[a] = GC::ReadBarrier(*(DObject **)ptr); reg.atag[a] = ATAG_OBJECT; NEXTOP; + OP(LOS): + ASSERTA(a); ASSERTA(B); ASSERTKD(C); + GETADDR(PB,KC,X_READ_NIL); + reg.a[a] = *(DObject **)ptr; + reg.atag[a] = ATAG_OBJECT; + NEXTOP; + OP(LOS_R): + ASSERTA(a); ASSERTA(B); ASSERTD(C); + GETADDR(PB,RC,X_READ_NIL); + reg.a[a] = *(DObject **)ptr; + reg.atag[a] = ATAG_OBJECT; + NEXTOP; OP(LP): ASSERTA(a); ASSERTA(B); ASSERTKD(C); GETADDR(PB,KC,X_READ_NIL); diff --git a/src/scripting/vm/vmops.h b/src/scripting/vm/vmops.h index 86554940ea..3fc3d7643f 100644 --- a/src/scripting/vm/vmops.h +++ b/src/scripting/vm/vmops.h @@ -44,6 +44,8 @@ xx(LS, ls, RSRPKI, LS_R, 4, REGT_INT), // load string xx(LS_R, ls, RSRPRI, NOP, 0, 0), xx(LO, lo, RPRPKI, LO_R, 4, REGT_INT), // load object xx(LO_R, lo, RPRPRI, NOP, 0, 0), +xx(LOS, los, RPRPKI, LOS_R, 4, REGT_INT), // load object (stack version without read barrier) +xx(LOS_R, lo, RPRPRI, NOP, 0, 0), xx(LP, lp, RPRPKI, LP_R, 4, REGT_INT), // load pointer xx(LP_R, lp, RPRPRI, NOP, 0, 0), xx(LV2, lv2, RVRPKI, LV2_R, 4, REGT_INT), // load vector2