kernel: pass ref in Process
This commit is contained in:
parent
213b259cf1
commit
9565091fc2
|
@ -14,6 +14,7 @@ class AddressArbiter;
|
||||||
class Event;
|
class Event;
|
||||||
class Mutex;
|
class Mutex;
|
||||||
class CodeSet;
|
class CodeSet;
|
||||||
|
class Process;
|
||||||
|
|
||||||
enum class ResetType {
|
enum class ResetType {
|
||||||
OneShot,
|
OneShot,
|
||||||
|
@ -53,6 +54,8 @@ public:
|
||||||
SharedPtr<Mutex> CreateMutex(bool initial_locked, std::string name = "Unknown");
|
SharedPtr<Mutex> CreateMutex(bool initial_locked, std::string name = "Unknown");
|
||||||
|
|
||||||
SharedPtr<CodeSet> CreateCodeSet(std::string name, u64 program_id);
|
SharedPtr<CodeSet> CreateCodeSet(std::string name, u64 program_id);
|
||||||
|
|
||||||
|
SharedPtr<Process> CreateProcess(SharedPtr<CodeSet> code_set);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
|
|
@ -34,8 +34,8 @@ CodeSet::~CodeSet() {}
|
||||||
|
|
||||||
u32 Process::next_process_id;
|
u32 Process::next_process_id;
|
||||||
|
|
||||||
SharedPtr<Process> Process::Create(SharedPtr<CodeSet> code_set) {
|
SharedPtr<Process> KernelSystem::CreateProcess(SharedPtr<CodeSet> code_set) {
|
||||||
SharedPtr<Process> process(new Process);
|
SharedPtr<Process> process(new Process(*this));
|
||||||
|
|
||||||
process->codeset = std::move(code_set);
|
process->codeset = std::move(code_set);
|
||||||
process->flags.raw = 0;
|
process->flags.raw = 0;
|
||||||
|
@ -304,7 +304,7 @@ ResultCode Process::LinearFree(VAddr target, u32 size) {
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
Kernel::Process::Process() {}
|
Kernel::Process::Process(KernelSystem& kernel) : kernel(kernel) {}
|
||||||
Kernel::Process::~Process() {}
|
Kernel::Process::~Process() {}
|
||||||
|
|
||||||
void ClearProcessList() {
|
void ClearProcessList() {
|
||||||
|
|
|
@ -117,8 +117,6 @@ private:
|
||||||
|
|
||||||
class Process final : public Object {
|
class Process final : public Object {
|
||||||
public:
|
public:
|
||||||
static SharedPtr<Process> Create(SharedPtr<CodeSet> code_set);
|
|
||||||
|
|
||||||
std::string GetTypeName() const override {
|
std::string GetTypeName() const override {
|
||||||
return "Process";
|
return "Process";
|
||||||
}
|
}
|
||||||
|
@ -201,8 +199,11 @@ public:
|
||||||
ResultCode LinearFree(VAddr target, u32 size);
|
ResultCode LinearFree(VAddr target, u32 size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Process();
|
explicit Process(Kernel::KernelSystem& kernel);
|
||||||
~Process() override;
|
~Process() override;
|
||||||
|
|
||||||
|
friend class KernelSystem;
|
||||||
|
KernelSystem& kernel;
|
||||||
};
|
};
|
||||||
|
|
||||||
void ClearProcessList();
|
void ClearProcessList();
|
||||||
|
|
|
@ -267,7 +267,7 @@ ResultStatus AppLoader_THREEDSX::Load(Kernel::SharedPtr<Kernel::Process>& proces
|
||||||
return ResultStatus::Error;
|
return ResultStatus::Error;
|
||||||
codeset->name = filename;
|
codeset->name = filename;
|
||||||
|
|
||||||
process = Kernel::Process::Create(std::move(codeset));
|
process = Core::System::GetInstance().Kernel().CreateProcess(std::move(codeset));
|
||||||
process->svc_access_mask.set();
|
process->svc_access_mask.set();
|
||||||
process->address_mappings = default_address_mappings;
|
process->address_mappings = default_address_mappings;
|
||||||
|
|
||||||
|
|
|
@ -396,7 +396,7 @@ ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
||||||
SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR);
|
SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR);
|
||||||
codeset->name = filename;
|
codeset->name = filename;
|
||||||
|
|
||||||
process = Kernel::Process::Create(std::move(codeset));
|
process = Core::System::GetInstance().Kernel().CreateProcess(std::move(codeset));
|
||||||
process->svc_access_mask.set();
|
process->svc_access_mask.set();
|
||||||
process->address_mappings = default_address_mappings;
|
process->address_mappings = default_address_mappings;
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ ResultStatus AppLoader_NCCH::LoadExec(Kernel::SharedPtr<Kernel::Process>& proces
|
||||||
codeset->entrypoint = codeset->CodeSegment().addr;
|
codeset->entrypoint = codeset->CodeSegment().addr;
|
||||||
codeset->memory = std::make_shared<std::vector<u8>>(std::move(code));
|
codeset->memory = std::make_shared<std::vector<u8>>(std::move(code));
|
||||||
|
|
||||||
process = Kernel::Process::Create(std::move(codeset));
|
process = Core::System::GetInstance().Kernel().CreateProcess(std::move(codeset));
|
||||||
|
|
||||||
// Attach a resource limit to the process based on the resource limit category
|
// Attach a resource limit to the process based on the resource limit category
|
||||||
process->resource_limit =
|
process->resource_limit =
|
||||||
|
|
|
@ -19,7 +19,7 @@ TestEnvironment::TestEnvironment(bool mutable_memory_)
|
||||||
CoreTiming::Init();
|
CoreTiming::Init();
|
||||||
kernel = std::make_unique<Kernel::KernelSystem>(0);
|
kernel = std::make_unique<Kernel::KernelSystem>(0);
|
||||||
|
|
||||||
Kernel::g_current_process = Kernel::Process::Create(kernel->CreateCodeSet("", 0));
|
Kernel::g_current_process = kernel->CreateProcess(kernel->CreateCodeSet("", 0));
|
||||||
page_table = &Kernel::g_current_process->vm_manager.page_table;
|
page_table = &Kernel::g_current_process->vm_manager.page_table;
|
||||||
|
|
||||||
page_table->pointers.fill(nullptr);
|
page_table->pointers.fill(nullptr);
|
||||||
|
|
|
@ -25,7 +25,7 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel
|
||||||
auto session = std::get<SharedPtr<ServerSession>>(ServerSession::CreateSessionPair());
|
auto session = std::get<SharedPtr<ServerSession>>(ServerSession::CreateSessionPair());
|
||||||
HLERequestContext context(std::move(session));
|
HLERequestContext context(std::move(session));
|
||||||
|
|
||||||
auto process = Process::Create(kernel.CreateCodeSet("", 0));
|
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
||||||
HandleTable handle_table;
|
HandleTable handle_table;
|
||||||
|
|
||||||
SECTION("works with empty cmdbuf") {
|
SECTION("works with empty cmdbuf") {
|
||||||
|
@ -235,7 +235,7 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
|
||||||
auto session = std::get<SharedPtr<ServerSession>>(ServerSession::CreateSessionPair());
|
auto session = std::get<SharedPtr<ServerSession>>(ServerSession::CreateSessionPair());
|
||||||
HLERequestContext context(std::move(session));
|
HLERequestContext context(std::move(session));
|
||||||
|
|
||||||
auto process = Process::Create(kernel.CreateCodeSet("", 0));
|
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
||||||
HandleTable handle_table;
|
HandleTable handle_table;
|
||||||
auto* input = context.CommandBuffer();
|
auto* input = context.CommandBuffer();
|
||||||
u32_le output[IPC::COMMAND_BUFFER_LENGTH];
|
u32_le output[IPC::COMMAND_BUFFER_LENGTH];
|
||||||
|
|
|
@ -13,7 +13,7 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
|
||||||
CoreTiming::Init();
|
CoreTiming::Init();
|
||||||
Kernel::KernelSystem kernel(0);
|
Kernel::KernelSystem kernel(0);
|
||||||
SECTION("these regions should not be mapped on an empty process") {
|
SECTION("these regions should not be mapped on an empty process") {
|
||||||
auto process = Kernel::Process::Create(kernel.CreateCodeSet("", 0));
|
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
||||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false);
|
CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false);
|
||||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::HEAP_VADDR) == false);
|
CHECK(Memory::IsValidVirtualAddress(*process, Memory::HEAP_VADDR) == false);
|
||||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::LINEAR_HEAP_VADDR) == false);
|
CHECK(Memory::IsValidVirtualAddress(*process, Memory::LINEAR_HEAP_VADDR) == false);
|
||||||
|
@ -24,14 +24,14 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") {
|
SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") {
|
||||||
auto process = Kernel::Process::Create(kernel.CreateCodeSet("", 0));
|
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
||||||
Kernel::MapSharedPages(process->vm_manager);
|
Kernel::MapSharedPages(process->vm_manager);
|
||||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true);
|
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true);
|
||||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true);
|
CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("special regions should be valid after mapping them") {
|
SECTION("special regions should be valid after mapping them") {
|
||||||
auto process = Kernel::Process::Create(kernel.CreateCodeSet("", 0));
|
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
||||||
SECTION("VRAM") {
|
SECTION("VRAM") {
|
||||||
Kernel::HandleSpecialMapping(process->vm_manager,
|
Kernel::HandleSpecialMapping(process->vm_manager,
|
||||||
{Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false});
|
{Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false});
|
||||||
|
@ -46,7 +46,7 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Unmapping a VAddr should make it invalid") {
|
SECTION("Unmapping a VAddr should make it invalid") {
|
||||||
auto process = Kernel::Process::Create(kernel.CreateCodeSet("", 0));
|
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
|
||||||
Kernel::MapSharedPages(process->vm_manager);
|
Kernel::MapSharedPages(process->vm_manager);
|
||||||
process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE);
|
process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE);
|
||||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false);
|
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false);
|
||||||
|
|
Reference in New Issue