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
This commit is contained in:
parent
e7fe7d7247
commit
00579927e4
119 changed files with 7998 additions and 3232 deletions
|
@ -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; }
|
||||
}
|
||||
}
|
149
Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs
Normal file
149
Ryujinx.HLE/Loaders/Executables/KernelInitialProcess.cs
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 Nro(Stream Input, string FilePath, long SourceAddress = 0, long BssAddress = 0)
|
||||
public ulong SourceAddress { get; private set; }
|
||||
public ulong BssAddress { get; private set; }
|
||||
|
||||
public NxRelocatableObject(Stream Input, ulong SourceAddress = 0, ulong BssAddress = 0)
|
||||
{
|
||||
this.FilePath = FilePath;
|
||||
this.SourceAddress = SourceAddress;
|
||||
this.BssAddress = BssAddress;
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue