Skip to content

Commit

Permalink
Merge remote-tracking branch 'gdkchan/skyline' into HDR
Browse files Browse the repository at this point in the history
  • Loading branch information
zandm7 committed May 3, 2022
2 parents c0829eb + aa9de1f commit c57050c
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 15 deletions.
16 changes: 10 additions & 6 deletions Ryujinx.HLE/HOS/ApplicationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public void LoadCart(string exeFsDir, string romFsFile = null)
MetaLoader metaData = ReadNpdm(codeFs);

_device.Configuration.VirtualFileSystem.ModLoader.CollectMods(
new[] { TitleId },
_device.Configuration.VirtualFileSystem.ModLoader.GetModsBasePath(),
new[] { TitleId },
_device.Configuration.VirtualFileSystem.ModLoader.GetModsBasePath(),
_device.Configuration.VirtualFileSystem.ModLoader.GetSdModsBasePath());

if (TitleId != 0)
Expand Down Expand Up @@ -393,8 +393,8 @@ private void LoadNca(Nca mainNca, Nca patchNca, Nca controlNca)
MetaLoader metaData = ReadNpdm(codeFs);

_device.Configuration.VirtualFileSystem.ModLoader.CollectMods(
_device.Configuration.ContentManager.GetAocTitleIds().Prepend(TitleId),
_device.Configuration.VirtualFileSystem.ModLoader.GetModsBasePath(),
_device.Configuration.ContentManager.GetAocTitleIds().Prepend(TitleId),
_device.Configuration.VirtualFileSystem.ModLoader.GetModsBasePath(),
_device.Configuration.VirtualFileSystem.ModLoader.GetSdModsBasePath());

if (controlNca != null)
Expand Down Expand Up @@ -571,8 +571,12 @@ private void LoadExeFs(IFileSystem codeFs, MetaLoader metaData = null)

Ptc.Initialize(TitleIdText, DisplayVersion, usePtc, memoryManagerMode);

// We allow it for nx-hbloader because it can be used to launch homebrew.
bool allowCodeMemoryForJit = TitleId == 0x010000000000100DUL;

metaData.GetNpdm(out Npdm npdm).ThrowIfFailure();
ProgramLoader.LoadNsos(_device.System.KernelContext, out ProcessTamperInfo tamperInfo, metaData, new ProgramInfo(in npdm), executables: programs);
ProgramInfo programInfo = new ProgramInfo(in npdm, allowCodeMemoryForJit);
ProgramLoader.LoadNsos(_device.System.KernelContext, out ProcessTamperInfo tamperInfo, metaData, programInfo, executables: programs);

_device.Configuration.VirtualFileSystem.ModLoader.LoadCheats(TitleId, tamperInfo, _device.TamperMachine);
}
Expand All @@ -581,7 +585,7 @@ public void LoadProgram(string filePath)
{
MetaLoader metaData = GetDefaultNpdm();
metaData.GetNpdm(out Npdm npdm).ThrowIfFailure();
ProgramInfo programInfo = new ProgramInfo(in npdm);
ProgramInfo programInfo = new ProgramInfo(in npdm, allowCodeMemoryForJit: true);

bool isNro = Path.GetExtension(filePath).ToLower() == ".nro";

Expand Down
10 changes: 10 additions & 0 deletions Ryujinx.HLE/HOS/Kernel/KernelStatic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,15 @@ internal static KProcess GetCurrentProcess()
{
return GetCurrentThread().Owner;
}

internal static KProcess GetProcessByPid(ulong pid)
{
if (Context.Processes.TryGetValue(pid, out KProcess process))
{
return process;
}

return null;
}
}
}
6 changes: 5 additions & 1 deletion Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class KProcess : KSynchronizationObject

public KProcessCapabilities Capabilities { get; private set; }

public bool AllowCodeMemoryForJit { get; private set; }

public ulong TitleId { get; private set; }
public bool IsApplication { get; private set; }
public ulong Pid { get; private set; }
Expand Down Expand Up @@ -90,7 +92,7 @@ class KProcess : KSynchronizationObject

public HleProcessDebugger Debugger { get; private set; }

