diff --git a/src/Ryujinx.Common/Utilities/OsUtils.cs b/src/Ryujinx.Common/Utilities/OsUtils.cs index a0791b092..29c6e187c 100644 --- a/src/Ryujinx.Common/Utilities/OsUtils.cs +++ b/src/Ryujinx.Common/Utilities/OsUtils.cs @@ -20,5 +20,21 @@ namespace Ryujinx.Common.Utilities Debug.Assert(res != -1); } } + + // "dumpable" attribute of the calling process + private const int PR_SET_DUMPABLE = 4; + + [DllImport("libc", SetLastError = true)] + private static extern int prctl(int option, int arg2); + + public static void SetCoreDumpable(bool dumpable) + { + if (OperatingSystem.IsLinux()) + { + int dumpableInt = dumpable ? 1 : 0; + int result = prctl(PR_SET_DUMPABLE, dumpableInt); + Debug.Assert(result == 0); + } + } } } diff --git a/src/Ryujinx/Program.cs b/src/Ryujinx/Program.cs index d9a85e3b0..0a6513190 100644 --- a/src/Ryujinx/Program.cs +++ b/src/Ryujinx/Program.cs @@ -7,6 +7,7 @@ using Ryujinx.Common.Configuration; using Ryujinx.Common.GraphicsDriver; using Ryujinx.Common.Logging; using Ryujinx.Common.SystemInterop; +using Ryujinx.Common.Utilities; using Ryujinx.Graphics.Vulkan.MoltenVK; using Ryujinx.Headless; using Ryujinx.Modules; @@ -16,6 +17,7 @@ using Ryujinx.UI.Common.Configuration; using Ryujinx.UI.Common.Helper; using Ryujinx.UI.Common.SystemInfo; using System; +using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; @@ -46,11 +48,23 @@ namespace Ryujinx.Ava _ = MessageBoxA(nint.Zero, "You are running an outdated version of Windows.\n\nRyujinx supports Windows 10 version 20H1 and newer.\n", $"Ryujinx {Version}", MbIconwarning); } + bool noGuiArg = ConsumeCommandLineArgument(ref args, "--no-gui") || ConsumeCommandLineArgument(ref args, "nogui"); + bool coreDumpArg = ConsumeCommandLineArgument(ref args, "--core-dumps"); + + // TODO: Ryujinx causes core dumps on Linux when it exits "uncleanly", eg. through an unhandled exception. + // This is undesirable and causes very odd behavior during development (the process stops responding, + // the .NET debugger freezes or suddenly detaches, /tmp/ gets filled etc.), unless explicitly requested by the user. + // This needs to be investigated, but calling prctl() is better than modifying system-wide settings or leaving this be. + if (!coreDumpArg) + { + OsUtils.SetCoreDumpable(false); + } + PreviewerDetached = true; - if (args.Length > 0 && args[0] is "--no-gui" or "nogui") + if (noGuiArg) { - HeadlessRyujinx.Entrypoint(args[1..]); + HeadlessRyujinx.Entrypoint(args); return; } @@ -84,6 +98,14 @@ namespace Ryujinx.Ava .UseSkia(); } + private static bool ConsumeCommandLineArgument(ref string[] args, string targetArgument) + { + List argList = [.. args]; + bool found = argList.Remove(targetArgument); + args = argList.ToArray(); + return found; + } + private static void Initialize(string[] args) { // Parse arguments