mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-15 10:30:05 +00:00
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
|
// 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
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user