2018-02-04 23:08:20 +00:00
|
|
|
using ChocolArm64.Memory;
|
|
|
|
using ChocolArm64.State;
|
2018-08-17 00:47:36 +01:00
|
|
|
using Ryujinx.HLE.Exceptions;
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
|
|
|
using Ryujinx.HLE.HOS.Services;
|
2018-06-11 01:46:42 +01:00
|
|
|
using Ryujinx.HLE.Logging;
|
2018-02-04 23:08:20 +00:00
|
|
|
using System;
|
2018-02-19 19:37:13 +00:00
|
|
|
using System.Threading;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
using static Ryujinx.HLE.HOS.ErrorCode;
|
2018-03-05 19:18:37 +00:00
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
|
|
|
partial class SvcHandler
|
|
|
|
{
|
2018-02-27 23:45:07 +00:00
|
|
|
private const int AllowedCpuIdBitmask = 0b1111;
|
|
|
|
|
|
|
|
private const bool EnableProcessDebugging = false;
|
|
|
|
|
|
|
|
private void SvcExitProcess(AThreadState ThreadState)
|
|
|
|
{
|
2018-08-17 00:47:36 +01:00
|
|
|
Device.System.ExitProcess(Process.ProcessId);
|
2018-02-27 23:45:07 +00:00
|
|
|
}
|
2018-02-15 12:16:16 +00:00
|
|
|
|
2018-03-05 15:58:19 +00:00
|
|
|
private void SvcClearEvent(AThreadState ThreadState)
|
|
|
|
{
|
|
|
|
int Handle = (int)ThreadState.X0;
|
|
|
|
|
|
|
|
//TODO: Implement events.
|
|
|
|
|
2018-03-05 19:18:37 +00:00
|
|
|
ThreadState.X0 = 0;
|
2018-03-05 15:58:19 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 19:28:07 +00:00
|
|
|
private void SvcCloseHandle(AThreadState ThreadState)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-02-18 19:28:07 +00:00
|
|
|
int Handle = (int)ThreadState.X0;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
object Obj = Process.HandleTable.CloseHandle(Handle);
|
|
|
|
|
|
|
|
if (Obj == null)
|
|
|
|
{
|
2018-08-17 00:47:36 +01:00
|
|
|
Device.Log.PrintWarning(LogClass.KernelSvc, $"Invalid handle 0x{Handle:x8}!");
|
2018-03-19 18:58:46 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Obj is KSession Session)
|
|
|
|
{
|
|
|
|
Session.Dispose();
|
|
|
|
}
|
2018-08-15 19:59:51 +01:00
|
|
|
else if (Obj is KTransferMemory TransferMemory)
|
2018-03-19 18:58:46 +00:00
|
|
|
{
|
2018-08-15 19:59:51 +01:00
|
|
|
Process.MemoryManager.ResetTransferMemory(
|
|
|
|
TransferMemory.Position,
|
|
|
|
TransferMemory.Size);
|
2018-03-19 18:58:46 +00:00
|
|
|
}
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-03-05 19:18:37 +00:00
|
|
|
ThreadState.X0 = 0;
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 19:28:07 +00:00
|
|
|
private void SvcResetSignal(AThreadState ThreadState)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-02-18 19:28:07 +00:00
|
|
|
int Handle = (int)ThreadState.X0;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
KEvent Event = Process.HandleTable.GetData<KEvent>(Handle);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
if (Event != null)
|
|
|
|
{
|
2018-04-19 03:52:23 +01:00
|
|
|
Event.WaitEvent.Reset();
|
2018-03-19 18:58:46 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-17 00:47:36 +01:00
|
|
|
Device.Log.PrintWarning(LogClass.KernelSvc, $"Invalid event handle 0x{Handle:x8}!");
|
2018-03-19 18:58:46 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle);
|
|
|
|
}
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 19:28:07 +00:00
|
|
|
private void SvcWaitSynchronization(AThreadState ThreadState)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-04-19 08:06:23 +01:00
|
|
|
long HandlesPtr = (long)ThreadState.X1;
|
|
|
|
int HandlesCount = (int)ThreadState.X2;
|
|
|
|
ulong Timeout = ThreadState.X3;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
Device.Log.PrintDebug(LogClass.KernelSvc,
|
|
|
|
"HandlesPtr = 0x" + HandlesPtr .ToString("x16") + ", " +
|
|
|
|
"HandlesCount = 0x" + HandlesCount.ToString("x8") + ", " +
|
|
|
|
"Timeout = 0x" + Timeout .ToString("x16"));
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 19:53:23 +01:00
|
|
|
|
|
|
|
if ((uint)HandlesCount > 0x40)
|
|
|
|
{
|
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.CountOutOfRange);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
KThread CurrThread = Process.GetThread(ThreadState.Tpidr);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 19:53:23 +01:00
|
|
|
WaitHandle[] Handles = new WaitHandle[HandlesCount + 1];
|
2018-03-19 18:58:46 +00:00
|
|
|
|
|
|
|
for (int Index = 0; Index < HandlesCount; Index++)
|
|
|
|
{
|
|
|
|
int Handle = Memory.ReadInt32(HandlesPtr + Index * 4);
|
|
|
|
|
|
|
|
KSynchronizationObject SyncObj = Process.HandleTable.GetData<KSynchronizationObject>(Handle);
|
|
|
|
|
|
|
|
if (SyncObj == null)
|
|
|
|
{
|
2018-08-17 00:47:36 +01:00
|
|
|
Device.Log.PrintWarning(LogClass.KernelSvc, $"Invalid handle 0x{Handle:x8}!");
|
2018-03-19 18:58:46 +00:00
|
|
|
|
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-19 03:52:23 +01:00
|
|
|
Handles[Index] = SyncObj.WaitEvent;
|
2018-03-19 18:58:46 +00:00
|
|
|
}
|
2018-02-14 02:43:08 +00:00
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 19:53:23 +01:00
|
|
|
using (AutoResetEvent WaitEvent = new AutoResetEvent(false))
|
|
|
|
{
|
|
|
|
if (!SyncWaits.TryAdd(CurrThread, WaitEvent))
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
Handles[HandlesCount] = WaitEvent;
|
2018-03-19 18:58:46 +00:00
|
|
|
|
2018-05-13 04:22:42 +01:00
|
|
|
Process.Scheduler.Suspend(CurrThread);
|
2018-03-19 18:58:46 +00:00
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 19:53:23 +01:00
|
|
|
int HandleIndex;
|
2018-03-19 18:58:46 +00:00
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 19:53:23 +01:00
|
|
|
ulong Result = 0;
|
|
|
|
|
|
|
|
if (Timeout != ulong.MaxValue)
|
|
|
|
{
|
|
|
|
HandleIndex = WaitHandle.WaitAny(Handles, NsTimeConverter.GetTimeMs(Timeout));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HandleIndex = WaitHandle.WaitAny(Handles);
|
|
|
|
}
|
2018-03-19 18:58:46 +00:00
|
|
|
|
|
|
|
if (HandleIndex == WaitHandle.WaitTimeout)
|
|
|
|
{
|
|
|
|
Result = MakeError(ErrorModule.Kernel, KernelErr.Timeout);
|
|
|
|
}
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 19:53:23 +01:00
|
|
|
else if (HandleIndex == HandlesCount)
|
|
|
|
{
|
|
|
|
Result = MakeError(ErrorModule.Kernel, KernelErr.Canceled);
|
|
|
|
}
|
|
|
|
|
|
|
|
SyncWaits.TryRemove(CurrThread, out _);
|
|
|
|
|
|
|
|
Process.Scheduler.Resume(CurrThread);
|
|
|
|
|
|
|
|
ThreadState.X0 = Result;
|
|
|
|
|
|
|
|
if (Result == 0)
|
|
|
|
{
|
|
|
|
ThreadState.X1 = (ulong)HandleIndex;
|
|
|
|
}
|
2018-03-19 18:58:46 +00:00
|
|
|
}
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 19:53:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void SvcCancelSynchronization(AThreadState ThreadState)
|
|
|
|
{
|
|
|
|
int ThreadHandle = (int)ThreadState.X0;
|
|
|
|
|
|
|
|
KThread Thread = GetThread(ThreadState.Tpidr, ThreadHandle);
|
|
|
|
|
|
|
|
if (Thread == null)
|
2018-03-19 18:58:46 +00:00
|
|
|
{
|
2018-08-17 00:47:36 +01:00
|
|
|
Device.Log.PrintWarning(LogClass.KernelSvc, $"Invalid thread handle 0x{ThreadHandle:x8}!");
|
2018-03-19 18:58:46 +00:00
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 19:53:23 +01:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle);
|
2018-02-14 02:43:08 +00:00
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 19:53:23 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-03-19 18:58:46 +00:00
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 19:53:23 +01:00
|
|
|
if (SyncWaits.TryRemove(Thread, out AutoResetEvent WaitEvent))
|
2018-03-19 18:58:46 +00:00
|
|
|
{
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 19:53:23 +01:00
|
|
|
WaitEvent.Set();
|
2018-03-19 18:58:46 +00:00
|
|
|
}
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 19:53:23 +01:00
|
|
|
|
|
|
|
ThreadState.X0 = 0;
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 19:28:07 +00:00
|
|
|
private void SvcGetSystemTick(AThreadState ThreadState)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-03-10 23:51:55 +00:00
|
|
|
ThreadState.X0 = ThreadState.CntpctEl0;
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 19:28:07 +00:00
|
|
|
private void SvcConnectToNamedPort(AThreadState ThreadState)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-02-18 19:28:07 +00:00
|
|
|
long StackPtr = (long)ThreadState.X0;
|
|
|
|
long NamePtr = (long)ThreadState.X1;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
|
|
|
string Name = AMemoryHelper.ReadAsciiString(Memory, NamePtr, 8);
|
|
|
|
|
|
|
|
//TODO: Validate that app has perms to access the service, and that the service
|
|
|
|
//actually exists, return error codes otherwise.
|
2018-04-06 06:38:59 +01:00
|
|
|
KSession Session = new KSession(ServiceFactory.MakeService(Name), Name);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-03-12 04:04:52 +00:00
|
|
|
ulong Handle = (ulong)Process.HandleTable.OpenHandle(Session);
|
2018-04-05 01:01:36 +01:00
|
|
|
|
2018-03-05 19:18:37 +00:00
|
|
|
ThreadState.X0 = 0;
|
2018-03-12 04:04:52 +00:00
|
|
|
ThreadState.X1 = Handle;
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 19:28:07 +00:00
|
|
|
private void SvcSendSyncRequest(AThreadState ThreadState)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-03-19 18:58:46 +00:00
|
|
|
SendSyncRequest(ThreadState, ThreadState.Tpidr, 0x100, (int)ThreadState.X0);
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 19:28:07 +00:00
|
|
|
private void SvcSendSyncRequestWithUserBuffer(AThreadState ThreadState)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-03-19 18:58:46 +00:00
|
|
|
SendSyncRequest(
|
|
|
|
ThreadState,
|
|
|
|
(long)ThreadState.X0,
|
|
|
|
(long)ThreadState.X1,
|
|
|
|
(int)ThreadState.X2);
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
private void SendSyncRequest(AThreadState ThreadState, long CmdPtr, long Size, int Handle)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-03-19 18:58:46 +00:00
|
|
|
KThread CurrThread = Process.GetThread(ThreadState.Tpidr);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-06-09 01:15:02 +01:00
|
|
|
byte[] CmdData = Memory.ReadBytes(CmdPtr, Size);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
KSession Session = Process.HandleTable.GetData<KSession>(Handle);
|
2018-02-19 19:37:13 +00:00
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
if (Session != null)
|
|
|
|
{
|
2018-05-13 04:22:42 +01:00
|
|
|
Process.Scheduler.Suspend(CurrThread);
|
2018-02-19 19:37:13 +00:00
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
IpcMessage Cmd = new IpcMessage(CmdData, CmdPtr);
|
2018-08-14 23:02:42 +01:00
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
long Result = IpcHandler.IpcCall(Device, Process, Memory, Session, Cmd, CmdPtr);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
Thread.Yield();
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
Process.Scheduler.Resume(CurrThread);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 19:53:23 +01:00
|
|
|
ThreadState.X0 = (ulong)Result;
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-17 00:47:36 +01:00
|
|
|
Device.Log.PrintWarning(LogClass.KernelSvc, $"Invalid session handle 0x{Handle:x8}!");
|
2018-02-19 19:37:13 +00:00
|
|
|
|
2018-03-19 18:58:46 +00:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle);
|
|
|
|
}
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 19:28:07 +00:00
|
|
|
private void SvcBreak(AThreadState ThreadState)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-02-18 19:28:07 +00:00
|
|
|
long Reason = (long)ThreadState.X0;
|
|
|
|
long Unknown = (long)ThreadState.X1;
|
|
|
|
long Info = (long)ThreadState.X2;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-04-22 06:48:17 +01:00
|
|
|
Process.PrintStackTrace(ThreadState);
|
|
|
|
|
2018-02-14 02:43:08 +00:00
|
|
|
throw new GuestBrokeExecutionException();
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 19:28:07 +00:00
|
|
|
private void SvcOutputDebugString(AThreadState ThreadState)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-02-18 19:28:07 +00:00
|
|
|
long Position = (long)ThreadState.X0;
|
|
|
|
long Size = (long)ThreadState.X1;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-03-16 00:06:24 +00:00
|
|
|
string Str = AMemoryHelper.ReadAsciiString(Memory, Position, Size);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
Device.Log.PrintWarning(LogClass.KernelSvc, Str);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-03-05 19:18:37 +00:00
|
|
|
ThreadState.X0 = 0;
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 19:28:07 +00:00
|
|
|
private void SvcGetInfo(AThreadState ThreadState)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-02-18 19:28:07 +00:00
|
|
|
long StackPtr = (long)ThreadState.X0;
|
|
|
|
int InfoType = (int)ThreadState.X1;
|
|
|
|
long Handle = (long)ThreadState.X2;
|
|
|
|
int InfoId = (int)ThreadState.X3;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-02-06 23:28:32 +00:00
|
|
|
//Fail for info not available on older Kernel versions.
|
|
|
|
if (InfoType == 18 ||
|
2018-03-30 16:27:48 +01:00
|
|
|
InfoType == 19 ||
|
2018-09-18 05:30:35 +01:00
|
|
|
InfoType == 20 ||
|
|
|
|
InfoType == 21)
|
2018-02-06 23:28:32 +00:00
|
|
|
{
|
2018-07-19 05:03:53 +01:00
|
|
|
ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidEnumValue);
|
2018-02-06 23:28:32 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-04 23:08:20 +00:00
|
|
|
switch (InfoType)
|
|
|
|
{
|
2018-02-27 23:45:07 +00:00
|
|
|
case 0:
|
|
|
|
ThreadState.X1 = AllowedCpuIdBitmask;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2018-08-15 19:59:51 +01:00
|
|
|
ThreadState.X1 = (ulong)Process.MemoryManager.MapRegionStart;
|
2018-02-27 23:45:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2018-08-15 19:59:51 +01:00
|
|
|
ThreadState.X1 = (ulong)Process.MemoryManager.MapRegionEnd -
|
|
|
|
(ulong)Process.MemoryManager.MapRegionStart;
|
2018-02-27 23:45:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2018-08-15 19:59:51 +01:00
|
|
|
ThreadState.X1 = (ulong)Process.MemoryManager.HeapRegionStart;
|
2018-02-27 23:45:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
2018-08-15 19:59:51 +01:00
|
|
|
ThreadState.X1 = (ulong)Process.MemoryManager.HeapRegionEnd -
|
|
|
|
(ulong)Process.MemoryManager.HeapRegionStart;
|
2018-02-27 23:45:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
2018-08-17 00:47:36 +01:00
|
|
|
ThreadState.X1 = (ulong)Process.Device.Memory.Allocator.TotalAvailableSize;
|
2018-02-27 23:45:07 +00:00
|
|
|
break;
|
2018-04-05 01:01:36 +01:00
|
|
|
|
2018-02-27 23:45:07 +00:00
|
|
|
case 7:
|
2018-08-17 00:47:36 +01:00
|
|
|
ThreadState.X1 = (ulong)Process.Device.Memory.Allocator.TotalUsedSize;
|
2018-02-27 23:45:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
ThreadState.X1 = EnableProcessDebugging ? 1 : 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
ThreadState.X1 = (ulong)Rng.Next() + ((ulong)Rng.Next() << 32);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 12:
|
2018-08-15 19:59:51 +01:00
|
|
|
ThreadState.X1 = (ulong)Process.MemoryManager.AddrSpaceStart;
|
2018-02-27 23:45:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 13:
|
2018-08-15 19:59:51 +01:00
|
|
|
ThreadState.X1 = (ulong)Process.MemoryManager.AddrSpaceEnd -
|
|
|
|
(ulong)Process.MemoryManager.AddrSpaceStart;
|
2018-02-27 23:45:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 14:
|
2018-08-15 19:59:51 +01:00
|
|
|
ThreadState.X1 = (ulong)Process.MemoryManager.NewMapRegionStart;
|
2018-02-27 23:45:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
2018-08-15 19:59:51 +01:00
|
|
|
ThreadState.X1 = (ulong)Process.MemoryManager.NewMapRegionEnd -
|
|
|
|
(ulong)Process.MemoryManager.NewMapRegionStart;
|
2018-02-27 23:45:07 +00:00
|
|
|
break;
|
2018-06-11 01:46:42 +01:00
|
|
|
|
2018-05-22 21:40:46 +01:00
|
|
|
case 16:
|
2018-08-15 19:59:51 +01:00
|
|
|
ThreadState.X1 = (ulong)(Process.MetaData?.SystemResourceSize ?? 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 17:
|
|
|
|
ThreadState.X1 = (ulong)Process.MemoryManager.PersonalMmHeapUsage;
|
2018-05-22 21:40:46 +01:00
|
|
|
break;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-04-22 06:48:17 +01:00
|
|
|
default:
|
|
|
|
Process.PrintStackTrace(ThreadState);
|
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
throw new NotImplementedException($"SvcGetInfo: {InfoType} 0x{Handle:x8} {InfoId}");
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 19:18:37 +00:00
|
|
|
ThreadState.X0 = 0;
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-24 23:09:10 +00:00
|
|
|
}
|