Add bounds to address table on ARMeilleure

This commit is contained in:
riperiperi 2024-06-24 22:26:07 +01:00
parent 8454a22438
commit dad35360bd
2 changed files with 8 additions and 6 deletions

View File

@ -211,9 +211,12 @@ namespace ARMeilleure.Instructions
// Deliberately attempts to avoid branches.
var level0 = table.Levels[0];
int clearBits0 = 64 - (level0.Index + level0.Length);
// Currently no bounds check. Maybe conditionally do this for unsafe host mapped.
Operand index = context.ShiftLeft(context.ShiftRightUI(guestAddress, Const(level0.Index)), Const(3));
Operand index = context.ShiftLeft(
context.ShiftRightUI(context.ShiftLeft(guestAddress, Const(clearBits0)), Const(clearBits0 + level0.Index)),
Const(3)
);
Operand tableBase = !context.HasPtc ?
Const(table.Base) :
@ -223,11 +226,10 @@ namespace ARMeilleure.Instructions
// Second level
var level1 = table.Levels[1];
int clearBits = 64 - (level1.Index + level1.Length);
int clearBits1 = 64 - (level1.Index + level1.Length);
Operand index2 = context.ShiftLeft(
context.ShiftRightUI(context.ShiftLeft(guestAddress, Const(clearBits)), Const(clearBits + level1.Index)),
context.ShiftRightUI(context.ShiftLeft(guestAddress, Const(clearBits1)), Const(clearBits1 + level1.Index)),
Const(3)
);

View File

@ -29,7 +29,7 @@ namespace ARMeilleure.Translation.PTC
private const string OuterHeaderMagicString = "PTCohd\0\0";
private const string InnerHeaderMagicString = "PTCihd\0\0";
private const uint InternalVersion = 26957; //! To be incremented manually for each change to the ARMeilleure project.
private const uint InternalVersion = 26958; //! To be incremented manually for each change to the ARMeilleure project.
private const string ActualDir = "0";
private const string BackupDir = "1";