mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2025-06-28 18:20:47 -07:00
Horizon: Impl Prepo, Fixes bugs, Clean things (#4220)
* Horizon: Impl Prepo, Fixes bugs, Clean things * remove ToArray() * resultCode > status * Remove old services * Addresses gdkchan's comments and more cleanup * Addresses Gdkchan's feedback 2 * Reorganize services, make sure service are loaded before guest Co-Authored-By: gdkchan <5624669+gdkchan@users.noreply.github.com> * Create interfaces for lm and sm Co-authored-by: gdkchan <5624669+gdkchan@users.noreply.github.com>
This commit is contained in:
@ -9,23 +9,23 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.Horizon.LogManager
|
||||
namespace Ryujinx.Horizon.LogManager.Ipc
|
||||
{
|
||||
partial class LmLogger : IServiceObject
|
||||
partial class LmLogger : ILmLogger
|
||||
{
|
||||
private readonly LmLog _log;
|
||||
private readonly ulong _clientProcessId;
|
||||
private readonly LogService _log;
|
||||
private readonly ulong _pid;
|
||||
|
||||
public LmLogger(LmLog log, ulong clientProcessId)
|
||||
public LmLogger(LogService log, ulong pid)
|
||||
{
|
||||
_log = log;
|
||||
_clientProcessId = clientProcessId;
|
||||
_pid = pid;
|
||||
}
|
||||
|
||||
[CmifCommand(0)]
|
||||
public Result Log([Buffer(HipcBufferFlags.In | HipcBufferFlags.AutoSelect)] Span<byte> message)
|
||||
{
|
||||
if (!SetProcessId(message, _clientProcessId))
|
||||
if (!SetProcessId(message, _pid))
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
@ -35,7 +35,7 @@ namespace Ryujinx.Horizon.LogManager
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
[CmifCommand(1)]
|
||||
[CmifCommand(1)] // 3.0.0+
|
||||
public Result SetDestination(LogDestination destination)
|
||||
{
|
||||
_log.LogDestination = destination;
|
||||
@ -48,7 +48,6 @@ namespace Ryujinx.Horizon.LogManager
|
||||
ref LogPacketHeader header = ref MemoryMarshal.Cast<byte, LogPacketHeader>(message)[0];
|
||||
|
||||
uint expectedMessageSize = (uint)Unsafe.SizeOf<LogPacketHeader>() + header.PayloadSize;
|
||||
|
||||
if (expectedMessageSize != (uint)message.Length)
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.ServiceLm, $"Invalid message size (expected 0x{expectedMessageSize:X} but got 0x{message.Length:X}).");
|
||||
@ -63,13 +62,11 @@ namespace Ryujinx.Horizon.LogManager
|
||||
|
||||
private static string LogImpl(ReadOnlySpan<byte> message)
|
||||
{
|
||||
SpanReader reader = new SpanReader(message);
|
||||
SpanReader reader = new(message);
|
||||
LogPacketHeader header = reader.Read<LogPacketHeader>();
|
||||
StringBuilder builder = new();
|
||||
|
||||
LogPacketHeader header = reader.Read<LogPacketHeader>();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine($"Guest Log:\n Log level: {header.Severity}");
|
||||
builder.AppendLine($"Guest Log:\n Log level: {header.Severity}");
|
||||
|
||||
while (reader.Length > 0)
|
||||
{
|
||||
@ -78,7 +75,7 @@ namespace Ryujinx.Horizon.LogManager
|
||||
|
||||
LogDataChunkKey field = (LogDataChunkKey)type;
|
||||
|
||||
string fieldStr = string.Empty;
|
||||
string fieldStr;
|
||||
|
||||
if (field == LogDataChunkKey.Start)
|
||||
{
|
||||
@ -111,16 +108,16 @@ namespace Ryujinx.Horizon.LogManager
|
||||
fieldStr = $"Field{field}: '{Encoding.UTF8.GetString(reader.GetSpan(size)).TrimEnd()}'";
|
||||
}
|
||||
|
||||
sb.AppendLine($" {fieldStr}");
|
||||
builder.AppendLine($" {fieldStr}");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
private static int ReadUleb128(ref SpanReader reader)
|
||||
{
|
||||
int result = 0;
|
||||
int count = 0;
|
||||
int count = 0;
|
||||
|
||||
byte encoded;
|
||||
|
||||
@ -136,4 +133,4 @@ namespace Ryujinx.Horizon.LogManager
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,18 +2,19 @@
|
||||
using Ryujinx.Horizon.Sdk.Lm;
|
||||
using Ryujinx.Horizon.Sdk.Sf;
|
||||
|
||||
namespace Ryujinx.Horizon.LogManager
|
||||
namespace Ryujinx.Horizon.LogManager.Ipc
|
||||
{
|
||||
partial class LmLog : IServiceObject
|
||||
partial class LogService : ILogService
|
||||
{
|
||||
public LogDestination LogDestination { get; set; } = LogDestination.TargetManager;
|
||||
|
||||
[CmifCommand(0)]
|
||||
public Result OpenLogger(out LmLogger logger, [ClientProcessId] ulong clientProcessId)
|
||||
public Result OpenLogger(out LmLogger logger, [ClientProcessId] ulong pid)
|
||||
{
|
||||
logger = new LmLogger(this, clientProcessId);
|
||||
// NOTE: Internal name is Logger, but we rename it LmLogger to avoid name clash with Ryujinx.Common.Logging logger.
|
||||
logger = new LmLogger(this, pid);
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using Ryujinx.Horizon.Sdk.Sf.Hipc;
|
||||
using Ryujinx.Horizon.LogManager.Ipc;
|
||||
using Ryujinx.Horizon.Sdk.Sf.Hipc;
|
||||
using Ryujinx.Horizon.Sdk.Sm;
|
||||
using Ryujinx.Horizon.Sm;
|
||||
|
||||
namespace Ryujinx.Horizon.LogManager
|
||||
{
|
||||
@ -9,36 +9,25 @@ namespace Ryujinx.Horizon.LogManager
|
||||
private const int LogMaxSessionsCount = 42;
|
||||
|
||||
private const int PointerBufferSize = 0x400;
|
||||
private const int MaxDomains = 31;
|
||||
private const int MaxDomainObjects = 61;
|
||||
private const int MaxDomains = 31;
|
||||
private const int MaxDomainObjects = 61;
|
||||
private const int MaxPortsCount = 1;
|
||||
|
||||
private const int MaxPortsCount = 1;
|
||||
private static readonly ManagerOptions _logManagerOptions = new(PointerBufferSize, MaxDomains, MaxDomainObjects, false);
|
||||
|
||||
private static readonly ManagerOptions _logManagerOptions = new ManagerOptions(
|
||||
PointerBufferSize,
|
||||
MaxDomains,
|
||||
MaxDomainObjects,
|
||||
false);
|
||||
|
||||
private static readonly ServiceName _logServiceName = ServiceName.Encode("lm");
|
||||
|
||||
private SmApi _sm;
|
||||
private SmApi _sm;
|
||||
private ServerManager _serverManager;
|
||||
|
||||
private LmLog _logServiceObject;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
HeapAllocator allocator = new HeapAllocator();
|
||||
HeapAllocator allocator = new();
|
||||
|
||||
_sm = new SmApi();
|
||||
_sm.Initialize().AbortOnFailure();
|
||||
|
||||
_serverManager = new ServerManager(allocator, _sm, MaxPortsCount, _logManagerOptions, LogMaxSessionsCount);
|
||||
|
||||
_logServiceObject = new LmLog();
|
||||
|
||||
_serverManager.RegisterObjectForServer(_logServiceObject, _logServiceName, LogMaxSessionsCount);
|
||||
_serverManager.RegisterObjectForServer(new LogService(), ServiceName.Encode("lm"), LogMaxSessionsCount);
|
||||
}
|
||||
|
||||
public void ServiceRequests()
|
||||
@ -51,4 +40,4 @@ namespace Ryujinx.Horizon.LogManager
|
||||
_serverManager.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,13 +2,16 @@
|
||||
{
|
||||
class LmMain : IService
|
||||
{
|
||||
public static void Main()
|
||||
public static void Main(ServiceTable serviceTable)
|
||||
{
|
||||
LmIpcServer ipcServer = new LmIpcServer();
|
||||
LmIpcServer ipcServer = new();
|
||||
|
||||
ipcServer.Initialize();
|
||||
|
||||
serviceTable.SignalServiceReady();
|
||||
|
||||
ipcServer.ServiceRequests();
|
||||
ipcServer.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user