Skip to content

Commit

Permalink
Fixed a bug with stack->register transition
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Aug 25, 2022
1 parent c3ec4cd commit 10a5df4
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions ILRuntime/Runtime/Intepreter/ILIntepreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4672,11 +4672,33 @@ ExceptionHandler FindExceptionHandlerByBranchTarget(int addr, int branchTarget,
}
return eh;
}

void RelocateValueTypeManagedObj(StackObject* esp, AutoList mStack, ref int curIdx)
{
StackObject* descripter = ResolveReference(esp);
for (int i = descripter->ValueLow; i > 0; i--)
{
StackObject* cur = descripter - i;
if (cur->ObjectType >= ObjectTypes.Object)
{
mStack[curIdx] = mStack[cur->Value];
cur->Value = curIdx;
curIdx--;
}
else
{
if (cur->ObjectType == ObjectTypes.ValueTypeObjectReference)
{
RelocateValueTypeManagedObj(cur, mStack, ref curIdx);
}
}
}
}

void PrepareRegisterCallStack(StackObject* esp, AutoList mStack, ILMethod method)
{
var pCnt = method.HasThis ? method.ParameterCount + 1 : method.ParameterCount;
StackObject* basePointer = esp - pCnt;
int mBase = mStack.Count;
int existing = 0;
for (int i = 0; i < pCnt; i++)
{
Expand All @@ -4690,24 +4712,29 @@ void PrepareRegisterCallStack(StackObject* esp, AutoList mStack, ILMethod method
}
if (existing > 0)
{
mBase = mBase - existing;
int curIdx = mStack.Count - 1;
for (int i = pCnt - 1; i >= 0; i--)
{
StackObject* cur = basePointer + i;
if (cur->ObjectType >= ObjectTypes.Object)
{
mStack[mBase + i] = mStack[cur->Value];
cur->Value = mBase + i;
mStack[curIdx] = mStack[cur->Value];
cur->Value = curIdx;
}
else
{
if (cur->ObjectType == ObjectTypes.Null)
{
cur->ObjectType = ObjectTypes.Object;
cur->Value = mBase + i;
cur->Value = curIdx;
}
else if (cur->ObjectType == ObjectTypes.ValueTypeObjectReference)
{
RelocateValueTypeManagedObj(cur, mStack, ref curIdx);
}
mStack[mBase + i] = null;
mStack[curIdx] = null;
}
curIdx--;
}
}
}
Expand Down

0 comments on commit 10a5df4

Please sign in to comment.