/ src / Ryujinx.UI.Common / Helper / LinuxHelper.cs
LinuxHelper.cs
 1  using System;
 2  using System.Diagnostics;
 3  using System.IO;
 4  using System.Runtime.Versioning;
 5  
 6  namespace Ryujinx.UI.Common.Helper
 7  {
 8      [SupportedOSPlatform("linux")]
 9      public static class LinuxHelper
10      {
11          // NOTE: This value was determined by manual tests and might need to be increased again.
12          public const int RecommendedVmMaxMapCount = 524288;
13          public const string VmMaxMapCountPath = "/proc/sys/vm/max_map_count";
14          public const string SysCtlConfigPath = "/etc/sysctl.d/99-Ryujinx.conf";
15          public static int VmMaxMapCount => int.Parse(File.ReadAllText(VmMaxMapCountPath));
16          public static string PkExecPath { get; } = GetBinaryPath("pkexec");
17  
18          private static string GetBinaryPath(string binary)
19          {
20              string pathVar = Environment.GetEnvironmentVariable("PATH");
21  
22              if (pathVar is null || string.IsNullOrEmpty(binary))
23              {
24                  return null;
25              }
26  
27              foreach (var searchPath in pathVar.Split(":", StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries))
28              {
29                  string binaryPath = Path.Combine(searchPath, binary);
30  
31                  if (File.Exists(binaryPath))
32                  {
33                      return binaryPath;
34                  }
35              }
36  
37              return null;
38          }
39  
40          public static int RunPkExec(string command)
41          {
42              if (PkExecPath == null)
43              {
44                  return 1;
45              }
46  
47              using Process process = new()
48              {
49                  StartInfo =
50                  {
51                      FileName = PkExecPath,
52                      ArgumentList = { "sh", "-c", command },
53                  },
54              };
55  
56              process.Start();
57              process.WaitForExit();
58  
59              return process.ExitCode;
60          }
61      }
62  }