HOS: Load RomFs by pid (#4301)

We currently loading only one RomFs at a time, which could be wrong if one day we want to load more than one guest at time.
This PR fixes that by loading romfs by pid.
This commit is contained in:
Ac_K 2023-01-18 14:50:42 +01:00 committed by GitHub
parent 410be95ab6
commit f449895e6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 24 deletions

View file

@ -16,6 +16,7 @@ using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS;
using System;
using System.Buffers.Text;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
@ -35,7 +36,8 @@ namespace Ryujinx.HLE.FileSystem
public EmulatedGameCard GameCard { get; private set; }
public EmulatedSdCard SdCard { get; private set; }
public ModLoader ModLoader { get; private set; }
public Stream RomFs { get; private set; }
private readonly ConcurrentDictionary<ulong, Stream> _romFsByPid;
private static bool _isInitialized = false;
@ -55,17 +57,34 @@ namespace Ryujinx.HLE.FileSystem
{
ReloadKeySet();
ModLoader = new ModLoader(); // Should only be created once
_romFsByPid = new ConcurrentDictionary<ulong, Stream>();
}
public void LoadRomFs(string fileName)
public void LoadRomFs(ulong pid, string fileName)
{
RomFs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
var romfsStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
_romFsByPid.AddOrUpdate(pid, romfsStream, (pid, oldStream) =>
{
oldStream.Close();
return romfsStream;
});
}
public void SetRomFs(Stream romfsStream)
public void SetRomFs(ulong pid, Stream romfsStream)
{
RomFs?.Close();
RomFs = romfsStream;
_romFsByPid.AddOrUpdate(pid, romfsStream, (pid, oldStream) =>
{
oldStream.Close();
return romfsStream;
});
}
public Stream GetRomFs(ulong pid)
{
return _romFsByPid[pid];
}
public string GetFullPath(string basePath, string fileName)
@ -583,7 +602,12 @@ namespace Ryujinx.HLE.FileSystem
{
if (disposing)
{
RomFs?.Dispose();
foreach (var stream in _romFsByPid.Values)
{
stream.Close();
}
_romFsByPid.Clear();
}
}
}