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
|
|
|
|
|
{
|
|
|
|
|
public ServiceCtx Context { get; }
|
2019-01-21 03:04:52 +01:00
|
|
|
|
public IpcMessage Request { get; }
|
2019-01-11 01:11:46 +01:00
|
|
|
|
|
|
|
|
|
public ServiceNotImplementedException(ServiceCtx context)
|
|
|
|
|
: this(context, "The service call is not implemented.")
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
public ServiceNotImplementedException(ServiceCtx context, string message)
|
|
|
|
|
: base(message)
|
|
|
|
|
{
|
|
|
|
|
Context = context;
|
|
|
|
|
Request = context.Request;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ServiceNotImplementedException(ServiceCtx context, string message, Exception inner)
|
|
|
|
|
: base(message, inner)
|
|
|
|
|
{
|
|
|
|
|
Context = context;
|
|
|
|
|
Request = context.Request;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected ServiceNotImplementedException(SerializationInfo info, StreamingContext context)
|
|
|
|
|
: 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)
|
|
|
|
|
{
|
|
|
|
|
var ipcService = Context.Session.Service;
|
|
|
|
|
var ipcCommands = ipcService.Commands;
|
|
|
|
|
|
|
|
|
|
// Find the handler for the method called
|
2019-07-12 03:13:43 +02:00
|
|
|
|
var ipcHandler = ipcCommands.FirstOrDefault(x => x.Value as MethodBase == callingMethod);
|
2019-01-11 01:11:46 +01:00
|
|
|
|
var ipcCommandId = ipcHandler.Key;
|
|
|
|
|
var ipcMethod = ipcHandler.Value;
|
|
|
|
|
|
|
|
|
|
if (ipcMethod != null)
|
|
|
|
|
{
|
2019-07-12 03:13:43 +02:00
|
|
|
|
sb.AppendLine($"Service Command: {ipcService.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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|