Update to LibHac 0.13.1 (#2328)
Update the LibHac dependency to version 0.13.1. This brings a ton of improvements and changes such as: - Refactor `FsSrv` to match the official refactoring done in FS. - Change how the `Horizon` and `HorizonClient` classes are handled. Each client created represents a different process with its own process ID and client state. - Add FS access control to handle permissions for FS service method calls. - Add FS program registry to keep track of the program ID, location and permissions of each process. - Add FS program index map info manager to track the program IDs and indexes of multi-application programs. - Add all FS IPC interfaces. - Rewrite `Fs.Fsa` code to be more accurate. - Rewrite a lot of `FsSrv` code to be more accurate. - Extend directory save data to store `SaveDataExtraData` - Extend directory save data to lock the save directory to allow only one accessor at a time. - Improve waiting and retrying when encountering access issues in `LocalFileSystem` and `DirectorySaveDataFileSystem`. - More `IFileSystemProxy` methods should work now. - Probably a bunch more stuff. On the Ryujinx side: - Forward most `IFileSystemProxy` methods to LibHac. - Register programs and program index map info when launching an application. - Remove hacks and workarounds for missing LibHac functionality. - Recreate missing save data extra data found on emulator startup. - Create system save data that wasn't indexed correctly on an older LibHac version. `FsSrv` now enforces access control for each process. When a process tries to open a save data file system, FS reads the save's extra data to determine who the save owner is and if the caller has permission to open the save data. Previously-created save data did not have extra data created when the save was created. With access control checks in place, this means that processes with no permissions (most games) wouldn't be able to access their own save data. The extra data can be partially created from data in the save data indexer, which should be enough for access control purposes.
This commit is contained in:
parent
04dce402ac
commit
19afb3209c
31 changed files with 1795 additions and 574 deletions
|
@ -1,7 +1,9 @@
|
|||
using LibHac;
|
||||
using LibHac.Common;
|
||||
using LibHac.Fs;
|
||||
using LibHac.Fs.Fsa;
|
||||
using LibHac.Fs.Shim;
|
||||
using LibHac.Ncm;
|
||||
using Ryujinx.HLE.HOS.Services.Mii.Types;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
|
@ -14,8 +16,6 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
|||
|
||||
private const ulong DatabaseTestSaveDataId = 0x8000000000000031;
|
||||
private const ulong DatabaseSaveDataId = 0x8000000000000030;
|
||||
private const ulong NsTitleId = 0x010000000000001F;
|
||||
private const ulong SdbTitleId = 0x0100000000000039;
|
||||
|
||||
private static U8String DatabasePath = new U8String("mii:/MiiDatabase.dat");
|
||||
private static U8String MountName = new U8String("mii");
|
||||
|
@ -23,7 +23,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
|||
private NintendoFigurineDatabase _database;
|
||||
private bool _isDirty;
|
||||
|
||||
private FileSystemClient _filesystemClient;
|
||||
private HorizonClient _horizonClient;
|
||||
|
||||
protected ulong UpdateCounter { get; private set; }
|
||||
|
||||
|
@ -94,74 +94,62 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
|||
return virtualIndex;
|
||||
}
|
||||
|
||||
public void InitializeDatabase(Switch device)
|
||||
public void InitializeDatabase(HorizonClient horizonClient)
|
||||
{
|
||||
_filesystemClient = device.FileSystem.FsClient;
|
||||
_horizonClient = horizonClient;
|
||||
|
||||
// Ensure we have valid data in the database
|
||||
_database.Format();
|
||||
|
||||
// TODO: Unmount is currently not implemented properly at dispose, implement that and decrement MountCounter.
|
||||
MountCounter = 0;
|
||||
|
||||
MountSave();
|
||||
}
|
||||
|
||||
private Result MountSave()
|
||||
{
|
||||
Result result = Result.Success;
|
||||
|
||||
if (MountCounter == 0)
|
||||
if (MountCounter != 0)
|
||||
{
|
||||
ulong targetSaveDataId;
|
||||
ulong targetTitleId;
|
||||
MountCounter++;
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
ulong saveDataId = IsTestModeEnabled ? DatabaseTestSaveDataId : DatabaseSaveDataId;
|
||||
|
||||
Result result = _horizonClient.Fs.MountSystemSaveData(MountName, SaveDataSpaceId.System, saveDataId);
|
||||
|
||||
if (result.IsFailure())
|
||||
{
|
||||
if (!ResultFs.TargetNotFound.Includes(result))
|
||||
return result;
|
||||
|
||||
if (IsTestModeEnabled)
|
||||
{
|
||||
targetSaveDataId = DatabaseTestSaveDataId;
|
||||
targetTitleId = SdbTitleId;
|
||||
result = _horizonClient.Fs.CreateSystemSaveData(saveDataId, 0x10000, 0x10000,
|
||||
SaveDataFlags.KeepAfterResettingSystemSaveDataWithoutUserSaveData);
|
||||
if (result.IsFailure()) return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
targetSaveDataId = DatabaseSaveDataId;
|
||||
|
||||
// Nintendo use NS TitleID when creating the production save even on sdb, let's follow that behaviour.
|
||||
targetTitleId = NsTitleId;
|
||||
result = _horizonClient.Fs.CreateSystemSaveData(saveDataId, SystemProgramId.Ns.Value, 0x10000,
|
||||
0x10000, SaveDataFlags.KeepAfterResettingSystemSaveDataWithoutUserSaveData);
|
||||
if (result.IsFailure()) return result;
|
||||
}
|
||||
|
||||
U8Span mountName = new U8Span(MountName);
|
||||
|
||||
result = _filesystemClient.MountSystemSaveData(mountName, SaveDataSpaceId.System, targetSaveDataId);
|
||||
|
||||
if (result.IsFailure())
|
||||
{
|
||||
if (ResultFs.TargetNotFound.Includes(result))
|
||||
{
|
||||
// TODO: We're currently always specifying the owner ID because FS doesn't have a way of
|
||||
// knowing which process called it
|
||||
result = _filesystemClient.CreateSystemSaveData(targetSaveDataId, targetTitleId, 0x10000,
|
||||
0x10000, SaveDataFlags.KeepAfterResettingSystemSaveDataWithoutUserSaveData);
|
||||
if (result.IsFailure()) return result;
|
||||
|
||||
result = _filesystemClient.MountSystemSaveData(mountName, SaveDataSpaceId.System, targetSaveDataId);
|
||||
if (result.IsFailure()) return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == Result.Success)
|
||||
{
|
||||
MountCounter++;
|
||||
}
|
||||
result = _horizonClient.Fs.MountSystemSaveData(MountName, SaveDataSpaceId.System, saveDataId);
|
||||
if (result.IsFailure()) return result;
|
||||
}
|
||||
|
||||
if (result == Result.Success)
|
||||
{
|
||||
MountCounter++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ResultCode DeleteFile()
|
||||
{
|
||||
ResultCode result = (ResultCode)_filesystemClient.DeleteFile(DatabasePath).Value;
|
||||
ResultCode result = (ResultCode)_horizonClient.Fs.DeleteFile(DatabasePath).Value;
|
||||
|
||||
_filesystemClient.Commit(MountName);
|
||||
_horizonClient.Fs.Commit(MountName);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -179,17 +167,17 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
|||
|
||||
ResetDatabase();
|
||||
|
||||
Result result = _filesystemClient.OpenFile(out FileHandle handle, DatabasePath, OpenMode.Read);
|
||||
Result result = _horizonClient.Fs.OpenFile(out FileHandle handle, DatabasePath, OpenMode.Read);
|
||||
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
result = _filesystemClient.GetFileSize(out long fileSize, handle);
|
||||
result = _horizonClient.Fs.GetFileSize(out long fileSize, handle);
|
||||
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
if (fileSize == Unsafe.SizeOf<NintendoFigurineDatabase>())
|
||||
{
|
||||
result = _filesystemClient.ReadFile(handle, 0, _database.AsSpan());
|
||||
result = _horizonClient.Fs.ReadFile(handle, 0, _database.AsSpan());
|
||||
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
|
@ -211,7 +199,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
|||
}
|
||||
}
|
||||
|
||||
_filesystemClient.CloseFile(handle);
|
||||
_horizonClient.Fs.CloseFile(handle);
|
||||
|
||||
return (ResultCode)result.Value;
|
||||
}
|
||||
|
@ -225,32 +213,32 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
|||
|
||||
private Result ForceSaveDatabase()
|
||||
{
|
||||
Result result = _filesystemClient.CreateFile(DatabasePath, Unsafe.SizeOf<NintendoFigurineDatabase>());
|
||||
Result result = _horizonClient.Fs.CreateFile(DatabasePath, Unsafe.SizeOf<NintendoFigurineDatabase>());
|
||||
|
||||
if (result.IsSuccess() || ResultFs.PathAlreadyExists.Includes(result))
|
||||
{
|
||||
result = _filesystemClient.OpenFile(out FileHandle handle, DatabasePath, OpenMode.Write);
|
||||
result = _horizonClient.Fs.OpenFile(out FileHandle handle, DatabasePath, OpenMode.Write);
|
||||
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
result = _filesystemClient.GetFileSize(out long fileSize, handle);
|
||||
result = _horizonClient.Fs.GetFileSize(out long fileSize, handle);
|
||||
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
// If the size doesn't match, recreate the file
|
||||
if (fileSize != Unsafe.SizeOf<NintendoFigurineDatabase>())
|
||||
{
|
||||
_filesystemClient.CloseFile(handle);
|
||||
_horizonClient.Fs.CloseFile(handle);
|
||||
|
||||
result = _filesystemClient.DeleteFile(DatabasePath);
|
||||
result = _horizonClient.Fs.DeleteFile(DatabasePath);
|
||||
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
result = _filesystemClient.CreateFile(DatabasePath, Unsafe.SizeOf<NintendoFigurineDatabase>());
|
||||
result = _horizonClient.Fs.CreateFile(DatabasePath, Unsafe.SizeOf<NintendoFigurineDatabase>());
|
||||
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
result = _filesystemClient.OpenFile(out handle, DatabasePath, OpenMode.Write);
|
||||
result = _horizonClient.Fs.OpenFile(out handle, DatabasePath, OpenMode.Write);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -260,10 +248,10 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
|||
}
|
||||
}
|
||||
|
||||
result = _filesystemClient.WriteFile(handle, 0, _database.AsReadOnlySpan(), WriteOption.Flush);
|
||||
result = _horizonClient.Fs.WriteFile(handle, 0, _database.AsReadOnlySpan(), WriteOption.Flush);
|
||||
}
|
||||
|
||||
_filesystemClient.CloseFile(handle);
|
||||
_horizonClient.Fs.CloseFile(handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,7 +259,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii
|
|||
{
|
||||
_isDirty = false;
|
||||
|
||||
result = _filesystemClient.Commit(MountName);
|
||||
result = _horizonClient.Fs.Commit(MountName);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue