diff options
author | TSRBerry <20988865+TSRBerry@users.noreply.github.com> | 2023-05-30 01:48:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-30 01:48:37 +0200 |
commit | 35d91a0e58cb0b2916b7a4f138c63fcc12b71112 (patch) | |
tree | 4735140e36567ddaefb9089e9a0d5685b5f9079f /src/Ryujinx.Memory/MemoryManagementUnix.cs | |
parent | a73a5d7e85e4008a7d8c7eb8abd6bae80b950bba (diff) |
Linux: Automatically increase vm.max_map_count if it's too low (#4702)1.1.842
* memory: Check results of pinvoke calls
* Increase vm.max_map_count when running Ryujinx
* Add SupportedOSPlatform attribute for WindowsApiException
* Revert increasing vm.max_map_count via script
* Add LinuxHelper to detect and increase vm.max_map_count
With GUI dialogs, this should be a bit more user-friendly.
* Supply arguments as a list to RunPkExec
* Add error logging in case RunPkExec() fails
* Prevent Gtk from crashing
Diffstat (limited to 'src/Ryujinx.Memory/MemoryManagementUnix.cs')
-rw-r--r-- | src/Ryujinx.Memory/MemoryManagementUnix.cs | 29 |
1 files changed, 23 insertions, 6 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) |