mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-11-11 09:36:39 +00:00
cf6cd71488
* IPC refactor part 2: Use ReplyAndReceive on HLE services and remove special handling from kernel * Fix for applet transfer memory + some nits * Keep handles if possible to avoid server handle table exhaustion * Fix IPC ZeroFill bug * am: Correctly implement CreateManagedDisplayLayer and implement CreateManagedDisplaySeparableLayer CreateManagedDisplaySeparableLayer is requires since 10.x+ when appletResourceUserId != 0 * Make it exit properly * Make ServiceNotImplementedException show the full message again * Allow yielding execution to avoid starving other threads * Only wait if active * Merge IVirtualMemoryManager and IAddressSpaceManager * Fix Ro loading data from the wrong process Co-authored-by: Thog <me@thog.eu>
123 lines
No EOL
3.6 KiB
C#
123 lines
No EOL
3.6 KiB
C#
using System;
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Memory
|
|
{
|
|
class KMemoryBlock
|
|
{
|
|
public ulong BaseAddress { get; private set; }
|
|
public ulong PagesCount { get; private set; }
|
|
|
|
public MemoryState State { get; private set; }
|
|
public KMemoryPermission Permission { get; private set; }
|
|
public MemoryAttribute Attribute { get; private set; }
|
|
public KMemoryPermission SourcePermission { get; private set; }
|
|
|
|
public int IpcRefCount { get; private set; }
|
|
public int DeviceRefCount { get; private set; }
|
|
|
|
public KMemoryBlock(
|
|
ulong baseAddress,
|
|
ulong pagesCount,
|
|
MemoryState state,
|
|
KMemoryPermission permission,
|
|
MemoryAttribute attribute,
|
|
int ipcRefCount = 0,
|
|
int deviceRefCount = 0)
|
|
{
|
|
BaseAddress = baseAddress;
|
|
PagesCount = pagesCount;
|
|
State = state;
|
|
Attribute = attribute;
|
|
Permission = permission;
|
|
IpcRefCount = ipcRefCount;
|
|
DeviceRefCount = deviceRefCount;
|
|
}
|
|
|
|
public void SetState(KMemoryPermission permission, MemoryState state, MemoryAttribute attribute)
|
|
{
|
|
Permission = permission;
|
|
State = state;
|
|
Attribute &= MemoryAttribute.IpcAndDeviceMapped;
|
|
Attribute |= attribute;
|
|
}
|
|
|
|
public void SetIpcMappingPermission(KMemoryPermission newPermission)
|
|
{
|
|
int oldIpcRefCount = IpcRefCount++;
|
|
|
|
if ((ushort)IpcRefCount == 0)
|
|
{
|
|
throw new InvalidOperationException("IPC reference count increment overflowed.");
|
|
}
|
|
|
|
if (oldIpcRefCount == 0)
|
|
{
|
|
SourcePermission = Permission;
|
|
|
|
Permission &= ~KMemoryPermission.ReadAndWrite;
|
|
Permission |= KMemoryPermission.ReadAndWrite & newPermission;
|
|
}
|
|
|
|
Attribute |= MemoryAttribute.IpcMapped;
|
|
}
|
|
|
|
public void RestoreIpcMappingPermission()
|
|
{
|
|
int oldIpcRefCount = IpcRefCount--;
|
|
|
|
if (oldIpcRefCount == 0)
|
|
{
|
|
throw new InvalidOperationException("IPC reference count decrement underflowed.");
|
|
}
|
|
|
|
if (oldIpcRefCount == 1)
|
|
{
|
|
Permission = SourcePermission;
|
|
|
|
SourcePermission = KMemoryPermission.None;
|
|
|
|
Attribute &= ~MemoryAttribute.IpcMapped;
|
|
}
|
|
}
|
|
|
|
public KMemoryBlock SplitRightAtAddress(ulong address)
|
|
{
|
|
ulong leftAddress = BaseAddress;
|
|
|
|
ulong leftPagesCount = (address - leftAddress) / KMemoryManager.PageSize;
|
|
|
|
BaseAddress = address;
|
|
|
|
PagesCount -= leftPagesCount;
|
|
|
|
return new KMemoryBlock(
|
|
leftAddress,
|
|
leftPagesCount,
|
|
State,
|
|
Permission,
|
|
Attribute,
|
|
IpcRefCount,
|
|
DeviceRefCount);
|
|
}
|
|
|
|
public void AddPages(ulong pagesCount)
|
|
{
|
|
PagesCount += pagesCount;
|
|
}
|
|
|
|
public KMemoryInfo GetInfo()
|
|
{
|
|
ulong size = PagesCount * KMemoryManager.PageSize;
|
|
|
|
return new KMemoryInfo(
|
|
BaseAddress,
|
|
size,
|
|
State,
|
|
Permission,
|
|
Attribute,
|
|
SourcePermission,
|
|
IpcRefCount,
|
|
DeviceRefCount);
|
|
}
|
|
}
|
|
} |