Skip to content

Commit 5bf7b5b

Browse files
committed
Only update stack memory region if stack offset changes
1 parent 1b69961 commit 5bf7b5b

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Processor.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ public bool Execute(bool runUntilHalt, Stream? stdoutOverride = null)
152152
byte opcodeLow = (byte)(0x0F & opcode);
153153
ulong operandStart = ++Registers[(int)Register.rpo];
154154

155+
ulong oldSO = Registers[(int)Register.rso];
156+
155157
// Local variables used to hold additional state information while executing instructions
156158
ulong initial;
157159
ulong mathend;
@@ -3358,14 +3360,15 @@ is not (ulong)StatusFlags.Sign and not (ulong)StatusFlags.Overflow)
33583360
default:
33593361
throw new InvalidOpcodeException(string.Format(Strings.Processor_Error_Opcode_Extension_Set, extensionSet));
33603362
}
3361-
if (MapStack)
3363+
ulong newSO = Registers[(int)Register.rso];
3364+
if (MapStack && newSO != oldSO)
33623365
{
33633366
// Update the mapped memory occupied by the stack, and throw an error if the stack has collided with allocated memory
3364-
if (Registers[(int)Register.rso] > (ulong)Memory.LongLength)
3367+
if (newSO > (ulong)Memory.LongLength)
33653368
{
33663369
throw new StackSizeException(Strings.Processor_Error_Stack_Out_Of_Range);
33673370
}
3368-
_mappedMemoryRanges[^1] = new Range((long)Registers[(int)Register.rso], Memory.LongLength);
3371+
_mappedMemoryRanges[^1] = new Range((long)newSO, Memory.LongLength);
33693372
if (_mappedMemoryRanges.Count >= 2 && _mappedMemoryRanges[^2].Overlaps(_mappedMemoryRanges[^1]))
33703373
{
33713374
throw new StackSizeException(Strings.Processor_Error_Stack_Collide);

0 commit comments

Comments
 (0)