Add Ncm.ProgramLocation

This commit is contained in:
Alex Barney 2021-04-22 13:39:22 -07:00
parent 1744e0a562
commit 52c0903f61
3 changed files with 42 additions and 12 deletions

View file

@ -1,4 +1,5 @@
using System.Threading;
using System;
using System.Threading;
using LibHac.Common;
using LibHac.Diag;
using LibHac.Fs.Shim;
@ -50,12 +51,10 @@ namespace LibHac
return new HorizonClient(this, new ProcessId(processId));
}
public HorizonClient CreateHorizonClient(ProgramId programId, AccessControlBits.Bits fsPermissions)
public HorizonClient CreateHorizonClient(ProgramLocation location, AccessControlBits.Bits fsPermissions)
{
HorizonClient client = CreateHorizonClient();
var dataHeader = new AccessControlDataHeader();
var descriptor = new AccessControlDescriptor();
var dataHeader = new AccessControlDataHeader();
descriptor.Version = 1;
dataHeader.Version = 1;
@ -63,9 +62,23 @@ namespace LibHac
descriptor.AccessFlags = (ulong)fsPermissions;
dataHeader.AccessFlags = (ulong)fsPermissions;
LoaderClient.Fs.RegisterProgram(client.ProcessId.Value, programId, StorageId.BuiltInUser,
SpanHelpers.AsReadOnlyByteSpan(in dataHeader), SpanHelpers.AsReadOnlyByteSpan(in descriptor))
.ThrowIfFailure();
return CreateHorizonClientImpl(location, SpanHelpers.AsReadOnlyByteSpan(in dataHeader),
SpanHelpers.AsReadOnlyByteSpan(in descriptor));
}
public HorizonClient CreateHorizonClient(ProgramLocation location, ReadOnlySpan<byte> fsAccessControlData,
ReadOnlySpan<byte> fsAccessControlDescriptor)
{
return CreateHorizonClientImpl(location, fsAccessControlData, fsAccessControlDescriptor);
}
private HorizonClient CreateHorizonClientImpl(ProgramLocation location, ReadOnlySpan<byte> accessControlData,
ReadOnlySpan<byte> accessControlDescriptor)
{
HorizonClient client = CreateHorizonClient();
LoaderClient.Fs.RegisterProgram(client.ProcessId.Value, location.ProgramId, location.StorageId,
accessControlData, accessControlDescriptor).ThrowIfFailure();
return client;
}

View file

@ -0,0 +1,14 @@
namespace LibHac.Ncm
{
public readonly struct ProgramLocation
{
public readonly ProgramId ProgramId;
public readonly StorageId StorageId;
public ProgramLocation(ProgramId programId, StorageId storageId)
{
ProgramId = programId;
StorageId = storageId;
}
}
}

View file

@ -20,11 +20,14 @@ namespace LibHac.Tests.FsSrv
var programs = new HorizonClient[count];
programs[0] = hos.CreateHorizonClient(new ProgramId(1), AccessControlBits.Bits.RegisterProgramIndexMapInfo);
programs[0] = hos.CreateHorizonClient(new ProgramLocation(new ProgramId(1), StorageId.BuiltInSystem),
AccessControlBits.Bits.RegisterProgramIndexMapInfo);
for (int i = 1; i < programs.Length; i++)
{
programs[i] = hos.CreateHorizonClient(new ProgramId((ulong)(i + 1)), AccessControlBits.Bits.None);
programs[i] =
hos.CreateHorizonClient(new ProgramLocation(new ProgramId((ulong)(i + 1)), StorageId.BuiltInSystem),
AccessControlBits.Bits.None);
}
var map = new ProgramIndexMapInfo[count];