Android: NCE support

This commit is contained in:
KeatonTheBot
2025-05-26 16:02:20 -05:00
parent 19dd23c288
commit cd3221abdc
35 changed files with 3783 additions and 45 deletions
+26 -10
View File
@@ -5,6 +5,8 @@ namespace Ryujinx.Cpu
{
public class AddressSpace : IDisposable
{
private const MemoryAllocationFlags AsFlags = MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible;
private readonly MemoryBlock _backingMemory;
public MemoryBlock Base { get; }
@@ -25,28 +27,42 @@ namespace Ryujinx.Cpu
{
addressSpace = null;
const MemoryAllocationFlags AsFlags = MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible;
MemoryBlock baseMemory = null;
MemoryBlock mirrorMemory = null;
try
{
baseMemory = new MemoryBlock(asSize, AsFlags);
mirrorMemory = new MemoryBlock(asSize, AsFlags);
addressSpace = new AddressSpace(backingMemory, baseMemory, mirrorMemory, asSize);
}
catch (SystemException)
{
baseMemory?.Dispose();
mirrorMemory?.Dispose();
}
return addressSpace != null;
}
public static bool TryCreateWithoutMirror(ulong asSize, out MemoryBlock addressSpace)
{
addressSpace = null;
ulong minAddressSpaceSize = Math.Min(asSize, 1UL << 36);
// Attempt to create the address space with expected size or try to reduce it until it succeed.
for (ulong addressSpaceSize = asSize; addressSpaceSize >= minAddressSpaceSize; addressSpaceSize >>= 1)
for (ulong addressSpaceSize = asSize; addressSpaceSize >= minAddressSpaceSize; addressSpaceSize -= 0x100000000UL)
{
MemoryBlock baseMemory = null;
MemoryBlock mirrorMemory = null;
try
{
baseMemory = new MemoryBlock(addressSpaceSize, AsFlags);
mirrorMemory = new MemoryBlock(addressSpaceSize, AsFlags);
addressSpace = new AddressSpace(backingMemory, baseMemory, mirrorMemory, addressSpaceSize);
MemoryBlock baseMemory = new MemoryBlock(addressSpaceSize, AsFlags);
addressSpace = baseMemory;
break;
}
catch (SystemException)
{
baseMemory?.Dispose();
mirrorMemory?.Dispose();
}
}