mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-08-21 22:33:22 +02:00
Merge pull request #3745 from bunnei/fix-homebrew-load
Fix process memory initialization for ELF and NRO
This commit is contained in:
commit
cd47ccec49
@ -51,6 +51,17 @@ Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) {
|
|||||||
return Loader::ResultStatus::Success;
|
return Loader::ResultStatus::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*static*/ ProgramMetadata ProgramMetadata::GetDefault() {
|
||||||
|
ProgramMetadata result;
|
||||||
|
|
||||||
|
result.LoadManual(
|
||||||
|
true /*is_64_bit*/, FileSys::ProgramAddressSpaceType::Is39Bit /*address_space*/,
|
||||||
|
0x2c /*main_thread_prio*/, 0 /*main_thread_core*/, 0x00100000 /*main_thread_stack_size*/,
|
||||||
|
{}, 0xFFFFFFFFFFFFFFFF /*filesystem_permissions*/, {} /*capabilities*/);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void ProgramMetadata::LoadManual(bool is_64_bit, ProgramAddressSpaceType address_space,
|
void ProgramMetadata::LoadManual(bool is_64_bit, ProgramAddressSpaceType address_space,
|
||||||
s32 main_thread_prio, u32 main_thread_core,
|
s32 main_thread_prio, u32 main_thread_core,
|
||||||
u32 main_thread_stack_size, u64 title_id,
|
u32 main_thread_stack_size, u64 title_id,
|
||||||
|
@ -44,9 +44,13 @@ public:
|
|||||||
ProgramMetadata();
|
ProgramMetadata();
|
||||||
~ProgramMetadata();
|
~ProgramMetadata();
|
||||||
|
|
||||||
|
/// Gets a default ProgramMetadata configuration, should only be used for homebrew formats where
|
||||||
|
/// we do not have an NPDM file
|
||||||
|
static ProgramMetadata GetDefault();
|
||||||
|
|
||||||
Loader::ResultStatus Load(VirtualFile file);
|
Loader::ResultStatus Load(VirtualFile file);
|
||||||
|
|
||||||
// Load from parameters instead of NPDM file, used for KIP
|
/// Load from parameters instead of NPDM file, used for KIP
|
||||||
void LoadManual(bool is_64_bit, ProgramAddressSpaceType address_space, s32 main_thread_prio,
|
void LoadManual(bool is_64_bit, ProgramAddressSpaceType address_space, s32 main_thread_prio,
|
||||||
u32 main_thread_core, u32 main_thread_stack_size, u64 title_id,
|
u32 main_thread_core, u32 main_thread_stack_size, u64 title_id,
|
||||||
u64 filesystem_permissions, KernelCapabilityDescriptors capabilities);
|
u64 filesystem_permissions, KernelCapabilityDescriptors capabilities);
|
||||||
|
@ -398,6 +398,11 @@ AppLoader_ELF::LoadResult AppLoader_ELF::Load(Kernel::Process& process) {
|
|||||||
Kernel::CodeSet codeset = elf_reader.LoadInto(base_address);
|
Kernel::CodeSet codeset = elf_reader.LoadInto(base_address);
|
||||||
const VAddr entry_point = codeset.entrypoint;
|
const VAddr entry_point = codeset.entrypoint;
|
||||||
|
|
||||||
|
// Setup the process code layout
|
||||||
|
if (process.LoadFromMetadata(FileSys::ProgramMetadata::GetDefault(), buffer.size()).IsError()) {
|
||||||
|
return {ResultStatus::ErrorNotInitialized, {}};
|
||||||
|
}
|
||||||
|
|
||||||
process.LoadModule(std::move(codeset), entry_point);
|
process.LoadModule(std::move(codeset), entry_point);
|
||||||
|
|
||||||
is_loaded = true;
|
is_loaded = true;
|
||||||
|
@ -131,7 +131,7 @@ static constexpr u32 PageAlignSize(u32 size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data,
|
static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data,
|
||||||
const std::string& name, VAddr load_base) {
|
const std::string& name) {
|
||||||
if (data.size() < sizeof(NroHeader)) {
|
if (data.size() < sizeof(NroHeader)) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -187,19 +187,25 @@ static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data,
|
|||||||
codeset.DataSegment().size += bss_size;
|
codeset.DataSegment().size += bss_size;
|
||||||
program_image.resize(static_cast<u32>(program_image.size()) + bss_size);
|
program_image.resize(static_cast<u32>(program_image.size()) + bss_size);
|
||||||
|
|
||||||
|
// Setup the process code layout
|
||||||
|
if (process.LoadFromMetadata(FileSys::ProgramMetadata::GetDefault(), program_image.size())
|
||||||
|
.IsError()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Load codeset for current process
|
// Load codeset for current process
|
||||||
codeset.memory = std::move(program_image);
|
codeset.memory = std::move(program_image);
|
||||||
process.LoadModule(std::move(codeset), load_base);
|
process.LoadModule(std::move(codeset), process.PageTable().GetCodeRegionStart());
|
||||||
|
|
||||||
// Register module with GDBStub
|
// Register module with GDBStub
|
||||||
GDBStub::RegisterModule(name, load_base, load_base);
|
GDBStub::RegisterModule(name, process.PageTable().GetCodeRegionStart(),
|
||||||
|
process.PageTable().GetCodeRegionEnd());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& file,
|
bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& file) {
|
||||||
VAddr load_base) {
|
return LoadNroImpl(process, file.ReadAllBytes(), file.GetName());
|
||||||
return LoadNroImpl(process, file.ReadAllBytes(), file.GetName(), load_base);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process) {
|
AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process) {
|
||||||
@ -207,10 +213,7 @@ AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process) {
|
|||||||
return {ResultStatus::ErrorAlreadyLoaded, {}};
|
return {ResultStatus::ErrorAlreadyLoaded, {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load NRO
|
if (!LoadNro(process, *file)) {
|
||||||
const VAddr base_address = process.PageTable().GetCodeRegionStart();
|
|
||||||
|
|
||||||
if (!LoadNro(process, *file, base_address)) {
|
|
||||||
return {ResultStatus::ErrorLoadingNRO, {}};
|
return {ResultStatus::ErrorLoadingNRO, {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public:
|
|||||||
bool IsRomFSUpdatable() const override;
|
bool IsRomFSUpdatable() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool LoadNro(Kernel::Process& process, const FileSys::VfsFile& file, VAddr load_base);
|
bool LoadNro(Kernel::Process& process, const FileSys::VfsFile& file);
|
||||||
|
|
||||||
std::vector<u8> icon_data;
|
std::vector<u8> icon_data;
|
||||||
std::unique_ptr<FileSys::NACP> nacp;
|
std::unique_ptr<FileSys::NACP> nacp;
|
||||||
|
Loading…
Reference in New Issue
Block a user