Implement kernel GetInfo AliasRegionExtraSize
This commit is contained in:
parent
827069e784
commit
b37f7caacb
6 changed files with 73 additions and 70 deletions
|
@ -1,10 +0,0 @@
|
|||
namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
{
|
||||
enum AddressSpaceType
|
||||
{
|
||||
Addr32Bits = 0,
|
||||
Addr36Bits = 1,
|
||||
Addr32BitsNoMap = 2,
|
||||
Addr39Bits = 3,
|
||||
}
|
||||
}
|
|
@ -58,11 +58,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
public ulong AslrRegionStart { get; private set; }
|
||||
public ulong AslrRegionEnd { get; private set; }
|
||||
|
||||
#pragma warning disable IDE0052 // Remove unread private member
|
||||
private ulong _heapCapacity;
|
||||
#pragma warning restore IDE0052
|
||||
|
||||
public ulong PhysicalMemoryUsage { get; private set; }
|
||||
public ulong AliasRegionExtraSize { get; private set; }
|
||||
|
||||
private readonly KMemoryBlockManager _blockManager;
|
||||
|
||||
|
@ -98,30 +97,21 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
_reservedAddressSpaceSize = reservedAddressSpaceSize;
|
||||
}
|
||||
|
||||
private static readonly int[] _addrSpaceSizes = { 32, 36, 32, 39 };
|
||||
|
||||
public Result InitializeForProcess(
|
||||
AddressSpaceType addrSpaceType,
|
||||
bool aslrEnabled,
|
||||
ProcessCreationFlags flags,
|
||||
bool fromBack,
|
||||
MemoryRegion memRegion,
|
||||
ulong address,
|
||||
ulong size,
|
||||
KMemoryBlockSlabManager slabManager)
|
||||
{
|
||||
if ((uint)addrSpaceType > (uint)AddressSpaceType.Addr39Bits)
|
||||
{
|
||||
throw new ArgumentException($"AddressSpaceType bigger than {(uint)AddressSpaceType.Addr39Bits}: {(uint)addrSpaceType}", nameof(addrSpaceType));
|
||||
}
|
||||
|
||||
_contextId = Context.ContextIdManager.GetId();
|
||||
|
||||
ulong addrSpaceBase = 0;
|
||||
ulong addrSpaceSize = 1UL << _addrSpaceSizes[(int)addrSpaceType];
|
||||
ulong addrSpaceSize = 1UL << GetAddressSpaceWidth(flags);
|
||||
|
||||
Result result = CreateUserAddressSpace(
|
||||
addrSpaceType,
|
||||
aslrEnabled,
|
||||
flags,
|
||||
fromBack,
|
||||
addrSpaceBase,
|
||||
addrSpaceSize,
|
||||
|
@ -138,6 +128,22 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
return result;
|
||||
}
|
||||
|
||||
private static int GetAddressSpaceWidth(ProcessCreationFlags flags)
|
||||
{
|
||||
switch (flags & ProcessCreationFlags.AddressSpaceMask)
|
||||
{
|
||||
case ProcessCreationFlags.AddressSpace32Bit:
|
||||
case ProcessCreationFlags.AddressSpace32BitWithoutAlias:
|
||||
return 32;
|
||||
case ProcessCreationFlags.AddressSpace64BitDeprecated:
|
||||
return 36;
|
||||
case ProcessCreationFlags.AddressSpace64Bit:
|
||||
return 39;
|
||||
}
|
||||
|
||||
throw new ArgumentException($"Invalid process flags {flags}", nameof(flags));
|
||||
}
|
||||
|
||||
private struct Region
|
||||
{
|
||||
public ulong Start;
|
||||
|
@ -147,8 +153,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
}
|
||||
|
||||
private Result CreateUserAddressSpace(
|
||||
AddressSpaceType addrSpaceType,
|
||||
bool aslrEnabled,
|
||||
ProcessCreationFlags flags,
|
||||
bool fromBack,
|
||||
ulong addrSpaceStart,
|
||||
ulong addrSpaceEnd,
|
||||
|
@ -168,9 +173,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
ulong stackAndTlsIoStart;
|
||||
ulong stackAndTlsIoEnd;
|
||||
|
||||
switch (addrSpaceType)
|
||||
AliasRegionExtraSize = 0;
|
||||
|
||||
switch (flags & ProcessCreationFlags.AddressSpaceMask)
|
||||
{
|
||||
case AddressSpaceType.Addr32Bits:
|
||||
case ProcessCreationFlags.AddressSpace32Bit:
|
||||
aliasRegion.Size = 0x40000000;
|
||||
heapRegion.Size = 0x40000000;
|
||||
stackRegion.Size = 0;
|
||||
|
@ -183,7 +190,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
stackAndTlsIoEnd = 0x40000000;
|
||||
break;
|
||||
|
||||
case AddressSpaceType.Addr36Bits:
|
||||
case ProcessCreationFlags.AddressSpace64BitDeprecated:
|
||||
aliasRegion.Size = 0x180000000;
|
||||
heapRegion.Size = 0x180000000;
|
||||
stackRegion.Size = 0;
|
||||
|
@ -196,7 +203,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
stackAndTlsIoEnd = 0x80000000;
|
||||
break;
|
||||
|
||||
case AddressSpaceType.Addr32BitsNoMap:
|
||||
case ProcessCreationFlags.AddressSpace32BitWithoutAlias:
|
||||
aliasRegion.Size = 0;
|
||||
heapRegion.Size = 0x80000000;
|
||||
stackRegion.Size = 0;
|
||||
|
@ -209,7 +216,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
stackAndTlsIoEnd = 0x40000000;
|
||||
break;
|
||||
|
||||
case AddressSpaceType.Addr39Bits:
|
||||
case ProcessCreationFlags.AddressSpace64Bit:
|
||||
if (_reservedAddressSpaceSize < addrSpaceEnd)
|
||||
{
|
||||
int addressSpaceWidth = (int)ulong.Log2(_reservedAddressSpaceSize);
|
||||
|
@ -218,8 +225,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
heapRegion.Size = 0x180000000;
|
||||
stackRegion.Size = 1UL << (addressSpaceWidth - 8);
|
||||
tlsIoRegion.Size = 1UL << (addressSpaceWidth - 3);
|
||||
CodeRegionStart = BitUtils.AlignDown<ulong>(address, RegionAlignment);
|
||||
codeRegionSize = BitUtils.AlignUp<ulong>(endAddr, RegionAlignment) - CodeRegionStart;
|
||||
CodeRegionStart = BitUtils.AlignDown(address, RegionAlignment);
|
||||
codeRegionSize = BitUtils.AlignUp(endAddr, RegionAlignment) - CodeRegionStart;
|
||||
stackAndTlsIoStart = 0;
|
||||
stackAndTlsIoEnd = 0;
|
||||
AslrRegionStart = 0x8000000;
|
||||
|
@ -239,9 +246,16 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
stackAndTlsIoStart = 0;
|
||||
stackAndTlsIoEnd = 0;
|
||||
}
|
||||
|
||||
if (flags.HasFlag(ProcessCreationFlags.EnableAliasRegionExtraSize))
|
||||
{
|
||||
AliasRegionExtraSize = addrSpaceEnd / 8;
|
||||
aliasRegion.Size += AliasRegionExtraSize;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentException($"AddressSpaceType bigger than {(uint)AddressSpaceType.Addr39Bits}: {(uint)addrSpaceType}", nameof(addrSpaceType));
|
||||
throw new ArgumentException($"Invalid process flags {flags}", nameof(flags));
|
||||
}
|
||||
|
||||
CodeRegionEnd = CodeRegionStart + codeRegionSize;
|
||||
|
@ -266,6 +280,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
|
||||
ulong aslrMaxOffset = mapAvailableSize - mapTotalSize;
|
||||
|
||||
bool aslrEnabled = flags.HasFlag(ProcessCreationFlags.EnableAslr);
|
||||
|
||||
_aslrEnabled = aslrEnabled;
|
||||
|
||||
AddrSpaceStart = addrSpaceStart;
|
||||
|
@ -725,7 +741,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|||
{
|
||||
address = 0;
|
||||
|
||||
if (size > HeapRegionEnd - HeapRegionStart)
|
||||
if (size > HeapRegionEnd - HeapRegionStart || size > _heapCapacity)
|
||||
{
|
||||
return KernelResult.OutOfMemory;
|
||||
}
|
||||
|
|
|
@ -126,8 +126,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
_contextFactory = contextFactory ?? new ProcessContextFactory();
|
||||
_customThreadStart = customThreadStart;
|
||||
|
||||
AddressSpaceType addrSpaceType = (AddressSpaceType)((int)(creationInfo.Flags & ProcessCreationFlags.AddressSpaceMask) >> (int)ProcessCreationFlags.AddressSpaceShift);
|
||||
|
||||
Pid = KernelContext.NewKipId();
|
||||
|
||||
if (Pid == 0 || Pid >= KernelConstants.InitialProcessId)
|
||||
|
@ -137,8 +135,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
|
||||
InitializeMemoryManager(creationInfo.Flags);
|
||||
|
||||
bool aslrEnabled = creationInfo.Flags.HasFlag(ProcessCreationFlags.EnableAslr);
|
||||
|
||||
ulong codeAddress = creationInfo.CodeAddress;
|
||||
|
||||
ulong codeSize = (ulong)creationInfo.CodePagesCount * KPageTableBase.PageSize;
|
||||
|
@ -148,9 +144,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
: KernelContext.SmallMemoryBlockSlabManager;
|
||||
|
||||
Result result = MemoryManager.InitializeForProcess(
|
||||
addrSpaceType,
|
||||
aslrEnabled,
|
||||
!aslrEnabled,
|
||||
creationInfo.Flags,
|
||||
!creationInfo.Flags.HasFlag(ProcessCreationFlags.EnableAslr),
|
||||
memRegion,
|
||||
codeAddress,
|
||||
codeSize,
|
||||
|
@ -234,8 +229,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
: KernelContext.SmallMemoryBlockSlabManager;
|
||||
}
|
||||
|
||||
AddressSpaceType addrSpaceType = (AddressSpaceType)((int)(creationInfo.Flags & ProcessCreationFlags.AddressSpaceMask) >> (int)ProcessCreationFlags.AddressSpaceShift);
|
||||
|
||||
Pid = KernelContext.NewProcessId();
|
||||
|
||||
if (Pid == ulong.MaxValue || Pid < KernelConstants.InitialProcessId)
|
||||
|
@ -245,16 +238,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
|
||||
InitializeMemoryManager(creationInfo.Flags);
|
||||
|
||||
bool aslrEnabled = creationInfo.Flags.HasFlag(ProcessCreationFlags.EnableAslr);
|
||||
|
||||
ulong codeAddress = creationInfo.CodeAddress;
|
||||
|
||||
ulong codeSize = codePagesCount * KPageTableBase.PageSize;
|
||||
|
||||
Result result = MemoryManager.InitializeForProcess(
|
||||
addrSpaceType,
|
||||
aslrEnabled,
|
||||
!aslrEnabled,
|
||||
creationInfo.Flags,
|
||||
!creationInfo.Flags.HasFlag(ProcessCreationFlags.EnableAslr),
|
||||
memRegion,
|
||||
codeAddress,
|
||||
codeSize,
|
||||
|
|
|
@ -29,6 +29,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
PoolPartitionMask = 0xf << PoolPartitionShift,
|
||||
|
||||
OptimizeMemoryAllocation = 1 << 11,
|
||||
DisableDeviceAddressSpaceMerge = 1 << 12,
|
||||
EnableAliasRegionExtraSize = 1 << 13,
|
||||
|
||||
All =
|
||||
Is64Bit |
|
||||
|
@ -38,6 +40,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
|||
IsApplication |
|
||||
DeprecatedUseSecureMemory |
|
||||
PoolPartitionMask |
|
||||
OptimizeMemoryAllocation,
|
||||
OptimizeMemoryAllocation |
|
||||
DisableDeviceAddressSpaceMerge |
|
||||
EnableAliasRegionExtraSize,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,14 +21,17 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
SystemResourceSizeTotal,
|
||||
SystemResourceSizeUsed,
|
||||
ProgramId,
|
||||
// NOTE: Added in 4.0.0, removed in 5.0.0.
|
||||
InitialProcessIdRange,
|
||||
InitialProcessIdRange, // NOTE: Added in 4.0.0, removed in 5.0.0.
|
||||
UserExceptionContextAddress,
|
||||
TotalNonSystemMemorySize,
|
||||
UsedNonSystemMemorySize,
|
||||
IsApplication,
|
||||
FreeThreadCount,
|
||||
ThreadTickCount,
|
||||
IsSvcPermitted,
|
||||
IoRegionHint,
|
||||
AliasRegionExtraSize,
|
||||
|
||||
MesosphereCurrentProcess = 65001,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,17 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
return KernelResult.InvalidSize;
|
||||
}
|
||||
|
||||
if (info.Flags.HasFlag(ProcessCreationFlags.EnableAliasRegionExtraSize))
|
||||
{
|
||||
if ((info.Flags & ProcessCreationFlags.AddressSpaceMask) != ProcessCreationFlags.AddressSpace64Bit ||
|
||||
info.SystemResourcePagesCount <= 0)
|
||||
{
|
||||
return KernelResult.InvalidState;
|
||||
}
|
||||
|
||||
// TODO: Check that we are in debug mode.
|
||||
}
|
||||
|
||||
if (info.Flags.HasFlag(ProcessCreationFlags.OptimizeMemoryAllocation) &&
|
||||
!info.Flags.HasFlag(ProcessCreationFlags.IsApplication))
|
||||
{
|
||||
|
@ -1978,6 +1989,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
case InfoType.UsedNonSystemMemorySize:
|
||||
case InfoType.IsApplication:
|
||||
case InfoType.FreeThreadCount:
|
||||
case InfoType.AliasRegionExtraSize:
|
||||
{
|
||||
if (subId != 0)
|
||||
{
|
||||
|
@ -2006,22 +2018,19 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
value = process.MemoryManager.AliasRegionStart;
|
||||
break;
|
||||
case InfoType.AliasRegionSize:
|
||||
value = (process.MemoryManager.AliasRegionEnd -
|
||||
process.MemoryManager.AliasRegionStart);
|
||||
value = process.MemoryManager.AliasRegionEnd - process.MemoryManager.AliasRegionStart;
|
||||
break;
|
||||
|
||||
case InfoType.HeapRegionAddress:
|
||||
value = process.MemoryManager.HeapRegionStart;
|
||||
break;
|
||||
case InfoType.HeapRegionSize:
|
||||
value = (process.MemoryManager.HeapRegionEnd -
|
||||
process.MemoryManager.HeapRegionStart);
|
||||
value = process.MemoryManager.HeapRegionEnd - process.MemoryManager.HeapRegionStart;
|
||||
break;
|
||||
|
||||
case InfoType.TotalMemorySize:
|
||||
value = process.GetMemoryCapacity();
|
||||
break;
|
||||
|
||||
case InfoType.UsedMemorySize:
|
||||
value = process.GetMemoryUsage();
|
||||
break;
|
||||
|
@ -2029,7 +2038,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
case InfoType.AslrRegionAddress:
|
||||
value = process.MemoryManager.GetAddrSpaceBaseAddr();
|
||||
break;
|
||||
|
||||
case InfoType.AslrRegionSize:
|
||||
value = process.MemoryManager.GetAddrSpaceSize();
|
||||
break;
|
||||
|
@ -2038,20 +2046,17 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
value = process.MemoryManager.StackRegionStart;
|
||||
break;
|
||||
case InfoType.StackRegionSize:
|
||||
value = (process.MemoryManager.StackRegionEnd -
|
||||
process.MemoryManager.StackRegionStart);
|
||||
value = process.MemoryManager.StackRegionEnd - process.MemoryManager.StackRegionStart;
|
||||
break;
|
||||
|
||||
case InfoType.SystemResourceSizeTotal:
|
||||
value = process.PersonalMmHeapPagesCount * KPageTableBase.PageSize;
|
||||
break;
|
||||
|
||||
case InfoType.SystemResourceSizeUsed:
|
||||
if (process.PersonalMmHeapPagesCount != 0)
|
||||
{
|
||||
value = process.MemoryManager.GetMmUsedPages() * KPageTableBase.PageSize;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case InfoType.ProgramId:
|
||||
|
@ -2065,7 +2070,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
case InfoType.TotalNonSystemMemorySize:
|
||||
value = process.GetMemoryCapacityWithoutPersonalMmHeap();
|
||||
break;
|
||||
|
||||
case InfoType.UsedNonSystemMemorySize:
|
||||
value = process.GetMemoryUsageWithoutPersonalMmHeap();
|
||||
break;
|
||||
|
@ -2084,10 +2088,12 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
{
|
||||
value = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case InfoType.AliasRegionExtraSize:
|
||||
value = process.MemoryManager.AliasRegionExtraSize;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2104,7 +2110,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
value = KernelStatic.GetCurrentProcess().Debug ? 1UL : 0UL;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2136,7 +2141,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
value = (uint)resLimHandle;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2155,7 +2159,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
value = (ulong)KTimeManager.ConvertHostTicksToTicks(_context.Schedulers[currentCore].TotalIdleTimeTicks);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2174,7 +2177,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
KProcess currentProcess = KernelStatic.GetCurrentProcess();
|
||||
|
||||
value = currentProcess.RandomEntropy[subId];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2220,7 +2222,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
|
||||
value = (ulong)KTimeManager.ConvertHostTicksToTicks(totalTimeRunning);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2247,7 +2248,6 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
|
|||
}
|
||||
|
||||
value = (ulong)outHandle;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue