mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-08-20 12:33:22 +02:00
Merge pull request #914 from lioncash/codeset
kernel/process: Use accessors instead of class members for referencing segment array
This commit is contained in:
commit
206f2e3436
@ -142,9 +142,9 @@ void Process::LoadModule(SharedPtr<CodeSet> module_, VAddr base_addr) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Map CodeSet segments
|
// Map CodeSet segments
|
||||||
MapSegment(module_->code, VMAPermission::ReadExecute, MemoryState::CodeStatic);
|
MapSegment(module_->CodeSegment(), VMAPermission::ReadExecute, MemoryState::CodeStatic);
|
||||||
MapSegment(module_->rodata, VMAPermission::Read, MemoryState::CodeMutable);
|
MapSegment(module_->RODataSegment(), VMAPermission::Read, MemoryState::CodeMutable);
|
||||||
MapSegment(module_->data, VMAPermission::ReadWrite, MemoryState::CodeMutable);
|
MapSegment(module_->DataSegment(), VMAPermission::ReadWrite, MemoryState::CodeMutable);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) {
|
ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -55,6 +56,12 @@ enum class ProcessStatus { Created, Running, Exited };
|
|||||||
class ResourceLimit;
|
class ResourceLimit;
|
||||||
|
|
||||||
struct CodeSet final : public Object {
|
struct CodeSet final : public Object {
|
||||||
|
struct Segment {
|
||||||
|
size_t offset = 0;
|
||||||
|
VAddr addr = 0;
|
||||||
|
u32 size = 0;
|
||||||
|
};
|
||||||
|
|
||||||
static SharedPtr<CodeSet> Create(std::string name);
|
static SharedPtr<CodeSet> Create(std::string name);
|
||||||
|
|
||||||
std::string GetTypeName() const override {
|
std::string GetTypeName() const override {
|
||||||
@ -69,24 +76,38 @@ struct CodeSet final : public Object {
|
|||||||
return HANDLE_TYPE;
|
return HANDLE_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Name of the process
|
Segment& CodeSegment() {
|
||||||
std::string name;
|
return segments[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
const Segment& CodeSegment() const {
|
||||||
|
return segments[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
Segment& RODataSegment() {
|
||||||
|
return segments[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
const Segment& RODataSegment() const {
|
||||||
|
return segments[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
Segment& DataSegment() {
|
||||||
|
return segments[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
const Segment& DataSegment() const {
|
||||||
|
return segments[2];
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<std::vector<u8>> memory;
|
std::shared_ptr<std::vector<u8>> memory;
|
||||||
|
|
||||||
struct Segment {
|
std::array<Segment, 3> segments;
|
||||||
size_t offset = 0;
|
|
||||||
VAddr addr = 0;
|
|
||||||
u32 size = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
Segment segments[3];
|
|
||||||
Segment& code = segments[0];
|
|
||||||
Segment& rodata = segments[1];
|
|
||||||
Segment& data = segments[2];
|
|
||||||
|
|
||||||
VAddr entrypoint;
|
VAddr entrypoint;
|
||||||
|
|
||||||
|
/// Name of the process
|
||||||
|
std::string name;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CodeSet();
|
CodeSet();
|
||||||
~CodeSet() override;
|
~CodeSet() override;
|
||||||
|
@ -311,11 +311,11 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) {
|
|||||||
CodeSet::Segment* codeset_segment;
|
CodeSet::Segment* codeset_segment;
|
||||||
u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X);
|
u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X);
|
||||||
if (permission_flags == (PF_R | PF_X)) {
|
if (permission_flags == (PF_R | PF_X)) {
|
||||||
codeset_segment = &codeset->code;
|
codeset_segment = &codeset->CodeSegment();
|
||||||
} else if (permission_flags == (PF_R)) {
|
} else if (permission_flags == (PF_R)) {
|
||||||
codeset_segment = &codeset->rodata;
|
codeset_segment = &codeset->RODataSegment();
|
||||||
} else if (permission_flags == (PF_R | PF_W)) {
|
} else if (permission_flags == (PF_R | PF_W)) {
|
||||||
codeset_segment = &codeset->data;
|
codeset_segment = &codeset->DataSegment();
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(Loader, "Unexpected ELF PT_LOAD segment id {} with flags {:X}", i,
|
LOG_ERROR(Loader, "Unexpected ELF PT_LOAD segment id {} with flags {:X}", i,
|
||||||
p->p_flags);
|
p->p_flags);
|
||||||
|
@ -159,7 +159,7 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) {
|
|||||||
// Resize program image to include .bss section and page align each section
|
// 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);
|
bss_size = PageAlignSize(mod_header.bss_end_offset - mod_header.bss_start_offset);
|
||||||
}
|
}
|
||||||
codeset->data.size += bss_size;
|
codeset->DataSegment().size += bss_size;
|
||||||
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
|
||||||
|
@ -127,7 +127,7 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) {
|
|||||||
// Resize program image to include .bss section and page align each section
|
// 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);
|
bss_size = PageAlignSize(mod_header.bss_end_offset - mod_header.bss_start_offset);
|
||||||
}
|
}
|
||||||
codeset->data.size += bss_size;
|
codeset->DataSegment().size += bss_size;
|
||||||
const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)};
|
const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)};
|
||||||
program_image.resize(image_size);
|
program_image.resize(image_size);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user