diff options
| -rw-r--r-- | src/core/loader/nro.cpp | 29 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.cpp | 3 | ||||
| -rw-r--r-- | src/yuzu/bootmanager.h | 10 | 
3 files changed, 15 insertions, 27 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; diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 61d678c9b..b9dc4943a 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp @@ -15,8 +15,7 @@  #include "input_common/motion_emu.h"  #include "yuzu/bootmanager.h" -EmuThread::EmuThread(GRenderWindow* render_window) -    : exec_step(false), running(false), stop_run(false), render_window(render_window) {} +EmuThread::EmuThread(GRenderWindow* render_window) : render_window(render_window) {}  void EmuThread::run() {      render_window->MakeCurrent(); diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index 6974edcbb..130bc613b 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h @@ -58,7 +58,7 @@ public:       * @return True if the emulation thread is running, otherwise false       * @note This function is thread-safe       */ -    bool IsRunning() { +    bool IsRunning() const {          return running;      } @@ -68,12 +68,12 @@ public:      void RequestStop() {          stop_run = true;          SetRunning(false); -    }; +    }  private: -    bool exec_step; -    bool running; -    std::atomic<bool> stop_run; +    bool exec_step = false; +    bool running = false; +    std::atomic<bool> stop_run{false};      std::mutex running_mutex;      std::condition_variable running_cv; | 
