aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/Loaders/Executable.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2018-08-15 15:59:51 -0300
committerGitHub <noreply@github.com>2018-08-15 15:59:51 -0300
commitc393cdf8e3775bc95850e4d8c8e4c446b286d3b4 (patch)
tree25035a244741d2daf3f7d6be8b23153ff061ea15 /Ryujinx.HLE/Loaders/Executable.cs
parent76d95dee05e3c51c18e1799f54cc407e0f633b4e (diff)
More flexible memory manager (#307)
* Keep track mapped buffers with fixed offsets * Started rewriting the memory manager * Initial support for MapPhysicalMemory and UnmapPhysicalMemory, other tweaks * MapPhysicalMemory/UnmapPhysicalMemory support, other tweaks * Rebased * Optimize the map/unmap physical memory svcs * Integrate shared font support * Fix address space reserve alignment * Some fixes related to gpu memory mapping * Some cleanup * Only try uploading const buffers that are really used * Check if memory region is contiguous * Rebased * Add missing count increment on IsRegionModified * Check for reads/writes outside of the address space, optimize translation with a tail call
Diffstat (limited to 'Ryujinx.HLE/Loaders/Executable.cs')
-rw-r--r--Ryujinx.HLE/Loaders/Executable.cs67
1 files changed, 30 insertions, 37 deletions
diff --git a/Ryujinx.HLE/Loaders/Executable.cs b/Ryujinx.HLE/Loaders/Executable.cs
index 84f5ff39..ba5f8d7e 100644
--- a/Ryujinx.HLE/Loaders/Executable.cs
+++ b/Ryujinx.HLE/Loaders/Executable.cs
@@ -1,6 +1,8 @@
using ChocolArm64.Memory;
using Ryujinx.HLE.Loaders.Executables;
using Ryujinx.HLE.OsHle;
+using Ryujinx.HLE.OsHle.Handles;
+using Ryujinx.HLE.OsHle.Utilities;
using System.Collections.Generic;
using System.IO;
@@ -18,12 +20,14 @@ namespace Ryujinx.HLE.Loaders
public string FilePath { get; private set; }
- private AMemory Memory;
-
public long ImageBase { get; private set; }
public long ImageEnd { get; private set; }
- public Executable(IExecutable Exe, AMemory Memory, long ImageBase)
+ private AMemory Memory;
+
+ private KMemoryManager MemoryManager;
+
+ public Executable(IExecutable Exe, KMemoryManager MemoryManager, AMemory Memory, long ImageBase)
{
Dynamic = new List<ElfDyn>();
@@ -36,23 +40,34 @@ namespace Ryujinx.HLE.Loaders
Name = Path.GetFileNameWithoutExtension(FilePath.Replace(Homebrew.TemporaryNroSuffix, ""));
}
- this.Memory = Memory;
- this.ImageBase = ImageBase;
- this.ImageEnd = ImageBase;
+ this.Memory = Memory;
+ this.MemoryManager = MemoryManager;
+ this.ImageBase = ImageBase;
+ this.ImageEnd = ImageBase;
- WriteData(ImageBase + Exe.TextOffset, Exe.Text, MemoryType.CodeStatic, AMemoryPerm.RX);
- WriteData(ImageBase + Exe.ROOffset, Exe.RO, MemoryType.CodeMutable, AMemoryPerm.Read);
- WriteData(ImageBase + Exe.DataOffset, Exe.Data, MemoryType.CodeMutable, AMemoryPerm.RW);
+ long TextPosition = ImageBase + (uint)Exe.TextOffset;
+ long ROPosition = ImageBase + (uint)Exe.ROOffset;
+ long DataPosition = ImageBase + (uint)Exe.DataOffset;
- if (Exe.Mod0Offset == 0)
- {
- int BssOffset = Exe.DataOffset + Exe.Data.Length;
- int BssSize = Exe.BssSize;
+ long TextSize = (uint)IntUtils.AlignUp(Exe.Text.Length, KMemoryManager.PageSize);
+ long ROSize = (uint)IntUtils.AlignUp(Exe.RO.Length, KMemoryManager.PageSize);
+ long DataSize = (uint)IntUtils.AlignUp(Exe.Data.Length, KMemoryManager.PageSize);
+
+ long DataAndBssSize = (uint)IntUtils.AlignUp(Exe.BssSize, KMemoryManager.PageSize) + DataSize;
+
+ ImageEnd = DataPosition + DataAndBssSize;
- MapBss(ImageBase + BssOffset, BssSize);
+ MemoryManager.HleMapProcessCode(TextPosition, TextSize + ROSize + DataAndBssSize);
- ImageEnd = ImageBase + BssOffset + BssSize;
+ MemoryManager.SetProcessMemoryPermission(ROPosition, ROSize, MemoryPermission.Read);
+ MemoryManager.SetProcessMemoryPermission(DataPosition, DataAndBssSize, MemoryPermission.ReadAndWrite);
+ Memory.WriteBytes(TextPosition, Exe.Text);
+ Memory.WriteBytes(ROPosition, Exe.RO);
+ Memory.WriteBytes(DataPosition, Exe.Data);
+
+ if (Exe.Mod0Offset == 0)
+ {
return;
}
@@ -66,10 +81,6 @@ namespace Ryujinx.HLE.Loaders
long EhHdrEndOffset = Memory.ReadInt32(Mod0Offset + 0x14) + Mod0Offset;
long ModObjOffset = Memory.ReadInt32(Mod0Offset + 0x18) + Mod0Offset;
- MapBss(BssStartOffset, BssEndOffset - BssStartOffset);
-
- ImageEnd = BssEndOffset;
-
while (true)
{
long TagVal = Memory.ReadInt64(DynamicOffset + 0);
@@ -102,24 +113,6 @@ namespace Ryujinx.HLE.Loaders
}
}
- private void WriteData(
- long Position,
- byte[] Data,
- MemoryType Type,
- AMemoryPerm Perm)
- {
- Memory.Manager.Map(Position, Data.Length, (int)Type, AMemoryPerm.Write);
-
- Memory.WriteBytes(Position, Data);
-
- Memory.Manager.Reprotect(Position, Data.Length, Perm);
- }
-
- private void MapBss(long Position, long Size)
- {
- Memory.Manager.Map(Position, Size, (int)MemoryType.Normal, AMemoryPerm.RW);
- }
-
private ElfRel GetRelocation(long Position)
{
long Offset = Memory.ReadInt64(Position + 0);