2018-11-28 23:18:09 +01:00
|
|
|
using Ryujinx.Common;
|
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel
|
2018-08-15 20:59:51 +02:00
|
|
|
{
|
|
|
|
class KSharedMemory
|
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
private KPageList PageList;
|
|
|
|
|
|
|
|
private long OwnerPid;
|
|
|
|
|
|
|
|
private MemoryPermission OwnerPermission;
|
|
|
|
private MemoryPermission UserPermission;
|
|
|
|
|
|
|
|
public KSharedMemory(
|
|
|
|
KPageList PageList,
|
|
|
|
long OwnerPid,
|
|
|
|
MemoryPermission OwnerPermission,
|
|
|
|
MemoryPermission UserPermission)
|
|
|
|
{
|
|
|
|
this.PageList = PageList;
|
|
|
|
this.OwnerPid = OwnerPid;
|
|
|
|
this.OwnerPermission = OwnerPermission;
|
|
|
|
this.UserPermission = UserPermission;
|
|
|
|
}
|
2018-08-15 20:59:51 +02:00
|
|
|
|
2018-11-28 23:18:09 +01:00
|
|
|
public KernelResult MapIntoProcess(
|
|
|
|
KMemoryManager MemoryManager,
|
|
|
|
ulong Address,
|
|
|
|
ulong Size,
|
|
|
|
KProcess Process,
|
|
|
|
MemoryPermission Permission)
|
2018-08-15 20:59:51 +02:00
|
|
|
{
|
2018-11-28 23:18:09 +01:00
|
|
|
ulong PagesCountRounded = BitUtils.DivRoundUp(Size, KMemoryManager.PageSize);
|
|
|
|
|
|
|
|
if (PageList.GetPagesCount() != PagesCountRounded)
|
|
|
|
{
|
|
|
|
return KernelResult.InvalidSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryPermission ExpectedPermission = Process.Pid == OwnerPid
|
|
|
|
? OwnerPermission
|
|
|
|
: UserPermission;
|
|
|
|
|
|
|
|
if (Permission != ExpectedPermission)
|
|
|
|
{
|
|
|
|
return KernelResult.InvalidPermission;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MemoryManager.MapPages(Address, PageList, MemoryState.SharedMemory, Permission);
|
|
|
|
}
|
|
|
|
|
|
|
|
public KernelResult UnmapFromProcess(
|
|
|
|
KMemoryManager MemoryManager,
|
|
|
|
ulong Address,
|
|
|
|
ulong Size,
|
|
|
|
KProcess Process)
|
|
|
|
{
|
|
|
|
ulong PagesCountRounded = BitUtils.DivRoundUp(Size, KMemoryManager.PageSize);
|
|
|
|
|
|
|
|
if (PageList.GetPagesCount() != PagesCountRounded)
|
|
|
|
{
|
|
|
|
return KernelResult.InvalidSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MemoryManager.UnmapPages(Address, PageList, MemoryState.SharedMemory);
|
2018-08-15 20:59:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|