ProcessResult.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using LibHac.Loader;
  2. using LibHac.Ns;
  3. using Ryujinx.Common.Logging;
  4. using Ryujinx.Cpu;
  5. using Ryujinx.HLE.HOS.SystemState;
  6. using Ryujinx.HLE.Loaders.Processes.Extensions;
  7. using Ryujinx.Horizon.Common;
  8. namespace Ryujinx.HLE.Loaders.Processes
  9. {
  10. public struct ProcessResult
  11. {
  12. public static ProcessResult Failed => new(null, new ApplicationControlProperty(), false, false, null, 0, 0, 0, TitleLanguage.AmericanEnglish);
  13. private readonly byte _mainThreadPriority;
  14. private readonly uint _mainThreadStackSize;
  15. public readonly IDiskCacheLoadState DiskCacheLoadState;
  16. public readonly MetaLoader MetaLoader;
  17. public readonly ApplicationControlProperty ApplicationControlProperties;
  18. public readonly ulong ProcessId;
  19. public string Name;
  20. public ulong ProgramId;
  21. public readonly string ProgramIdText;
  22. public readonly bool Is64Bit;
  23. public readonly bool DiskCacheEnabled;
  24. public readonly bool AllowCodeMemoryForJit;
  25. public ProcessResult(
  26. MetaLoader metaLoader,
  27. ApplicationControlProperty applicationControlProperties,
  28. bool diskCacheEnabled,
  29. bool allowCodeMemoryForJit,
  30. IDiskCacheLoadState diskCacheLoadState,
  31. ulong pid,
  32. byte mainThreadPriority,
  33. uint mainThreadStackSize,
  34. TitleLanguage titleLanguage)
  35. {
  36. _mainThreadPriority = mainThreadPriority;
  37. _mainThreadStackSize = mainThreadStackSize;
  38. DiskCacheLoadState = diskCacheLoadState;
  39. ProcessId = pid;
  40. MetaLoader = metaLoader;
  41. ApplicationControlProperties = applicationControlProperties;
  42. if (metaLoader is not null)
  43. {
  44. ulong programId = metaLoader.GetProgramId();
  45. if (ApplicationControlProperties.Title.ItemsRo.Length > 0)
  46. {
  47. var langIndex = ApplicationControlProperties.Title.ItemsRo.Length > (int)titleLanguage ? (int)titleLanguage : 0;
  48. Name = ApplicationControlProperties.Title[langIndex].NameString.ToString();
  49. }
  50. else
  51. {
  52. Name = metaLoader.GetProgramName();
  53. }
  54. ProgramId = programId;
  55. ProgramIdText = $"{programId:x16}";
  56. Is64Bit = metaLoader.IsProgram64Bit();
  57. }
  58. DiskCacheEnabled = diskCacheEnabled;
  59. AllowCodeMemoryForJit = allowCodeMemoryForJit;
  60. }
  61. public bool Start(Switch device)
  62. {
  63. device.Configuration.ContentManager.LoadEntries(device);
  64. Result result = device.System.KernelContext.Processes[ProcessId].Start(_mainThreadPriority, _mainThreadStackSize);
  65. if (result != Result.Success)
  66. {
  67. Logger.Error?.Print(LogClass.Loader, $"Process start returned error \"{result}\".");
  68. return false;
  69. }
  70. // TODO: LibHac npdm currently doesn't support version field.
  71. string version;
  72. if (ProgramId > 0x0100000000007FFF)
  73. {
  74. version = ApplicationControlProperties.DisplayVersionString.ToString();
  75. }
  76. else
  77. {
  78. version = device.System.ContentManager.GetCurrentFirmwareVersion().VersionString;
  79. }
  80. Logger.Info?.Print(LogClass.Loader, $"Application Loaded: {Name} v{version} [{ProgramIdText}] [{(Is64Bit ? "64-bit" : "32-bit")}]");
  81. return true;
  82. }
  83. }
  84. }