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:
parent
e7e65ccbc9
commit
c94d47cc40
6 changed files with 102 additions and 5 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue