2018-04-19 04:52:23 +02:00
|
|
|
using ChocolArm64.State;
|
2018-10-17 19:15:50 +02:00
|
|
|
using Ryujinx.Common.Logging;
|
2018-09-23 20:11:46 +02:00
|
|
|
using System.Collections.Generic;
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
using static Ryujinx.HLE.HOS.ErrorCode;
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
|
|
|
partial class SvcHandler
|
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
private void SvcWaitSynchronization(CpuThreadState threadState)
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
long handlesPtr = (long)threadState.X1;
|
|
|
|
int handlesCount = (int)threadState.X2;
|
|
|
|
long timeout = (long)threadState.X3;
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-10-17 19:15:50 +02:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc,
|
2018-12-01 21:01:59 +01:00
|
|
|
"HandlesPtr = 0x" + handlesPtr .ToString("x16") + ", " +
|
|
|
|
"HandlesCount = 0x" + handlesCount.ToString("x8") + ", " +
|
|
|
|
"Timeout = 0x" + timeout .ToString("x16"));
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if ((uint)handlesCount > 0x40)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.CountOutOfRange);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
List<KSynchronizationObject> syncObjs = new List<KSynchronizationObject>();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
for (int index = 0; index < handlesCount; index++)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
int handle = _memory.ReadInt32(handlesPtr + index * 4);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc, $"Sync handle 0x{handle:x8}");
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
KSynchronizationObject syncObj = _process.HandleTable.GetObject<KSynchronizationObject>(handle);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (syncObj == null)
|
2018-09-23 20:11:46 +02:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
syncObjs.Add(syncObj);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
int hndIndex = (int)threadState.X1;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
ulong high = threadState.X1 & (0xffffffffUL << 32);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
long result = _system.Synchronization.WaitFor(syncObjs.ToArray(), timeout, ref hndIndex);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (result != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
if (result == MakeError(ErrorModule.Kernel, KernelErr.Timeout) ||
|
|
|
|
result == MakeError(ErrorModule.Kernel, KernelErr.Cancelled))
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc, $"Operation failed with error 0x{result:x}!");
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{result:x}!");
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = (ulong)result;
|
|
|
|
threadState.X1 = (uint)hndIndex | high;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
private void SvcCancelSynchronization(CpuThreadState threadState)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
int threadHandle = (int)threadState.X0;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc, "ThreadHandle = 0x" + threadHandle.ToString("x8"));
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
KThread thread = _process.HandleTable.GetKThread(threadHandle);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (thread == null)
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Invalid thread handle 0x{threadHandle:x8}!");
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle);
|
2018-04-19 04:52:23 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
thread.CancelSynchronization();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = 0;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
private void SvcArbitrateLock(CpuThreadState threadState)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
int ownerHandle = (int)threadState.X0;
|
|
|
|
long mutexAddress = (long)threadState.X1;
|
|
|
|
int requesterHandle = (int)threadState.X2;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-10-17 19:15:50 +02:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc,
|
2018-12-01 21:01:59 +01:00
|
|
|
"OwnerHandle = 0x" + ownerHandle .ToString("x8") + ", " +
|
|
|
|
"MutexAddress = 0x" + mutexAddress .ToString("x16") + ", " +
|
|
|
|
"RequesterHandle = 0x" + requesterHandle.ToString("x8"));
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (IsPointingInsideKernel(mutexAddress))
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Invalid mutex address 0x{mutexAddress:x16}!");
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm);
|
2018-04-19 04:52:23 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (IsAddressNotWordAligned(mutexAddress))
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned mutex address 0x{mutexAddress:x16}!");
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress);
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
KProcess currentProcess = _system.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
long result = currentProcess.AddressArbiter.ArbitrateLock(ownerHandle, mutexAddress, requesterHandle);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (result != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{result:x}!");
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = (ulong)result;
|
2018-04-19 04:52:23 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
private void SvcArbitrateUnlock(CpuThreadState threadState)
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
long mutexAddress = (long)threadState.X0;
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc, "MutexAddress = 0x" + mutexAddress.ToString("x16"));
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (IsPointingInsideKernel(mutexAddress))
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Invalid mutex address 0x{mutexAddress:x16}!");
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (IsAddressNotWordAligned(mutexAddress))
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned mutex address 0x{mutexAddress:x16}!");
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
KProcess currentProcess = _system.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
long result = currentProcess.AddressArbiter.ArbitrateUnlock(mutexAddress);
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (result != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{result:x}!");
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = (ulong)result;
|
2018-04-19 04:52:23 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
private void SvcWaitProcessWideKeyAtomic(CpuThreadState threadState)
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
long mutexAddress = (long)threadState.X0;
|
|
|
|
long condVarAddress = (long)threadState.X1;
|
|
|
|
int threadHandle = (int)threadState.X2;
|
|
|
|
long timeout = (long)threadState.X3;
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-10-17 19:15:50 +02:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc,
|
2018-12-01 21:01:59 +01:00
|
|
|
"MutexAddress = 0x" + mutexAddress .ToString("x16") + ", " +
|
|
|
|
"CondVarAddress = 0x" + condVarAddress.ToString("x16") + ", " +
|
|
|
|
"ThreadHandle = 0x" + threadHandle .ToString("x8") + ", " +
|
|
|
|
"Timeout = 0x" + timeout .ToString("x16"));
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (IsPointingInsideKernel(mutexAddress))
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Invalid mutex address 0x{mutexAddress:x16}!");
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (IsAddressNotWordAligned(mutexAddress))
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned mutex address 0x{mutexAddress:x16}!");
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
KProcess currentProcess = _system.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
long result = currentProcess.AddressArbiter.WaitProcessWideKeyAtomic(
|
|
|
|
mutexAddress,
|
|
|
|
condVarAddress,
|
|
|
|
threadHandle,
|
|
|
|
timeout);
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (result != 0)
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
if (result == MakeError(ErrorModule.Kernel, KernelErr.Timeout))
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc, $"Operation failed with error 0x{result:x}!");
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{result:x}!");
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
2018-04-19 04:52:23 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = (ulong)result;
|
2018-04-19 04:52:23 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
private void SvcSignalProcessWideKey(CpuThreadState threadState)
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
long address = (long)threadState.X0;
|
|
|
|
int count = (int)threadState.X1;
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-10-17 19:15:50 +02:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc,
|
2018-12-01 21:01:59 +01:00
|
|
|
"Address = 0x" + address.ToString("x16") + ", " +
|
|
|
|
"Count = 0x" + count .ToString("x8"));
|
2018-05-16 03:36:08 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
KProcess currentProcess = _system.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
currentProcess.AddressArbiter.SignalProcessWideKey(address, count);
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = 0;
|
2018-04-19 04:52:23 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
private void SvcWaitForAddress(CpuThreadState threadState)
|
2018-07-19 06:03:53 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
long address = (long)threadState.X0;
|
|
|
|
ArbitrationType type = (ArbitrationType)threadState.X1;
|
|
|
|
int value = (int)threadState.X2;
|
|
|
|
long timeout = (long)threadState.X3;
|
2018-07-19 06:03:53 +02:00
|
|
|
|
2018-10-17 19:15:50 +02:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc,
|
2018-12-01 21:01:59 +01:00
|
|
|
"Address = 0x" + address.ToString("x16") + ", " +
|
|
|
|
"Type = " + type .ToString() + ", " +
|
|
|
|
"Value = 0x" + value .ToString("x8") + ", " +
|
|
|
|
"Timeout = 0x" + timeout.ToString("x16"));
|
2018-07-19 06:03:53 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (IsPointingInsideKernel(address))
|
2018-07-19 06:03:53 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Invalid address 0x{address:x16}!");
|
2018-07-19 06:03:53 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm);
|
2018-07-19 06:03:53 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (IsAddressNotWordAligned(address))
|
2018-07-19 06:03:53 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned address 0x{address:x16}!");
|
2018-07-19 06:03:53 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress);
|
2018-07-19 06:03:53 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
KProcess currentProcess = _system.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
long result;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
switch (type)
|
2018-07-19 06:03:53 +02:00
|
|
|
{
|
|
|
|
case ArbitrationType.WaitIfLessThan:
|
2018-12-01 21:01:59 +01:00
|
|
|
result = currentProcess.AddressArbiter.WaitForAddressIfLessThan(address, value, false, timeout);
|
2018-07-19 06:03:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ArbitrationType.DecrementAndWaitIfLessThan:
|
2018-12-01 21:01:59 +01:00
|
|
|
result = currentProcess.AddressArbiter.WaitForAddressIfLessThan(address, value, true, timeout);
|
2018-07-19 06:03:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ArbitrationType.WaitIfEqual:
|
2018-12-01 21:01:59 +01:00
|
|
|
result = currentProcess.AddressArbiter.WaitForAddressIfEqual(address, value, timeout);
|
2018-07-19 06:03:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-12-01 21:01:59 +01:00
|
|
|
result = MakeError(ErrorModule.Kernel, KernelErr.InvalidEnumValue);
|
2018-07-19 06:03:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (result != 0)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{result:x}!");
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = (ulong)result;
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
private void SvcSignalToAddress(CpuThreadState threadState)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
long address = (long)threadState.X0;
|
|
|
|
SignalType type = (SignalType)threadState.X1;
|
|
|
|
int value = (int)threadState.X2;
|
|
|
|
int count = (int)threadState.X3;
|
2018-06-22 04:05:42 +02:00
|
|
|
|
2018-10-17 19:15:50 +02:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc,
|
2018-12-01 21:01:59 +01:00
|
|
|
"Address = 0x" + address.ToString("x16") + ", " +
|
|
|
|
"Type = " + type .ToString() + ", " +
|
|
|
|
"Value = 0x" + value .ToString("x8") + ", " +
|
|
|
|
"Count = 0x" + count .ToString("x8"));
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (IsPointingInsideKernel(address))
|
2018-05-14 08:09:08 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Invalid address 0x{address:x16}!");
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (IsAddressNotWordAligned(address))
|
2018-05-14 08:01:10 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned address 0x{address:x16}!");
|
2018-06-22 04:05:42 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress);
|
2018-06-22 04:05:42 +02:00
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
return;
|
2018-04-26 04:11:26 +02:00
|
|
|
}
|
2018-05-14 08:01:10 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
KProcess currentProcess = _system.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
long result;
|
2018-06-22 04:05:42 +02:00
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
switch (type)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
case SignalType.Signal:
|
2018-12-01 21:01:59 +01:00
|
|
|
result = currentProcess.AddressArbiter.Signal(address, count);
|
2018-09-19 01:36:43 +02:00
|
|
|
break;
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
case SignalType.SignalAndIncrementIfEqual:
|
2018-12-01 21:01:59 +01:00
|
|
|
result = currentProcess.AddressArbiter.SignalAndIncrementIfEqual(address, value, count);
|
2018-09-19 01:36:43 +02:00
|
|
|
break;
|
2018-06-22 04:05:42 +02:00
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
case SignalType.SignalAndModifyIfEqual:
|
2018-12-01 21:01:59 +01:00
|
|
|
result = currentProcess.AddressArbiter.SignalAndModifyIfEqual(address, value, count);
|
2018-09-19 01:36:43 +02:00
|
|
|
break;
|
2018-06-22 04:05:42 +02:00
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
default:
|
2018-12-01 21:01:59 +01:00
|
|
|
result = MakeError(ErrorModule.Kernel, KernelErr.InvalidEnumValue);
|
2018-09-19 01:36:43 +02:00
|
|
|
break;
|
2018-06-22 04:05:42 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
if (result != 0)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{result:x}!");
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
threadState.X0 = (ulong)result;
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
private bool IsPointingInsideKernel(long address)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
return ((ulong)address + 0x1000000000) < 0xffffff000;
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:01:59 +01:00
|
|
|
private bool IsAddressNotWordAligned(long address)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-01 21:01:59 +01:00
|
|
|
return (address & 3) != 0;
|
2018-04-19 04:52:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|