Skip to content

Commit 12c8b44

Browse files
ViRb3SamboyCoding
authored andcommitted
Fix ArmV8 segment boundary crash
1 parent 58fc404 commit 12c8b44

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Cpp2IL.Core/InstructionSets/NewArmV8InstructionSet.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ public override Memory<byte> GetRawBytesForMethod(MethodAnalysisContext context,
3232
}
3333

3434
var result = NewArm64Utils.GetArm64MethodBodyAtVirtualAddress(context.UnderlyingPointer);
35-
var endVa = result.LastValid().Address + 4;
35+
var lastInsn = result.LastValid();
3636

3737
var start = (int)context.AppContext.Binary.MapVirtualAddressToRaw(context.UnderlyingPointer);
38-
var end = (int)context.AppContext.Binary.MapVirtualAddressToRaw(endVa);
38+
// Map the last instruction (always within segment) and add 4 (ARM64 instruction size).
39+
// This avoids mapping endVa which may land exactly at a segment boundary gap.
40+
var end = (int)context.AppContext.Binary.MapVirtualAddressToRaw(lastInsn.Address) + 4;
3941

4042
//Sanity check
4143
if (start < 0 || end < 0 || start >= context.AppContext.Binary.RawLength || end >= context.AppContext.Binary.RawLength)

0 commit comments

Comments
 (0)