ProcessResult.cs 3.3 KB

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