2019-01-10 19:11:46 -05:00
|
|
|
|
using Ryujinx.Common;
|
|
|
|
|
using Ryujinx.HLE.HOS;
|
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
|
|
|
|
using Ryujinx.HLE.HOS.Services;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.Exceptions
|
|
|
|
|
{
|
|
|
|
|
[Serializable]
|
|
|
|
|
internal class ServiceNotImplementedException : Exception
|
|
|
|
|
{
|
2021-03-18 19:31:08 -04:00
|
|
|
|
public IpcService Service { get; }
|
2019-01-10 19:11:46 -05:00
|
|
|
|
public ServiceCtx Context { get; }
|
2019-01-20 21:04:52 -05:00
|
|
|
|
public IpcMessage Request { get; }
|
2019-01-10 19:11:46 -05:00
|
|
|
|
|
2021-08-11 15:16:42 -04:00
|
|
|
|
public ServiceNotImplementedException(IpcService service, ServiceCtx context)
|
|
|
|
|
: this(service, context, "The service call is not implemented.")
|
2019-01-10 19:11:46 -05:00
|
|
|
|
{ }
|
|
|
|
|
|
2021-08-11 15:16:42 -04:00
|
|
|
|
public ServiceNotImplementedException(IpcService service, ServiceCtx context, string message)
|
2019-01-10 19:11:46 -05:00
|
|
|
|
: base(message)
|
|
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
|
Service = service;
|
2019-01-10 19:11:46 -05:00
|
|
|
|
Context = context;
|
|
|
|
|
Request = context.Request;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 15:16:42 -04:00
|
|
|
|
public ServiceNotImplementedException(IpcService service, ServiceCtx context, string message, Exception inner)
|
2019-01-10 19:11:46 -05:00
|
|
|
|
: base(message, inner)
|
|
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
|
Service = service;
|
2019-01-10 19:11:46 -05:00
|
|
|
|
Context = context;
|
|
|
|
|
Request = context.Request;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
|
protected ServiceNotImplementedException(SerializationInfo info, StreamingContext context)
|
2019-01-10 19:11:46 -05:00
|
|
|
|
: base(info, context)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
public override string Message
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return base.Message +
|
|
|
|
|
Environment.NewLine +
|
|
|
|
|
Environment.NewLine +
|
|
|
|
|
BuildMessage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string BuildMessage()
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
// Print the IPC command details (service name, command ID, and handler)
|
|
|
|
|
(Type callingType, MethodBase callingMethod) = WalkStackTrace(new StackTrace(this));
|
|
|
|
|
|
|
|
|
|
if (callingType != null && callingMethod != null)
|
|
|
|
|
{
|
2021-08-11 15:16:42 -04:00
|
|
|
|
// If the type is past 0xF, we are using TIPC
|
|
|
|
|
var ipcCommands = Request.Type > IpcMessageType.TipcCloseSession ?
|
|
|
|
|
Service.TipcCommands : Service.HipcCommands;
|
2019-01-10 19:11:46 -05:00
|
|
|
|
|
|
|
|
|
// Find the handler for the method called
|
2020-12-01 18:23:43 -05:00
|
|
|
|
var ipcHandler = ipcCommands.FirstOrDefault(x => x.Value == callingMethod);
|
2019-01-10 19:11:46 -05:00
|
|
|
|
var ipcCommandId = ipcHandler.Key;
|
|
|
|
|
var ipcMethod = ipcHandler.Value;
|
|
|
|
|
|
|
|
|
|
if (ipcMethod != null)
|
|
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
|
sb.AppendLine($"Service Command: {Service.GetType().FullName}: {ipcCommandId} ({ipcMethod.Name})");
|
2019-01-10 19:11:46 -05:00
|
|
|
|
sb.AppendLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-14 23:37:54 -04:00
|
|
|
|
sb.AppendLine("Guest Stack Trace:");
|
|
|
|
|
sb.AppendLine(Context.Thread.GetGuestStackTrace());
|
2019-01-10 19:11:46 -05:00
|
|
|
|
|
2019-03-14 23:37:54 -04:00
|
|
|
|
// Print buffer information
|
|
|
|
|
if (Request.PtrBuff.Count > 0 ||
|
|
|
|
|
Request.SendBuff.Count > 0 ||
|
|
|
|
|
Request.ReceiveBuff.Count > 0 ||
|
|
|
|
|
Request.ExchangeBuff.Count > 0 ||
|
|
|
|
|
Request.RecvListBuff.Count > 0)
|
2019-01-10 19:11:46 -05:00
|
|
|
|
{
|
2019-03-14 23:37:54 -04:00
|
|
|
|
sb.AppendLine("Buffer Information:");
|
2019-01-10 19:11:46 -05:00
|
|
|
|
|
2019-03-14 23:37:54 -04:00
|
|
|
|
if (Request.PtrBuff.Count > 0)
|
2019-01-10 19:11:46 -05:00
|
|
|
|
{
|
2019-03-14 23:37:54 -04:00
|
|
|
|
sb.AppendLine("\tPtrBuff:");
|
2019-01-10 19:11:46 -05:00
|
|
|
|
|
2019-03-14 23:37:54 -04:00
|
|
|
|
foreach (var buff in Request.PtrBuff)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine($"\t[{buff.Index}] Position: 0x{buff.Position:x16} Size: 0x{buff.Size:x16}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-10 19:11:46 -05:00
|
|
|
|
|
2019-03-14 23:37:54 -04:00
|
|
|
|
if (Request.SendBuff.Count > 0)
|
2019-01-10 19:11:46 -05:00
|
|
|
|
{
|
2019-03-14 23:37:54 -04:00
|
|
|
|
sb.AppendLine("\tSendBuff:");
|
2019-01-10 19:11:46 -05:00
|
|
|
|
|
2019-03-14 23:37:54 -04:00
|
|
|
|
foreach (var buff in Request.SendBuff)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine($"\tPosition: 0x{buff.Position:x16} Size: 0x{buff.Size:x16} Flags: {buff.Flags}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-10 19:11:46 -05:00
|
|
|
|
|
2019-03-14 23:37:54 -04:00
|
|
|
|
if (Request.ReceiveBuff.Count > 0)
|
2019-01-10 19:11:46 -05:00
|
|
|
|
{
|
2019-03-14 23:37:54 -04:00
|
|
|
|
sb.AppendLine("\tReceiveBuff:");
|
2019-01-10 19:11:46 -05:00
|
|
|
|
|
2019-03-14 23:37:54 -04:00
|
|
|
|
foreach (var buff in Request.ReceiveBuff)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine($"\tPosition: 0x{buff.Position:x16} Size: 0x{buff.Size:x16} Flags: {buff.Flags}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-10 19:11:46 -05:00
|
|
|
|
|
2019-03-14 23:37:54 -04:00
|
|
|
|
if (Request.ExchangeBuff.Count > 0)
|
2019-01-10 19:11:46 -05:00
|
|
|
|
{
|
2019-03-14 23:37:54 -04:00
|
|
|
|
sb.AppendLine("\tExchangeBuff:");
|
2019-01-10 19:11:46 -05:00
|
|
|
|
|
2019-03-14 23:37:54 -04:00
|
|
|
|
foreach (var buff in Request.ExchangeBuff)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine($"\tPosition: 0x{buff.Position:x16} Size: 0x{buff.Size:x16} Flags: {buff.Flags}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-10 19:11:46 -05:00
|
|
|
|
|
2019-03-14 23:37:54 -04:00
|
|
|
|
if (Request.RecvListBuff.Count > 0)
|
2019-01-10 19:11:46 -05:00
|
|
|
|
{
|
2019-03-14 23:37:54 -04:00
|
|
|
|
sb.AppendLine("\tRecvListBuff:");
|
|
|
|
|
|
|
|
|
|
foreach (var buff in Request.RecvListBuff)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine($"\tPosition: 0x{buff.Position:x16} Size: 0x{buff.Size:x16}");
|
|
|
|
|
}
|
2019-01-10 19:11:46 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-14 23:37:54 -04:00
|
|
|
|
sb.AppendLine();
|
|
|
|
|
}
|
2019-01-10 19:11:46 -05:00
|
|
|
|
|
|
|
|
|
sb.AppendLine("Raw Request Data:");
|
|
|
|
|
sb.Append(HexUtils.HexTable(Request.RawData));
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private (Type, MethodBase) WalkStackTrace(StackTrace trace)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
StackFrame frame;
|
|
|
|
|
// Find the IIpcService method that threw this exception
|
|
|
|
|
while ((frame = trace.GetFrame(i++)) != null)
|
|
|
|
|
{
|
|
|
|
|
var method = frame.GetMethod();
|
|
|
|
|
var declType = method.DeclaringType;
|
|
|
|
|
|
2021-03-18 19:31:08 -04:00
|
|
|
|
if (typeof(IpcService).IsAssignableFrom(declType))
|
2019-01-10 19:11:46 -05:00
|
|
|
|
{
|
|
|
|
|
return (declType, method);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (null, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|