diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2018-11-28 20:18:09 -0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-28 20:18:09 -0200 |
| commit | 00579927e43bf55ee06ae02933c1e755fb4120eb (patch) | |
| tree | 0fd06db7b28e0accf87b465ec6f4dc74691febab /Ryujinx.HLE/Loaders/Executables | |
| parent | e7fe7d724778535f8eff390abef54274a343c0b7 (diff) | |
Better process implementation (#491)
* Initial implementation of KProcess
* Some improvements to the memory manager, implement back guest stack trace printing
* Better GetInfo implementation, improve checking in some places with information from process capabilities
* Allow the cpu to read/write from the correct memory locations for accesses crossing a page boundary
* Change long -> ulong for address/size on memory related methods to avoid unnecessary casts
* Attempt at implementing ldr:ro with new KProcess
* Allow BSS with size 0 on ldr:ro
* Add checking for memory block slab heap usage, return errors if full, exit gracefully
* Use KMemoryBlockSize const from KMemoryManager
* Allow all methods to read from non-contiguous locations
* Fix for TransactParcelAuto
* Address PR feedback, additionally fix some small issues related to the KIP loader and implement SVCs GetProcessId, GetProcessList, GetSystemInfo, CreatePort and ManageNamedPort
* Fix wrong check for source pages count from page list on MapPhysicalMemory
* Fix some issues with UnloadNro on ldr:ro
Diffstat (limited to 'Ryujinx.HLE/Loaders/Executables')
| -rw-r--r-- | Ryujinx.HLE/Loaders/Executables/IExecutable.cs | 9 | ||||
| -rw-r--r-- | Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs | 149 | ||||
| -rw-r--r-- | Ryujinx.HLE/Loaders/Executables/NxRelocatableObject.cs (renamed from Ryujinx.HLE/Loaders/Executables/Nro.cs) | 13 | ||||
| -rw-r--r-- | Ryujinx.HLE/Loaders/Executables/NxStaticObject.cs (renamed from Ryujinx.HLE/Loaders/Executables/Nso.cs) | 30 |
4 files changed, 163 insertions, 38 deletions
diff --git a/Ryujinx.HLE/Loaders/Executables/IExecutable.cs b/Ryujinx.HLE/Loaders/Executables/IExecutable.cs index 6f0952ab..d3eefde6 100644 --- a/Ryujinx.HLE/Loaders/Executables/IExecutable.cs +++ b/Ryujinx.HLE/Loaders/Executables/IExecutable.cs @@ -1,20 +1,15 @@ namespace Ryujinx.HLE.Loaders.Executables { - public interface IExecutable + interface IExecutable { - string FilePath { get; } - byte[] Text { get; } byte[] RO { get; } byte[] Data { get; } - long SourceAddress { get; } - long BssAddress { get; } - - int Mod0Offset { get; } int TextOffset { get; } int ROOffset { get; } int DataOffset { get; } + int BssOffset { get; } int BssSize { get; } } }
\ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs b/Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs new file mode 100644 index 00000000..1395d56f --- /dev/null +++ b/Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs @@ -0,0 +1,149 @@ +using Ryujinx.HLE.Loaders.Compression; +using System.IO; + +namespace Ryujinx.HLE.Loaders.Executables +{ + class KernelInitialProcess : IExecutable + { + public string Name { get; private set; } + + public long TitleId { get; private set; } + + public int ProcessCategory { get; private set; } + + public byte MainThreadPriority { get; private set; } + public byte DefaultProcessorId { get; private set; } + + public bool Is64Bits { get; private set; } + public bool Addr39Bits { get; private set; } + public bool IsService { get; private set; } + + public byte[] Text { get; private set; } + public byte[] RO { get; private set; } + public byte[] Data { get; private set; } + + public int TextOffset { get; private set; } + public int ROOffset { get; private set; } + public int DataOffset { get; private set; } + public int BssOffset { get; private set; } + public int BssSize { get; private set; } + + public int MainThreadStackSize { get; private set; } + + public int[] Capabilities { get; private set; } + + private struct SegmentHeader + { + public int Offset { get; private set; } + public int DecompressedSize { get; private set; } + public int CompressedSize { get; private set; } + public int Attribute { get; private set; } + + public SegmentHeader( + int Offset, + int DecompressedSize, + int CompressedSize, + int Attribute) + { + this.Offset = Offset; + this.DecompressedSize = DecompressedSize; + this.CompressedSize = CompressedSize; + this.Attribute = Attribute; + } + } + + public KernelInitialProcess(Stream Input) + { + BinaryReader Reader = new BinaryReader(Input); + + string Magic = ReadString(Reader, 4); + + if (Magic != "KIP1") + { + + } + + Name = ReadString(Reader, 12); + + TitleId = Reader.ReadInt64(); + + ProcessCategory = Reader.ReadInt32(); + + MainThreadPriority = Reader.ReadByte(); + DefaultProcessorId = Reader.ReadByte(); + + byte Reserved = Reader.ReadByte(); + byte Flags = Reader.ReadByte(); + + Is64Bits = (Flags & 0x08) != 0; + Addr39Bits = (Flags & 0x10) != 0; + IsService = (Flags & 0x20) != 0; + + SegmentHeader[] Segments = new SegmentHeader[6]; + + for (int Index = 0; Index < Segments.Length; Index++) + { + Segments[Index] = new SegmentHeader( + Reader.ReadInt32(), + Reader.ReadInt32(), + Reader.ReadInt32(), + Reader.ReadInt32()); + } + + TextOffset = Segments[0].Offset; + ROOffset = Segments[1].Offset; + DataOffset = Segments[2].Offset; + BssOffset = Segments[3].Offset; + BssSize = Segments[3].DecompressedSize; + + MainThreadStackSize = Segments[1].Attribute; + + Capabilities = new int[8]; + + for (int Index = 0; Index < Capabilities.Length; Index++) + { + Capabilities[Index] = Reader.ReadInt32(); + } + + Input.Seek(0x100, SeekOrigin.Begin); + + Text = ReadSegment(Segments[0], Input); + RO = ReadSegment(Segments[1], Input); + Data = ReadSegment(Segments[2], Input); + } + + private byte[] ReadSegment(SegmentHeader Header, Stream Input) + { + long End = Input.Position + Header.CompressedSize; + + Input.Seek(End, SeekOrigin.Begin); + + byte[] Data = BackwardsLz.Decompress(Input, Header.DecompressedSize); + + Input.Seek(End, SeekOrigin.Begin); + + return Data; + } + + private static string ReadString(BinaryReader Reader, int MaxSize) + { + string Value = string.Empty; + + for (int Index = 0; Index < MaxSize; Index++) + { + char Chr = (char)Reader.ReadByte(); + + if (Chr == '\0') + { + Reader.BaseStream.Seek(MaxSize - Index - 1, SeekOrigin.Current); + + break; + } + + Value += Chr; + } + + return Value; + } + } +}
\ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Executables/Nro.cs b/Ryujinx.HLE/Loaders/Executables/NxRelocatableObject.cs index 6015da21..20de5b5d 100644 --- a/Ryujinx.HLE/Loaders/Executables/Nro.cs +++ b/Ryujinx.HLE/Loaders/Executables/NxRelocatableObject.cs @@ -2,10 +2,8 @@ using System.IO; namespace Ryujinx.HLE.Loaders.Executables { - class Nro : IExecutable + class NxRelocatableObject : IExecutable { - public string FilePath { get; private set; } - public byte[] Text { get; private set; } public byte[] RO { get; private set; } public byte[] Data { get; private set; } @@ -16,12 +14,13 @@ namespace Ryujinx.HLE.Loaders.Executables public int DataOffset { get; private set; } public int BssSize { get; private set; } - public long SourceAddress { get; private set; } - public long BssAddress { get; private set; } + public int BssOffset => DataOffset + Data.Length; + + public ulong SourceAddress { get; private set; } + public ulong BssAddress { get; private set; } - public Nro(Stream Input, string FilePath, long SourceAddress = 0, long BssAddress = 0) + public NxRelocatableObject(Stream Input, ulong SourceAddress = 0, ulong BssAddress = 0) { - this.FilePath = FilePath; this.SourceAddress = SourceAddress; this.BssAddress = BssAddress; diff --git a/Ryujinx.HLE/Loaders/Executables/Nso.cs b/Ryujinx.HLE/Loaders/Executables/NxStaticObject.cs index c7b48a5f..9fecb650 100644 --- a/Ryujinx.HLE/Loaders/Executables/Nso.cs +++ b/Ryujinx.HLE/Loaders/Executables/NxStaticObject.cs @@ -4,22 +4,18 @@ using System.IO; namespace Ryujinx.HLE.Loaders.Executables { - class Nso : IExecutable + class NxStaticObject : IExecutable { - public string FilePath { get; private set; } - public byte[] Text { get; private set; } public byte[] RO { get; private set; } public byte[] Data { get; private set; } - public int Mod0Offset { get; private set; } public int TextOffset { get; private set; } public int ROOffset { get; private set; } public int DataOffset { get; private set; } public int BssSize { get; private set; } - public long SourceAddress { get; private set; } - public long BssAddress { get; private set; } + public int BssOffset => DataOffset + Data.Length; [Flags] private enum NsoFlags @@ -32,13 +28,8 @@ namespace Ryujinx.HLE.Loaders.Executables HasDataHash = 1 << 5 } - public Nso(Stream Input, string FilePath) + public NxStaticObject(Stream Input) { - this.FilePath = FilePath; - - SourceAddress = 0; - BssAddress = 0; - BinaryReader Reader = new BinaryReader(Input); Input.Seek(0, SeekOrigin.Begin); @@ -89,7 +80,7 @@ namespace Ryujinx.HLE.Loaders.Executables Text = Reader.ReadBytes(TextSize); - if (Flags.HasFlag(NsoFlags.IsTextCompressed) || true) + if (Flags.HasFlag(NsoFlags.IsTextCompressed)) { Text = Lz4.Decompress(Text, TextDecSize); } @@ -99,7 +90,7 @@ namespace Ryujinx.HLE.Loaders.Executables RO = Reader.ReadBytes(ROSize); - if (Flags.HasFlag(NsoFlags.IsROCompressed) || true) + if (Flags.HasFlag(NsoFlags.IsROCompressed)) { RO = Lz4.Decompress(RO, RODecSize); } @@ -109,19 +100,10 @@ namespace Ryujinx.HLE.Loaders.Executables Data = Reader.ReadBytes(DataSize); - if (Flags.HasFlag(NsoFlags.IsDataCompressed) || true) + if (Flags.HasFlag(NsoFlags.IsDataCompressed)) { Data = Lz4.Decompress(Data, DataDecSize); } - - using (MemoryStream TextMS = new MemoryStream(Text)) - { - BinaryReader TextReader = new BinaryReader(TextMS); - - TextMS.Seek(4, SeekOrigin.Begin); - - Mod0Offset = TextReader.ReadInt32(); - } } } }
\ No newline at end of file |
