loader: Make the Load() function take a process as a regular reference, not a SharedPtr
A process should never require being reference counted in this situation. If the handle to a process is freed before this function is called, it's definitely a bug with our lifetime management, so we can put the requirement in place for the API that the process must be a valid instance.
This commit is contained in:
parent
0921558a9f
commit
a63e6f9dfd
|
@ -202,7 +202,7 @@ struct System::Impl {
|
||||||
return init_result;
|
return init_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Loader::ResultStatus load_result{app_loader->Load(kernel.CurrentProcess())};
|
const Loader::ResultStatus load_result{app_loader->Load(*kernel.CurrentProcess())};
|
||||||
if (load_result != Loader::ResultStatus::Success) {
|
if (load_result != Loader::ResultStatus::Success) {
|
||||||
LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", static_cast<int>(load_result));
|
LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", static_cast<int>(load_result));
|
||||||
Shutdown();
|
Shutdown();
|
||||||
|
|
|
@ -86,8 +86,7 @@ FileType AppLoader_DeconstructedRomDirectory::IdentifyType(const FileSys::Virtua
|
||||||
return FileType::Error;
|
return FileType::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus AppLoader_DeconstructedRomDirectory::Load(
|
ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process) {
|
||||||
Kernel::SharedPtr<Kernel::Process>& process) {
|
|
||||||
if (is_loaded) {
|
if (is_loaded) {
|
||||||
return ResultStatus::ErrorAlreadyLoaded;
|
return ResultStatus::ErrorAlreadyLoaded;
|
||||||
}
|
}
|
||||||
|
@ -130,10 +129,10 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(
|
||||||
return ResultStatus::Error32BitISA;
|
return ResultStatus::Error32BitISA;
|
||||||
}
|
}
|
||||||
|
|
||||||
process->LoadFromMetadata(metadata);
|
process.LoadFromMetadata(metadata);
|
||||||
|
|
||||||
// Load NSO modules
|
// Load NSO modules
|
||||||
const VAddr base_address = process->vm_manager.GetCodeRegionBaseAddress();
|
const VAddr base_address = process.vm_manager.GetCodeRegionBaseAddress();
|
||||||
VAddr next_load_addr = base_address;
|
VAddr next_load_addr = base_address;
|
||||||
for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3",
|
for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3",
|
||||||
"subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) {
|
"subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) {
|
||||||
|
@ -147,7 +146,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
process->Run(base_address, metadata.GetMainThreadPriority(), metadata.GetMainThreadStackSize());
|
process.Run(base_address, metadata.GetMainThreadPriority(), metadata.GetMainThreadStackSize());
|
||||||
|
|
||||||
// Find the RomFS by searching for a ".romfs" file in this directory
|
// Find the RomFS by searching for a ".romfs" file in this directory
|
||||||
const auto& files = dir->GetFiles();
|
const auto& files = dir->GetFiles();
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/file_sys/program_metadata.h"
|
#include "core/file_sys/program_metadata.h"
|
||||||
#include "core/hle/kernel/object.h"
|
|
||||||
#include "core/loader/loader.h"
|
#include "core/loader/loader.h"
|
||||||
|
|
||||||
namespace Loader {
|
namespace Loader {
|
||||||
|
@ -38,7 +37,7 @@ public:
|
||||||
return IdentifyType(file);
|
return IdentifyType(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
|
ResultStatus Load(Kernel::Process& process) override;
|
||||||
|
|
||||||
ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override;
|
ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override;
|
||||||
ResultStatus ReadIcon(std::vector<u8>& buffer) override;
|
ResultStatus ReadIcon(std::vector<u8>& buffer) override;
|
||||||
|
|
|
@ -387,7 +387,7 @@ FileType AppLoader_ELF::IdentifyType(const FileSys::VirtualFile& file) {
|
||||||
return FileType::Error;
|
return FileType::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
ResultStatus AppLoader_ELF::Load(Kernel::Process& process) {
|
||||||
if (is_loaded)
|
if (is_loaded)
|
||||||
return ResultStatus::ErrorAlreadyLoaded;
|
return ResultStatus::ErrorAlreadyLoaded;
|
||||||
|
|
||||||
|
@ -395,13 +395,13 @@ ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
||||||
if (buffer.size() != file->GetSize())
|
if (buffer.size() != file->GetSize())
|
||||||
return ResultStatus::ErrorIncorrectELFFileSize;
|
return ResultStatus::ErrorIncorrectELFFileSize;
|
||||||
|
|
||||||
const VAddr base_address = process->vm_manager.GetCodeRegionBaseAddress();
|
const VAddr base_address = process.vm_manager.GetCodeRegionBaseAddress();
|
||||||
ElfReader elf_reader(&buffer[0]);
|
ElfReader elf_reader(&buffer[0]);
|
||||||
SharedPtr<CodeSet> codeset = elf_reader.LoadInto(base_address);
|
SharedPtr<CodeSet> codeset = elf_reader.LoadInto(base_address);
|
||||||
codeset->name = file->GetName();
|
codeset->name = file->GetName();
|
||||||
|
|
||||||
process->LoadModule(codeset, codeset->entrypoint);
|
process.LoadModule(codeset, codeset->entrypoint);
|
||||||
process->Run(codeset->entrypoint, 48, Memory::DEFAULT_STACK_SIZE);
|
process.Run(codeset->entrypoint, 48, Memory::DEFAULT_STACK_SIZE);
|
||||||
|
|
||||||
is_loaded = true;
|
is_loaded = true;
|
||||||
return ResultStatus::Success;
|
return ResultStatus::Success;
|
||||||
|
|
|
@ -8,9 +8,6 @@
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/loader/loader.h"
|
#include "core/loader/loader.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Loader namespace
|
|
||||||
|
|
||||||
namespace Loader {
|
namespace Loader {
|
||||||
|
|
||||||
/// Loads an ELF/AXF file
|
/// Loads an ELF/AXF file
|
||||||
|
@ -29,7 +26,7 @@ public:
|
||||||
return IdentifyType(file);
|
return IdentifyType(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
|
ResultStatus Load(Kernel::Process& process) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Loader
|
} // namespace Loader
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/file_sys/vfs.h"
|
#include "core/file_sys/vfs.h"
|
||||||
#include "core/hle/kernel/object.h"
|
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
struct AddressMapping;
|
struct AddressMapping;
|
||||||
|
@ -136,7 +135,7 @@ public:
|
||||||
* @param process The newly created process.
|
* @param process The newly created process.
|
||||||
* @return The status result of the operation.
|
* @return The status result of the operation.
|
||||||
*/
|
*/
|
||||||
virtual ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) = 0;
|
virtual ResultStatus Load(Kernel::Process& process) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the system mode that this application needs.
|
* Loads the system mode that this application needs.
|
||||||
|
|
|
@ -41,7 +41,7 @@ FileType AppLoader_NAX::GetFileType() {
|
||||||
return IdentifyTypeImpl(*nax);
|
return IdentifyTypeImpl(*nax);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus AppLoader_NAX::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
ResultStatus AppLoader_NAX::Load(Kernel::Process& process) {
|
||||||
if (is_loaded) {
|
if (is_loaded) {
|
||||||
return ResultStatus::ErrorAlreadyLoaded;
|
return ResultStatus::ErrorAlreadyLoaded;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
|
|
||||||
FileType GetFileType() override;
|
FileType GetFileType() override;
|
||||||
|
|
||||||
ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
|
ResultStatus Load(Kernel::Process& process) override;
|
||||||
|
|
||||||
ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override;
|
ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override;
|
||||||
ResultStatus ReadProgramId(u64& out_program_id) override;
|
ResultStatus ReadProgramId(u64& out_program_id) override;
|
||||||
|
|
|
@ -30,7 +30,7 @@ FileType AppLoader_NCA::IdentifyType(const FileSys::VirtualFile& file) {
|
||||||
return FileType::Error;
|
return FileType::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus AppLoader_NCA::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
ResultStatus AppLoader_NCA::Load(Kernel::Process& process) {
|
||||||
if (is_loaded) {
|
if (is_loaded) {
|
||||||
return ResultStatus::ErrorAlreadyLoaded;
|
return ResultStatus::ErrorAlreadyLoaded;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/file_sys/vfs.h"
|
#include "core/file_sys/vfs.h"
|
||||||
#include "core/hle/kernel/object.h"
|
|
||||||
#include "core/loader/loader.h"
|
#include "core/loader/loader.h"
|
||||||
|
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
|
@ -34,7 +33,7 @@ public:
|
||||||
return IdentifyType(file);
|
return IdentifyType(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
|
ResultStatus Load(Kernel::Process& process) override;
|
||||||
|
|
||||||
ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override;
|
ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override;
|
||||||
u64 ReadRomFSIVFCOffset() const override;
|
u64 ReadRomFSIVFCOffset() const override;
|
||||||
|
|
|
@ -175,19 +175,19 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
ResultStatus AppLoader_NRO::Load(Kernel::Process& process) {
|
||||||
if (is_loaded) {
|
if (is_loaded) {
|
||||||
return ResultStatus::ErrorAlreadyLoaded;
|
return ResultStatus::ErrorAlreadyLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load NRO
|
// Load NRO
|
||||||
const VAddr base_address = process->vm_manager.GetCodeRegionBaseAddress();
|
const VAddr base_address = process.vm_manager.GetCodeRegionBaseAddress();
|
||||||
|
|
||||||
if (!LoadNro(file, base_address)) {
|
if (!LoadNro(file, base_address)) {
|
||||||
return ResultStatus::ErrorLoadingNRO;
|
return ResultStatus::ErrorLoadingNRO;
|
||||||
}
|
}
|
||||||
|
|
||||||
process->Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE);
|
process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE);
|
||||||
|
|
||||||
is_loaded = true;
|
is_loaded = true;
|
||||||
return ResultStatus::Success;
|
return ResultStatus::Success;
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/hle/kernel/object.h"
|
|
||||||
#include "core/loader/linker.h"
|
#include "core/loader/linker.h"
|
||||||
#include "core/loader/loader.h"
|
#include "core/loader/loader.h"
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ public:
|
||||||
return IdentifyType(file);
|
return IdentifyType(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
|
ResultStatus Load(Kernel::Process& process) override;
|
||||||
|
|
||||||
ResultStatus ReadIcon(std::vector<u8>& buffer) override;
|
ResultStatus ReadIcon(std::vector<u8>& buffer) override;
|
||||||
ResultStatus ReadProgramId(u64& out_program_id) override;
|
ResultStatus ReadProgramId(u64& out_program_id) override;
|
||||||
|
|
|
@ -153,17 +153,17 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) {
|
||||||
return load_base + image_size;
|
return load_base + image_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus AppLoader_NSO::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
ResultStatus AppLoader_NSO::Load(Kernel::Process& process) {
|
||||||
if (is_loaded) {
|
if (is_loaded) {
|
||||||
return ResultStatus::ErrorAlreadyLoaded;
|
return ResultStatus::ErrorAlreadyLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load module
|
// Load module
|
||||||
const VAddr base_address = process->vm_manager.GetCodeRegionBaseAddress();
|
const VAddr base_address = process.vm_manager.GetCodeRegionBaseAddress();
|
||||||
LoadModule(file, base_address);
|
LoadModule(file, base_address);
|
||||||
LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address);
|
LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address);
|
||||||
|
|
||||||
process->Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE);
|
process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE);
|
||||||
|
|
||||||
is_loaded = true;
|
is_loaded = true;
|
||||||
return ResultStatus::Success;
|
return ResultStatus::Success;
|
||||||
|
|
|
@ -4,9 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/hle/kernel/object.h"
|
|
||||||
#include "core/loader/linker.h"
|
#include "core/loader/linker.h"
|
||||||
#include "core/loader/loader.h"
|
#include "core/loader/loader.h"
|
||||||
|
|
||||||
|
@ -30,7 +28,7 @@ public:
|
||||||
|
|
||||||
static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base);
|
static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base);
|
||||||
|
|
||||||
ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
|
ResultStatus Load(Kernel::Process& process) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Loader
|
} // namespace Loader
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
#include "core/file_sys/control_metadata.h"
|
#include "core/file_sys/control_metadata.h"
|
||||||
#include "core/file_sys/nca_metadata.h"
|
#include "core/file_sys/nca_metadata.h"
|
||||||
#include "core/file_sys/patch_manager.h"
|
#include "core/file_sys/patch_manager.h"
|
||||||
#include "core/file_sys/registered_cache.h"
|
|
||||||
#include "core/file_sys/romfs.h"
|
|
||||||
#include "core/file_sys/submission_package.h"
|
#include "core/file_sys/submission_package.h"
|
||||||
#include "core/hle/kernel/process.h"
|
#include "core/hle/kernel/process.h"
|
||||||
#include "core/loader/deconstructed_rom_directory.h"
|
#include "core/loader/deconstructed_rom_directory.h"
|
||||||
|
@ -62,7 +60,7 @@ FileType AppLoader_NSP::IdentifyType(const FileSys::VirtualFile& file) {
|
||||||
return FileType::Error;
|
return FileType::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus AppLoader_NSP::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
ResultStatus AppLoader_NSP::Load(Kernel::Process& process) {
|
||||||
if (is_loaded) {
|
if (is_loaded) {
|
||||||
return ResultStatus::ErrorAlreadyLoaded;
|
return ResultStatus::ErrorAlreadyLoaded;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
return IdentifyType(file);
|
return IdentifyType(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
|
ResultStatus Load(Kernel::Process& process) override;
|
||||||
|
|
||||||
ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override;
|
ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override;
|
||||||
ResultStatus ReadProgramId(u64& out_program_id) override;
|
ResultStatus ReadProgramId(u64& out_program_id) override;
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
#include "core/file_sys/content_archive.h"
|
#include "core/file_sys/content_archive.h"
|
||||||
#include "core/file_sys/control_metadata.h"
|
#include "core/file_sys/control_metadata.h"
|
||||||
#include "core/file_sys/patch_manager.h"
|
#include "core/file_sys/patch_manager.h"
|
||||||
#include "core/file_sys/romfs.h"
|
|
||||||
#include "core/file_sys/submission_package.h"
|
|
||||||
#include "core/hle/kernel/process.h"
|
#include "core/hle/kernel/process.h"
|
||||||
#include "core/loader/nca.h"
|
#include "core/loader/nca.h"
|
||||||
#include "core/loader/xci.h"
|
#include "core/loader/xci.h"
|
||||||
|
@ -46,7 +44,7 @@ FileType AppLoader_XCI::IdentifyType(const FileSys::VirtualFile& file) {
|
||||||
return FileType::Error;
|
return FileType::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus AppLoader_XCI::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
ResultStatus AppLoader_XCI::Load(Kernel::Process& process) {
|
||||||
if (is_loaded) {
|
if (is_loaded) {
|
||||||
return ResultStatus::ErrorAlreadyLoaded;
|
return ResultStatus::ErrorAlreadyLoaded;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
return IdentifyType(file);
|
return IdentifyType(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
|
ResultStatus Load(Kernel::Process& process) override;
|
||||||
|
|
||||||
ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override;
|
ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override;
|
||||||
ResultStatus ReadProgramId(u64& out_program_id) override;
|
ResultStatus ReadProgramId(u64& out_program_id) override;
|
||||||
|
|
Reference in New Issue