diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/kernel/process.h | 45 | ||||
| -rw-r--r-- | src/core/hle/kernel/shared_memory.cpp | 38 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 11 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 2 | ||||
| -rw-r--r-- | src/core/loader/elf.cpp | 6 | ||||
| -rw-r--r-- | src/core/loader/nro.cpp | 2 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 2 | ||||
| -rw-r--r-- | src/core/memory.cpp | 16 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/video_core.h | 3 |
11 files changed, 79 insertions, 54 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 5403ceef5..edf34c5a3 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -142,9 +142,9 @@ void Process::LoadModule(SharedPtr<CodeSet> module_, VAddr base_addr) { | |||
| 142 | }; | 142 | }; |
| 143 | 143 | ||
| 144 | // Map CodeSet segments | 144 | // Map CodeSet segments |
| 145 | MapSegment(module_->code, VMAPermission::ReadExecute, MemoryState::CodeStatic); | 145 | MapSegment(module_->CodeSegment(), VMAPermission::ReadExecute, MemoryState::CodeStatic); |
| 146 | MapSegment(module_->rodata, VMAPermission::Read, MemoryState::CodeMutable); | 146 | MapSegment(module_->RODataSegment(), VMAPermission::Read, MemoryState::CodeMutable); |
| 147 | MapSegment(module_->data, VMAPermission::ReadWrite, MemoryState::CodeMutable); | 147 | MapSegment(module_->DataSegment(), VMAPermission::ReadWrite, MemoryState::CodeMutable); |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) { | 150 | ResultVal<VAddr> Process::HeapAllocate(VAddr target, u64 size, VMAPermission perms) { |
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index 98d8da35e..992689186 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | ||
| 7 | #include <bitset> | 8 | #include <bitset> |
| 8 | #include <cstddef> | 9 | #include <cstddef> |
| 9 | #include <memory> | 10 | #include <memory> |
| @@ -55,6 +56,12 @@ enum class ProcessStatus { Created, Running, Exited }; | |||
| 55 | class ResourceLimit; | 56 | class ResourceLimit; |
| 56 | 57 | ||
| 57 | struct CodeSet final : public Object { | 58 | struct CodeSet final : public Object { |
| 59 | struct Segment { | ||
| 60 | size_t offset = 0; | ||
| 61 | VAddr addr = 0; | ||
| 62 | u32 size = 0; | ||
| 63 | }; | ||
| 64 | |||
| 58 | static SharedPtr<CodeSet> Create(std::string name); | 65 | static SharedPtr<CodeSet> Create(std::string name); |
| 59 | 66 | ||
| 60 | std::string GetTypeName() const override { | 67 | std::string GetTypeName() const override { |
| @@ -69,24 +76,38 @@ struct CodeSet final : public Object { | |||
| 69 | return HANDLE_TYPE; | 76 | return HANDLE_TYPE; |
| 70 | } | 77 | } |
| 71 | 78 | ||
| 72 | /// Name of the process | 79 | Segment& CodeSegment() { |
| 73 | std::string name; | 80 | return segments[0]; |
| 81 | } | ||
| 74 | 82 | ||
| 75 | std::shared_ptr<std::vector<u8>> memory; | 83 | const Segment& CodeSegment() const { |
| 84 | return segments[0]; | ||
| 85 | } | ||
| 76 | 86 | ||
| 77 | struct Segment { | 87 | Segment& RODataSegment() { |
| 78 | size_t offset = 0; | 88 | return segments[1]; |
| 79 | VAddr addr = 0; | 89 | } |
| 80 | u32 size = 0; | ||
| 81 | }; | ||
| 82 | 90 | ||
| 83 | Segment segments[3]; | 91 | const Segment& RODataSegment() const { |
| 84 | Segment& code = segments[0]; | 92 | return segments[1]; |
| 85 | Segment& rodata = segments[1]; | 93 | } |
| 86 | Segment& data = segments[2]; | ||
| 87 | 94 | ||
| 95 | Segment& DataSegment() { | ||
| 96 | return segments[2]; | ||
| 97 | } | ||
| 98 | |||
| 99 | const Segment& DataSegment() const { | ||
| 100 | return segments[2]; | ||
| 101 | } | ||
| 102 | |||
| 103 | std::shared_ptr<std::vector<u8>> memory; | ||
| 104 | |||
| 105 | std::array<Segment, 3> segments; | ||
| 88 | VAddr entrypoint; | 106 | VAddr entrypoint; |
| 89 | 107 | ||
| 108 | /// Name of the process | ||
| 109 | std::string name; | ||
| 110 | |||
| 90 | private: | 111 | private: |
| 91 | CodeSet(); | 112 | CodeSet(); |
| 92 | ~CodeSet() override; | 113 | ~CodeSet() override; |
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index b3ddebb3d..21ddc2f7d 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp | |||
| @@ -28,20 +28,32 @@ SharedPtr<SharedMemory> SharedMemory::Create(SharedPtr<Process> owner_process, u | |||
| 28 | shared_memory->permissions = permissions; | 28 | shared_memory->permissions = permissions; |
| 29 | shared_memory->other_permissions = other_permissions; | 29 | shared_memory->other_permissions = other_permissions; |
| 30 | 30 | ||
| 31 | auto& vm_manager = shared_memory->owner_process->vm_manager; | 31 | if (address == 0) { |
| 32 | 32 | shared_memory->backing_block = std::make_shared<std::vector<u8>>(size); | |
| 33 | // The memory is already available and mapped in the owner process. | 33 | shared_memory->backing_block_offset = 0; |
| 34 | auto vma = vm_manager.FindVMA(address); | 34 | |
| 35 | ASSERT_MSG(vma != vm_manager.vma_map.end(), "Invalid memory address"); | 35 | // Refresh the address mappings for the current process. |
| 36 | ASSERT_MSG(vma->second.backing_block, "Backing block doesn't exist for address"); | 36 | if (Core::CurrentProcess() != nullptr) { |
| 37 | 37 | Core::CurrentProcess()->vm_manager.RefreshMemoryBlockMappings( | |
| 38 | // The returned VMA might be a bigger one encompassing the desired address. | 38 | shared_memory->backing_block.get()); |
| 39 | auto vma_offset = address - vma->first; | 39 | } |
| 40 | ASSERT_MSG(vma_offset + size <= vma->second.size, | 40 | } else { |
| 41 | "Shared memory exceeds bounds of mapped block"); | 41 | auto& vm_manager = shared_memory->owner_process->vm_manager; |
| 42 | |||
| 43 | // The memory is already available and mapped in the owner process. | ||
| 44 | auto vma = vm_manager.FindVMA(address); | ||
| 45 | ASSERT_MSG(vma != vm_manager.vma_map.end(), "Invalid memory address"); | ||
| 46 | ASSERT_MSG(vma->second.backing_block, "Backing block doesn't exist for address"); | ||
| 47 | |||
| 48 | // The returned VMA might be a bigger one encompassing the desired address. | ||
| 49 | auto vma_offset = address - vma->first; | ||
| 50 | ASSERT_MSG(vma_offset + size <= vma->second.size, | ||
| 51 | "Shared memory exceeds bounds of mapped block"); | ||
| 52 | |||
| 53 | shared_memory->backing_block = vma->second.backing_block; | ||
| 54 | shared_memory->backing_block_offset = vma->second.offset + vma_offset; | ||
| 55 | } | ||
| 42 | 56 | ||
| 43 | shared_memory->backing_block = vma->second.backing_block; | ||
| 44 | shared_memory->backing_block_offset = vma->second.offset + vma_offset; | ||
| 45 | shared_memory->base_address = address; | 57 | shared_memory->base_address = address; |
| 46 | 58 | ||
| 47 | return shared_memory; | 59 | return shared_memory; |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index ea9554cbb..b9022feae 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -339,6 +339,17 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, | |||
| 339 | tls_slots.emplace_back(0); // The page is completely available at the start | 339 | tls_slots.emplace_back(0); // The page is completely available at the start |
| 340 | available_page = tls_slots.size() - 1; | 340 | available_page = tls_slots.size() - 1; |
| 341 | available_slot = 0; // Use the first slot in the new page | 341 | available_slot = 0; // Use the first slot in the new page |
| 342 | |||
| 343 | // Allocate some memory from the end of the linear heap for this region. | ||
| 344 | const size_t offset = thread->tls_memory->size(); | ||
| 345 | thread->tls_memory->insert(thread->tls_memory->end(), Memory::PAGE_SIZE, 0); | ||
| 346 | |||
| 347 | auto& vm_manager = owner_process->vm_manager; | ||
| 348 | vm_manager.RefreshMemoryBlockMappings(thread->tls_memory.get()); | ||
| 349 | |||
| 350 | vm_manager.MapMemoryBlock(Memory::TLS_AREA_VADDR + available_page * Memory::PAGE_SIZE, | ||
| 351 | thread->tls_memory, 0, Memory::PAGE_SIZE, | ||
| 352 | MemoryState::ThreadLocal); | ||
| 342 | } | 353 | } |
| 343 | 354 | ||
| 344 | // Mark the slot as used | 355 | // Mark the slot as used |
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 146955e13..adc804248 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -265,6 +265,8 @@ public: | |||
| 265 | private: | 265 | private: |
| 266 | Thread(); | 266 | Thread(); |
| 267 | ~Thread() override; | 267 | ~Thread() override; |
| 268 | |||
| 269 | std::shared_ptr<std::vector<u8>> tls_memory = std::make_shared<std::vector<u8>>(); | ||
| 268 | }; | 270 | }; |
| 269 | 271 | ||
| 270 | /** | 272 | /** |
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 352938dcb..a7133f5a6 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -311,11 +311,11 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) { | |||
| 311 | CodeSet::Segment* codeset_segment; | 311 | CodeSet::Segment* codeset_segment; |
| 312 | u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); | 312 | u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); |
| 313 | if (permission_flags == (PF_R | PF_X)) { | 313 | if (permission_flags == (PF_R | PF_X)) { |
| 314 | codeset_segment = &codeset->code; | 314 | codeset_segment = &codeset->CodeSegment(); |
| 315 | } else if (permission_flags == (PF_R)) { | 315 | } else if (permission_flags == (PF_R)) { |
| 316 | codeset_segment = &codeset->rodata; | 316 | codeset_segment = &codeset->RODataSegment(); |
| 317 | } else if (permission_flags == (PF_R | PF_W)) { | 317 | } else if (permission_flags == (PF_R | PF_W)) { |
| 318 | codeset_segment = &codeset->data; | 318 | codeset_segment = &codeset->DataSegment(); |
| 319 | } else { | 319 | } else { |
| 320 | LOG_ERROR(Loader, "Unexpected ELF PT_LOAD segment id {} with flags {:X}", i, | 320 | LOG_ERROR(Loader, "Unexpected ELF PT_LOAD segment id {} with flags {:X}", i, |
| 321 | p->p_flags); | 321 | p->p_flags); |
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 7d3ec2a76..dc053cdad 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -159,7 +159,7 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) { | |||
| 159 | // Resize program image to include .bss section and page align each section | 159 | // Resize program image to include .bss section and page align each section |
| 160 | bss_size = PageAlignSize(mod_header.bss_end_offset - mod_header.bss_start_offset); | 160 | bss_size = PageAlignSize(mod_header.bss_end_offset - mod_header.bss_start_offset); |
| 161 | } | 161 | } |
| 162 | codeset->data.size += bss_size; | 162 | codeset->DataSegment().size += bss_size; |
| 163 | program_image.resize(static_cast<u32>(program_image.size()) + bss_size); | 163 | program_image.resize(static_cast<u32>(program_image.size()) + bss_size); |
| 164 | 164 | ||
| 165 | // Load codeset for current process | 165 | // Load codeset for current process |
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 06b1b33f4..fee7d58c6 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -127,7 +127,7 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) { | |||
| 127 | // Resize program image to include .bss section and page align each section | 127 | // Resize program image to include .bss section and page align each section |
| 128 | bss_size = PageAlignSize(mod_header.bss_end_offset - mod_header.bss_start_offset); | 128 | bss_size = PageAlignSize(mod_header.bss_end_offset - mod_header.bss_start_offset); |
| 129 | } | 129 | } |
| 130 | codeset->data.size += bss_size; | 130 | codeset->DataSegment().size += bss_size; |
| 131 | const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)}; | 131 | const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)}; |
| 132 | program_image.resize(image_size); | 132 | program_image.resize(image_size); |
| 133 | 133 | ||
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 0d41b2527..4b3bb7b31 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -99,22 +99,6 @@ void RemoveDebugHook(PageTable& page_table, VAddr base, u64 size, MemoryHookPoin | |||
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | /** | 101 | /** |
| 102 | * This function should only be called for virtual addreses with attribute `PageType::Special`. | ||
| 103 | */ | ||
| 104 | static std::set<MemoryHookPointer> GetSpecialHandlers(const PageTable& page_table, VAddr vaddr, | ||
| 105 | u64 size) { | ||
| 106 | std::set<MemoryHookPointer> result; | ||
| 107 | auto interval = boost::icl::discrete_interval<VAddr>::closed(vaddr, vaddr + size - 1); | ||
| 108 | auto interval_list = page_table.special_regions.equal_range(interval); | ||
| 109 | for (auto it = interval_list.first; it != interval_list.second; ++it) { | ||
| 110 | for (const auto& region : it->second) { | ||
| 111 | result.insert(region.handler); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | return result; | ||
| 115 | } | ||
| 116 | |||
| 117 | /** | ||
| 118 | * Gets a pointer to the exact memory at the virtual address (i.e. not page aligned) | 102 | * Gets a pointer to the exact memory at the virtual address (i.e. not page aligned) |
| 119 | * using a VMA from the current process | 103 | * using a VMA from the current process |
| 120 | */ | 104 | */ |
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index acf067050..68db3c22a 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -412,7 +412,6 @@ public: | |||
| 412 | } | 412 | } |
| 413 | declarations.AddNewLine(); | 413 | declarations.AddNewLine(); |
| 414 | 414 | ||
| 415 | unsigned const_buffer_layout = 0; | ||
| 416 | for (const auto& entry : GetConstBuffersDeclarations()) { | 415 | for (const auto& entry : GetConstBuffersDeclarations()) { |
| 417 | declarations.AddLine("layout(std140) uniform " + entry.GetName()); | 416 | declarations.AddLine("layout(std140) uniform " + entry.GetName()); |
| 418 | declarations.AddLine('{'); | 417 | declarations.AddLine('{'); |
| @@ -420,7 +419,6 @@ public: | |||
| 420 | "[MAX_CONSTBUFFER_ELEMENTS];"); | 419 | "[MAX_CONSTBUFFER_ELEMENTS];"); |
| 421 | declarations.AddLine("};"); | 420 | declarations.AddLine("};"); |
| 422 | declarations.AddNewLine(); | 421 | declarations.AddNewLine(); |
| 423 | ++const_buffer_layout; | ||
| 424 | } | 422 | } |
| 425 | declarations.AddNewLine(); | 423 | declarations.AddNewLine(); |
| 426 | 424 | ||
diff --git a/src/video_core/video_core.h b/src/video_core/video_core.h index 8707e9881..519b757f5 100644 --- a/src/video_core/video_core.h +++ b/src/video_core/video_core.h | |||
| @@ -23,9 +23,6 @@ extern std::unique_ptr<RendererBase> g_renderer; ///< Renderer plugin | |||
| 23 | // qt ui) | 23 | // qt ui) |
| 24 | extern std::atomic<bool> g_toggle_framelimit_enabled; | 24 | extern std::atomic<bool> g_toggle_framelimit_enabled; |
| 25 | 25 | ||
| 26 | /// Start the video core | ||
| 27 | void Start(); | ||
| 28 | |||
| 29 | /// Initialize the video core | 26 | /// Initialize the video core |
| 30 | bool Init(EmuWindow& emu_window); | 27 | bool Init(EmuWindow& emu_window); |
| 31 | 28 | ||