2018-02-05 00:08:20 +01:00
|
|
|
using ChocolArm64.Memory;
|
2018-12-18 06:33:36 +01:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Ipc;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Process;
|
2019-03-15 04:37:54 +01:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2018-02-05 00:08:20 +01:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
namespace Ryujinx.HLE.HOS.Ipc
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
static class IpcHandler
|
|
|
|
{
|
2018-12-18 06:33:36 +01:00
|
|
|
public static KernelResult IpcCall(
|
2019-01-18 23:26:39 +01:00
|
|
|
Switch device,
|
|
|
|
KProcess process,
|
|
|
|
MemoryManager memory,
|
2019-03-15 04:37:54 +01:00
|
|
|
KThread thread,
|
2019-01-18 23:26:39 +01:00
|
|
|
KClientSession session,
|
|
|
|
IpcMessage request,
|
|
|
|
long cmdPtr)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
IpcMessage response = new IpcMessage();
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
using (MemoryStream raw = new MemoryStream(request.RawData))
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
BinaryReader reqReader = new BinaryReader(raw);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (request.Type == IpcMessageType.Request ||
|
|
|
|
request.Type == IpcMessageType.RequestWithContext)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
response.Type = IpcMessageType.Response;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
using (MemoryStream resMs = new MemoryStream())
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
BinaryWriter resWriter = new BinaryWriter(resMs);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
ServiceCtx context = new ServiceCtx(
|
|
|
|
device,
|
|
|
|
process,
|
|
|
|
memory,
|
2019-03-15 04:37:54 +01:00
|
|
|
thread,
|
2018-12-06 12:16:24 +01:00
|
|
|
session,
|
|
|
|
request,
|
|
|
|
response,
|
|
|
|
reqReader,
|
|
|
|
resWriter);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
session.Service.CallMethod(context);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
response.RawData = resMs.ToArray();
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
else if (request.Type == IpcMessageType.Control ||
|
|
|
|
request.Type == IpcMessageType.ControlWithContext)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
long magic = reqReader.ReadInt64();
|
|
|
|
long cmdId = reqReader.ReadInt64();
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
switch (cmdId)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-03-12 05:04:52 +01:00
|
|
|
case 0:
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
request = FillResponse(response, 0, session.Service.ConvertToDomain());
|
2018-03-12 05:04:52 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
request = FillResponse(response, 0, 0x500);
|
2018-04-05 02:01:36 +02:00
|
|
|
|
2018-03-12 05:04:52 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-04-05 02:01:36 +02:00
|
|
|
//TODO: Whats the difference between IpcDuplicateSession/Ex?
|
|
|
|
case 2:
|
2018-03-12 05:04:52 +01:00
|
|
|
case 4:
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
int unknown = reqReader.ReadInt32();
|
2018-03-12 05:04:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (process.HandleTable.GenerateHandle(session, out int handle) != KernelResult.Success)
|
2018-09-23 20:11:46 +02:00
|
|
|
{
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
}
|
2018-03-12 05:04:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
response.HandleDesc = IpcHandleDesc.MakeMove(handle);
|
2018-03-12 05:04:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
request = FillResponse(response, 0);
|
2018-03-12 05:04:52 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
default: throw new NotImplementedException(cmdId.ToString());
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
else if (request.Type == IpcMessageType.CloseSession)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
//TODO
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
throw new NotImplementedException(request.Type.ToString());
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
memory.WriteBytes(cmdPtr, response.GetBytes(cmdPtr));
|
2018-02-05 00:08:20 +01: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 20:53:23 +02:00
|
|
|
|
2018-12-18 06:33:36 +01:00
|
|
|
return KernelResult.Success;
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private static IpcMessage FillResponse(IpcMessage response, long result, params int[] values)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
using (MemoryStream ms = new MemoryStream())
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
BinaryWriter writer = new BinaryWriter(ms);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
foreach (int value in values)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
writer.Write(value);
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return FillResponse(response, result, ms.ToArray());
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private static IpcMessage FillResponse(IpcMessage response, long result, byte[] data = null)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
response.Type = IpcMessageType.Response;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
using (MemoryStream ms = new MemoryStream())
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
BinaryWriter writer = new BinaryWriter(ms);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
writer.Write(IpcMagic.Sfco);
|
|
|
|
writer.Write(result);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (data != null)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
writer.Write(data);
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
response.RawData = ms.ToArray();
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return response;
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-25 00:08:29 +01:00
|
|
|
}
|