ams.mitm: fix deadlock when building multiple romfs simultaneously (closes #1972)

This commit is contained in:
Michael Scire 2025-09-02 18:35:42 -07:00
parent 081e76a2b5
commit 98bc030b37

View File

@ -215,6 +215,9 @@ namespace ams::mitm::fs {
using namespace ams::fs; using namespace ams::fs;
std::shared_ptr<ams::fs::IStorage> GetLayeredRomfsStorage(ncm::ProgramId program_id, ::FsStorage &data_storage, bool is_process_romfs) { std::shared_ptr<ams::fs::IStorage> GetLayeredRomfsStorage(ncm::ProgramId program_id, ::FsStorage &data_storage, bool is_process_romfs) {
/*Prepare to find or create a new storage. */
LayeredRomfsStorageImpl *impl = nullptr;
{
std::scoped_lock lk(g_storage_set_mutex); std::scoped_lock lk(g_storage_set_mutex);
/* Find an existing storage. */ /* Find an existing storage. */
@ -238,7 +241,6 @@ namespace ams::mitm::fs {
} }
/* Create a new storage. */ /* Create a new storage. */
LayeredRomfsStorageImpl *impl;
{ {
::FsFile data_file; ::FsFile data_file;
if (R_SUCCEEDED(OpenAtmosphereSdFile(std::addressof(data_file), program_id, "romfs.bin", OpenMode_Read))) { if (R_SUCCEEDED(OpenAtmosphereSdFile(std::addressof(data_file), program_id, "romfs.bin", OpenMode_Read))) {
@ -250,8 +252,10 @@ namespace ams::mitm::fs {
/* Insert holder. Reference count will now be one. */ /* Insert holder. Reference count will now be one. */
g_storage_set.insert(*(new LayeredRomfsStorageHolder(impl, is_process_romfs))); g_storage_set.insert(*(new LayeredRomfsStorageHolder(impl, is_process_romfs)));
}
/* Begin initialization. When this finishes, a decref will occur. */ /* Begin initialization. When this finishes, a decref will occur. */
AMS_ABORT_UNLESS(impl != nullptr);
impl->BeginInitialize(); impl->BeginInitialize();
/* Return a new shared storage for the impl. */ /* Return a new shared storage for the impl. */