mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-12-23 00:40:58 +01:00
process: Support loading multiple codesets.
This commit is contained in:
parent
6bafd3f4f7
commit
fa1c7c7ee1
2 changed files with 27 additions and 20 deletions
|
@ -33,7 +33,7 @@ u32 Process::next_process_id;
|
||||||
SharedPtr<Process> Process::Create(SharedPtr<CodeSet> code_set) {
|
SharedPtr<Process> Process::Create(SharedPtr<CodeSet> code_set) {
|
||||||
SharedPtr<Process> process(new Process);
|
SharedPtr<Process> process(new Process);
|
||||||
|
|
||||||
process->codeset = std::move(code_set);
|
process->codeset = code_set;
|
||||||
process->flags.raw = 0;
|
process->flags.raw = 0;
|
||||||
process->flags.memory_region.Assign(MemoryRegion::APPLICATION);
|
process->flags.memory_region.Assign(MemoryRegion::APPLICATION);
|
||||||
|
|
||||||
|
@ -113,24 +113,6 @@ void Process::ParseKernelCaps(const u32* kernel_caps, size_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process::Run(s32 main_thread_priority, u32 stack_size) {
|
void Process::Run(s32 main_thread_priority, u32 stack_size) {
|
||||||
memory_region = GetMemoryRegion(flags.memory_region);
|
|
||||||
|
|
||||||
auto MapSegment = [&](CodeSet::Segment& segment, VMAPermission permissions,
|
|
||||||
MemoryState memory_state) {
|
|
||||||
auto vma = vm_manager
|
|
||||||
.MapMemoryBlock(segment.addr, codeset->memory, segment.offset, segment.size,
|
|
||||||
memory_state)
|
|
||||||
.Unwrap();
|
|
||||||
vm_manager.Reprotect(vma, permissions);
|
|
||||||
misc_memory_used += segment.size;
|
|
||||||
memory_region->used += segment.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);
|
|
||||||
|
|
||||||
// Allocate and map stack
|
// Allocate and map stack
|
||||||
vm_manager
|
vm_manager
|
||||||
.MapMemoryBlock(Memory::HEAP_VADDR_END - stack_size,
|
.MapMemoryBlock(Memory::HEAP_VADDR_END - stack_size,
|
||||||
|
@ -148,6 +130,25 @@ void Process::Run(s32 main_thread_priority, u32 stack_size) {
|
||||||
|
|
||||||
vm_manager.LogLayout(Log::Level::Debug);
|
vm_manager.LogLayout(Log::Level::Debug);
|
||||||
Kernel::SetupMainThread(codeset->entrypoint, main_thread_priority);
|
Kernel::SetupMainThread(codeset->entrypoint, main_thread_priority);
|
||||||
|
|
||||||
|
void Process::LoadModule(SharedPtr<CodeSet> module_, VAddr base_addr) {
|
||||||
|
memory_region = GetMemoryRegion(flags.memory_region);
|
||||||
|
|
||||||
|
auto MapSegment = [&](CodeSet::Segment& segment, VMAPermission permissions,
|
||||||
|
MemoryState memory_state) {
|
||||||
|
auto vma = vm_manager
|
||||||
|
.MapMemoryBlock(segment.addr + base_addr, module_->memory, segment.offset, segment.size,
|
||||||
|
memory_state)
|
||||||
|
.Unwrap();
|
||||||
|
vm_manager.Reprotect(vma, permissions);
|
||||||
|
misc_memory_used += segment.size;
|
||||||
|
memory_region->used += segment.size;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Map CodeSet segments
|
||||||
|
MapSegment(module_->code, VMAPermission::ReadExecute, MemoryState::Code);
|
||||||
|
MapSegment(module_->rodata, VMAPermission::Read, MemoryState::Code);
|
||||||
|
MapSegment(module_->data, VMAPermission::ReadWrite, MemoryState::Private);
|
||||||
}
|
}
|
||||||
|
|
||||||
VAddr Process::GetLinearHeapAreaAddress() const {
|
VAddr Process::GetLinearHeapAreaAddress() const {
|
||||||
|
|
|
@ -79,7 +79,11 @@ struct CodeSet final : public Object {
|
||||||
u32 size = 0;
|
u32 size = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Segment code, rodata, data;
|
Segment segments[3];
|
||||||
|
Segment& code = segments[0];
|
||||||
|
Segment& rodata = segments[1];
|
||||||
|
Segment& data = segments[2];
|
||||||
|
|
||||||
VAddr entrypoint;
|
VAddr entrypoint;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -136,6 +140,8 @@ public:
|
||||||
*/
|
*/
|
||||||
void Run(s32 main_thread_priority, u32 stack_size);
|
void Run(s32 main_thread_priority, u32 stack_size);
|
||||||
|
|
||||||
|
void LoadModule(SharedPtr<CodeSet> module_, VAddr base_addr);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Memory Management
|
// Memory Management
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue