2018-11-28 22:18:09 +00:00
|
|
|
using Ryujinx.Common;
|
|
|
|
|
2018-08-16 23:47:36 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel
|
2018-08-15 18:59:51 +00:00
|
|
|
{
|
|
|
|
class KSharedMemory
|
|
|
|
{
|
2018-11-28 22:18:09 +00: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 18:59:51 +00:00
|
|
|
|
2018-11-28 22:18:09 +00:00
|
|
|
public KernelResult MapIntoProcess(
|
|
|
|
KMemoryManager MemoryManager,
|
|
|
|
ulong Address,
|
|
|
|
ulong Size,
|
|
|
|
KProcess Process,
|
|
|
|
MemoryPermission Permission)
|
2018-08-15 18:59:51 +00:00
|
|
|
{
|
2018-11-28 22:18:09 +00: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 18:59:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|