forked from Ryubing/Ryujinx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Horizon: Implement arp:r and arp:w services (#5802)
* Horizon: Implement arp:r and arp:w services * Fix formatting * Remove HLE arp services * Revert "Remove HLE arp services" This reverts commit c576fcccadb963db56b96bacabd1c1ac7abfb1ab. * Keep LibHac impl since it's used in bcat * Addresses gdkchan's feedback * ArpApi in PrepoIpcServer and remove LmApi * Fix 2 * Fixes ArpApi init * Fix encoding * Update PrepoService.cs * Fix prepo
- Loading branch information
Showing
40 changed files
with
1,415 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Ryujinx.Horizon.Arp.Ipc; | ||
using Ryujinx.Horizon.Sdk.Arp; | ||
using Ryujinx.Horizon.Sdk.Arp.Detail; | ||
using Ryujinx.Horizon.Sdk.Sf.Hipc; | ||
using Ryujinx.Horizon.Sdk.Sm; | ||
|
||
namespace Ryujinx.Horizon.Arp | ||
{ | ||
class ArpIpcServer | ||
{ | ||
private const int ArpRMaxSessionsCount = 16; | ||
private const int ArpWMaxSessionsCount = 8; | ||
private const int MaxSessionsCount = ArpRMaxSessionsCount + ArpWMaxSessionsCount; | ||
|
||
private const int PointerBufferSize = 0x1000; | ||
private const int MaxDomains = 24; | ||
private const int MaxDomainObjects = 32; | ||
private const int MaxPortsCount = 2; | ||
|
||
private static readonly ManagerOptions _managerOptions = new(PointerBufferSize, MaxDomains, MaxDomainObjects, false); | ||
|
||
private SmApi _sm; | ||
private ServerManager _serverManager; | ||
private ApplicationInstanceManager _applicationInstanceManager; | ||
|
||
public IReader Reader { get; private set; } | ||
public IWriter Writer { get; private set; } | ||
|
||
public void Initialize() | ||
{ | ||
HeapAllocator allocator = new(); | ||
|
||
_sm = new SmApi(); | ||
_sm.Initialize().AbortOnFailure(); | ||
|
||
_serverManager = new ServerManager(allocator, _sm, MaxPortsCount, _managerOptions, MaxSessionsCount); | ||
|
||
_applicationInstanceManager = new ApplicationInstanceManager(); | ||
|
||
Reader reader = new(_applicationInstanceManager); | ||
Reader = reader; | ||
|
||
Writer writer = new(_applicationInstanceManager); | ||
Writer = writer; | ||
|
||
_serverManager.RegisterObjectForServer(reader, ServiceName.Encode("arp:r"), ArpRMaxSessionsCount); | ||
_serverManager.RegisterObjectForServer(writer, ServiceName.Encode("arp:w"), ArpWMaxSessionsCount); | ||
} | ||
|
||
public void ServiceRequests() | ||
{ | ||
_serverManager.ServiceRequests(); | ||
} | ||
|
||
public void Shutdown() | ||
{ | ||
_applicationInstanceManager.Dispose(); | ||
_serverManager.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Ryujinx.Horizon.Arp | ||
{ | ||
class ArpMain : IService | ||
{ | ||
public static void Main(ServiceTable serviceTable) | ||
{ | ||
ArpIpcServer arpIpcServer = new(); | ||
|
||
arpIpcServer.Initialize(); | ||
|
||
serviceTable.ArpReader = arpIpcServer.Reader; | ||
serviceTable.ArpWriter = arpIpcServer.Writer; | ||
|
||
serviceTable.SignalServiceReady(); | ||
|
||
arpIpcServer.ServiceRequests(); | ||
arpIpcServer.Shutdown(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
using Ryujinx.Horizon.Common; | ||
using Ryujinx.Horizon.Sdk.Arp; | ||
using Ryujinx.Horizon.Sdk.Arp.Detail; | ||
using Ryujinx.Horizon.Sdk.Ns; | ||
using Ryujinx.Horizon.Sdk.Sf; | ||
using Ryujinx.Horizon.Sdk.Sf.Hipc; | ||
using System; | ||
|
||
namespace Ryujinx.Horizon.Arp.Ipc | ||
{ | ||
partial class Reader : IReader, IServiceObject | ||
{ | ||
private readonly ApplicationInstanceManager _applicationInstanceManager; | ||
|
||
public Reader(ApplicationInstanceManager applicationInstanceManager) | ||
{ | ||
_applicationInstanceManager = applicationInstanceManager; | ||
} | ||
|
||
[CmifCommand(0)] | ||
public Result GetApplicationLaunchProperty(out ApplicationLaunchProperty applicationLaunchProperty, ulong applicationInstanceId) | ||
{ | ||
if (_applicationInstanceManager.Entries[applicationInstanceId] == null || !_applicationInstanceManager.Entries[applicationInstanceId].LaunchProperty.HasValue) | ||
{ | ||
applicationLaunchProperty = default; | ||
|
||
return ArpResult.InvalidInstanceId; | ||
} | ||
|
||
applicationLaunchProperty = _applicationInstanceManager.Entries[applicationInstanceId].LaunchProperty.Value; | ||
|
||
return Result.Success; | ||
} | ||
|
||
[CmifCommand(1)] | ||
public Result GetApplicationControlProperty([Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias, 0x4000)] out ApplicationControlProperty applicationControlProperty, ulong applicationInstanceId) | ||
{ | ||
if (_applicationInstanceManager.Entries[applicationInstanceId] == null || !_applicationInstanceManager.Entries[applicationInstanceId].ControlProperty.HasValue) | ||
{ | ||
applicationControlProperty = default; | ||
|
||
return ArpResult.InvalidInstanceId; | ||
} | ||
|
||
applicationControlProperty = _applicationInstanceManager.Entries[applicationInstanceId].ControlProperty.Value; | ||
|
||
return Result.Success; | ||
} | ||
|
||
[CmifCommand(2)] | ||
public Result GetApplicationProcessProperty(out ApplicationProcessProperty applicationProcessProperty, ulong applicationInstanceId) | ||
{ | ||
if (_applicationInstanceManager.Entries[applicationInstanceId] == null || !_applicationInstanceManager.Entries[applicationInstanceId].ProcessProperty.HasValue) | ||
{ | ||
applicationProcessProperty = default; | ||
|
||
return ArpResult.InvalidInstanceId; | ||
} | ||
|
||
applicationProcessProperty = _applicationInstanceManager.Entries[applicationInstanceId].ProcessProperty.Value; | ||
|
||
return Result.Success; | ||
} | ||
|
||
[CmifCommand(3)] | ||
public Result GetApplicationInstanceId(out ulong applicationInstanceId, ulong pid) | ||
{ | ||
applicationInstanceId = 0; | ||
|
||
if (pid == 0) | ||
{ | ||
return ArpResult.InvalidPid; | ||
} | ||
|
||
for (int i = 0; i < _applicationInstanceManager.Entries.Length; i++) | ||
{ | ||
if (_applicationInstanceManager.Entries[i] != null && _applicationInstanceManager.Entries[i].Pid == pid) | ||
{ | ||
applicationInstanceId = (ulong)i; | ||
|
||
return Result.Success; | ||
} | ||
} | ||
|
||
return ArpResult.InvalidPid; | ||
} | ||
|
||
[CmifCommand(4)] | ||
public Result GetApplicationInstanceUnregistrationNotifier(out IUnregistrationNotifier unregistrationNotifier) | ||
{ | ||
unregistrationNotifier = new UnregistrationNotifier(_applicationInstanceManager); | ||
|
||
return Result.Success; | ||
} | ||
|
||
[CmifCommand(5)] | ||
public Result ListApplicationInstanceId(out int count, [Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Span<ulong> applicationInstanceIdList) | ||
{ | ||
count = 0; | ||
|
||
if (_applicationInstanceManager.Entries[0] != null) | ||
{ | ||
applicationInstanceIdList[count++] = 0; | ||
} | ||
|
||
if (_applicationInstanceManager.Entries[1] != null) | ||
{ | ||
applicationInstanceIdList[count++] = 1; | ||
} | ||
|
||
return Result.Success; | ||
} | ||
|
||
[CmifCommand(6)] | ||
public Result GetMicroApplicationInstanceId(out ulong microApplicationInstanceId, [ClientProcessId] ulong pid) | ||
{ | ||
return GetApplicationInstanceId(out microApplicationInstanceId, pid); | ||
} | ||
|
||
[CmifCommand(7)] | ||
public Result GetApplicationCertificate([Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias | HipcBufferFlags.FixedSize, 0x528)] out ApplicationCertificate applicationCertificate, ulong applicationInstanceId) | ||
{ | ||
if (_applicationInstanceManager.Entries[applicationInstanceId] == null) | ||
{ | ||
applicationCertificate = default; | ||
|
||
return ArpResult.InvalidInstanceId; | ||
} | ||
|
||
applicationCertificate = _applicationInstanceManager.Entries[applicationInstanceId].Certificate.Value; | ||
|
||
return Result.Success; | ||
} | ||
} | ||
} |
Oops, something went wrong.