citra-emu
/
citra-canary
Archived
1
0
Fork 0

kernel/process: Use accessors instead of class members for referencing segment array

Using member variables for referencing the segments array increases the
size of the class in memory for little benefit. The same behavior can be
achieved through the use of accessors that just return the relevant
segment.
This commit is contained in:
Lioncash 2018-08-03 14:33:59 -04:00 committed by fearlessTobi
parent 47025552c7
commit 37e78de206
3 changed files with 41 additions and 17 deletions

View File

@ -133,9 +133,9 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) {
}; };
// Map CodeSet segments // Map CodeSet segments
MapSegment(codeset->code, VMAPermission::ReadExecute, MemoryState::Code); MapSegment(codeset->CodeSegment(), VMAPermission::ReadExecute, MemoryState::Code);
MapSegment(codeset->rodata, VMAPermission::Read, MemoryState::Code); MapSegment(codeset->RODataSegment(), VMAPermission::Read, MemoryState::Code);
MapSegment(codeset->data, VMAPermission::ReadWrite, MemoryState::Private); MapSegment(codeset->DataSegment(), VMAPermission::ReadWrite, MemoryState::Private);
// Allocate and map stack // Allocate and map stack
vm_manager vm_manager

View File

@ -55,6 +55,12 @@ class ResourceLimit;
struct MemoryRegionInfo; struct MemoryRegionInfo;
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, u64 program_id); static SharedPtr<CodeSet> Create(std::string name, u64 program_id);
std::string GetTypeName() const override { std::string GetTypeName() const override {
@ -69,22 +75,40 @@ struct CodeSet final : public Object {
return HANDLE_TYPE; return HANDLE_TYPE;
} }
Segment& CodeSegment() {
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;
Segment segments[3];
VAddr entrypoint;
/// Name of the process /// Name of the process
std::string name; std::string name;
/// Title ID corresponding to the process /// Title ID corresponding to the process
u64 program_id; u64 program_id;
std::shared_ptr<std::vector<u8>> memory;
struct Segment {
size_t offset = 0;
VAddr addr = 0;
u32 size = 0;
};
Segment code, rodata, data;
VAddr entrypoint;
private: private:
CodeSet(); CodeSet();
~CodeSet() override; ~CodeSet() override;

View File

@ -310,11 +310,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);