From 57bb0abda3dc277dc7575250fdb080edb83abcbc Mon Sep 17 00:00:00 2001 From: gdkchan Date: Thu, 30 Jul 2020 10:16:41 -0300 Subject: Print guest stack trace on invalid memory access (#1407) * Print guest stack trace on invalid memory access * Improve XML docs --- Ryujinx.Memory/InvalidMemoryRegionException.cs | 19 ++++++++++++++ Ryujinx.Memory/MemoryBlock.cs | 36 +++++++++++++------------- 2 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 Ryujinx.Memory/InvalidMemoryRegionException.cs (limited to 'Ryujinx.Memory') diff --git a/Ryujinx.Memory/InvalidMemoryRegionException.cs b/Ryujinx.Memory/InvalidMemoryRegionException.cs new file mode 100644 index 00000000..9fc938c6 --- /dev/null +++ b/Ryujinx.Memory/InvalidMemoryRegionException.cs @@ -0,0 +1,19 @@ +using System; + +namespace Ryujinx.Memory +{ + public class InvalidMemoryRegionException : Exception + { + public InvalidMemoryRegionException() : base("Attempted to access a invalid memory region.") + { + } + + public InvalidMemoryRegionException(string message) : base(message) + { + } + + public InvalidMemoryRegionException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/Ryujinx.Memory/MemoryBlock.cs b/Ryujinx.Memory/MemoryBlock.cs index 065e0713..198e275b 100644 --- a/Ryujinx.Memory/MemoryBlock.cs +++ b/Ryujinx.Memory/MemoryBlock.cs @@ -25,7 +25,7 @@ namespace Ryujinx.Memory /// Initializes a new instance of the memory block class. /// /// Size of the memory block - /// Flags that control memory block memory allocation + /// Flags that controls memory block memory allocation /// Throw when there's no enough memory to allocate the requested size /// Throw when the current platform is not supported public MemoryBlock(ulong size, MemoryAllocationFlags flags = MemoryAllocationFlags.None) @@ -50,7 +50,7 @@ namespace Ryujinx.Memory /// Size of the range to be committed /// True if the operation was successful, false otherwise /// Throw when the memory block has already been disposed - /// Throw when either or are out of range + /// Throw when either or are out of range public bool Commit(ulong offset, ulong size) { return MemoryManagement.Commit(GetPointerInternal(offset, size), size); @@ -63,7 +63,7 @@ namespace Ryujinx.Memory /// Size of the range to be reprotected /// New memory permissions /// Throw when the memory block has already been disposed - /// Throw when either or are out of range + /// Throw when either or are out of range /// Throw when is invalid public void Reprotect(ulong offset, ulong size, MemoryPermission permission) { @@ -76,7 +76,7 @@ namespace Ryujinx.Memory /// Starting offset of the range being read /// Span where the bytes being read will be copied to /// Throw when the memory block has already been disposed - /// Throw when the memory region specified for the the data is out of range + /// Throw when the memory region specified for the the data is out of range [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Read(ulong offset, Span data) { @@ -90,7 +90,7 @@ namespace Ryujinx.Memory /// Offset where the data is located /// Data at the specified address /// Throw when the memory block has already been disposed - /// Throw when the memory region specified for the the data is out of range + /// Throw when the memory region specified for the the data is out of range [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Read(ulong offset) where T : unmanaged { @@ -103,7 +103,7 @@ namespace Ryujinx.Memory /// Starting offset of the range being written /// Span where the bytes being written will be copied from /// Throw when the memory block has already been disposed - /// Throw when the memory region specified for the the data is out of range + /// Throw when the memory region specified for the the data is out of range [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Write(ulong offset, ReadOnlySpan data) { @@ -117,7 +117,7 @@ namespace Ryujinx.Memory /// Offset to write the data into /// Data to be written /// Throw when the memory block has already been disposed - /// Throw when the memory region specified for the the data is out of range + /// Throw when the memory region specified for the the data is out of range [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Write(ulong offset, T data) where T : unmanaged { @@ -131,7 +131,7 @@ namespace Ryujinx.Memory /// Source offset to read the data from /// Size of the copy in bytes /// Throw when the memory block has already been disposed - /// Throw when , or is out of range + /// Throw when , or is out of range public void Copy(ulong dstOffset, ulong srcOffset, ulong size) { const int MaxChunkSize = 1 << 30; @@ -150,7 +150,7 @@ namespace Ryujinx.Memory /// Offset of the region to fill with zeros /// Size in bytes of the region to fill /// Throw when the memory block has already been disposed - /// Throw when either or are out of range + /// Throw when either or are out of range public void ZeroFill(ulong offset, ulong size) { const int MaxChunkSize = 1 << 30; @@ -170,7 +170,7 @@ namespace Ryujinx.Memory /// Offset of the memory region /// A reference to the given memory region data /// Throw when the memory block has already been disposed - /// Throw when either or are out of range + /// Throw when either or are out of range [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe ref T GetRef(ulong offset) where T : unmanaged { @@ -187,7 +187,7 @@ namespace Ryujinx.Memory if (endOffset > Size || endOffset < offset) { - ThrowArgumentOutOfRange(); + ThrowInvalidMemoryRegionException(); } return ref Unsafe.AsRef((void*)PtrAddr(ptr, offset)); @@ -200,7 +200,7 @@ namespace Ryujinx.Memory /// Size in bytes of the region /// The pointer to the memory region /// Throw when the memory block has already been disposed - /// Throw when either or are out of range + /// Throw when either or are out of range [MethodImpl(MethodImplOptions.AggressiveInlining)] public IntPtr GetPointer(ulong offset, int size) => GetPointerInternal(offset, (ulong)size); @@ -218,20 +218,20 @@ namespace Ryujinx.Memory if (endOffset > Size || endOffset < offset) { - ThrowArgumentOutOfRange(); + ThrowInvalidMemoryRegionException(); } return PtrAddr(ptr, offset); } /// - /// Gets the of a given memory block region. + /// Gets the of a given memory block region. /// /// Start offset of the memory region /// Size in bytes of the region /// Span of the memory region /// Throw when the memory block has already been disposed - /// Throw when either or are out of range + /// Throw when either or are out of range [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe Span GetSpan(ulong offset, int size) { @@ -239,13 +239,13 @@ namespace Ryujinx.Memory } /// - /// Gets the of a given memory block region. + /// Gets the of a given memory block region. /// /// Start offset of the memory region /// Size in bytes of the region /// Memory of the memory region /// Throw when the memory block has already been disposed - /// Throw when either or are out of range + /// Throw when either or are out of range [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe Memory GetMemory(ulong offset, int size) { @@ -285,6 +285,6 @@ namespace Ryujinx.Memory } private void ThrowObjectDisposed() => throw new ObjectDisposedException(nameof(MemoryBlock)); - private void ThrowArgumentOutOfRange() => throw new ArgumentOutOfRangeException(); + private void ThrowInvalidMemoryRegionException() => throw new InvalidMemoryRegionException(); } } -- cgit v1.2.3