summaryrefslogtreecommitdiffstats
path: root/src/core/loader
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2018-01-18 00:16:09 +0100
committergdkchan <gab.dark.100@gmail.com>2018-01-18 00:16:09 +0100
commitd3e63e42204c8e8be02af651fd6281ac204ccba5 (patch)
tree663e403c56816990ed057b0aad4b254f4cdfa811 /src/core/loader
parentMerge pull request #76 from Rozelette/master (diff)
downloadyuzu-d3e63e42204c8e8be02af651fd6281ac204ccba5.tar
yuzu-d3e63e42204c8e8be02af651fd6281ac204ccba5.tar.gz
yuzu-d3e63e42204c8e8be02af651fd6281ac204ccba5.tar.bz2
yuzu-d3e63e42204c8e8be02af651fd6281ac204ccba5.tar.lz
yuzu-d3e63e42204c8e8be02af651fd6281ac204ccba5.tar.xz
yuzu-d3e63e42204c8e8be02af651fd6281ac204ccba5.tar.zst
yuzu-d3e63e42204c8e8be02af651fd6281ac204ccba5.zip
Diffstat (limited to 'src/core/loader')
-rw-r--r--src/core/loader/nro.cpp29
1 files changed, 9 insertions, 20 deletions
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp
index 66c61b038..6864a1926 100644
--- a/src/core/loader/nro.cpp
+++ b/src/core/loader/nro.cpp
@@ -62,20 +62,6 @@ static constexpr u32 PageAlignSize(u32 size) {
return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK;
}
-static std::vector<u8> ReadSegment(FileUtil::IOFile& file, const NroSegmentHeader& header) {
- std::vector<u8> data;
- data.resize(header.size);
-
- file.Seek(header.offset + sizeof(NroHeader), SEEK_SET);
- size_t bytes_read{file.ReadBytes(data.data(), header.size)};
- if (header.size != PageAlignSize(static_cast<u32>(bytes_read))) {
- LOG_CRITICAL(Loader, "Failed to read NRO segment bytes", header.size);
- return {};
- }
-
- return data;
-}
-
bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) {
FileUtil::IOFile file(path, "rb");
if (!file.IsOpen()) {
@@ -95,7 +81,7 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) {
// Build program image
Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("", 0);
std::vector<u8> program_image;
- program_image.resize(PageAlignSize(nro_header.file_size + nro_header.bss_size));
+ program_image.resize(PageAlignSize(nro_header.file_size));
file.Seek(0, SEEK_SET);
file.ReadBytes(program_image.data(), nro_header.file_size);
@@ -107,15 +93,16 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) {
// Read MOD header
ModHeader mod_header{};
- u32 bss_size{Memory::PAGE_SIZE}; // Default .bss to page size if MOD0 section doesn't exist
+ // Default .bss to NRO header bss size if MOD0 section doesn't exist
+ u32 bss_size{PageAlignSize(nro_header.bss_size)};
std::memcpy(&mod_header, program_image.data() + nro_header.module_header_offset,
sizeof(ModHeader));
const bool has_mod_header{mod_header.magic == Common::MakeMagic('M', 'O', 'D', '0')};
if (has_mod_header) {
// Resize program image to include .bss section and page align each section
bss_size = PageAlignSize(mod_header.bss_end_offset - mod_header.bss_start_offset);
- codeset->data.size += bss_size;
}
+ codeset->data.size += bss_size;
program_image.resize(PageAlignSize(static_cast<u32>(program_image.size()) + bss_size));
// Load codeset for current process
@@ -134,9 +121,11 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) {
return ResultStatus::Error;
}
- // Load and relocate "main" and "sdk" NSO
- static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR};
process = Kernel::Process::Create("main");
+
+ // Load NRO
+ static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR};
+
if (!LoadNro(filepath, base_addr)) {
return ResultStatus::ErrorInvalidFormat;
}
@@ -145,7 +134,7 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) {
process->address_mappings = default_address_mappings;
process->resource_limit =
Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION);
- process->Run(base_addr, 48, Kernel::DEFAULT_STACK_SIZE);
+ process->Run(base_addr + sizeof(NroHeader), 48, Kernel::DEFAULT_STACK_SIZE);
is_loaded = true;
return ResultStatus::Success;