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:
parent
47025552c7
commit
37e78de206
|
@ -133,9 +133,9 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) {
|
|||
};
|
||||
|
||||
// Map CodeSet segments
|
||||
MapSegment(codeset->code, VMAPermission::ReadExecute, MemoryState::Code);
|
||||
MapSegment(codeset->rodata, VMAPermission::Read, MemoryState::Code);
|
||||
MapSegment(codeset->data, VMAPermission::ReadWrite, MemoryState::Private);
|
||||
MapSegment(codeset->CodeSegment(), VMAPermission::ReadExecute, MemoryState::Code);
|
||||
MapSegment(codeset->RODataSegment(), VMAPermission::Read, MemoryState::Code);
|
||||
MapSegment(codeset->DataSegment(), VMAPermission::ReadWrite, MemoryState::Private);
|
||||
|
||||
// Allocate and map stack
|
||||
vm_manager
|
||||
|
|
|
@ -55,6 +55,12 @@ class ResourceLimit;
|
|||
struct MemoryRegionInfo;
|
||||
|
||||
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);
|
||||
|
||||
std::string GetTypeName() const override {
|
||||
|
@ -69,22 +75,40 @@ struct CodeSet final : public Object {
|
|||
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
|
||||
std::string name;
|
||||
/// Title ID corresponding to the process
|
||||
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:
|
||||
CodeSet();
|
||||
~CodeSet() override;
|
||||
|
|
|
@ -310,11 +310,11 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) {
|
|||
CodeSet::Segment* codeset_segment;
|
||||
u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X);
|
||||
if (permission_flags == (PF_R | PF_X)) {
|
||||
codeset_segment = &codeset->code;
|
||||
codeset_segment = &codeset->CodeSegment();
|
||||
} else if (permission_flags == (PF_R)) {
|
||||
codeset_segment = &codeset->rodata;
|
||||
codeset_segment = &codeset->RODataSegment();
|
||||
} else if (permission_flags == (PF_R | PF_W)) {
|
||||
codeset_segment = &codeset->data;
|
||||
codeset_segment = &codeset->DataSegment();
|
||||
} else {
|
||||
LOG_ERROR(Loader, "Unexpected ELF PT_LOAD segment id {} with flags {:X}", i,
|
||||
p->p_flags);
|
||||
|
|
Loading…
Reference in New Issue