|
|
|
@ -17,6 +17,7 @@ |
|
|
|
#include "core/hle/kernel/vm_manager.h"
|
|
|
|
#include "core/loader/nso.h"
|
|
|
|
#include "core/memory.h"
|
|
|
|
#include "core/settings.h"
|
|
|
|
|
|
|
|
namespace Loader { |
|
|
|
|
|
|
|
@ -94,6 +95,7 @@ static constexpr u32 PageAlignSize(u32 size) { |
|
|
|
} |
|
|
|
|
|
|
|
VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, |
|
|
|
bool should_pass_arguments, |
|
|
|
boost::optional<FileSys::PatchManager> pm) { |
|
|
|
if (file == nullptr) |
|
|
|
return {}; |
|
|
|
@ -125,6 +127,17 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, |
|
|
|
codeset->segments[i].size = PageAlignSize(static_cast<u32>(data.size())); |
|
|
|
} |
|
|
|
|
|
|
|
if (should_pass_arguments && !Settings::values.program_args.empty()) { |
|
|
|
const auto arg_data = Settings::values.program_args; |
|
|
|
codeset->DataSegment().size += 0x9000; |
|
|
|
NSOArgumentHeader args_header{0x9000, arg_data.size(), {}}; |
|
|
|
program_image.resize(static_cast<u32>(program_image.size()) + 0x9000); |
|
|
|
std::memcpy(program_image.data() + program_image.size() - 0x9000, &args_header, |
|
|
|
sizeof(NSOArgumentHeader)); |
|
|
|
std::memcpy(program_image.data() + program_image.size() - 0x8FE0, arg_data.data(), |
|
|
|
arg_data.size()); |
|
|
|
} |
|
|
|
|
|
|
|
// MOD header pointer is at .text offset + 4
|
|
|
|
u32 module_offset; |
|
|
|
std::memcpy(&module_offset, program_image.data() + 4, sizeof(u32)); |
|
|
|
@ -172,7 +185,7 @@ ResultStatus AppLoader_NSO::Load(Kernel::Process& process) { |
|
|
|
|
|
|
|
// Load module
|
|
|
|
const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); |
|
|
|
LoadModule(file, base_address); |
|
|
|
LoadModule(file, base_address, true); |
|
|
|
LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); |
|
|
|
|
|
|
|
process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE); |
|
|
|
|