VERY experimental Nintendo Switch 2 emulator
C++
hle: kernel: Migrate MemoryLayout to KMemoryLayout.
bunnei8c9e87ab6649
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txtindex 442618e900..d12260d9c1 100644--- a/src/core/CMakeLists.txt+++ b/src/core/CMakeLists.txt@@ -166,6 +166,7 @@ add_library(core STATIChle/kernel/k_light_condition_variable.hhle/kernel/k_light_lock.cpphle/kernel/k_light_lock.h+ hle/kernel/k_memory_layout.hhle/kernel/k_page_bitmap.hhle/kernel/k_priority_queue.hhle/kernel/k_readable_event.cpp@@ -196,7 +197,6 @@ add_library(core STATIChle/kernel/memory/memory_block.hhle/kernel/memory/memory_block_manager.cpphle/kernel/memory/memory_block_manager.h- hle/kernel/memory/memory_layout.hhle/kernel/memory/memory_manager.cpphle/kernel/memory/memory_manager.hhle/kernel/memory/memory_types.hdiff --git a/src/core/hle/kernel/memory/memory_layout.h b/src/core/hle/kernel/k_memory_layout.hsimilarity index 75%rename from src/core/hle/kernel/memory/memory_layout.hrename to src/core/hle/kernel/k_memory_layout.hindex c7c0b2f491..0821d2d8c3 100644--- a/src/core/hle/kernel/memory/memory_layout.h+++ b/src/core/hle/kernel/k_memory_layout.h@@ -7,7 +7,7 @@#include "common/common_types.h"#include "core/device_memory.h"-namespace Kernel::Memory {+namespace Kernel {constexpr std::size_t KernelAslrAlignment = 2 * 1024 * 1024;constexpr std::size_t KernelVirtualAddressSpaceWidth = 1ULL << 39;@@ -27,8 +27,8 @@ constexpr bool IsKernelAddress(VAddr address) {return KernelVirtualAddressSpaceBase <= address && address < KernelVirtualAddressSpaceEnd;}-class MemoryRegion final {- friend class MemoryLayout;+class KMemoryRegion final {+ friend class KMemoryLayout;public:constexpr PAddr StartAddress() const {@@ -40,29 +40,29 @@ public:}private:- constexpr MemoryRegion() = default;- constexpr MemoryRegion(PAddr start_address, PAddr end_address)+ constexpr KMemoryRegion() = default;+ constexpr KMemoryRegion(PAddr start_address, PAddr end_address): start_address{start_address}, end_address{end_address} {}const PAddr start_address{};const PAddr end_address{};};-class MemoryLayout final {+class KMemoryLayout final {public:- constexpr const MemoryRegion& Application() const {+ constexpr const KMemoryRegion& Application() const {return application;}- constexpr const MemoryRegion& Applet() const {+ constexpr const KMemoryRegion& Applet() const {return applet;}- constexpr const MemoryRegion& System() const {+ constexpr const KMemoryRegion& System() const {return system;}- static constexpr MemoryLayout GetDefaultLayout() {+ static constexpr KMemoryLayout GetDefaultLayout() {constexpr std::size_t application_size{0xcd500000};constexpr std::size_t applet_size{0x1fb00000};constexpr PAddr application_start_address{Core::DramMemoryMap::End - application_size};@@ -76,15 +76,15 @@ public:}private:- constexpr MemoryLayout(PAddr application_start_address, std::size_t application_size,- PAddr applet_start_address, std::size_t applet_size,- PAddr system_start_address, std::size_t system_size)+ constexpr KMemoryLayout(PAddr application_start_address, std::size_t application_size,+ PAddr applet_start_address, std::size_t applet_size,+ PAddr system_start_address, std::size_t system_size): application{application_start_address, application_size},applet{applet_start_address, applet_size}, system{system_start_address, system_size} {}- const MemoryRegion application;- const MemoryRegion applet;- const MemoryRegion system;+ const KMemoryRegion application;+ const KMemoryRegion applet;+ const KMemoryRegion system;};-} // namespace Kernel::Memory+} // namespace Kerneldiff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cppindex e5620da5ac..1661afbd97 100644--- a/src/core/hle/kernel/k_thread.cpp+++ b/src/core/hle/kernel/k_thread.cpp@@ -20,13 +20,13 @@#include "core/hardware_properties.h"#include "core/hle/kernel/handle_table.h"#include "core/hle/kernel/k_condition_variable.h"+#include "core/hle/kernel/k_memory_layout.h"#include "core/hle/kernel/k_resource_limit.h"#include "core/hle/kernel/k_scheduler.h"#include "core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h"#include "core/hle/kernel/k_thread.h"#include "core/hle/kernel/k_thread_queue.h"#include "core/hle/kernel/kernel.h"-#include "core/hle/kernel/memory/memory_layout.h"#include "core/hle/kernel/object.h"#include "core/hle/kernel/process.h"#include "core/hle/kernel/svc_results.h"@@ -782,7 +782,7 @@ void KThread::AddWaiterImpl(KThread* thread) {}// Keep track of how many kernel waiters we have.- if (Memory::IsKernelAddressKey(thread->GetAddressKey())) {+ if (IsKernelAddressKey(thread->GetAddressKey())) {ASSERT((num_kernel_waiters++) >= 0);}@@ -795,7 +795,7 @@ void KThread::RemoveWaiterImpl(KThread* thread) {ASSERT(kernel.GlobalSchedulerContext().IsLocked());// Keep track of how many kernel waiters we have.- if (Memory::IsKernelAddressKey(thread->GetAddressKey())) {+ if (IsKernelAddressKey(thread->GetAddressKey())) {ASSERT((num_kernel_waiters--) > 0);}@@ -870,7 +870,7 @@ KThread* KThread::RemoveWaiterByKey(s32* out_num_waiters, VAddr key) {KThread* thread = std::addressof(*it);// Keep track of how many kernel waiters we have.- if (Memory::IsKernelAddressKey(thread->GetAddressKey())) {+ if (IsKernelAddressKey(thread->GetAddressKey())) {ASSERT((num_kernel_waiters--) > 0);}it = waiter_list.erase(it);diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cppindex 5eb602843a..98b3ec7120 100644--- a/src/core/hle/kernel/kernel.cpp+++ b/src/core/hle/kernel/kernel.cpp@@ -27,12 +27,12 @@#include "core/hardware_properties.h"#include "core/hle/kernel/client_port.h"#include "core/hle/kernel/handle_table.h"+#include "core/hle/kernel/k_memory_layout.h"#include "core/hle/kernel/k_resource_limit.h"#include "core/hle/kernel/k_scheduler.h"#include "core/hle/kernel/k_shared_memory.h"#include "core/hle/kernel/k_thread.h"#include "core/hle/kernel/kernel.h"-#include "core/hle/kernel/memory/memory_layout.h"#include "core/hle/kernel/memory/memory_manager.h"#include "core/hle/kernel/memory/slab_heap.h"#include "core/hle/kernel/physical_core.h"@@ -266,7 +266,7 @@ struct KernelCore::Impl {void InitializeMemoryLayout() {// Initialize memory layout- constexpr Memory::MemoryLayout layout{Memory::MemoryLayout::GetDefaultLayout()};+ constexpr KMemoryLayout layout{KMemoryLayout::GetDefaultLayout()};constexpr std::size_t hid_size{0x40000};constexpr std::size_t font_size{0x1100000};constexpr std::size_t irs_size{0x8000};diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cppindex 85899f83c0..12cfdcf2c0 100644--- a/src/core/hle/kernel/svc.cpp+++ b/src/core/hle/kernel/svc.cpp@@ -27,6 +27,7 @@#include "core/hle/kernel/k_address_arbiter.h"#include "core/hle/kernel/k_condition_variable.h"#include "core/hle/kernel/k_event.h"+#include "core/hle/kernel/k_memory_layout.h"#include "core/hle/kernel/k_readable_event.h"#include "core/hle/kernel/k_resource_limit.h"#include "core/hle/kernel/k_scheduler.h"@@ -38,7 +39,6 @@#include "core/hle/kernel/k_writable_event.h"#include "core/hle/kernel/kernel.h"#include "core/hle/kernel/memory/memory_block.h"-#include "core/hle/kernel/memory/memory_layout.h"#include "core/hle/kernel/memory/page_table.h"#include "core/hle/kernel/physical_core.h"#include "core/hle/kernel/process.h"@@ -508,7 +508,7 @@ static ResultCode ArbitrateLock(Core::System& system, Handle thread_handle, VAddthread_handle, address, tag);// Validate the input address.- if (Memory::IsKernelAddress(address)) {+ if (IsKernelAddress(address)) {LOG_ERROR(Kernel_SVC, "Attempting to arbitrate a lock on a kernel address (address={:08X})",address);return ResultInvalidCurrentMemory;@@ -531,8 +531,7 @@ static ResultCode ArbitrateUnlock(Core::System& system, VAddr address) {LOG_TRACE(Kernel_SVC, "called address=0x{:X}", address);// Validate the input address.-- if (Memory::IsKernelAddress(address)) {+ if (IsKernelAddress(address)) {LOG_ERROR(Kernel_SVC,"Attempting to arbitrate an unlock on a kernel address (address={:08X})",address);@@ -1638,7 +1637,7 @@ static ResultCode WaitProcessWideKeyAtomic(Core::System& system, VAddr address,cv_key, tag, timeout_ns);// Validate input.- if (Memory::IsKernelAddress(address)) {+ if (IsKernelAddress(address)) {LOG_ERROR(Kernel_SVC, "Attempted to wait on kernel address (address={:08X})", address);return ResultInvalidCurrentMemory;}@@ -1720,7 +1719,7 @@ static ResultCode WaitForAddress(Core::System& system, VAddr address, Svc::Arbitaddress, arb_type, value, timeout_ns);// Validate input.- if (Memory::IsKernelAddress(address)) {+ if (IsKernelAddress(address)) {LOG_ERROR(Kernel_SVC, "Attempting to wait on kernel address (address={:08X})", address);return ResultInvalidCurrentMemory;}@@ -1765,7 +1764,7 @@ static ResultCode SignalToAddress(Core::System& system, VAddr address, Svc::Signaddress, signal_type, value, count);// Validate input.- if (Memory::IsKernelAddress(address)) {+ if (IsKernelAddress(address)) {LOG_ERROR(Kernel_SVC, "Attempting to signal to a kernel address (address={:08X})", address);return ResultInvalidCurrentMemory;}