yuzu-emu
/
yuzu
Archived
1
0
Fork 0

kernel/codeset: Make CodeSet's memory data member a regular std::vector

The use of a shared_ptr is an implementation detail of the VMManager
itself when mapping memory. Because of that, we shouldn't require all
users of the CodeSet to have to allocate the shared_ptr ahead of time.
It's intended that CodeSet simply pass in the required direct data, and
that the memory manager takes care of it from that point on.

This means we just do the shared pointer allocation in a single place,
when loading modules, as opposed to in each loader.
This commit is contained in:
Lioncash 2019-03-22 14:51:36 -04:00
parent 7b6d516faa
commit c0a01f3adc
5 changed files with 8 additions and 7 deletions

View File

@ -5,7 +5,6 @@
#pragma once #pragma once
#include <cstddef> #include <cstddef>
#include <memory>
#include <vector> #include <vector>
#include "common/common_types.h" #include "common/common_types.h"
@ -78,7 +77,7 @@ struct CodeSet final {
} }
/// The overall data that backs this code set. /// The overall data that backs this code set.
std::shared_ptr<std::vector<u8>> memory; std::vector<u8> memory;
/// The segments that comprise this code set. /// The segments that comprise this code set.
std::array<Segment, 3> segments; std::array<Segment, 3> segments;

View File

@ -210,11 +210,13 @@ void Process::FreeTLSSlot(VAddr tls_address) {
} }
void Process::LoadModule(CodeSet module_, VAddr base_addr) { void Process::LoadModule(CodeSet module_, VAddr base_addr) {
const auto memory = std::make_shared<std::vector<u8>>(std::move(module_.memory));
const auto MapSegment = [&](const CodeSet::Segment& segment, VMAPermission permissions, const auto MapSegment = [&](const CodeSet::Segment& segment, VMAPermission permissions,
MemoryState memory_state) { MemoryState memory_state) {
const auto vma = vm_manager const auto vma = vm_manager
.MapMemoryBlock(segment.addr + base_addr, module_.memory, .MapMemoryBlock(segment.addr + base_addr, memory, segment.offset,
segment.offset, segment.size, memory_state) segment.size, memory_state)
.Unwrap(); .Unwrap();
vm_manager.Reprotect(vma, permissions); vm_manager.Reprotect(vma, permissions);
}; };

View File

@ -341,7 +341,7 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) {
} }
codeset.entrypoint = base_addr + header->e_entry; codeset.entrypoint = base_addr + header->e_entry;
codeset.memory = std::make_shared<std::vector<u8>>(std::move(program_image)); codeset.memory = std::move(program_image);
LOG_DEBUG(Loader, "Done loading."); LOG_DEBUG(Loader, "Done loading.");

View File

@ -187,7 +187,7 @@ static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data,
program_image.resize(static_cast<u32>(program_image.size()) + bss_size); program_image.resize(static_cast<u32>(program_image.size()) + bss_size);
// Load codeset for current process // Load codeset for current process
codeset.memory = std::make_shared<std::vector<u8>>(std::move(program_image)); codeset.memory = std::move(program_image);
process.LoadModule(std::move(codeset), load_base); process.LoadModule(std::move(codeset), load_base);
// Register module with GDBStub // Register module with GDBStub

View File

@ -178,7 +178,7 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
} }
// Load codeset for current process // Load codeset for current process
codeset.memory = std::make_shared<std::vector<u8>>(std::move(program_image)); codeset.memory = std::move(program_image);
process.LoadModule(std::move(codeset), load_base); process.LoadModule(std::move(codeset), load_base);
// Register module with GDBStub // Register module with GDBStub