From 374e660b78869b7dc64bb03865f4f8382dc98cb0 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sat, 20 Oct 2018 19:07:52 -0300 Subject: [PATCH] Print stack trace on invalid memory accesses (#461) * Print stack trace on invalid memory accesses * Rebased, change code region base address for 39-bits address space, print stack trace on break and undefined instructions too --- Events/AInvalidAccessEventArgs.cs | 14 ++++++++++++++ Memory/AMemory.cs | 7 +++++++ 2 files changed, 21 insertions(+) create mode 100644 Events/AInvalidAccessEventArgs.cs diff --git a/Events/AInvalidAccessEventArgs.cs b/Events/AInvalidAccessEventArgs.cs new file mode 100644 index 0000000..a5c472a --- /dev/null +++ b/Events/AInvalidAccessEventArgs.cs @@ -0,0 +1,14 @@ +using System; + +namespace ChocolArm64.Events +{ + public class AInvalidAccessEventArgs : EventArgs + { + public long Position { get; private set; } + + public AInvalidAccessEventArgs(long Position) + { + this.Position = Position; + } + } +} \ No newline at end of file diff --git a/Memory/AMemory.cs b/Memory/AMemory.cs index bb6a2b5..2854871 100644 --- a/Memory/AMemory.cs +++ b/Memory/AMemory.cs @@ -1,3 +1,4 @@ +using ChocolArm64.Events; using ChocolArm64.Exceptions; using ChocolArm64.State; using System; @@ -51,6 +52,8 @@ namespace ChocolArm64.Memory private byte*** PageTable; + public event EventHandler InvalidAccess; + public AMemory(IntPtr Ram) { Monitors = new Dictionary(); @@ -512,6 +515,8 @@ Unmapped: return (byte*)Ptr + (Position & PageMask); } + InvalidAccess?.Invoke(this, new AInvalidAccessEventArgs(Position)); + throw new VmmPageFaultException(Position); } @@ -560,6 +565,8 @@ Unmapped: return (byte*)Ptr + (Position & PageMask); } + InvalidAccess?.Invoke(this, new AInvalidAccessEventArgs(Position)); + throw new VmmPageFaultException(Position); }