diff options
| author | 2018-10-12 11:36:31 -0400 | |
|---|---|---|
| committer | 2018-10-12 12:07:32 -0400 | |
| commit | 1abed2f4c42c7a389cb0e019f183d3ec94971af1 (patch) | |
| tree | c8459ae8d497e7a148365f93e971b817a0adf0f6 /src/core/loader/elf.cpp | |
| parent | Merge pull request #1474 from ogniK5377/hwopus-decodeinterleavedwithperformance (diff) | |
| download | yuzu-1abed2f4c42c7a389cb0e019f183d3ec94971af1.tar.gz yuzu-1abed2f4c42c7a389cb0e019f183d3ec94971af1.tar.xz yuzu-1abed2f4c42c7a389cb0e019f183d3ec94971af1.zip | |
kernel/process: Make CodeSet a regular non-inherited object
These only exist to ferry data into a Process instance and end up going
out of scope quite early. Because of this, we can just make it a plain
struct for holding things and just std::move it into the relevant
function. There's no need to make this inherit from the kernel's Object
type.
Diffstat (limited to 'src/core/loader/elf.cpp')
| -rw-r--r-- | src/core/loader/elf.cpp | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index e67b49fc9..6057c7f26 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -9,16 +9,11 @@ | |||
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "common/file_util.h" | 10 | #include "common/file_util.h" |
| 11 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 12 | #include "core/core.h" | ||
| 13 | #include "core/hle/kernel/kernel.h" | ||
| 14 | #include "core/hle/kernel/process.h" | 12 | #include "core/hle/kernel/process.h" |
| 15 | #include "core/hle/kernel/vm_manager.h" | 13 | #include "core/hle/kernel/vm_manager.h" |
| 16 | #include "core/loader/elf.h" | 14 | #include "core/loader/elf.h" |
| 17 | #include "core/memory.h" | 15 | #include "core/memory.h" |
| 18 | 16 | ||
| 19 | using Kernel::CodeSet; | ||
| 20 | using Kernel::SharedPtr; | ||
| 21 | |||
| 22 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 23 | // ELF Header Constants | 18 | // ELF Header Constants |
| 24 | 19 | ||
| @@ -211,7 +206,7 @@ public: | |||
| 211 | u32 GetFlags() const { | 206 | u32 GetFlags() const { |
| 212 | return (u32)(header->e_flags); | 207 | return (u32)(header->e_flags); |
| 213 | } | 208 | } |
| 214 | SharedPtr<CodeSet> LoadInto(VAddr vaddr); | 209 | Kernel::CodeSet LoadInto(VAddr vaddr); |
| 215 | 210 | ||
| 216 | int GetNumSegments() const { | 211 | int GetNumSegments() const { |
| 217 | return (int)(header->e_phnum); | 212 | return (int)(header->e_phnum); |
| @@ -274,7 +269,7 @@ const char* ElfReader::GetSectionName(int section) const { | |||
| 274 | return nullptr; | 269 | return nullptr; |
| 275 | } | 270 | } |
| 276 | 271 | ||
| 277 | SharedPtr<CodeSet> ElfReader::LoadInto(VAddr vaddr) { | 272 | Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { |
| 278 | LOG_DEBUG(Loader, "String section: {}", header->e_shstrndx); | 273 | LOG_DEBUG(Loader, "String section: {}", header->e_shstrndx); |
| 279 | 274 | ||
| 280 | // Should we relocate? | 275 | // Should we relocate? |
| @@ -302,8 +297,7 @@ SharedPtr<CodeSet> ElfReader::LoadInto(VAddr vaddr) { | |||
| 302 | std::vector<u8> program_image(total_image_size); | 297 | std::vector<u8> program_image(total_image_size); |
| 303 | std::size_t current_image_position = 0; | 298 | std::size_t current_image_position = 0; |
| 304 | 299 | ||
| 305 | auto& kernel = Core::System::GetInstance().Kernel(); | 300 | Kernel::CodeSet codeset; |
| 306 | SharedPtr<CodeSet> codeset = CodeSet::Create(kernel, ""); | ||
| 307 | 301 | ||
| 308 | for (unsigned int i = 0; i < header->e_phnum; ++i) { | 302 | for (unsigned int i = 0; i < header->e_phnum; ++i) { |
| 309 | const Elf32_Phdr* p = &segments[i]; | 303 | const Elf32_Phdr* p = &segments[i]; |
| @@ -311,14 +305,14 @@ SharedPtr<CodeSet> ElfReader::LoadInto(VAddr vaddr) { | |||
| 311 | p->p_vaddr, p->p_filesz, p->p_memsz); | 305 | p->p_vaddr, p->p_filesz, p->p_memsz); |
| 312 | 306 | ||
| 313 | if (p->p_type == PT_LOAD) { | 307 | if (p->p_type == PT_LOAD) { |
| 314 | CodeSet::Segment* codeset_segment; | 308 | Kernel::CodeSet::Segment* codeset_segment; |
| 315 | u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); | 309 | u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); |
| 316 | if (permission_flags == (PF_R | PF_X)) { | 310 | if (permission_flags == (PF_R | PF_X)) { |
| 317 | codeset_segment = &codeset->CodeSegment(); | 311 | codeset_segment = &codeset.CodeSegment(); |
| 318 | } else if (permission_flags == (PF_R)) { | 312 | } else if (permission_flags == (PF_R)) { |
| 319 | codeset_segment = &codeset->RODataSegment(); | 313 | codeset_segment = &codeset.RODataSegment(); |
| 320 | } else if (permission_flags == (PF_R | PF_W)) { | 314 | } else if (permission_flags == (PF_R | PF_W)) { |
| 321 | codeset_segment = &codeset->DataSegment(); | 315 | codeset_segment = &codeset.DataSegment(); |
| 322 | } else { | 316 | } else { |
| 323 | LOG_ERROR(Loader, "Unexpected ELF PT_LOAD segment id {} with flags {:X}", i, | 317 | LOG_ERROR(Loader, "Unexpected ELF PT_LOAD segment id {} with flags {:X}", i, |
| 324 | p->p_flags); | 318 | p->p_flags); |
| @@ -345,8 +339,8 @@ SharedPtr<CodeSet> ElfReader::LoadInto(VAddr vaddr) { | |||
| 345 | } | 339 | } |
| 346 | } | 340 | } |
| 347 | 341 | ||
| 348 | codeset->entrypoint = base_addr + header->e_entry; | 342 | codeset.entrypoint = base_addr + header->e_entry; |
| 349 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); | 343 | codeset.memory = std::make_shared<std::vector<u8>>(std::move(program_image)); |
| 350 | 344 | ||
| 351 | LOG_DEBUG(Loader, "Done loading."); | 345 | LOG_DEBUG(Loader, "Done loading."); |
| 352 | 346 | ||
| @@ -397,11 +391,11 @@ ResultStatus AppLoader_ELF::Load(Kernel::Process& process) { | |||
| 397 | 391 | ||
| 398 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); | 392 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); |
| 399 | ElfReader elf_reader(&buffer[0]); | 393 | ElfReader elf_reader(&buffer[0]); |
| 400 | SharedPtr<CodeSet> codeset = elf_reader.LoadInto(base_address); | 394 | Kernel::CodeSet codeset = elf_reader.LoadInto(base_address); |
| 401 | codeset->name = file->GetName(); | 395 | const VAddr entry_point = codeset.entrypoint; |
| 402 | 396 | ||
| 403 | process.LoadModule(codeset, codeset->entrypoint); | 397 | process.LoadModule(std::move(codeset), entry_point); |
| 404 | process.Run(codeset->entrypoint, 48, Memory::DEFAULT_STACK_SIZE); | 398 | process.Run(entry_point, 48, Memory::DEFAULT_STACK_SIZE); |
| 405 | 399 | ||
| 406 | is_loaded = true; | 400 | is_loaded = true; |
| 407 | return ResultStatus::Success; | 401 | return ResultStatus::Success; |