kernel: Implement SetMemoryPermission syscall (#2772)

* kernel: Implement SetMemoryPermission syscall

This commit implement the SetMemoryPermission syscall accurately.
This also fix KMemoryPermission not being an unsigned 32 bits type and
add the "DontCare" bit (used by shared memory, currently unused in
Ryujinx)

* Update MemoryPermission mask

* Address gdkchan's comments

* Fix a nit

* Address gdkchan's comment
This commit is contained in:
Mary 2021-10-24 01:24:49 +02:00 committed by GitHub
parent e7e65ccbc9
commit c94d47cc40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 102 additions and 5 deletions

View file

@ -799,6 +799,52 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return KernelResult.Success;
}
public KernelResult SetMemoryPermission(ulong address, ulong size, KMemoryPermission permission)
{
lock (_blockManager)
{
if (CheckRange(
address,
size,
MemoryState.PermissionChangeAllowed,
MemoryState.PermissionChangeAllowed,
KMemoryPermission.None,
KMemoryPermission.None,
MemoryAttribute.Mask,
MemoryAttribute.None,
MemoryAttribute.IpcAndDeviceMapped,
out MemoryState oldState,
out KMemoryPermission oldPermission,
out _))
{
if (permission != oldPermission)
{
if (!_slabManager.CanAllocate(MaxBlocksNeededForInsertion))
{
return KernelResult.OutOfResource;
}
ulong pagesCount = size / PageSize;
KernelResult result = Reprotect(address, pagesCount, permission);
if (result != KernelResult.Success)
{
return result;
}
_blockManager.InsertBlock(address, pagesCount, oldState, permission);
}
return KernelResult.Success;
}
else
{
return KernelResult.InvalidMemState;
}
}
}
public ulong GetTotalHeapSize()
{
lock (_blockManager)