From 9860bfb2cdb2a3f6093d936d647b1f254a23120d Mon Sep 17 00:00:00 2001 From: Mary Date: Mon, 26 Jun 2023 03:37:12 +0200 Subject: [PATCH] misc: memory: Migrate from OutOfMemoryException to SystemException entirely (#5399) Fix a regression with address space allocation while providing more information about the context of the exception. --- src/Ryujinx.Cpu/AddressSpace.cs | 2 +- src/Ryujinx.Memory/MemoryBlock.cs | 6 +++--- src/Ryujinx.Memory/MemoryManagementUnix.cs | 12 ++++++------ src/Ryujinx.Memory/MemoryManagementWindows.cs | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Ryujinx.Cpu/AddressSpace.cs b/src/Ryujinx.Cpu/AddressSpace.cs index 0e27b1582..e051244d5 100644 --- a/src/Ryujinx.Cpu/AddressSpace.cs +++ b/src/Ryujinx.Cpu/AddressSpace.cs @@ -199,7 +199,7 @@ namespace Ryujinx.Cpu break; } - catch (OutOfMemoryException) + catch (SystemException) { baseMemory?.Dispose(); mirrorMemory?.Dispose(); diff --git a/src/Ryujinx.Memory/MemoryBlock.cs b/src/Ryujinx.Memory/MemoryBlock.cs index 2cf04628a..e7fc47516 100644 --- a/src/Ryujinx.Memory/MemoryBlock.cs +++ b/src/Ryujinx.Memory/MemoryBlock.cs @@ -31,7 +31,7 @@ namespace Ryujinx.Memory /// /// Size of the memory block in bytes /// Flags that controls memory block memory allocation - /// Throw when there's no enough memory to allocate the requested size + /// Throw when there's an error while allocating the requested size /// Throw when the current platform is not supported public MemoryBlock(ulong size, MemoryAllocationFlags flags = MemoryAllocationFlags.None) { @@ -66,7 +66,7 @@ namespace Ryujinx.Memory /// /// Size of the memory block in bytes /// Shared memory to use as backing storage for this block - /// Throw when there's no enough address space left to map the shared memory + /// Throw when there's an error while mapping the shared memory /// Throw when the current platform is not supported private MemoryBlock(ulong size, IntPtr sharedMemory) { @@ -82,7 +82,7 @@ namespace Ryujinx.Memory /// /// A new memory block that shares storage with this one /// Throw when the current memory block does not support mirroring - /// Throw when there's no enough address space left to map the shared memory + /// Throw when there's an error while mapping the shared memory /// Throw when the current platform is not supported public MemoryBlock CreateMirror() { diff --git a/src/Ryujinx.Memory/MemoryManagementUnix.cs b/src/Ryujinx.Memory/MemoryManagementUnix.cs index d665b2294..4314c3928 100644 --- a/src/Ryujinx.Memory/MemoryManagementUnix.cs +++ b/src/Ryujinx.Memory/MemoryManagementUnix.cs @@ -147,12 +147,12 @@ namespace Ryujinx.Memory fd = shm_open((IntPtr)pMemName, 0x2 | 0x200 | 0x800 | 0x400, 384); // O_RDWR | O_CREAT | O_EXCL | O_TRUNC, 0600 if (fd == -1) { - throw new OutOfMemoryException(); + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } if (shm_unlink((IntPtr)pMemName) != 0) { - throw new OutOfMemoryException(); + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } } } @@ -165,22 +165,22 @@ namespace Ryujinx.Memory fd = mkstemp((IntPtr)pFileName); if (fd == -1) { - throw new OutOfMemoryException(); + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } if (unlink((IntPtr)pFileName) != 0) { - throw new OutOfMemoryException(); + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } } } if (ftruncate(fd, (IntPtr)size) != 0) { - throw new OutOfMemoryException(); + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } - return (IntPtr)fd; + return fd; } public static void DestroySharedMemory(IntPtr handle) diff --git a/src/Ryujinx.Memory/MemoryManagementWindows.cs b/src/Ryujinx.Memory/MemoryManagementWindows.cs index d7d78bd86..aaed5a637 100644 --- a/src/Ryujinx.Memory/MemoryManagementWindows.cs +++ b/src/Ryujinx.Memory/MemoryManagementWindows.cs @@ -114,7 +114,7 @@ namespace Ryujinx.Memory if (handle == IntPtr.Zero) { - throw new OutOfMemoryException(); + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } return handle; @@ -134,7 +134,7 @@ namespace Ryujinx.Memory if (ptr == IntPtr.Zero) { - throw new OutOfMemoryException(); + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } return ptr;