From dc144d2e190e03729b16e402da9c36eec5aaf53f Mon Sep 17 00:00:00 2001 From: Elise Date: Wed, 8 Apr 2020 00:41:02 +0200 Subject: Use libhac for loading NSO and KIP (#1047) * Use libhac for loading NSOs and KIPs * Fix formatting * Refactor KIP and NSO executables for libhac * Fix up formatting * Remove Ryujinx.HLE.Loaders.Compression * Remove reference to Ryujinx.HLE.Loaders.Compression in NxStaticObject.cs * Remove reference to Ryujinx.HLE.Loaders.Compression in KernelInitialProcess.cs * Rename classes in Ryujinx.HLE.Loaders.Executables * Fix space alignment * Fix up formatting --- Ryujinx.HLE/HOS/Horizon.cs | 18 +++++++++--------- Ryujinx.HLE/HOS/ProgramLoader.cs | 23 ++++++++++++----------- Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs | 2 +- Ryujinx.HLE/HOS/Services/Ro/Types/NroInfo.cs | 4 ++-- 4 files changed, 24 insertions(+), 23 deletions(-) (limited to 'Ryujinx.HLE/HOS') diff --git a/Ryujinx.HLE/HOS/Horizon.cs b/Ryujinx.HLE/HOS/Horizon.cs index ee8c2a20..302ee100 100644 --- a/Ryujinx.HLE/HOS/Horizon.cs +++ b/Ryujinx.HLE/HOS/Horizon.cs @@ -32,7 +32,7 @@ using System.Reflection; using System.Threading; using TimeServiceManager = Ryujinx.HLE.HOS.Services.Time.TimeManager; -using NxStaticObject = Ryujinx.HLE.Loaders.Executables.NxStaticObject; +using NsoExecutable = Ryujinx.HLE.Loaders.Executables.NsoExecutable; using static LibHac.Fs.ApplicationSaveDataManagement; @@ -271,9 +271,9 @@ namespace Ryujinx.HLE.HOS public void LoadKip(string kipFile) { - using (FileStream fs = new FileStream(kipFile, FileMode.Open)) + using (IStorage fs = new LocalStorage(kipFile, FileAccess.Read)) { - ProgramLoader.LoadKernelInitalProcess(this, new KernelInitialProcess(fs)); + ProgramLoader.LoadKernelInitalProcess(this, new KipExecutable(fs)); } } @@ -543,9 +543,9 @@ namespace Ryujinx.HLE.HOS Logger.PrintInfo(LogClass.Loader, $"Loading {file.Name}..."); - codeFs.OpenFile(out IFile nsoFile, file.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure(); - - NxStaticObject staticObject = new NxStaticObject(nsoFile.AsStream()); + codeFs.OpenFile(out IFile nsoFile, file.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure(); + + NsoExecutable staticObject = new NsoExecutable(nsoFile.AsStorage()); staticObjects.Add(staticObject); } @@ -569,13 +569,13 @@ namespace Ryujinx.HLE.HOS bool isNro = Path.GetExtension(filePath).ToLower() == ".nro"; - FileStream input = new FileStream(filePath, FileMode.Open); IExecutable staticObject; if (isNro) { - NxRelocatableObject obj = new NxRelocatableObject(input); + FileStream input = new FileStream(filePath, FileMode.Open); + NroExecutable obj = new NroExecutable(input); staticObject = obj; // homebrew NRO can actually have some data after the actual NRO @@ -648,7 +648,7 @@ namespace Ryujinx.HLE.HOS } else { - staticObject = new NxStaticObject(input); + staticObject = new NsoExecutable(new LocalStorage(filePath, FileAccess.Read)); } ContentManager.LoadEntries(Device); diff --git a/Ryujinx.HLE/HOS/ProgramLoader.cs b/Ryujinx.HLE/HOS/ProgramLoader.cs index 19c77380..d6f3d1d3 100644 --- a/Ryujinx.HLE/HOS/ProgramLoader.cs +++ b/Ryujinx.HLE/HOS/ProgramLoader.cs @@ -1,4 +1,5 @@ using ARMeilleure.Memory; +using LibHac; using Ryujinx.Common; using Ryujinx.Common.Logging; using Ryujinx.HLE.HOS.Kernel.Common; @@ -17,7 +18,7 @@ namespace Ryujinx.HLE.HOS private const int ArgsDataSize = 0x9000; private const int ArgsTotalSize = ArgsHeaderSize + ArgsDataSize; - public static bool LoadKernelInitalProcess(Horizon system, KernelInitialProcess kip) + public static bool LoadKernelInitalProcess(Horizon system, KipExecutable kip) { int endOffset = kip.DataOffset + kip.Data.Length; @@ -30,7 +31,7 @@ namespace Ryujinx.HLE.HOS int codePagesCount = codeSize / KMemoryManager.PageSize; - ulong codeBaseAddress = kip.Addr39Bits ? 0x8000000UL : 0x200000UL; + ulong codeBaseAddress = (kip.Header.Flags & 0x10) != 0 ? 0x8000000UL : 0x200000UL; ulong codeAddress = codeBaseAddress + (ulong)kip.TextOffset; @@ -43,27 +44,27 @@ namespace Ryujinx.HLE.HOS mmuFlags |= 0x20; } - if (kip.Addr39Bits) + if ((kip.Header.Flags & 0x10) != 0) { mmuFlags |= (int)AddressSpaceType.Addr39Bits << 1; } - if (kip.Is64Bits) + if ((kip.Header.Flags & 0x08) != 0) { mmuFlags |= 1; } ProcessCreationInfo creationInfo = new ProcessCreationInfo( - kip.Name, - kip.ProcessCategory, - kip.TitleId, + kip.Header.Name, + kip.Header.ProcessCategory, + kip.Header.TitleId, codeAddress, codePagesCount, mmuFlags, 0, 0); - MemoryRegion memoryRegion = kip.IsService + MemoryRegion memoryRegion = (kip.Header.Flags & 0x20) != 0 ? MemoryRegion.Service : MemoryRegion.Application; @@ -103,9 +104,9 @@ namespace Ryujinx.HLE.HOS return false; } - process.DefaultCpuCore = kip.DefaultProcessorId; + process.DefaultCpuCore = kip.Header.DefaultCore; - result = process.Start(kip.MainThreadPriority, (ulong)kip.MainThreadStackSize); + result = process.Start(kip.Header.MainThreadPriority, (ulong)kip.Header.Sections[1].Attribute); if (result != KernelResult.Success) { @@ -309,4 +310,4 @@ namespace Ryujinx.HLE.HOS return SetProcessMemoryPermission(dataStart, end - dataStart, MemoryPermission.ReadAndWrite); } } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs index d2eb3873..e8bebb8a 100644 --- a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs +++ b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs @@ -157,7 +157,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro stream.Position = 0; - NxRelocatableObject executable = new NxRelocatableObject(stream, nroAddress, bssAddress); + NroExecutable executable = new NroExecutable(stream, nroAddress, bssAddress); // check if everything is page align. if ((executable.Text.Length & 0xFFF) != 0 || (executable.Ro.Length & 0xFFF) != 0 || diff --git a/Ryujinx.HLE/HOS/Services/Ro/Types/NroInfo.cs b/Ryujinx.HLE/HOS/Services/Ro/Types/NroInfo.cs index a0911627..45daf1bd 100644 --- a/Ryujinx.HLE/HOS/Services/Ro/Types/NroInfo.cs +++ b/Ryujinx.HLE/HOS/Services/Ro/Types/NroInfo.cs @@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro { class NroInfo { - public NxRelocatableObject Executable { get; private set; } + public NroExecutable Executable { get; private set; } public byte[] Hash { get; private set; } public ulong NroAddress { get; private set; } @@ -15,7 +15,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro public ulong NroMappedAddress { get; set; } public NroInfo( - NxRelocatableObject executable, + NroExecutable executable, byte[] hash, ulong nroAddress, ulong nroSize, -- cgit v1.2.3