diff options
| author | 2018-02-27 10:22:15 -0500 | |
|---|---|---|
| committer | 2018-03-01 19:03:53 -0500 | |
| commit | 827f8ca3c77ad0b7e667c64b5c983b3b3ffe8d7d (patch) | |
| tree | e557f60eddcd74f0ab380a81dd42749b3e46ef4e /src | |
| parent | FS: Implement MountSaveData and some of the IFile interface. (diff) | |
| download | yuzu-827f8ca3c77ad0b7e667c64b5c983b3b3ffe8d7d.tar.gz yuzu-827f8ca3c77ad0b7e667c64b5c983b3b3ffe8d7d.tar.xz yuzu-827f8ca3c77ad0b7e667c64b5c983b3b3ffe8d7d.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 8 | ||||
| -rw-r--r-- | src/core/hle/kernel/process.h | 9 | ||||
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 6 | ||||
| -rw-r--r-- | src/core/loader/elf.cpp | 4 | ||||
| -rw-r--r-- | src/core/loader/nro.cpp | 4 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 8 | ||||
| -rw-r--r-- | src/core/loader/nso.h | 2 | ||||
| -rw-r--r-- | src/tests/core/arm/arm_test_common.cpp | 2 | ||||
| -rw-r--r-- | src/tests/core/memory/memory.cpp | 8 |
9 files changed, 25 insertions, 26 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 8e74059ea..bb6dc28d7 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -20,12 +20,9 @@ namespace Kernel { | |||
| 20 | // Lists all processes that exist in the current session. | 20 | // Lists all processes that exist in the current session. |
| 21 | static std::vector<SharedPtr<Process>> process_list; | 21 | static std::vector<SharedPtr<Process>> process_list; |
| 22 | 22 | ||
| 23 | SharedPtr<CodeSet> CodeSet::Create(std::string name, u64 program_id) { | 23 | SharedPtr<CodeSet> CodeSet::Create(std::string name) { |
| 24 | SharedPtr<CodeSet> codeset(new CodeSet); | 24 | SharedPtr<CodeSet> codeset(new CodeSet); |
| 25 | |||
| 26 | codeset->name = std::move(name); | 25 | codeset->name = std::move(name); |
| 27 | codeset->program_id = program_id; | ||
| 28 | |||
| 29 | return codeset; | 26 | return codeset; |
| 30 | } | 27 | } |
| 31 | 28 | ||
| @@ -34,13 +31,14 @@ CodeSet::~CodeSet() {} | |||
| 34 | 31 | ||
| 35 | u32 Process::next_process_id; | 32 | u32 Process::next_process_id; |
| 36 | 33 | ||
| 37 | SharedPtr<Process> Process::Create(std::string&& name) { | 34 | SharedPtr<Process> Process::Create(std::string&& name, u64 program_id) { |
| 38 | SharedPtr<Process> process(new Process); | 35 | SharedPtr<Process> process(new Process); |
| 39 | 36 | ||
| 40 | process->name = std::move(name); | 37 | process->name = std::move(name); |
| 41 | process->flags.raw = 0; | 38 | process->flags.raw = 0; |
| 42 | process->flags.memory_region.Assign(MemoryRegion::APPLICATION); | 39 | process->flags.memory_region.Assign(MemoryRegion::APPLICATION); |
| 43 | process->status = ProcessStatus::Created; | 40 | process->status = ProcessStatus::Created; |
| 41 | process->program_id = program_id; | ||
| 44 | 42 | ||
| 45 | process_list.push_back(process); | 43 | process_list.push_back(process); |
| 46 | return process; | 44 | return process; |
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index add98472f..1de12efd3 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h | |||
| @@ -56,7 +56,7 @@ class ResourceLimit; | |||
| 56 | struct MemoryRegionInfo; | 56 | struct MemoryRegionInfo; |
| 57 | 57 | ||
| 58 | struct CodeSet final : public Object { | 58 | struct CodeSet final : public Object { |
| 59 | static SharedPtr<CodeSet> Create(std::string name, u64 program_id); | 59 | static SharedPtr<CodeSet> Create(std::string name); |
| 60 | 60 | ||
| 61 | std::string GetTypeName() const override { | 61 | std::string GetTypeName() const override { |
| 62 | return "CodeSet"; | 62 | return "CodeSet"; |
| @@ -72,8 +72,6 @@ struct CodeSet final : public Object { | |||
| 72 | 72 | ||
| 73 | /// Name of the process | 73 | /// Name of the process |
| 74 | std::string name; | 74 | std::string name; |
| 75 | /// Title ID corresponding to the process | ||
| 76 | u64 program_id; | ||
| 77 | 75 | ||
| 78 | std::shared_ptr<std::vector<u8>> memory; | 76 | std::shared_ptr<std::vector<u8>> memory; |
| 79 | 77 | ||
| @@ -97,7 +95,7 @@ private: | |||
| 97 | 95 | ||
| 98 | class Process final : public Object { | 96 | class Process final : public Object { |
| 99 | public: | 97 | public: |
| 100 | static SharedPtr<Process> Create(std::string&& name); | 98 | static SharedPtr<Process> Create(std::string&& name, u64 program_id); |
| 101 | 99 | ||
| 102 | std::string GetTypeName() const override { | 100 | std::string GetTypeName() const override { |
| 103 | return "Process"; | 101 | return "Process"; |
| @@ -113,6 +111,9 @@ public: | |||
| 113 | 111 | ||
| 114 | static u32 next_process_id; | 112 | static u32 next_process_id; |
| 115 | 113 | ||
| 114 | /// Title ID corresponding to the process | ||
| 115 | u64 program_id; | ||
| 116 | |||
| 116 | /// Resource limit descriptor for this process | 117 | /// Resource limit descriptor for this process |
| 117 | SharedPtr<ResourceLimit> resource_limit; | 118 | SharedPtr<ResourceLimit> resource_limit; |
| 118 | 119 | ||
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 864cf25cd..459d127c2 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp | |||
| @@ -110,8 +110,6 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( | |||
| 110 | return ResultStatus::Error; | 110 | return ResultStatus::Error; |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | process = Kernel::Process::Create("main"); | ||
| 114 | |||
| 115 | const std::string directory = filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP; | 113 | const std::string directory = filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP; |
| 116 | const std::string npdm_path = directory + DIR_SEP + "main.npdm"; | 114 | const std::string npdm_path = directory + DIR_SEP + "main.npdm"; |
| 117 | 115 | ||
| @@ -121,13 +119,15 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( | |||
| 121 | } | 119 | } |
| 122 | metadata.Print(); | 120 | metadata.Print(); |
| 123 | 121 | ||
| 122 | process = Kernel::Process::Create("main", metadata.GetTitleID()); | ||
| 123 | |||
| 124 | // Load NSO modules | 124 | // Load NSO modules |
| 125 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; | 125 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; |
| 126 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", | 126 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", |
| 127 | "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { | 127 | "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { |
| 128 | const std::string path = directory + DIR_SEP + module; | 128 | const std::string path = directory + DIR_SEP + module; |
| 129 | const VAddr load_addr = next_load_addr; | 129 | const VAddr load_addr = next_load_addr; |
| 130 | next_load_addr = AppLoader_NSO::LoadModule(path, load_addr, metadata.GetTitleID()); | 130 | next_load_addr = AppLoader_NSO::LoadModule(path, load_addr); |
| 131 | if (next_load_addr) { | 131 | if (next_load_addr) { |
| 132 | LOG_DEBUG(Loader, "loaded module %s @ 0x%" PRIx64, module, load_addr); | 132 | LOG_DEBUG(Loader, "loaded module %s @ 0x%" PRIx64, module, load_addr); |
| 133 | } else { | 133 | } else { |
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index b87320656..cdd41f237 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -300,7 +300,7 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) { | |||
| 300 | std::vector<u8> program_image(total_image_size); | 300 | std::vector<u8> program_image(total_image_size); |
| 301 | size_t current_image_position = 0; | 301 | size_t current_image_position = 0; |
| 302 | 302 | ||
| 303 | SharedPtr<CodeSet> codeset = CodeSet::Create("", 0); | 303 | SharedPtr<CodeSet> codeset = CodeSet::Create(""); |
| 304 | 304 | ||
| 305 | for (unsigned int i = 0; i < header->e_phnum; ++i) { | 305 | for (unsigned int i = 0; i < header->e_phnum; ++i) { |
| 306 | Elf32_Phdr* p = &segments[i]; | 306 | Elf32_Phdr* p = &segments[i]; |
| @@ -406,7 +406,7 @@ ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 406 | SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR); | 406 | SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR); |
| 407 | codeset->name = filename; | 407 | codeset->name = filename; |
| 408 | 408 | ||
| 409 | process = Kernel::Process::Create("main"); | 409 | process = Kernel::Process::Create("main", 0); |
| 410 | process->LoadModule(codeset, codeset->entrypoint); | 410 | process->LoadModule(codeset, codeset->entrypoint); |
| 411 | process->svc_access_mask.set(); | 411 | process->svc_access_mask.set(); |
| 412 | process->address_mappings = default_address_mappings; | 412 | process->address_mappings = default_address_mappings; |
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 6f8a2f21e..c557b66dc 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -83,7 +83,7 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) { | |||
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | // Build program image | 85 | // Build program image |
| 86 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("", 0); | 86 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(""); |
| 87 | std::vector<u8> program_image; | 87 | std::vector<u8> program_image; |
| 88 | program_image.resize(PageAlignSize(nro_header.file_size)); | 88 | program_image.resize(PageAlignSize(nro_header.file_size)); |
| 89 | file.Seek(0, SEEK_SET); | 89 | file.Seek(0, SEEK_SET); |
| @@ -125,7 +125,7 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 125 | return ResultStatus::Error; | 125 | return ResultStatus::Error; |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | process = Kernel::Process::Create("main"); | 128 | process = Kernel::Process::Create("main", 0); |
| 129 | 129 | ||
| 130 | // Load NRO | 130 | // Load NRO |
| 131 | static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; | 131 | static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; |
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 7f8d24dd6..00b5d1d49 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -92,7 +92,7 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 92 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; | 92 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | VAddr AppLoader_NSO::LoadModule(const std::string& path, VAddr load_base, u64 tid) { | 95 | VAddr AppLoader_NSO::LoadModule(const std::string& path, VAddr load_base) { |
| 96 | FileUtil::IOFile file(path, "rb"); | 96 | FileUtil::IOFile file(path, "rb"); |
| 97 | if (!file.IsOpen()) { | 97 | if (!file.IsOpen()) { |
| 98 | return {}; | 98 | return {}; |
| @@ -109,7 +109,7 @@ VAddr AppLoader_NSO::LoadModule(const std::string& path, VAddr load_base, u64 ti | |||
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | // Build program image | 111 | // Build program image |
| 112 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("", tid); | 112 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(""); |
| 113 | std::vector<u8> program_image; | 113 | std::vector<u8> program_image; |
| 114 | for (int i = 0; i < nso_header.segments.size(); ++i) { | 114 | for (int i = 0; i < nso_header.segments.size(); ++i) { |
| 115 | std::vector<u8> data = | 115 | std::vector<u8> data = |
| @@ -155,10 +155,10 @@ ResultStatus AppLoader_NSO::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 155 | return ResultStatus::Error; | 155 | return ResultStatus::Error; |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | process = Kernel::Process::Create("main"); | 158 | process = Kernel::Process::Create("main", 0); |
| 159 | 159 | ||
| 160 | // Load module | 160 | // Load module |
| 161 | LoadModule(filepath, Memory::PROCESS_IMAGE_VADDR, 0); | 161 | LoadModule(filepath, Memory::PROCESS_IMAGE_VADDR); |
| 162 | LOG_DEBUG(Loader, "loaded module %s @ 0x%" PRIx64, filepath.c_str(), | 162 | LOG_DEBUG(Loader, "loaded module %s @ 0x%" PRIx64, filepath.c_str(), |
| 163 | Memory::PROCESS_IMAGE_VADDR); | 163 | Memory::PROCESS_IMAGE_VADDR); |
| 164 | 164 | ||
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index 14eb1d87e..1ae30a824 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h | |||
| @@ -29,7 +29,7 @@ public: | |||
| 29 | return IdentifyType(file, filepath); | 29 | return IdentifyType(file, filepath); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | static VAddr LoadModule(const std::string& path, VAddr load_base, u64 tid); | 32 | static VAddr LoadModule(const std::string& path, VAddr load_base); |
| 33 | 33 | ||
| 34 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; | 34 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; |
| 35 | 35 | ||
diff --git a/src/tests/core/arm/arm_test_common.cpp b/src/tests/core/arm/arm_test_common.cpp index 88bbbc95c..9296e1e94 100644 --- a/src/tests/core/arm/arm_test_common.cpp +++ b/src/tests/core/arm/arm_test_common.cpp | |||
| @@ -15,7 +15,7 @@ static Memory::PageTable* page_table = nullptr; | |||
| 15 | TestEnvironment::TestEnvironment(bool mutable_memory_) | 15 | TestEnvironment::TestEnvironment(bool mutable_memory_) |
| 16 | : mutable_memory(mutable_memory_), test_memory(std::make_shared<TestMemory>(this)) { | 16 | : mutable_memory(mutable_memory_), test_memory(std::make_shared<TestMemory>(this)) { |
| 17 | 17 | ||
| 18 | Kernel::g_current_process = Kernel::Process::Create(""); | 18 | Kernel::g_current_process = Kernel::Process::Create("", 0); |
| 19 | page_table = &Kernel::g_current_process->vm_manager.page_table; | 19 | page_table = &Kernel::g_current_process->vm_manager.page_table; |
| 20 | 20 | ||
| 21 | page_table->pointers.fill(nullptr); | 21 | page_table->pointers.fill(nullptr); |
diff --git a/src/tests/core/memory/memory.cpp b/src/tests/core/memory/memory.cpp index 165496a54..0e0a43dcb 100644 --- a/src/tests/core/memory/memory.cpp +++ b/src/tests/core/memory/memory.cpp | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory][!hide]") { | 10 | TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory][!hide]") { |
| 11 | SECTION("these regions should not be mapped on an empty process") { | 11 | SECTION("these regions should not be mapped on an empty process") { |
| 12 | auto process = Kernel::Process::Create(""); | 12 | auto process = Kernel::Process::Create("", 0); |
| 13 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false); | 13 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::PROCESS_IMAGE_VADDR) == false); |
| 14 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::HEAP_VADDR) == false); | 14 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::HEAP_VADDR) == false); |
| 15 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::LINEAR_HEAP_VADDR) == false); | 15 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::LINEAR_HEAP_VADDR) == false); |
| @@ -20,14 +20,14 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory][!hide]") { | |||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") { | 22 | SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") { |
| 23 | auto process = Kernel::Process::Create(""); | 23 | auto process = Kernel::Process::Create("", 0); |
| 24 | Kernel::MapSharedPages(process->vm_manager); | 24 | Kernel::MapSharedPages(process->vm_manager); |
| 25 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true); | 25 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == true); |
| 26 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true); | 26 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::SHARED_PAGE_VADDR) == true); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | SECTION("special regions should be valid after mapping them") { | 29 | SECTION("special regions should be valid after mapping them") { |
| 30 | auto process = Kernel::Process::Create(""); | 30 | auto process = Kernel::Process::Create("", 0); |
| 31 | SECTION("VRAM") { | 31 | SECTION("VRAM") { |
| 32 | Kernel::HandleSpecialMapping(process->vm_manager, | 32 | Kernel::HandleSpecialMapping(process->vm_manager, |
| 33 | {Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false}); | 33 | {Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false}); |
| @@ -48,7 +48,7 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory][!hide]") { | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | SECTION("Unmapping a VAddr should make it invalid") { | 50 | SECTION("Unmapping a VAddr should make it invalid") { |
| 51 | auto process = Kernel::Process::Create(""); | 51 | auto process = Kernel::Process::Create("", 0); |
| 52 | Kernel::MapSharedPages(process->vm_manager); | 52 | Kernel::MapSharedPages(process->vm_manager); |
| 53 | process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE); | 53 | process->vm_manager.UnmapRange(Memory::CONFIG_MEMORY_VADDR, Memory::CONFIG_MEMORY_SIZE); |
| 54 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false); | 54 | CHECK(Memory::IsValidVirtualAddress(*process, Memory::CONFIG_MEMORY_VADDR) == false); |