public KProcess(KernelContext context) : base(context)
public KProcess(KernelContext context, bool allowCodeMemoryForJit = false) : base(context)
{
_processLock = new object();
_threadingLock = new object();
Expand All @@ -102,6 +104,8 @@ public KProcess(KernelContext context) : base(context)

Capabilities = new KProcessCapabilities();

AllowCodeMemoryForJit = allowCodeMemoryForJit;

RandomEntropy = new ulong[KScheduler.CpuCoresCount];
PinnedThreads = new KThread[KScheduler.CpuCoresCount];

Expand Down
7 changes: 3 additions & 4 deletions Ryujinx.HLE/HOS/Kernel/SupervisorCall/Syscall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.Memory;
using System;
using System.Threading;

Expand Down Expand Up @@ -1363,10 +1362,10 @@ public KernelResult ControlCodeMemory(int handle, CodeMemoryOperation op, ulong

KCodeMemory codeMemory = currentProcess.HandleTable.GetObject<KCodeMemory>(handle);

// Newer versions of the return also returns an error here if the owner and process
// Newer versions of the kernel also returns an error here if the owner and process
// where the operation will happen are the same. We do not return an error here
// because some homebrew requires this to be patched out to work (for JIT).
if (codeMemory == null /* || codeMemory.Owner == currentProcess */)
// for homebrew because some of them requires this to be patched out to work (for JIT).
if (codeMemory == null || (!currentProcess.AllowCodeMemoryForJit && codeMemory.Owner == currentProcess))
{
return KernelResult.InvalidHandle;
}
Expand Down
14 changes: 11 additions & 3 deletions Ryujinx.HLE/HOS/ProgramLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ struct ProgramInfo
{
public string Name;
public ulong ProgramId;
public bool AllowCodeMemoryForJit;

public ProgramInfo(in Npdm npdm)
public ProgramInfo(in Npdm npdm, bool allowCodeMemoryForJit)
{
Name = StringUtils.Utf8ZToString(npdm.Meta.Value.ProgramName);
ProgramId = npdm.Aci.Value.ProgramId.Value;
AllowCodeMemoryForJit = allowCodeMemoryForJit;
}
}

Expand Down Expand Up @@ -141,7 +143,13 @@ public static bool LoadKip(KernelContext context, KipExecutable kip)
return true;
}

public static bool LoadNsos(KernelContext context, out ProcessTamperInfo tamperInfo, MetaLoader metaData, ProgramInfo programInfo, byte[] arguments = null, params IExecutable[] executables)
public static bool LoadNsos(
KernelContext context,
out ProcessTamperInfo tamperInfo,
MetaLoader metaData,
ProgramInfo programInfo,
byte[] arguments = null,
params IExecutable[] executables)
{
LibHac.Result rc = metaData.GetNpdm(out var npdm);

Expand Down Expand Up @@ -243,7 +251,7 @@ public static bool LoadNsos(KernelContext context, out ProcessTamperInfo tamperI
return false;
}

KProcess process = new KProcess(context);
KProcess process = new KProcess(context, programInfo.AllowCodeMemoryForJit);

MemoryRegion memoryRegion = (MemoryRegion)((npdm.Acid.Value.Flags >> 2) & 0xf);

Expand Down
25 changes: 24 additions & 1 deletion Ryujinx.HLE/HOS/Services/Pm/IDebugMonitorInterface.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
namespace Ryujinx.HLE.HOS.Services.Pm
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;

namespace Ryujinx.HLE.HOS.Services.Pm
{
[Service("pm:dmnt")]
class IDebugMonitorInterface : IpcService
{
public IDebugMonitorInterface(ServiceCtx context) { }

[CommandHipc(65000)]
// AtmosphereGetProcessInfo(os::ProcessId process_id) -> sf::OutCopyHandle out_process_handle, sf::Out<ncm::ProgramLocation> out_loc, sf::Out<cfg::OverrideStatus> out_status
public ResultCode GetProcessInfo(ServiceCtx context)
{
ulong pid = context.RequestData.ReadUInt64();

KProcess process = KernelStatic.GetProcessByPid(pid);

if (context.Process.HandleTable.GenerateHandle(process, out int processHandle) != KernelResult.Success)
{
throw new System.Exception("Out of handles!");
}

context.Response.HandleDesc = IpcHandleDesc.MakeCopy(processHandle);

return ResultCode.Success;
}
}
}

0 comments on commit c57050c

Please sign in to comment.