diff options
Diffstat (limited to 'src/Ryujinx.Memory')
| -rw-r--r-- | src/Ryujinx.Memory/MemoryManagementUnix.cs | 29 | ||||
| -rw-r--r-- | src/Ryujinx.Memory/MemoryManagementWindows.cs | 5 | ||||
| -rw-r--r-- | src/Ryujinx.Memory/MemoryManagerUnixHelper.cs | 5 | ||||
| -rw-r--r-- | src/Ryujinx.Memory/MemoryProtectionException.cs | 3 | ||||
| -rw-r--r-- | src/Ryujinx.Memory/WindowsShared/WindowsApi.cs | 2 | ||||
| -rw-r--r-- | src/Ryujinx.Memory/WindowsShared/WindowsApiException.cs | 2 |
6 files changed, 37 insertions, 9 deletions
diff --git a/src/Ryujinx.Memory/MemoryManagementUnix.cs b/src/Ryujinx.Memory/MemoryManagementUnix.cs index affcff92..30baf035 100644 --- a/src/Ryujinx.Memory/MemoryManagementUnix.cs +++ b/src/Ryujinx.Memory/MemoryManagementUnix.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Concurrent; +using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; @@ -53,9 +54,9 @@ namespace Ryujinx.Memory IntPtr ptr = mmap(IntPtr.Zero, size, prot, flags, -1, 0); - if (ptr == new IntPtr(-1L)) + if (ptr == MAP_FAILED) { - throw new OutOfMemoryException(); + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } if (!_allocations.TryAdd(ptr, size)) @@ -76,17 +77,33 @@ namespace Ryujinx.Memory prot |= MmapProts.PROT_EXEC; } - return mprotect(address, size, prot) == 0; + if (mprotect(address, size, prot) != 0) + { + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); + } + + return true; } public static bool Decommit(IntPtr address, ulong size) { // Must be writable for madvise to work properly. - mprotect(address, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE); + if (mprotect(address, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE) != 0) + { + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); + } - madvise(address, size, MADV_REMOVE); + if (madvise(address, size, MADV_REMOVE) != 0) + { + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); + } + + if (mprotect(address, size, MmapProts.PROT_NONE) != 0) + { + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); + } - return mprotect(address, size, MmapProts.PROT_NONE) == 0; + return true; } public static bool Reprotect(IntPtr address, ulong size, MemoryPermission permission) diff --git a/src/Ryujinx.Memory/MemoryManagementWindows.cs b/src/Ryujinx.Memory/MemoryManagementWindows.cs index 2f89a921..cbf3ecba 100644 --- a/src/Ryujinx.Memory/MemoryManagementWindows.cs +++ b/src/Ryujinx.Memory/MemoryManagementWindows.cs @@ -1,5 +1,6 @@ using Ryujinx.Memory.WindowsShared; using System; +using System.Runtime.InteropServices; using System.Runtime.Versioning; namespace Ryujinx.Memory @@ -36,7 +37,7 @@ namespace Ryujinx.Memory if (ptr == IntPtr.Zero) { - throw new OutOfMemoryException(); + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } return ptr; @@ -48,7 +49,7 @@ namespace Ryujinx.Memory if (ptr == IntPtr.Zero) { - throw new OutOfMemoryException(); + throw new SystemException(Marshal.GetLastPInvokeErrorMessage()); } return ptr; diff --git a/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs b/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs index 204f1ca4..a7b207ab 100644 --- a/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs +++ b/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs @@ -1,8 +1,11 @@ using System; using System.Runtime.InteropServices; +using System.Runtime.Versioning; namespace Ryujinx.Memory { + [SupportedOSPlatform("linux")] + [SupportedOSPlatform("macos")] public static partial class MemoryManagerUnixHelper { [Flags] @@ -41,6 +44,8 @@ namespace Ryujinx.Memory O_SYNC = 256, } + public const IntPtr MAP_FAILED = -1; + private const int MAP_ANONYMOUS_LINUX_GENERIC = 0x20; private const int MAP_NORESERVE_LINUX_GENERIC = 0x4000; private const int MAP_UNLOCKED_LINUX_GENERIC = 0x80000; diff --git a/src/Ryujinx.Memory/MemoryProtectionException.cs b/src/Ryujinx.Memory/MemoryProtectionException.cs index 27e950a1..e5606e99 100644 --- a/src/Ryujinx.Memory/MemoryProtectionException.cs +++ b/src/Ryujinx.Memory/MemoryProtectionException.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.InteropServices; namespace Ryujinx.Memory { @@ -8,7 +9,7 @@ namespace Ryujinx.Memory { } - public MemoryProtectionException(MemoryPermission permission) : base($"Failed to set memory protection to \"{permission}\".") + public MemoryProtectionException(MemoryPermission permission) : base($"Failed to set memory protection to \"{permission}\": {Marshal.GetLastPInvokeErrorMessage()}") { } diff --git a/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs b/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs index 67e704ea..c554e320 100644 --- a/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs +++ b/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs @@ -1,8 +1,10 @@ using System; using System.Runtime.InteropServices; +using System.Runtime.Versioning; namespace Ryujinx.Memory.WindowsShared { + [SupportedOSPlatform("windows")] static partial class WindowsApi { public static readonly IntPtr InvalidHandleValue = new IntPtr(-1); diff --git a/src/Ryujinx.Memory/WindowsShared/WindowsApiException.cs b/src/Ryujinx.Memory/WindowsShared/WindowsApiException.cs index 3140d705..330c1842 100644 --- a/src/Ryujinx.Memory/WindowsShared/WindowsApiException.cs +++ b/src/Ryujinx.Memory/WindowsShared/WindowsApiException.cs @@ -1,7 +1,9 @@ using System; +using System.Runtime.Versioning; namespace Ryujinx.Memory.WindowsShared { + [SupportedOSPlatform("windows")] class WindowsApiException : Exception { public WindowsApiException() |
