2018-10-17 10:15:50 -07:00
|
|
|
using Ryujinx.Common.Logging;
|
2018-02-25 10:58:16 -08:00
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
|
|
|
|
2019-09-18 17:45:11 -07:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Lm.LogService
|
2018-02-25 10:58:16 -08:00
|
|
|
{
|
2018-03-19 11:58:46 -07:00
|
|
|
class ILogger : IpcService
|
2018-02-25 10:58:16 -08:00
|
|
|
{
|
2019-07-11 18:13:43 -07:00
|
|
|
public ILogger() { }
|
2018-02-25 10:58:16 -08:00
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(0)]
|
2020-08-03 16:32:53 -07:00
|
|
|
// Log(buffer<unknown, 0x21>)
|
|
|
|
public ResultCode Log(ServiceCtx context)
|
2019-12-08 05:35:25 -08:00
|
|
|
{
|
2020-08-03 16:32:53 -07:00
|
|
|
Logger.Guest?.Print(LogClass.ServiceLm, LogImpl(context));
|
2019-12-08 05:35:25 -08:00
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
return ResultCode.Success;
|
2019-12-08 05:35:25 -08:00
|
|
|
}
|
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
private string LogImpl(ServiceCtx context)
|
2018-02-25 10:58:16 -08:00
|
|
|
{
|
2021-04-24 03:16:01 -07:00
|
|
|
(ulong bufPos, ulong bufSize) = context.Request.GetBufferType0x21();
|
2020-05-03 15:54:50 -07:00
|
|
|
|
|
|
|
byte[] logBuffer = new byte[bufSize];
|
|
|
|
|
2021-04-24 03:16:01 -07:00
|
|
|
context.Memory.Read(bufPos, logBuffer);
|
2018-02-25 10:58:16 -08:00
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
using MemoryStream ms = new MemoryStream(logBuffer);
|
2018-02-25 10:58:16 -08:00
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
BinaryReader reader = new BinaryReader(ms);
|
2018-02-25 10:58:16 -08:00
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
long pid = reader.ReadInt64();
|
|
|
|
long threadContext = reader.ReadInt64();
|
|
|
|
short flags = reader.ReadInt16();
|
|
|
|
byte level = reader.ReadByte();
|
|
|
|
byte verbosity = reader.ReadByte();
|
|
|
|
int payloadLength = reader.ReadInt32();
|
2018-02-25 10:58:16 -08:00
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
StringBuilder sb = new StringBuilder();
|
2018-02-25 10:58:16 -08:00
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
sb.AppendLine($"Guest Log:\n Log level: {(LmLogLevel)level}");
|
2019-06-15 18:31:18 -07:00
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
while (ms.Position < ms.Length)
|
|
|
|
{
|
|
|
|
int type = ReadEncodedInt(reader);
|
|
|
|
int size = ReadEncodedInt(reader);
|
|
|
|
|
|
|
|
LmLogField field = (LmLogField)type;
|
|
|
|
|
|
|
|
string fieldStr = string.Empty;
|
|
|
|
|
|
|
|
if (field == LmLogField.Start)
|
2018-02-25 10:58:16 -08:00
|
|
|
{
|
2020-08-03 16:32:53 -07:00
|
|
|
reader.ReadBytes(size);
|
2018-02-25 10:58:16 -08:00
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (field == LmLogField.Stop)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (field == LmLogField.Line)
|
|
|
|
{
|
|
|
|
fieldStr = $"{field}: {reader.ReadInt32()}";
|
|
|
|
}
|
|
|
|
else if (field == LmLogField.DropCount)
|
|
|
|
{
|
|
|
|
fieldStr = $"{field}: {reader.ReadInt64()}";
|
|
|
|
}
|
|
|
|
else if (field == LmLogField.Time)
|
|
|
|
{
|
|
|
|
fieldStr = $"{field}: {reader.ReadInt64()}s";
|
|
|
|
}
|
|
|
|
else if (field < LmLogField.Count)
|
|
|
|
{
|
|
|
|
fieldStr = $"{field}: '{Encoding.UTF8.GetString(reader.ReadBytes(size)).TrimEnd()}'";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fieldStr = $"Field{field}: '{Encoding.UTF8.GetString(reader.ReadBytes(size)).TrimEnd()}'";
|
|
|
|
}
|
2018-02-25 10:58:16 -08:00
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
sb.AppendLine($" {fieldStr}");
|
2018-02-25 10:58:16 -08:00
|
|
|
}
|
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
return sb.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int ReadEncodedInt(BinaryReader reader)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
int position = 0;
|
|
|
|
|
|
|
|
byte encoded;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
encoded = reader.ReadByte();
|
|
|
|
|
|
|
|
result += (encoded & 0x7F) << (7 * position);
|
|
|
|
|
|
|
|
position++;
|
|
|
|
|
|
|
|
} while ((encoded & 0x80) != 0);
|
|
|
|
|
|
|
|
return result;
|
2018-02-25 10:58:16 -08:00
|
|
|
}
|
|
|
|
}
|
2019-07-11 18:13:43 -07:00
|
|
|
}
|