mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 05:40:04 +00:00 
			
		
		
		
	kernel: pass ref in CodeSet
This commit is contained in:
		
							parent
							
								
									7449ba85a6
								
							
						
					
					
						commit
						213b259cf1
					
				
					 10 changed files with 56 additions and 30 deletions
				
			
		|  | @ -3,6 +3,7 @@ | |||
| // Refer to the license.txt file included.
 | ||||
| 
 | ||||
| #include "core/core.h" | ||||
| #include "core/core_timing.h" | ||||
| #include "core/hle/kernel/process.h" | ||||
| #include "core/memory.h" | ||||
| #include "core/memory_setup.h" | ||||
|  | @ -15,7 +16,10 @@ 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::CodeSet::Create("", 0)); | ||||
|     CoreTiming::Init(); | ||||
|     kernel = std::make_unique<Kernel::KernelSystem>(0); | ||||
| 
 | ||||
|     Kernel::g_current_process = Kernel::Process::Create(kernel->CreateCodeSet("", 0)); | ||||
|     page_table = &Kernel::g_current_process->vm_manager.page_table; | ||||
| 
 | ||||
|     page_table->pointers.fill(nullptr); | ||||
|  | @ -30,6 +34,8 @@ TestEnvironment::TestEnvironment(bool mutable_memory_) | |||
| TestEnvironment::~TestEnvironment() { | ||||
|     Memory::UnmapRegion(*page_table, 0x80000000, 0x80000000); | ||||
|     Memory::UnmapRegion(*page_table, 0x00000000, 0x80000000); | ||||
| 
 | ||||
|     CoreTiming::Shutdown(); | ||||
| } | ||||
| 
 | ||||
| void TestEnvironment::SetMemory64(VAddr vaddr, u64 value) { | ||||
|  |  | |||
|  | @ -5,8 +5,8 @@ | |||
| #include <tuple> | ||||
| #include <unordered_map> | ||||
| #include <vector> | ||||
| 
 | ||||
| #include "common/common_types.h" | ||||
| #include "core/hle/kernel/kernel.h" | ||||
| #include "core/mmio.h" | ||||
| 
 | ||||
| namespace ArmTests { | ||||
|  | @ -79,6 +79,8 @@ private: | |||
|     bool mutable_memory; | ||||
|     std::shared_ptr<TestMemory> test_memory; | ||||
|     std::vector<WriteRecord> write_records; | ||||
| 
 | ||||
|     std::unique_ptr<Kernel::KernelSystem> kernel; | ||||
| }; | ||||
| 
 | ||||
| } // namespace ArmTests
 | ||||
|  |  | |||
|  | @ -3,6 +3,7 @@ | |||
| // Refer to the license.txt file included.
 | ||||
| 
 | ||||
| #include <catch2/catch.hpp> | ||||
| #include "core/core_timing.h" | ||||
| #include "core/hle/ipc.h" | ||||
| #include "core/hle/kernel/client_port.h" | ||||
| #include "core/hle/kernel/client_session.h" | ||||
|  | @ -14,16 +15,17 @@ | |||
| 
 | ||||
