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-05 01:52:39 +01:00
|
|
|
private void SvcWaitSynchronization(CpuThreadState ThreadState)
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
if ((uint)HandlesCount > 0x40)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.CountOutOfRange);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
List<KSynchronizationObject> SyncObjs = new List<KSynchronizationObject>();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
for (int Index = 0; Index < HandlesCount; Index++)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
int Handle = Memory.ReadInt32(HandlesPtr + Index * 4);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc, $"Sync handle 0x{Handle:x8}");
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
KSynchronizationObject SyncObj = Process.HandleTable.GetObject<KSynchronizationObject>(Handle);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (SyncObj == null)
|
2018-09-23 20:11:46 +02:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
SyncObjs.Add(SyncObj);
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
int HndIndex = (int)ThreadState.X1;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ulong High = ThreadState.X1 & (0xffffffffUL << 32);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
long Result = System.Synchronization.WaitFor(SyncObjs.ToArray(), Timeout, ref HndIndex);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Result != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc, $"Operation failed with error 0x{Result:x}!");
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = (ulong)Result;
|
|
|
|
ThreadState.X1 = (uint)HndIndex | High;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private void SvcCancelSynchronization(CpuThreadState ThreadState)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
int ThreadHandle = (int)ThreadState.X0;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc, "ThreadHandle = 0x" + ThreadHandle.ToString("x8"));
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
KThread Thread = Process.HandleTable.GetKThread(ThreadHandle);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Thread == null)
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Invalid thread handle 0x{ThreadHandle:x8}!");
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle);
|
2018-04-19 04:52:23 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
Thread.CancelSynchronization();
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = 0;
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private void SvcArbitrateLock(CpuThreadState ThreadState)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
if (IsPointingInsideKernel(MutexAddress))
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Invalid mutex address 0x{MutexAddress:x16}!");
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm);
|
2018-04-19 04:52:23 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (IsAddressNotWordAligned(MutexAddress))
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned mutex address 0x{MutexAddress:x16}!");
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
long Result = CurrentProcess.AddressArbiter.ArbitrateLock(OwnerHandle, MutexAddress, RequesterHandle);
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Result != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{Result:x}!");
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = (ulong)Result;
|
2018-04-19 04:52:23 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private void SvcArbitrateUnlock(CpuThreadState ThreadState)
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
long MutexAddress = (long)ThreadState.X0;
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc, "MutexAddress = 0x" + MutexAddress.ToString("x16"));
|
2018-04-26 04:11:26 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (IsPointingInsideKernel(MutexAddress))
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Invalid mutex address 0x{MutexAddress:x16}!");
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (IsAddressNotWordAligned(MutexAddress))
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned mutex address 0x{MutexAddress:x16}!");
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
long Result = CurrentProcess.AddressArbiter.ArbitrateUnlock(MutexAddress);
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Result != 0)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{Result:x}!");
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = (ulong)Result;
|
2018-04-19 04:52:23 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private void SvcWaitProcessWideKeyAtomic(CpuThreadState ThreadState)
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
if (IsPointingInsideKernel(MutexAddress))
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Invalid mutex address 0x{MutexAddress:x16}!");
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (IsAddressNotWordAligned(MutexAddress))
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned mutex address 0x{MutexAddress:x16}!");
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
long Result = CurrentProcess.AddressArbiter.WaitProcessWideKeyAtomic(
|
|
|
|
MutexAddress,
|
|
|
|
CondVarAddress,
|
|
|
|
ThreadHandle,
|
|
|
|
Timeout);
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Result != 0)
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Result == MakeError(ErrorModule.Kernel, KernelErr.Timeout))
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintDebug(LogClass.KernelSvc, $"Operation failed with error 0x{Result:x}!");
|
2018-09-19 01:36:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = (ulong)Result;
|
2018-04-19 04:52:23 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private void SvcSignalProcessWideKey(CpuThreadState ThreadState)
|
2018-04-19 04:52:23 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
"Address = 0x" + Address.ToString("x16") + ", " +
|
|
|
|
"Count = 0x" + Count .ToString("x8"));
|
2018-05-16 03:36:08 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
CurrentProcess.AddressArbiter.SignalProcessWideKey(Address, Count);
|
2018-04-19 04:52:23 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = 0;
|
2018-04-19 04:52:23 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private void SvcWaitForAddress(CpuThreadState ThreadState)
|
2018-07-19 06:03:53 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
if (IsPointingInsideKernel(Address))
|
2018-07-19 06:03:53 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Invalid address 0x{Address:x16}!");
|
2018-07-19 06:03:53 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm);
|
2018-07-19 06:03:53 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (IsAddressNotWordAligned(Address))
|
2018-07-19 06:03:53 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned address 0x{Address:x16}!");
|
2018-07-19 06:03:53 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidAddress);
|
2018-07-19 06:03:53 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
long Result;
|
2018-09-19 01:36:43 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
switch (Type)
|
2018-07-19 06:03:53 +02:00
|
|
|
{
|
|
|
|
case ArbitrationType.WaitIfLessThan:
|
2018-12-05 01:52:39 +01:00
|
|
|
Result = CurrentProcess.AddressArbiter.WaitForAddressIfLessThan(Address, Value, false, Timeout);
|
2018-07-19 06:03:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ArbitrationType.DecrementAndWaitIfLessThan:
|
2018-12-05 01:52:39 +01:00
|
|
|
Result = CurrentProcess.AddressArbiter.WaitForAddressIfLessThan(Address, Value, true, Timeout);
|
2018-07-19 06:03:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ArbitrationType.WaitIfEqual:
|
2018-12-05 01:52:39 +01:00
|
|
|
Result = CurrentProcess.AddressArbiter.WaitForAddressIfEqual(Address, Value, Timeout);
|
2018-07-19 06:03:53 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-12-05 01:52:39 +01:00
|
|
|
Result = MakeError(ErrorModule.Kernel, KernelErr.InvalidEnumValue);
|
2018-07-19 06:03:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Result != 0)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{Result:x}!");
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = (ulong)Result;
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private void SvcSignalToAddress(CpuThreadState ThreadState)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
if (IsPointingInsideKernel(Address))
|
2018-05-14 08:09:08 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Invalid address 0x{Address:x16}!");
|
2018-04-21 21:07:16 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.NoAccessPerm);
|
2018-04-21 21:07:16 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (IsAddressNotWordAligned(Address))
|
2018-05-14 08:01:10 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Unaligned address 0x{Address:x16}!");
|
2018-06-22 04:05:42 +02:00
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
long Result;
|
2018-06-22 04:05:42 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
switch (Type)
|
2018-09-19 01:36:43 +02:00
|
|
|
{
|
|
|
|
case SignalType.Signal:
|
2018-12-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
if (Result != 0)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Logger.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{Result:x}!");
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
ThreadState.X0 = (ulong)Result;
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private bool IsPointingInsideKernel(long Address)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
return ((ulong)Address + 0x1000000000) < 0xffffff000;
|
2018-04-21 21:07:16 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private bool IsAddressNotWordAligned(long Address)
|
2018-04-21 21:07:16 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
return (Address & 3) != 0;
|
2018-04-19 04:52:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|