Skip to content

Commit

Permalink
Fixed a stack violation if the argument of a method contains valuetyp…
Browse files Browse the repository at this point in the history
…ereference
  • Loading branch information
liiir1985 committed Apr 3, 2020
1 parent 32a3765 commit e5f45ad
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions ILRuntime/Runtime/Stack/RuntimeStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ public void PushFrame(ref StackFrame frame)
int mStackBase = frame.ManagedStackBase;
if (method.HasThis)
ret--;
for (StackObject* ptr = ret; ptr < frame.LocalVarPointer; ptr++)
{
if (ptr->ObjectType == ObjectTypes.ValueTypeObjectReference)
{
var addr = ILIntepreter.ResolveReference(ptr);
int start = int.MaxValue;
int end = int.MaxValue;
var tmp = addr;
CountValueTypeManaged(ptr, ref start, ref end, &tmp);

if (addr > frame.ValueTypeBasePointer)
{
frame.ValueTypeBasePointer = addr;
}
if (start < mStackBase)
mStackBase = start;
}
}
if(method.ReturnType != intepreter.AppDomain.VoidType)
{
*ret = *returnVal;
Expand Down Expand Up @@ -147,11 +165,11 @@ public void PushFrame(ref StackFrame frame)

public void RelocateValueTypeAndFreeAfterDst(StackObject* src, StackObject* dst)
{
var objRef2 = dst;
dst = ILIntepreter.ResolveReference(dst);
int start = int.MaxValue;
int end = int.MaxValue;
var objRef2 = dst;
CountValueTypeManaged(dst, ref start, ref end, &objRef2);
CountValueTypeManaged(objRef2, ref start, ref end, &objRef2);
RelocateValueType(src, ref dst, ref start);
ValueTypeStackPointer = dst;
if (start <= end)
Expand Down

0 comments on commit e5f45ad

Please sign in to comment.