2019-01-11 01:11:46 +01: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
|
|
|
|
|
{
|
2020-12-02 00:23:43 +01:00
|
|
|
|
public IIpcService Service { get; }
|
2019-01-11 01:11:46 +01:00
|
|
|
|
public ServiceCtx Context { get; }
|
2019-01-21 03:04:52 +01:00
|
|
|
|
public IpcMessage Request { get; }
|
2019-01-11 01:11:46 +01:00
|
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
|
public ServiceNotImplementedException(IIpcService service, ServiceCtx context)
|
|
|
|
|
: this(service, context, "The service call is not implemented.")
|
2019-01-11 01:11:46 +01:00
|
|
|
|
{ }
|
|
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
|
public ServiceNotImplementedException(IIpcService service, ServiceCtx context, string message)
|
2019-01-11 01:11:46 +01:00
|
|
|
|
: base(message)
|
|
|
|
|
{
|
2020-12-02 00:23:43 +01:00
|
|
|
|
Service = service;
|
2019-01-11 01:11:46 +01:00
|
|
|
|
Context = context;
|
|
|
|
|
Request = context.Request;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
|
public ServiceNotImplementedException(IIpcService service, ServiceCtx context, string message, Exception inner)
|
2019-01-11 01:11:46 +01:00
|
|
|
|
: base(message, inner)
|
|
|
|
|
{
|
2020-12-02 00:23:43 +01:00
|
|
|
|
Service = service;
|
2019-01-11 01:11:46 +01:00
|
|
|
|
Context = context;
|
|
|
|
|
Request = context.Request;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
|
protected ServiceNotImplementedException(SerializationInfo info, StreamingContext context)
|
2019-01-11 01:11:46 +01: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)
|
|
|
|
|
{
|
2020-12-02 00:23:43 +01:00
|
|
|
|
var ipcCommands = Service.Commands;
|
2019-01-11 01:11:46 +01:00
|
|
|
|
|
|
|
|
|
// Find the handler for the method called
|
2020-12-02 00:23:43 +01:00
|
|
|
|
var ipcHandler = ipcCommands.FirstOrDefault(x => x.Value == callingMethod);
|
2019-01-11 01:11:46 +01:00
|
|
|
|
var ipcCommandId = ipcHandler.Key;
|
|
|
|
|
var ipcMethod = ipcHandler.Value;
|
|
|
|
|
|
|
|
|
|
if (ipcMethod != null)
|
|
|
|
|
{
|
2020-12-02 00:23:43 +01:00
|
|
|
|
sb.AppendLine($"Service Command: {Service.GetType().FullName}: {ipcCommandId} ({ipcMethod.Name})");
|
2019-01-11 01:11:46 +01:00
|
|
|
|
sb.AppendLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-15 04:37:54 +01:00
|
|
|
|
sb.AppendLine("Guest Stack Trace:");
|
|
|
|
|
sb.AppendLine(Context.Thread.GetGuestStackTrace());
|
2019-01-11 01:11:46 +01:00
|
|
|
|
|
2019-03-15 04:37:54 +01: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-11 01:11:46 +01:00
|
|
|
|
{
|
2019-03-15 04:37:54 +01:00
|
|
|
|
sb.AppendLine("Buffer Information:");
|
2019-01-11 01:11:46 +01:00
|
|
|
|
|
2019-03-15 04:37:54 +01:00
|
|
|
|
if (Request.PtrBuff.Count > 0)
|
2019-01-11 01:11:46 +01:00
|
|
|
|
{
|
2019-03-15 04:37:54 +01:00
|
|
|
|
sb.AppendLine("\tPtrBuff:");
|
2019-01-11 01:11:46 +01:00
|
|
|
|
|
2019-03-15 04:37:54 +01:00
|
|
|
|
foreach (var buff in Request.PtrBuff)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine($"\t[{buff.Index}] Position: 0x{buff.Position:x16} Size: 0x{buff.Size:x16}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-11 01:11:46 +01:00
|
|
|
|
|
2019-03-15 04:37:54 +01:00
|
|
|
|
if (Request.SendBuff.Count > 0)
|
2019-01-11 01:11:46 +01:00
|
|
|
|
{
|
2019-03-15 04:37:54 +01:00
|
|
|
|
sb.AppendLine("\tSendBuff:");
|
2019-01-11 01:11:46 +01:00
|
|
|
|
|
2019-03-15 04:37:54 +01:00
|
|
|
|
foreach (var buff in Request.SendBuff)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine($"\tPosition: 0x{buff.Position:x16} Size: 0x{buff.Size:x16} Flags: {buff.Flags}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-11 01:11:46 +01:00
|
|
|
|
|
2019-03-15 04:37:54 +01:00
|
|
|
|
if (Request.ReceiveBuff.Count > 0)
|
2019-01-11 01:11:46 +01:00
|
|
|
|
{
|
2019-03-15 04:37:54 +01:00
|
|
|
|
sb.AppendLine("\tReceiveBuff:");
|
2019-01-11 01:11:46 +01:00
|
|
|
|
|
2019-03-15 04:37:54 +01:00
|
|
|
|
foreach (var buff in Request.ReceiveBuff)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine($"\tPosition: 0x{buff.Position:x16} Size: 0x{buff.Size:x16} Flags: {buff.Flags}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-11 01:11:46 +01:00
|
|
|
|
|
2019-03-15 04:37:54 +01:00
|
|
|
|
if (Request.ExchangeBuff.Count > 0)
|
2019-01-11 01:11:46 +01:00
|
|
|
|
{
|
2019-03-15 04:37:54 +01:00
|
|
|
|
sb.AppendLine("\tExchangeBuff:");
|
2019-01-11 01:11:46 +01:00
|
|
|
|
|
2019-03-15 04:37:54 +01:00
|
|
|
|
foreach (var buff in Request.ExchangeBuff)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine($"\tPosition: 0x{buff.Position:x16} Size: 0x{buff.Size:x16} Flags: {buff.Flags}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-11 01:11:46 +01:00
|
|
|
|
|
2019-03-15 04:37:54 +01:00
|
|
|
|
if (Request.RecvListBuff.Count > 0)
|
2019-01-11 01:11:46 +01:00
|
|
|
|
{
|
2019-03-15 04:37:54 +01:00
|
|
|
|
sb.AppendLine("\tRecvListBuff:");
|
|
|
|
|
|
|
|
|
|
foreach (var buff in Request.RecvListBuff)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine($"\tPosition: 0x{buff.Position:x16} Size: 0x{buff.Size:x16}");
|
|
|
|
|
}
|
2019-01-11 01:11:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-15 04:37:54 +01:00
|
|
|
|
sb.AppendLine();
|
|
|
|
|
}
|
2019-01-11 01:11:46 +01: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;
|
|
|
|
|
|
|
|
|
|
if (typeof(IIpcService).IsAssignableFrom(declType))
|
|
|
|
|
{
|
|
|
|
|
return (declType, method);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (null, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|