Revert Android changes

* "Android: NCE support" - Commit cd3221ab

* "Android: Numerous fixes" - Commit 19dd23c2

* "Android: Memory specific switches" - Commit 98b4ff33

* "Android: Remove unmanaged code" - Commit 846b5b6e
This commit is contained in:
KeatonTheBot
2025-09-14 14:51:44 -05:00
parent 3a387309b4
commit fe7a30c747
62 changed files with 138 additions and 5440 deletions
+2 -5
View File
@@ -24,8 +24,6 @@ namespace Ryujinx.HLE.HOS
private readonly ICpuContext _cpuContext;
private T _memoryManager;
public ulong ReservedSize { get; }
public IVirtualMemoryManager AddressSpace => _memoryManager;
public ulong AddressSpaceSize { get; }
@@ -36,8 +34,7 @@ namespace Ryujinx.HLE.HOS
GpuContext gpuContext,
T memoryManager,
ulong addressSpaceSize,
bool for64Bit,
ulong reservedSize = 0UL)
bool for64Bit)
{
if (memoryManager is IRefCounted rc)
{
@@ -50,8 +47,8 @@ namespace Ryujinx.HLE.HOS
_gpuContext = gpuContext;
_cpuContext = cpuEngine.CreateCpuContext(memoryManager, for64Bit);
_memoryManager = memoryManager;
AddressSpaceSize = addressSpaceSize;
ReservedSize = reservedSize;
}
public IExecutionContext CreateExecutionContext(ExceptionCallbacks exceptionCallbacks)
+15 -56
View File
@@ -4,7 +4,6 @@ using Ryujinx.Cpu;
using Ryujinx.Cpu.AppleHv;
using Ryujinx.Cpu.Jit;
using Ryujinx.Cpu.LightningJit;
using Ryujinx.Cpu.Nce;
using Ryujinx.Graphics.Gpu;
using Ryujinx.HLE.HOS.Kernel;
using Ryujinx.HLE.HOS.Kernel.Process;
@@ -47,43 +46,17 @@ namespace Ryujinx.HLE.HOS
_codeSize = codeSize;
}
public static NceCpuCodePatch CreateCodePatchForNce(KernelContext context, bool for64Bit, ReadOnlySpan<byte> textSection)
{
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64 && for64Bit && context.Device.Configuration.UseHypervisor && !OperatingSystem.IsMacOS())
{
return NcePatcher.CreatePatch(textSection);
}
return null;
}
public IProcessContext Create(KernelContext context, ulong pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit)
{
IArmProcessContext processContext;
bool isArm64Host = RuntimeInformation.ProcessArchitecture == Architecture.Arm64;
if (isArm64Host && for64Bit && context.Device.Configuration.UseHypervisor)
if (OperatingSystem.IsMacOS() && isArm64Host && for64Bit && context.Device.Configuration.UseHypervisor)
{
if (OperatingSystem.IsMacOS())
{
var cpuEngine = new HvEngine(_tickSource);
var memoryManager = new HvMemoryManager(context.Memory, addressSpaceSize, invalidAccessHandler);
processContext = new ArmProcessContext<HvMemoryManager>(pid, cpuEngine, _gpu, memoryManager, addressSpaceSize, for64Bit);
}
else
{
if (!AddressSpace.TryCreateWithoutMirror(addressSpaceSize, out var addressSpace))
{
throw new Exception("Address space creation failed");
}
Logger.Info?.Print(LogClass.Cpu, $"NCE Base AS Address: 0x{addressSpace.Pointer.ToInt64():X} Size: 0x{addressSpace.Size:X}");
var cpuEngine = new NceEngine(_tickSource);
var memoryManager = new MemoryManagerNative(addressSpace, context.Memory, addressSpaceSize, invalidAccessHandler);
processContext = new ArmProcessContext<MemoryManagerNative>(pid, cpuEngine, _gpu, memoryManager, addressSpace.Size, for64Bit, memoryManager.ReservedSize);
}
var cpuEngine = new HvEngine(_tickSource);
var memoryManager = new HvMemoryManager(context.Memory, addressSpaceSize, invalidAccessHandler);
processContext = new ArmProcessContext<HvMemoryManager>(pid, cpuEngine, _gpu, memoryManager, addressSpaceSize, for64Bit);
}
else
{
@@ -101,13 +74,11 @@ namespace Ryujinx.HLE.HOS
: new JitEngine(_tickSource);
AddressSpace addressSpace = null;
MemoryBlock asNoMirror = null;
// We want to use host tracked mode if the host page size is > 4KB.
if ((mode == MemoryManagerMode.HostMapped || mode == MemoryManagerMode.HostMappedUnsafe) && MemoryBlock.GetPageSize() <= 0x1000)
{
if (!AddressSpace.TryCreate(context.Memory, addressSpaceSize, out addressSpace) &&
!AddressSpace.TryCreateWithoutMirror(addressSpaceSize, out asNoMirror))
if (!AddressSpace.TryCreate(context.Memory, addressSpaceSize, out addressSpace))
{
Logger.Warning?.Print(LogClass.Cpu, "Address space creation failed, falling back to software page table");
@@ -118,47 +89,35 @@ namespace Ryujinx.HLE.HOS
switch (mode)
{
case MemoryManagerMode.SoftwarePageTable:
{
var mm = new MemoryManager(context.Memory, addressSpaceSize, invalidAccessHandler);
processContext = new ArmProcessContext<MemoryManager>(pid, cpuEngine, _gpu, mm, addressSpaceSize, for64Bit);
}
var memoryManager = new MemoryManager(context.Memory, addressSpaceSize, invalidAccessHandler);
processContext = new ArmProcessContext<MemoryManager>(pid, cpuEngine, _gpu, memoryManager, addressSpaceSize, for64Bit);
break;
case MemoryManagerMode.HostMapped:
case MemoryManagerMode.HostMappedUnsafe:
if (addressSpace == null && asNoMirror == null)
if (addressSpace == null)
{
var memoryManagerHostTracked = new MemoryManagerHostTracked(context.Memory, addressSpaceSize, mode == MemoryManagerMode.HostMappedUnsafe, invalidAccessHandler);
processContext = new ArmProcessContext<MemoryManagerHostTracked>(pid, cpuEngine, _gpu, memoryManagerHostTracked, addressSpaceSize, for64Bit);
}
else
{
bool unsafeMode = mode == MemoryManagerMode.HostMappedUnsafe;
if (addressSpaceSize != addressSpace.AddressSpaceSize)
{
Logger.Warning?.Print(LogClass.Emulation, $"Allocated address space (0x{addressSpace.AddressSpaceSize:X}) is smaller than guest application requirements (0x{addressSpaceSize:X})");
}
if (addressSpace != null)
{
var mm = new MemoryManagerHostMapped(addressSpace, unsafeMode, invalidAccessHandler);
processContext = new ArmProcessContext<MemoryManagerHostMapped>(pid, cpuEngine, _gpu, mm, addressSpace.AddressSpaceSize, for64Bit);
}
else
{
var mm = new MemoryManagerHostNoMirror(asNoMirror, context.Memory, unsafeMode, invalidAccessHandler);
processContext = new ArmProcessContext<MemoryManagerHostNoMirror>(pid, cpuEngine, _gpu, mm, asNoMirror.Size, for64Bit);
}
var memoryManagerHostMapped = new MemoryManagerHostMapped(addressSpace, mode == MemoryManagerMode.HostMappedUnsafe, invalidAccessHandler);
processContext = new ArmProcessContext<MemoryManagerHostMapped>(pid, cpuEngine, _gpu, memoryManagerHostMapped, addressSpace.AddressSpaceSize, for64Bit);
}
break;
default:
throw new InvalidOperationException($"{nameof(mode)} contains an invalid value: {mode}");
}
if (addressSpaceSize != processContext.AddressSpaceSize)
{
Logger.Warning?.Print(LogClass.Emulation, $"Allocated address space (0x{processContext.AddressSpaceSize:X}) is smaller than guest application requirements (0x{addressSpaceSize:X})");
}
}
DiskCacheLoadState = processContext.Initialize(_titleIdText, _displayVersion, _diskCacheEnabled, _codeAddress, _codeSize, _diskCacheSelector);
DiskCacheLoadState = processContext.Initialize(_titleIdText, _displayVersion, _diskCacheEnabled, _codeAddress, _codeSize, _diskCacheSelector ?? "default");
return processContext;
}
@@ -24,7 +24,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
{
return arrange switch
{
MemoryArrange.MemoryArrange4GiB or
MemoryArrange.MemoryArrange4GiB => 3455 * MiB,
MemoryArrange.MemoryArrange4GiBSystemDev or
MemoryArrange.MemoryArrange6GiBAppletDev => 3285 * MiB,
MemoryArrange.MemoryArrange4GiBAppletDev => 2048 * MiB,
@@ -104,7 +104,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
MemoryRegion memRegion,
ulong address,
ulong size,
ulong reservedSize,
KMemoryBlockSlabManager slabManager)
{
_contextId = Context.ContextIdManager.GetId();
@@ -120,7 +119,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
memRegion,
address,
size,
reservedSize,
slabManager);
if (result != Result.Success)
@@ -163,7 +161,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
MemoryRegion memRegion,
ulong address,
ulong size,
ulong reservedSize,
KMemoryBlockSlabManager slabManager)
{
ulong endAddr = address + size;
@@ -221,12 +218,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
break;
case ProcessCreationFlags.AddressSpace64Bit:
ulong reservedAddressSpaceSize = _reservedAddressSpaceSize;
if (_reservedAddressSpaceSize < addrSpaceEnd)
{
int addressSpaceWidth = (int)ulong.Log2(reservedAddressSpaceSize);
int addressSpaceWidth = (int)ulong.Log2(_reservedAddressSpaceSize);
aliasRegion.Size = reservedAddressSpaceSize >= 0x1800000000 ? 0x1000000000 : 1UL << (addressSpaceWidth - 3);
aliasRegion.Size = 1UL << (addressSpaceWidth - 3);
heapRegion.Size = 0x180000000;
stackRegion.Size = 1UL << (addressSpaceWidth - 8);
tlsIoRegion.Size = 1UL << (addressSpaceWidth - 3);
@@ -234,8 +230,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
codeRegionSize = BitUtils.AlignUp(endAddr, RegionAlignment) - CodeRegionStart;
stackAndTlsIoStart = 0;
stackAndTlsIoEnd = 0;
AslrRegionStart = Math.Max(reservedSize, 0x8000000);
addrSpaceEnd = reservedSize + reservedAddressSpaceSize;
AslrRegionStart = 0x8000000;
addrSpaceEnd = 1UL << addressSpaceWidth;
AslrRegionEnd = addrSpaceEnd;
}
else
@@ -246,7 +242,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
tlsIoRegion.Size = 0x1000000000;
CodeRegionStart = BitUtils.AlignDown(address, RegionAlignment);
codeRegionSize = BitUtils.AlignUp(endAddr, RegionAlignment) - CodeRegionStart;
AslrRegionStart = Math.Max(reservedSize, 0x8000000);
AslrRegionStart = 0x8000000;
AslrRegionEnd = AslrRegionStart + 0x7ff8000000;
stackAndTlsIoStart = 0;
stackAndTlsIoEnd = 0;
@@ -7,7 +7,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
interface IProcessContext : IDisposable
{
IVirtualMemoryManager AddressSpace { get; }
ulong ReservedSize { get; }
ulong AddressSpaceSize { get; }
+7 -14
View File
@@ -141,7 +141,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
InitializeMemoryManager(creationInfo.Flags);
ulong codeAddress = creationInfo.CodeAddress + Context.ReservedSize;
ulong codeAddress = creationInfo.CodeAddress;
ulong codeSize = (ulong)creationInfo.CodePagesCount * KPageTableBase.PageSize;
@@ -155,7 +155,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
memRegion,
codeAddress,
codeSize,
Context.ReservedSize,
slabManager);
if (result != Result.Success)
@@ -191,8 +190,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
KResourceLimit resourceLimit,
MemoryRegion memRegion,
IProcessContextFactory contextFactory,
ThreadStart customThreadStart = null,
ulong entrypointOffset = 0UL)
ThreadStart customThreadStart = null)
{
ResourceLimit = resourceLimit;
_memRegion = memRegion;
@@ -246,7 +244,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
InitializeMemoryManager(creationInfo.Flags);
ulong codeAddress = creationInfo.CodeAddress + Context.ReservedSize;
ulong codeAddress = creationInfo.CodeAddress;
ulong codeSize = codePagesCount * KPageTableBase.PageSize;
@@ -256,7 +254,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
memRegion,
codeAddress,
codeSize,
Context.ReservedSize,
slabManager);
if (result != Result.Success)
@@ -302,8 +299,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
CleanUpForError();
}
_entrypoint += entrypointOffset;
return result;
}
@@ -348,12 +343,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
Flags = creationInfo.Flags;
TitleId = creationInfo.TitleId;
_entrypoint = creationInfo.CodeAddress + Context.ReservedSize;
_entrypoint = creationInfo.CodeAddress;
_imageSize = (ulong)creationInfo.CodePagesCount * KPageTableBase.PageSize;
// 19.0.0+ sets all regions to same size
_memoryUsageCapacity = MemoryManager.HeapRegionEnd - MemoryManager.HeapRegionStart;
/*switch (Flags & ProcessCreationFlags.AddressSpaceMask)
switch (Flags & ProcessCreationFlags.AddressSpaceMask)
{
case ProcessCreationFlags.AddressSpace32Bit:
case ProcessCreationFlags.AddressSpace64BitDeprecated:
@@ -370,7 +363,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
break;
default:
throw new InvalidOperationException($"Invalid MMU flags value 0x{Flags:x2}.");
}*/
}
GenerateRandomEntropy();
@@ -548,7 +541,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
{
throw new InvalidOperationException("Trying to start a process with an invalid state!");
}
// TODO: after 19.0.0+ alignment is not needed
ulong stackSizeRounded = BitUtils.AlignUp<ulong>(stackSize, KPageTableBase.PageSize);
ulong neededSize = stackSizeRounded + _imageSize;
@@ -7,7 +7,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
class ProcessContext : IProcessContext
{
public IVirtualMemoryManager AddressSpace { get; }
public ulong ReservedSize => 0UL;
public ulong AddressSpaceSize { get; }
@@ -25,10 +25,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
IsAnyInternetRequestAccepted = true, // NOTE: Why not accept any internet request?
};
if (!PlatformInfo.IsBionic)
{
NetworkChange.NetworkAddressChanged += LocalInterfaceCacheHandler;
}
NetworkChange.NetworkAddressChanged += LocalInterfaceCacheHandler;
GeneralServiceManager.Add(_generalServiceDetail);
}
@@ -87,7 +84,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
networkProfile.IpSettingData.IpAddressSetting = new IpAddressSetting(interfaceProperties, unicastAddress);
networkProfile.IpSettingData.DnsSetting = new DnsSetting(interfaceProperties);
"KenjinxNetwork"u8.CopyTo(networkProfile.Name.AsSpan());
"RyujinxNetwork"u8.CopyTo(networkProfile.Name.AsSpan());
context.Memory.Write(networkProfileDataPosition, networkProfile);
@@ -199,10 +196,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
{
if (isDisposing)
{
if (!PlatformInfo.IsBionic)
{
NetworkChange.NetworkAddressChanged -= LocalInterfaceCacheHandler;
}
NetworkChange.NetworkAddressChanged -= LocalInterfaceCacheHandler;
GeneralServiceManager.Remove(_generalServiceDetail.ClientId);
}
@@ -1,19 +1,8 @@
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Services.Pm.Types;
namespace Ryujinx.HLE.HOS.Services.Pm
{
[Service("pm:bm")]
class IBootModeInterface : IpcService
{
public IBootModeInterface(ServiceCtx context) { }
[CommandCmif(0)]
// GetBootMode() -> u32
public ResultCode GetBootMode(ServiceCtx context)
{
context.ResponseData.Write((uint)BootMode.Normal);
return ResultCode.Success;
}
}
}
@@ -1,9 +0,0 @@
namespace Ryujinx.HLE.HOS.Services.Pm.Types
{
enum BootMode : uint
{
Normal = 0,
Maintenance = 1,
SafeMode = 2,
}
}
@@ -244,15 +244,6 @@ namespace Ryujinx.HLE.HOS.Services.Settings
return ResultCode.Success;
}
[CommandCmif(68)]
// GetSerialNumber() -> buffer<nn::settings::system::SerialNumber, 0x16>
public ResultCode GetSerialNumber(ServiceCtx context)
{
context.ResponseData.Write(Encoding.ASCII.GetBytes("RYU00000000000"));
return ResultCode.Success;
}
[CommandCmif(77)]
// GetDeviceNickName() -> buffer<nn::settings::system::DeviceNickName, 0x16>
public ResultCode GetDeviceNickName(ServiceCtx context)
@@ -1,4 +1,3 @@
using Ryujinx.Common;
using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Services.Spl.Types;
@@ -52,14 +51,6 @@ namespace Ryujinx.HLE.HOS.Services.Spl
context.ResponseData.Write(configValue);
if(PlatformInfo.IsBionic)
{
if (result == SmcResult.Success)
{
return ResultCode.Success;
}
}
return (ResultCode)((int)result << 9) | ResultCode.ModuleId;
}