| namespace Kernel { | ||||
| 
 | ||||
| static SharedPtr<Object> MakeObject() { | ||||
|     static Kernel::KernelSystem kernel(0); | ||||
| static SharedPtr<Object> MakeObject(Kernel::KernelSystem& kernel) { | ||||
|     return kernel.CreateEvent(ResetType::OneShot); | ||||
| } | ||||
| 
 | ||||
| TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel]") { | ||||
|     CoreTiming::Init(); | ||||
|     Kernel::KernelSystem kernel(0); | ||||
|     auto session = std::get<SharedPtr<ServerSession>>(ServerSession::CreateSessionPair()); | ||||
|     HLERequestContext context(std::move(session)); | ||||
| 
 | ||||
|     auto process = Process::Create(CodeSet::Create("", 0)); | ||||
|     auto process = Process::Create(kernel.CreateCodeSet("", 0)); | ||||
|     HandleTable handle_table; | ||||
| 
 | ||||
|     SECTION("works with empty cmdbuf") { | ||||
|  | @ -53,7 +55,7 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel | |||
|     } | ||||
| 
 | ||||
|     SECTION("translates move handles") { | ||||
|         auto a = MakeObject(); | ||||
|         auto a = MakeObject(kernel); | ||||
|         Handle a_handle = handle_table.Create(a).Unwrap(); | ||||
|         const u32_le input[]{ | ||||
|             IPC::MakeHeader(0, 0, 2), | ||||
|  | @ -69,7 +71,7 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel | |||
|     } | ||||
| 
 | ||||
|     SECTION("translates copy handles") { | ||||
|         auto a = MakeObject(); | ||||
|         auto a = MakeObject(kernel); | ||||
|         Handle a_handle = handle_table.Create(a).Unwrap(); | ||||
|         const u32_le input[]{ | ||||
|             IPC::MakeHeader(0, 0, 2), | ||||
|  | @ -85,9 +87,9 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel | |||
|     } | ||||
| 
 | ||||
|     SECTION("translates multi-handle descriptors") { | ||||
|         auto a = MakeObject(); | ||||
|         auto b = MakeObject(); | ||||
|         auto c = MakeObject(); | ||||
|         auto a = MakeObject(kernel); | ||||
|         auto b = MakeObject(kernel); | ||||
|         auto c = MakeObject(kernel); | ||||
|         const u32_le input[]{ | ||||
|             IPC::MakeHeader(0, 0, 5),        IPC::MoveHandleDesc(2), | ||||
|             handle_table.Create(a).Unwrap(), handle_table.Create(b).Unwrap(), | ||||
|  | @ -191,7 +193,7 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel | |||
|                                                     buffer_mapped->size(), MemoryState::Private); | ||||
|         REQUIRE(result.Code() == RESULT_SUCCESS); | ||||
| 
 | ||||
|         auto a = MakeObject(); | ||||
|         auto a = MakeObject(kernel); | ||||
|         const u32_le input[]{ | ||||
|             IPC::MakeHeader(0, 2, 8), | ||||
|             0x12345678, | ||||
|  | @ -223,13 +225,17 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel | |||
|         REQUIRE(process->vm_manager.UnmapRange(target_address_mapped, buffer_mapped->size()) == | ||||
|                 RESULT_SUCCESS); | ||||
|     } | ||||
| 
 | ||||
|     CoreTiming::Shutdown(); | ||||
| } | ||||
| 
 | ||||
| TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") { | ||||
|     CoreTiming::Init(); | ||||
|     Kernel::KernelSystem kernel(0); | ||||
|     auto session = std::get<SharedPtr<ServerSession>>(ServerSession::CreateSessionPair()); | ||||
|     HLERequestContext context(std::move(session)); | ||||
| 
 | ||||
|     auto process = Process::Create(CodeSet::Create("", 0)); | ||||
|     auto process = Process::Create(kernel.CreateCodeSet("", 0)); | ||||
|     HandleTable handle_table; | ||||
|     auto* input = context.CommandBuffer(); | ||||
|     u32_le output[IPC::COMMAND_BUFFER_LENGTH]; | ||||
|  | @ -256,8 +262,8 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") { | |||
|     } | ||||
| 
 | ||||
|     SECTION("translates move/copy handles") { | ||||
|         auto a = MakeObject(); | ||||
|         auto b = MakeObject(); | ||||
|         auto a = MakeObject(kernel); | ||||
|         auto b = MakeObject(kernel); | ||||
|         input[0] = IPC::MakeHeader(0, 0, 4); | ||||
|         input[1] = IPC::MoveHandleDesc(1); | ||||
|         input[2] = context.AddOutgoingHandle(a); | ||||
|  | @ -282,9 +288,9 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") { | |||
|     } | ||||
| 
 | ||||
|     SECTION("translates multi-handle descriptors") { | ||||
|         auto a = MakeObject(); | ||||
|         auto b = MakeObject(); | ||||
|         auto c = MakeObject(); | ||||
|         auto a = MakeObject(kernel); | ||||
|         auto b = MakeObject(kernel); | ||||
|         auto c = MakeObject(kernel); | ||||
|         input[0] = IPC::MakeHeader(0, 0, 5); | ||||
|         input[1] = IPC::MoveHandleDesc(2); | ||||
|         input[2] = context.AddOutgoingHandle(a); | ||||
|  | @ -362,6 +368,8 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") { | |||
|         REQUIRE(process->vm_manager.UnmapRange(target_address, output_buffer->size()) == | ||||
|                 RESULT_SUCCESS); | ||||
|     } | ||||
| 
 | ||||
|     CoreTiming::Shutdown(); | ||||
| } | ||||
| 
 | ||||
| } // namespace Kernel
 | ||||
|  |  | |||
|  | @ -3,14 +3,17 @@ | |||
| // Refer to the license.txt file included.
 | ||||
| 
 | ||||
| #include <catch2/catch.hpp> | ||||
| #include "core/core_timing.h" | ||||
| #include "core/hle/kernel/memory.h" | ||||
| #include "core/hle/kernel/process.h" | ||||
| #include "core/hle/shared_page.h" | ||||
| #include "core/memory.h" | ||||
| 
 | ||||
| TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") { | ||||
|     CoreTiming::Init(); | ||||
|     Kernel::KernelSystem kernel(0); | ||||
|     SECTION("these regions should not be mapped on an empty process") { | ||||
|         auto process = Kernel::Process::Create(Kernel::CodeSet::Create("", 0)); | ||||
|         auto process = Kernel::Process::Create(kernel.CreateCodeSet("", 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); | ||||
|  | @ -21,14 +24,14 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") { | |||
|     } | ||||
| 
 | ||||
|     SECTION("CONFIG_MEMORY_VADDR and SHARED_PAGE_VADDR should be valid after mapping them") { | ||||
|         auto process = Kernel::Process::Create(Kernel::CodeSet::Create("", 0)); | ||||
|         auto process = Kernel::Process::Create(kernel.CreateCodeSet("", 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(Kernel::CodeSet::Create("", 0)); | ||||
|         auto process = Kernel::Process::Create(kernel.CreateCodeSet("", 0)); | ||||
|         SECTION("VRAM") { | ||||
|             Kernel::HandleSpecialMapping(process->vm_manager, | ||||
|                                          {Memory::VRAM_VADDR, Memory::VRAM_SIZE, false, false}); | ||||
|  | @ -43,9 +46,11 @@ TEST_CASE("Memory::IsValidVirtualAddress", "[core][memory]") { | |||
|     } | ||||
| 
 | ||||
|     SECTION("Unmapping a VAddr should make it invalid") { | ||||
|         auto process = Kernel::Process::Create(Kernel::CodeSet::Create("", 0)); | ||||
|         auto process = Kernel::Process::Create(kernel.CreateCodeSet("", 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); | ||||
|     } | ||||
| 
 | ||||
|     CoreTiming::Shutdown(); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue