From 76f2b3d089f7f5c1b25f32752bad390f6bf30e1a Mon Sep 17 00:00:00 2001 From: riperiperi Date: Mon, 24 Jun 2024 22:26:07 +0100 Subject: [PATCH] Add bounds to address table on ARMeilleure --- src/ARMeilleure/Instructions/InstEmitFlowHelper.cs | 12 +++++++----- src/ARMeilleure/Translation/PTC/Ptc.cs | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ARMeilleure/Instructions/InstEmitFlowHelper.cs b/src/ARMeilleure/Instructions/InstEmitFlowHelper.cs index 12f1dba18..ab8e1e3bd 100644 --- a/src/ARMeilleure/Instructions/InstEmitFlowHelper.cs +++ b/src/ARMeilleure/Instructions/InstEmitFlowHelper.cs @@ -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) ); diff --git a/src/ARMeilleure/Translation/PTC/Ptc.cs b/src/ARMeilleure/Translation/PTC/Ptc.cs index 59ced5806..135ae73be 100644 --- a/src/ARMeilleure/Translation/PTC/Ptc.cs +++ b/src/ARMeilleure/Translation/PTC/Ptc.cs @@ -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";