summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Lioncash2019-03-22 14:51:36 -0400
committerGravatar Lioncash2019-03-22 18:43:46 -0400
commitc0a01f3adc466d07fc27020048e82cca60988970 (patch)
tree4bf8428709b8a55210a9591841c0dde623386ad1
parentMerge pull request #2234 from lioncash/mutex (diff)
downloadyuzu-c0a01f3adc466d07fc27020048e82cca60988970.tar.gz
yuzu-c0a01f3adc466d07fc27020048e82cca60988970.tar.xz
yuzu-c0a01f3adc466d07fc27020048e82cca60988970.zip
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.
-rw-r--r--src/core/hle/kernel/code_set.h3
-rw-r--r--src/core/hle/kernel/process.cpp6
-rw-r--r--src/core/loader/elf.cpp2
-rw-r--r--src/core/loader/nro.cpp2
-rw-r--r--src/core/loader/nso.cpp2
5 files changed, 8 insertions, 7 deletions
diff --git a/src/core/hle/kernel/code_set.h b/src/core/hle/kernel/code_set.h
index 834fd23d2..879957dcb 100644
--- a/src/core/hle/kernel/code_set.h
+++ b/src/core/hle/kernel/code_set.h
@@ -5,7 +5,6 @@
5#pragma once 5#pragma once
6 6
7#include <cstddef> 7#include <cstddef>
8#include <memory>
9#include <vector> 8#include <vector>
10 9
11#include "common/common_types.h" 10#include "common/common_types.h"
@@ -78,7 +77,7 @@ struct CodeSet final {
78 } 77 }
79 78
80 /// The overall data that backs this code set. 79 /// The overall data that backs this code set.
81 std::shared_ptr<std::vector<u8>> memory; 80 std::vector<u8> memory;
82 81
83 /// The segments that comprise this code set. 82 /// The segments that comprise this code set.
84 std::array<Segment, 3> segments; 83 std::array<Segment, 3> segments;
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index 0d782e4ba..87779a71c 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -210,11 +210,13 @@ void Process::FreeTLSSlot(VAddr tls_address) {
210} 210}
211 211
212void Process::LoadModule(CodeSet module_, VAddr base_addr) { 212void Process::LoadModule(CodeSet module_, VAddr base_addr) {
213 const auto memory = std::make_shared<std::vector<u8>>(std::move(module_.memory));
214
213 const auto MapSegment = [&](const CodeSet::Segment& segment, VMAPermission permissions, 215 const auto MapSegment = [&](const CodeSet::Segment& segment, VMAPermission permissions,
214 MemoryState memory_state) { 216 MemoryState memory_state) {
215 const auto vma = vm_manager 217 const auto vma = vm_manager
216 .MapMemoryBlock(segment.addr + base_addr, module_.memory, 218 .MapMemoryBlock(segment.addr + base_addr, memory, segment.offset,
217 segment.offset, segment.size, memory_state) 219 segment.size, memory_state)
218 .Unwrap(); 220 .Unwrap();
219 vm_manager.Reprotect(vma, permissions); 221 vm_manager.Reprotect(vma, permissions);
220 }; 222 };
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp
index 8b1920f22..46ac372f6 100644
--- a/src/core/loader/elf.cpp
+++ b/src/core/loader/elf.cpp
@@ -341,7 +341,7 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) {
341 } 341 }
342 342
343 codeset.entrypoint = base_addr + header->e_entry; 343 codeset.entrypoint = base_addr + header->e_entry;
344 codeset.memory = std::make_shared<std::vector<u8>>(std::move(program_image)); 344 codeset.memory = std::move(program_image);
345 345
346 LOG_DEBUG(Loader, "Done loading."); 346 LOG_DEBUG(Loader, "Done loading.");
347 347
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp
index 5de02a94b..31e4a0c84 100644
--- a/src/core/loader/nro.cpp
+++ b/src/core/loader/nro.cpp
@@ -187,7 +187,7 @@ static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data,
187 program_image.resize(static_cast<u32>(program_image.size()) + bss_size); 187 program_image.resize(static_cast<u32>(program_image.size()) + bss_size);
188 188
189 // Load codeset for current process 189 // Load codeset for current process
190 codeset.memory = std::make_shared<std::vector<u8>>(std::move(program_image)); 190 codeset.memory = std::move(program_image);
191 process.LoadModule(std::move(codeset), load_base); 191 process.LoadModule(std::move(codeset), load_base);
192 192
193 // Register module with GDBStub 193 // Register module with GDBStub
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp
index 0eb9fd7f7..5caceb267 100644
--- a/src/core/loader/nso.cpp
+++ b/src/core/loader/nso.cpp
@@ -178,7 +178,7 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
178 } 178 }
179 179
180 // Load codeset for current process 180 // Load codeset for current process
181 codeset.memory = std::make_shared<std::vector<u8>>(std::move(program_image)); 181 codeset.memory = std::move(program_image);
182 process.LoadModule(std::move(codeset), load_base); 182 process.LoadModule(std::move(codeset), load_base);
183 183
184 // Register module with GDBStub 184 // Register module with GDBStub