River : HLE: Make process identity explicit for service metadata resolution (#100)

This PR is the first in a batch of structural changes to Ryujinx.

**Changes**

- Added `ProcessIdentity` and `ProcessKind` to describe loaded programs by:
  - PID, program ID, application ID, program index, display version, process kind
- Stored identity metadata on `ProcessResult`.
- Added PID-based process lookup helpers to `ProcessLoader`.
- Updated HLE services to resolve application metadata through the caller PID instead of `Processes.ActiveApplication`.
- Added PTC/JIT disk cache initialization logging with PID, title ID, display version, selector, and enabled state.
- Added `ClientProcessId` property to ServiceCtx (/src/Ryujinx.HLE/HOS/ServiceCtx.cs) that uses the handle descriptor PId when available, falling back to `Process.Pid`.
- Updated 15 HLE service files to use `context.ClientProcessId` instead of `context.Process.Pid` for client process access, ensuring services correctly identify the calling process even when invoked via IPC with handle descriptors.

These changes make service metadata resolution more explicit and prepare the emulator for other structural changes later on.

Reviewed-on: https://git.ryujinx.app/projects/Ryubing/pulls/100
This commit is contained in:
Babib3l
2026-05-25 12:08:31 +00:00
committed by sh0inx
parent cc67e586ec
commit b62c58c2fe
23 changed files with 155 additions and 45 deletions

View File

@@ -0,0 +1,34 @@
namespace Ryujinx.HLE.Loaders.Processes
{
public readonly struct ProcessIdentity
{
public ulong ProcessId { get; }
public ulong ProgramId { get; }
public ulong ApplicationId { get; }
public byte ProgramIndex { get; }
public string ProgramIdText { get; }
public string DisplayVersion { get; }
public ProcessKind Kind { get; }
public ProcessIdentity(
ulong processId,
ulong programId,
byte programIndex,
string displayVersion,
ProcessKind kind)
{
ProcessId = processId;
ProgramId = programId;
ProgramIndex = programIndex;
ApplicationId = programId & ~0xFul;
ProgramIdText = $"{programId:x16}";
DisplayVersion = displayVersion ?? string.Empty;
Kind = kind;
}
public override string ToString()
{
return $"{Kind} pid={ProcessId} program={ProgramIdText} application={ApplicationId:x16} index={ProgramIndex} version={DisplayVersion}";
}
}
}

View File

@@ -0,0 +1,12 @@
namespace Ryujinx.HLE.Loaders.Processes
{
public enum ProcessKind
{
Unknown,
Application,
SystemApplication,
SystemApplet,
LibraryApplet,
Homebrew,
}
}

View File

@@ -93,6 +93,23 @@ namespace Ryujinx.HLE.Loaders.Processes
_processesByPid = new ConcurrentDictionary<ulong, ProcessResult>();
}
public bool TryGetProcess(ulong pid, out ProcessResult process)
{
return _processesByPid.TryGetValue(pid, out process);
}
public ProcessResult GetProcess(ulong pid)
{
if (_processesByPid.TryGetValue(pid, out ProcessResult process))
{
return process;
}
Logger.Warning?.Print(LogClass.Loader, $"Process metadata for pid {pid} was not found. Falling back to active application metadata.");
return ActiveApplication;
}
public bool LoadXci(string path, ulong applicationId)
{
FileStream stream = new(path, FileMode.Open, FileAccess.Read);

View File

@@ -436,6 +436,7 @@ namespace Ryujinx.HLE.Loaders.Processes
allowCodeMemoryForJit,
processContextFactory.DiskCacheLoadState,
process.Pid,
programIndex,
meta.MainThreadPriority,
meta.MainThreadStackSize,
device.System.State.DesiredTitleLanguage);

View File

@@ -10,7 +10,7 @@ namespace Ryujinx.HLE.Loaders.Processes
{
public class ProcessResult
{
public static ProcessResult Failed => new(null, new BlitStruct<ApplicationControlProperty>(1), false, false, null, 0, 0, 0, TitleLanguage.AmericanEnglish);
public static ProcessResult Failed => new(null, new BlitStruct<ApplicationControlProperty>(1), false, false, null, 0, 0, 0, 0, TitleLanguage.AmericanEnglish);
private readonly byte _mainThreadPriority;
private readonly uint _mainThreadStackSize;
@@ -28,6 +28,7 @@ namespace Ryujinx.HLE.Loaders.Processes
public readonly bool Is64Bit;
public readonly bool DiskCacheEnabled;
public readonly bool AllowCodeMemoryForJit;
public readonly ProcessIdentity Identity;
public ProcessResult(
MetaLoader metaLoader,
@@ -36,6 +37,7 @@ namespace Ryujinx.HLE.Loaders.Processes
bool allowCodeMemoryForJit,
IDiskCacheLoadState diskCacheLoadState,
ulong pid,
byte programIndex,
byte mainThreadPriority,
uint mainThreadStackSize,
TitleLanguage titleLanguage)
@@ -71,6 +73,7 @@ namespace Ryujinx.HLE.Loaders.Processes
ProgramId = programId;
ProgramIdText = $"{programId:x16}";
Is64Bit = metaLoader.IsProgram64Bit;
Identity = new ProcessIdentity(pid, programId, programIndex, DisplayVersion, GetProcessKind(programId));
}
else
@@ -84,6 +87,31 @@ namespace Ryujinx.HLE.Loaders.Processes
AllowCodeMemoryForJit = allowCodeMemoryForJit;
}
private static ProcessKind GetProcessKind(ulong programId)
{
if (programId == 0)
{
return ProcessKind.Application;
}
if (programId is >= 0x0100000000001000 and <= 0x0100000000001FFF)
{
return ProcessKind.SystemApplet;
}
if (programId is >= 0x0100000000000800 and <= 0x0100000000000FFF)
{
return ProcessKind.LibraryApplet;
}
if (programId <= 0x0100000000007FFF)
{
return ProcessKind.SystemApplication;
}
return ProcessKind.Application;
}
public bool Start(Switch device)
{
device.Configuration.ContentManager.LoadEntries(device);
@@ -109,6 +137,7 @@ namespace Ryujinx.HLE.Loaders.Processes
: device.System.ContentManager.GetCurrentFirmwareVersion()?.VersionString ?? "?";
Logger.Info?.Print(LogClass.Loader, $"Application Loaded: {name} v{version} [{ProgramIdText}] [{(Is64Bit ? "64-bit" : "32-bit")}]");
Logger.Info?.Print(LogClass.Loader, $"Process identity: {Identity}");
return true;
}