ProcessResult.cs 3.6 KB

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