mirror of
https://git.h3cjp.net/H3cJP/yuzu.git
synced 2024-11-14 12:13:00 +00:00
Kernel: Store the program id in the Process class instead of the CodeSet class.
There may be many CodeSets per Process, so it's wasteful and overcomplicated to store the program id in each of them.
This commit is contained in:
parent
cc6e4ae6cf
commit
827f8ca3c7
|
@ -20,12 +20,9 @@ namespace Kernel {
|
|||
// Lists all processes that exist in the current session.
|
||||
static std::vector<SharedPtr<Process>> process_list;
|
||||
|
||||
SharedPtr<CodeSet> CodeSet::Create(std::string name, u64 program_id) {
|
||||
SharedPtr<CodeSet> CodeSet::Create(std::string name) {
|
||||
SharedPtr<CodeSet> codeset(new CodeSet);
|
||||
|
||||
codeset->name = std::move(name);
|
||||
codeset->program_id = program_id;
|
||||
|
||||
return codeset;
|
||||
}
|
||||
|
||||
|
@ -34,13 +31,14 @@ CodeSet::~CodeSet() {}
|
|||
|
||||
u32 Process::next_process_id;
|
||||
|
||||
SharedPtr<Process> Process::Create(std::string&& name) {
|
||||
SharedPtr<Process> Process::Create(std::string&& name, u64 program_id) {
|
||||
SharedPtr<Process> process(new Process);
|
||||
|
||||
process->name = std::move(name);
|
||||
process->flags.raw = 0;
|
||||
process->flags.memory_region.Assign(MemoryRegion::APPLICATION);
|
||||
process->status = ProcessStatus::Created;
|
||||
process->program_id = program_id;
|
||||
|
||||
process_list.push_back(process);
|
||||
return process;
|
||||
|
|
|
@ -56,7 +56,7 @@ class ResourceLimit;
|
|||
struct MemoryRegionInfo;
|
||||
|
||||
struct CodeSet final : public Object {
|
||||
static SharedPtr<CodeSet> Create(std::string name, u64 program_id);
|
||||
static SharedPtr<CodeSet> Create(std::string name);
|
||||
|
||||
std::string GetTypeName() const override {
|
||||
return "CodeSet";
|
||||
|
@ -72,8 +72,6 @@ struct CodeSet final : public Object {
|
|||
|
||||
/// Name of the process
|
||||
std::string name;
|
||||
/// Title ID corresponding to the process
|
||||
u64 program_id;
|
||||
|
||||
std::shared_ptr<std::vector<u8>> memory;
|
||||
|
||||
|
@ -97,7 +95,7 @@ private:
|
|||
|
||||
class Process final : public Object {
|
||||
public:
|
||||
static SharedPtr<Process> Create(std::string&& name);
|
||||
static SharedPtr<Process> Create(std::string&& name, u64 program_id);
|
||||
|
||||
std::string GetTypeName() const override {
|
||||
return "Process";
|
||||
|
@ -113,6 +111,9 @@ public:
|
|||
|
||||
static u32 next_process_id;
|
||||
|
||||
/// Title ID corresponding to the process
|
||||
u64 program_id;
|
||||
|
||||
/// Resource limit descriptor for this process
|
||||
SharedPtr<ResourceLimit> resource_limit;
|
||||
|
||||
|
|
|
@ -110,8 +110,6 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(
|
|||
return ResultStatus::Error;
|
||||
}
|
||||
|
||||
process = Kernel::Process::Create("main");
|
||||
|
||||
const std::string directory = filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP;
|
||||
const std::string npdm_path = directory + DIR_SEP + "main.npdm";
|
||||
|
||||
|
@ -121,13 +119,15 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(
|
|||
}
|
||||
metadata.Print();
|
||||
|
||||
process = Kernel::Process::Create("main", metadata.GetTitleID());
|
||||
|
||||
// Load NSO modules
|
||||
VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR};
|
||||
for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3",
|
||||
"subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) {
|
||||
const std::string path = directory + DIR_SEP + module;
|
||||
const VAddr load_addr = next_load_addr;
|
||||
next_load_addr = AppLoader_NSO::LoadModule(path, load_addr, metadata.GetTitleID());
|
||||
next_load_addr = AppLoader_NSO::LoadModule(path, load_addr);
|
||||
if (next_load_addr) {
|
||||
LOG_DEBUG(Loader, "loaded module %s @ 0x%" PRIx64, module, load_addr);
|
||||
} else {
|
||||
|
|
|
@ -300,7 +300,7 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) {
|
|||
std::vector<u8> program_image(total_image_size);
|
||||
size_t current_image_position = 0;
|
||||
|
||||
SharedPtr<CodeSet> codeset = CodeSet::Create("", 0);
|
||||
SharedPtr<CodeSet> codeset = CodeSet::Create("");
|
||||
|
||||
for (unsigned int i = 0; i < header->e_phnum; ++i) {
|
||||
Elf32_Phdr* p = &segments[i];
|
||||
|
@ -406,7 +406,7 @@ ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
|||
SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR);
|
||||
codeset->name = filename;
|
||||
|
||||
process = Kernel::Process::Create("main");
|
||||
process = Kernel::Process::Create("main", 0);
|
||||
process->LoadModule(codeset, codeset->entrypoint);
|
||||
process->svc_access_mask.set();
|
||||
process->address_mappings = default_address_mappings;
|
||||
|
|
|
@ -83,7 +83,7 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) {
|
|||
}
|
||||
|
||||
// Build program image
|
||||
Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("", 0);
|
||||
Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("");
|
||||
std::vector<u8> program_image;
|
||||
program_image.resize(PageAlignSize(nro_header.file_size));
|
||||
file.Seek(0, SEEK_SET);
|
||||
|
@ -125,7 +125,7 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
|||
return ResultStatus::Error;
|
||||
}
|
||||
|
||||
process = Kernel::Process::Create("main");
|
||||
process = Kernel::Process::Create("main", 0);
|
||||
|
||||
// Load NRO
|
||||
static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR};
|
||||
|
|
|
@ -92,7 +92,7 @@ static constexpr u32 PageAlignSize(u32 size) {
|
|||
return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK;
|
||||
}
|
||||
|
||||
VAddr AppLoader_NSO::LoadModule(const std::string& path, VAddr load_base, u64 tid) {
|
||||
VAddr AppLoader_NSO::LoadModule(const std::string& path, VAddr load_base) {
|
||||
FileUtil::IOFile file(path, "rb");
|
||||
if (!file.IsOpen()) {
|
||||
return {};
|
||||
|
@ -109,7 +109,7 @@ VAddr AppLoader_NSO::LoadModule(const std::string& path, VAddr load_base, u64 ti
|
|||
}
|
||||
|
||||
// Build program image
|
||||
Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("", tid);
|
||||
Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("");
|
||||
std::vector<u8> program_image;
|
||||
for (int i = 0; i < nso_header.segments.size(); ++i) {
|
||||
std::vector<u8> data =
|
||||
|
@ -155,10 +155,10 @@ ResultStatus AppLoader_NSO::Load(Kernel::SharedPtr<Kernel::Process>& process) {
|
|||
return ResultStatus::Error;
|
||||
}
|
||||
|
||||
process = Kernel::Process::Create("main");
|
||||
process = Kernel::Process::Create("main", 0);
|
||||
|
||||
// Load module
|
||||
LoadModule(filepath, Memory::PROCESS_IMAGE_VADDR, 0);
|
||||
LoadModule(filepath, Memory::PROCESS_IMAGE_VADDR);
|
||||
LOG_DEBUG(Loader, "loaded module %s @ 0x%" PRIx64, filepath.c_str(),
|
||||
Memory::PROCESS_IMAGE_VADDR);
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
return IdentifyType(file, filepath);
|
||||
}
|
||||
|
||||
static VAddr LoadModule(const std::string& path, VAddr load_base, u64 tid);
|
||||
static VAddr LoadModule(const std::string& path, VAddr load_base);
|
||||
|
||||
ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ static Memory::PageTable* page_table = nullptr;
|
|||
TestEnvironment::TestEnvironment(bool mutable_memory_)
|
||||
: mutable_memory(mutable_memory_), test_memory(std::make_shared<TestMemory>(this)) {
|
||||
|
||||
Kernel::g_current_process = Kernel::Process::Create("");
|
||||
Kernel::g_current_process = Kernel::Process::Create("", 0);
|
||||
page_table = &Kernel::g_current_process->vm_manager.page_table;
|
||||
|
||||
page_table->pointers.fill(nullptr);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory][!hide]") {
|
||||
SECTION("these regions should not be mapped on an empty process") {
|
||||
auto process = Kernel::Process::Create("");
|
||||
auto process = Kernel::Process::Create("", 0);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::HEAP_VADDR) == false);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::LINEAR_HEAP_VADDR) == false);
|
||||
|
@ -20,14 +20,14 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory][!hide]") {
|
|||
}
|
||||
|
||||
SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") {
|
||||
auto process = Kernel::Process::Create("");
|
||||
auto process = Kernel::Process::Create("", 0);
|
||||
Kernel::MapSharedPages(process->vm_manager);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true);
|
||||
}
|
||||
|
||||
SECTION("special regions should be valid after mapping them") {
|
||||
auto process = Kernel::Process::Create("");
|
||||
auto process = Kernel::Process::Create("", 0);
|
||||
SECTION("VRAM") {
|
||||
Kernel::HandleSpecialMapping(process->vm_manager,
|
||||
{Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false});
|
||||
|
@ -48,7 +48,7 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory][!hide]") {
|
|||
}
|
||||
|
||||
SECTION("Unmapping a VAddr should make it invalid") {
|
||||
auto process = Kernel::Process::Create("");
|
||||
auto process = Kernel::Process::Create("", 0);
|
||||
Kernel::MapSharedPages(process->vm_manager);
|
||||
process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE);
|
||||
CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false);
|
||||
|
|
Loading…
Reference in a new issue