mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2024-11-16 01:55:27 +00:00
9f6b24edfd
* Implement session count decrement when the handle is closed * Remove unused field * Implement SendSyncRequestWithUserBuffer, SendAsyncRequestWithUserBuffer and ReplyAndReceiveWithUserBuffer syscalls * Nits * Fix swapped copy dst/src * Add missing pointer buffer descriptor write on reply * Fix IPC unaligned buffer copy and restoring client attributes on reply * Oops * Fix SetIpcMappingPermission * Fix unaligned copy bugs * Free memory used for temporary IPC buffers
123 lines
3.6 KiB
C#
123 lines
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 MemoryPermission Permission { get; private set; }
|
|
public MemoryAttribute Attribute { get; private set; }
|
|
public MemoryPermission SourcePermission { get; private set; }
|
|
|
|
public int IpcRefCount { get; private set; }
|
|
public int DeviceRefCount { get; private set; }
|
|
|
|
public KMemoryBlock(
|
|
ulong baseAddress,
|
|
ulong pagesCount,
|
|
MemoryState state,
|
|
MemoryPermission 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(MemoryPermission permission, MemoryState state, MemoryAttribute attribute)
|
|
{
|
|
Permission = permission;
|
|
State = state;
|
|
Attribute &= MemoryAttribute.IpcAndDeviceMapped;
|
|
Attribute |= attribute;
|
|
}
|
|
|
|
public void SetIpcMappingPermission(MemoryPermission newPermission)
|
|
{
|
|
int oldIpcRefCount = IpcRefCount++;
|
|
|
|
if ((ushort)IpcRefCount == 0)
|
|
{
|
|
throw new InvalidOperationException("IPC reference count increment overflowed.");
|
|
}
|
|
|
|
if (oldIpcRefCount == 0)
|
|
{
|
|
SourcePermission = Permission;
|
|
|
|
Permission &= ~MemoryPermission.ReadAndWrite;
|
|
Permission |= MemoryPermission.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 = MemoryPermission.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);
|
|
}
|
|
}
|
|
} |