From 0394dc56b754f3f1156318a1d0c6a57ca20addc1 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 15 Nov 2018 22:33:13 +0100 Subject: [PATCH] - generate a memset for the allocated stack memory because that's what the VM does (this really shouldn't be done by the VM either - the compiler backend should clear its registers if it wants them to be zero!) --- src/scripting/vm/jit.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/scripting/vm/jit.cpp b/src/scripting/vm/jit.cpp index 6063ee366..cd9bf6e0b 100644 --- a/src/scripting/vm/jit.cpp +++ b/src/scripting/vm/jit.cpp @@ -589,6 +589,21 @@ void JitCompiler::Setup() cc.mov(x86::word_ptr(vmframe, offsetof(VMFrame, MaxParam)), sfunc->MaxParam); cc.mov(x86::word_ptr(vmframe, offsetof(VMFrame, NumParam)), 0); + // Zero initialize the variables (retardedly stupid to do here - should be done by the compiler backend!!) + unsigned int clearoffset = (unsigned int)offsetof(VMFrame, NumParam) + 2; + unsigned int sselength = (sfunc->StackSize - clearoffset) / 4; + auto zerosse = newTempXmmPd(); + cc.xorpd(zerosse, zerosse); + for (unsigned int i = 0; i < sselength * 4; i += 4) + cc.movupd(x86::ptr(vmframe, clearoffset + i), zerosse); + if (clearoffset + sselength * 4 < sfunc->StackSize) + { + auto zero32 = newTempInt32(); + cc.xor_(zero32, zero32); + for (unsigned int i = clearoffset + sselength * 4; i < sfunc->StackSize; i++) + cc.mov(asmjit::x86::byte_ptr(vmframe, i), zero32.r8Lo()); + } + auto fillParams = CreateCall([](VMFrame *newf, VMValue *args, int numargs) { try {