diff options
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r-- | src/core/hle/kernel/k_address_arbiter.cpp | 10 | ||||
-rw-r--r-- | src/core/hle/kernel/k_condition_variable.cpp | 18 | ||||
-rw-r--r-- | src/core/hle/kernel/k_page_table.cpp | 54 | ||||
-rw-r--r-- | src/core/hle/kernel/k_page_table.h | 4 | ||||
-rw-r--r-- | src/core/hle/kernel/k_process.cpp | 22 | ||||
-rw-r--r-- | src/core/hle/kernel/k_process.h | 15 | ||||
-rw-r--r-- | src/core/hle/kernel/k_server_session.cpp | 4 | ||||
-rw-r--r-- | src/core/hle/kernel/k_thread.cpp | 11 | ||||
-rw-r--r-- | src/core/hle/kernel/k_thread.h | 4 | ||||
-rw-r--r-- | src/core/hle/kernel/kernel.cpp | 4 | ||||
-rw-r--r-- | src/core/hle/kernel/svc/svc_cache.cpp | 2 | ||||
-rw-r--r-- | src/core/hle/kernel/svc/svc_debug_string.cpp | 3 | ||||
-rw-r--r-- | src/core/hle/kernel/svc/svc_exception.cpp | 2 | ||||
-rw-r--r-- | src/core/hle/kernel/svc/svc_ipc.cpp | 4 | ||||
-rw-r--r-- | src/core/hle/kernel/svc/svc_port.cpp | 6 | ||||
-rw-r--r-- | src/core/hle/kernel/svc/svc_process.cpp | 2 | ||||
-rw-r--r-- | src/core/hle/kernel/svc/svc_query_memory.cpp | 4 | ||||
-rw-r--r-- | src/core/hle/kernel/svc/svc_synchronization.cpp | 3 | ||||
-rw-r--r-- | src/core/hle/kernel/svc/svc_thread.cpp | 4 |
19 files changed, 100 insertions, 76 deletions
diff --git a/src/core/hle/kernel/k_address_arbiter.cpp b/src/core/hle/kernel/k_address_arbiter.cpp index 274928dcf..08c254028 100644 --- a/src/core/hle/kernel/k_address_arbiter.cpp +++ b/src/core/hle/kernel/k_address_arbiter.cpp @@ -21,8 +21,8 @@ KAddressArbiter::~KAddressArbiter() = default; namespace { -bool ReadFromUser(Core::System& system, s32* out, KProcessAddress address) { - *out = system.Memory().Read32(GetInteger(address)); +bool ReadFromUser(KernelCore& kernel, s32* out, KProcessAddress address) { + *out = GetCurrentMemory(kernel).Read32(GetInteger(address)); return true; } @@ -209,7 +209,7 @@ Result KAddressArbiter::SignalAndModifyByWaitingCountIfEqual(uint64_t addr, s32 if (value != new_value) { succeeded = UpdateIfEqual(m_system, std::addressof(user_value), addr, value, new_value); } else { - succeeded = ReadFromUser(m_system, std::addressof(user_value), addr); + succeeded = ReadFromUser(m_kernel, std::addressof(user_value), addr); } R_UNLESS(succeeded, ResultInvalidCurrentMemory); @@ -252,7 +252,7 @@ Result KAddressArbiter::WaitIfLessThan(uint64_t addr, s32 value, bool decrement, if (decrement) { succeeded = DecrementIfLessThan(m_system, std::addressof(user_value), addr, value); } else { - succeeded = ReadFromUser(m_system, std::addressof(user_value), addr); + succeeded = ReadFromUser(m_kernel, std::addressof(user_value), addr); } if (!succeeded) { @@ -303,7 +303,7 @@ Result KAddressArbiter::WaitIfEqual(uint64_t addr, s32 value, s64 timeout) { // Read the value from userspace. s32 user_value{}; - if (!ReadFromUser(m_system, std::addressof(user_value), addr)) { + if (!ReadFromUser(m_kernel, std::addressof(user_value), addr)) { slp.CancelSleep(); R_THROW(ResultInvalidCurrentMemory); } diff --git a/src/core/hle/kernel/k_condition_variable.cpp b/src/core/hle/kernel/k_condition_variable.cpp index c6634313f..73017cf99 100644 --- a/src/core/hle/kernel/k_condition_variable.cpp +++ b/src/core/hle/kernel/k_condition_variable.cpp @@ -18,13 +18,13 @@ namespace Kernel { namespace { -bool ReadFromUser(Core::System& system, u32* out, KProcessAddress address) { - *out = system.Memory().Read32(GetInteger(address)); +bool ReadFromUser(KernelCore& kernel, u32* out, KProcessAddress address) { + *out = GetCurrentMemory(kernel).Read32(GetInteger(address)); return true; } -bool WriteToUser(Core::System& system, KProcessAddress address, const u32* p) { - system.Memory().Write32(GetInteger(address), *p); +bool WriteToUser(KernelCore& kernel, KProcessAddress address, const u32* p) { + GetCurrentMemory(kernel).Write32(GetInteger(address), *p); return true; } @@ -128,7 +128,7 @@ Result KConditionVariable::SignalToAddress(KProcessAddress addr) { // Write the value to userspace. Result result{ResultSuccess}; - if (WriteToUser(m_system, addr, std::addressof(next_value))) [[likely]] { + if (WriteToUser(m_kernel, addr, std::addressof(next_value))) [[likely]] { result = ResultSuccess; } else { result = ResultInvalidCurrentMemory; @@ -157,7 +157,7 @@ Result KConditionVariable::WaitForAddress(Handle handle, KProcessAddress addr, u // Read the tag from userspace. u32 test_tag{}; - R_UNLESS(ReadFromUser(m_system, std::addressof(test_tag), addr), + R_UNLESS(ReadFromUser(m_kernel, std::addressof(test_tag), addr), ResultInvalidCurrentMemory); // If the tag isn't the handle (with wait mask), we're done. @@ -257,7 +257,7 @@ void KConditionVariable::Signal(u64 cv_key, s32 count) { // If we have no waiters, clear the has waiter flag. if (it == m_tree.end() || it->GetConditionVariableKey() != cv_key) { const u32 has_waiter_flag{}; - WriteToUser(m_system, cv_key, std::addressof(has_waiter_flag)); + WriteToUser(m_kernel, cv_key, std::addressof(has_waiter_flag)); } } } @@ -301,12 +301,12 @@ Result KConditionVariable::Wait(KProcessAddress addr, u64 key, u32 value, s64 ti // Write to the cv key. { const u32 has_waiter_flag = 1; - WriteToUser(m_system, key, std::addressof(has_waiter_flag)); + WriteToUser(m_kernel, key, std::addressof(has_waiter_flag)); std::atomic_thread_fence(std::memory_order_seq_cst); } // Write the value to userspace. - if (!WriteToUser(m_system, addr, std::addressof(next_value))) { + if (!WriteToUser(m_kernel, addr, std::addressof(next_value))) { slp.CancelSleep(); R_THROW(ResultInvalidCurrentMemory); } diff --git a/src/core/hle/kernel/k_page_table.cpp b/src/core/hle/kernel/k_page_table.cpp index cb39387ea..02b5cada4 100644 --- a/src/core/hle/kernel/k_page_table.cpp +++ b/src/core/hle/kernel/k_page_table.cpp @@ -108,7 +108,8 @@ Result KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_type bool enable_das_merge, bool from_back, KMemoryManager::Pool pool, KProcessAddress code_addr, size_t code_size, KSystemResource* system_resource, - KResourceLimit* resource_limit) { + KResourceLimit* resource_limit, + Core::Memory::Memory& memory) { const auto GetSpaceStart = [this](KAddressSpaceInfo::Type type) { return KAddressSpaceInfo::GetAddressSpaceStart(m_address_space_width, type); @@ -117,6 +118,9 @@ Result KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_type return KAddressSpaceInfo::GetAddressSpaceSize(m_address_space_width, type); }; + // Set the tracking memory + m_memory = std::addressof(memory); + // Set our width and heap/alias sizes m_address_space_width = GetAddressSpaceWidthFromType(as_type); const KProcessAddress start = 0; @@ -334,10 +338,10 @@ Result KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_type void KPageTable::Finalize() { // Finalize memory blocks. - m_memory_block_manager.Finalize( - m_memory_block_slab_manager, [&](KProcessAddress addr, u64 size) { - m_system.Memory().UnmapRegion(*m_page_table_impl, addr, size); - }); + m_memory_block_manager.Finalize(m_memory_block_slab_manager, + [&](KProcessAddress addr, u64 size) { + m_memory->UnmapRegion(*m_page_table_impl, addr, size); + }); // Release any insecure mapped memory. if (m_mapped_insecure_memory) { @@ -1010,23 +1014,22 @@ Result KPageTable::SetupForIpcServer(KProcessAddress* out_addr, size_t size, clear_size = 0; } - std::memset(m_system.Memory().GetPointer<void>(GetInteger(start_partial_virt)), - fill_val, partial_offset); + std::memset(m_memory->GetPointer<void>(GetInteger(start_partial_virt)), fill_val, + partial_offset); std::memcpy( - m_system.Memory().GetPointer<void>(GetInteger(start_partial_virt) + partial_offset), - m_system.Memory().GetPointer<void>( - GetInteger( - GetHeapVirtualAddress(m_system.Kernel().MemoryLayout(), cur_block_addr)) + - partial_offset), + m_memory->GetPointer<void>(GetInteger(start_partial_virt) + partial_offset), + m_memory->GetPointer<void>(GetInteger(GetHeapVirtualAddress( + m_system.Kernel().MemoryLayout(), cur_block_addr)) + + partial_offset), copy_size); if (clear_size > 0) { - std::memset(m_system.Memory().GetPointer<void>(GetInteger(start_partial_virt) + - partial_offset + copy_size), + std::memset(m_memory->GetPointer<void>(GetInteger(start_partial_virt) + + partial_offset + copy_size), fill_val, clear_size); } } else { - std::memset(m_system.Memory().GetPointer<void>(GetInteger(start_partial_virt)), - fill_val, PageSize); + std::memset(m_memory->GetPointer<void>(GetInteger(start_partial_virt)), fill_val, + PageSize); } // Map the page. @@ -1099,15 +1102,14 @@ Result KPageTable::SetupForIpcServer(KProcessAddress* out_addr, size_t size, GetHeapVirtualAddress(m_system.Kernel().MemoryLayout(), end_partial_page); if (send) { const size_t copy_size = src_end - mapping_src_end; - std::memcpy(m_system.Memory().GetPointer<void>(GetInteger(end_partial_virt)), - m_system.Memory().GetPointer<void>(GetInteger(GetHeapVirtualAddress( + std::memcpy(m_memory->GetPointer<void>(GetInteger(end_partial_virt)), + m_memory->GetPointer<void>(GetInteger(GetHeapVirtualAddress( m_system.Kernel().MemoryLayout(), cur_block_addr))), copy_size); - std::memset( - m_system.Memory().GetPointer<void>(GetInteger(end_partial_virt) + copy_size), - fill_val, PageSize - copy_size); + std::memset(m_memory->GetPointer<void>(GetInteger(end_partial_virt) + copy_size), + fill_val, PageSize - copy_size); } else { - std::memset(m_system.Memory().GetPointer<void>(GetInteger(end_partial_virt)), fill_val, + std::memset(m_memory->GetPointer<void>(GetInteger(end_partial_virt)), fill_val, PageSize); } @@ -2800,7 +2802,7 @@ Result KPageTable::SetHeapSize(u64* out, size_t size) { // Clear all the newly allocated pages. for (size_t cur_page = 0; cur_page < num_pages; ++cur_page) { - std::memset(m_system.Memory().GetPointer(m_current_heap_end + (cur_page * PageSize)), 0, + std::memset(m_memory->GetPointer(m_current_heap_end + (cur_page * PageSize)), 0, PageSize); } @@ -3006,7 +3008,7 @@ Result KPageTable::Operate(KProcessAddress addr, size_t num_pages, const KPageGr const size_t size{node.GetNumPages() * PageSize}; // Map the pages. - m_system.Memory().MapMemoryRegion(*m_page_table_impl, addr, size, node.GetAddress()); + m_memory->MapMemoryRegion(*m_page_table_impl, addr, size, node.GetAddress()); addr += size; } @@ -3039,14 +3041,14 @@ Result KPageTable::Operate(KProcessAddress addr, size_t num_pages, KMemoryPermis SCOPE_EXIT({ pages_to_close.CloseAndReset(); }); this->AddRegionToPages(addr, num_pages, pages_to_close); - m_system.Memory().UnmapRegion(*m_page_table_impl, addr, num_pages * PageSize); + m_memory->UnmapRegion(*m_page_table_impl, addr, num_pages * PageSize); break; } case OperationType::MapFirst: case OperationType::Map: { ASSERT(map_addr); ASSERT(Common::IsAligned(GetInteger(map_addr), PageSize)); - m_system.Memory().MapMemoryRegion(*m_page_table_impl, addr, num_pages * PageSize, map_addr); + m_memory->MapMemoryRegion(*m_page_table_impl, addr, num_pages * PageSize, map_addr); // Open references to pages, if we should. if (IsHeapPhysicalAddress(m_kernel.MemoryLayout(), map_addr)) { diff --git a/src/core/hle/kernel/k_page_table.h b/src/core/hle/kernel/k_page_table.h index 1917b2a98..022d15f35 100644 --- a/src/core/hle/kernel/k_page_table.h +++ b/src/core/hle/kernel/k_page_table.h @@ -66,7 +66,8 @@ public: Result InitializeForProcess(FileSys::ProgramAddressSpaceType as_type, bool enable_aslr, bool enable_das_merge, bool from_back, KMemoryManager::Pool pool, KProcessAddress code_addr, size_t code_size, - KSystemResource* system_resource, KResourceLimit* resource_limit); + KSystemResource* system_resource, KResourceLimit* resource_limit, + Core::Memory::Memory& memory); void Finalize(); @@ -546,6 +547,7 @@ private: Core::System& m_system; KernelCore& m_kernel; + Core::Memory::Memory* m_memory{}; }; } // namespace Kernel diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp index 53f8139f3..efe86ad27 100644 --- a/src/core/hle/kernel/k_process.cpp +++ b/src/core/hle/kernel/k_process.cpp @@ -367,8 +367,8 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std: // Initialize process address space if (const Result result{m_page_table.InitializeForProcess( metadata.GetAddressSpaceType(), false, false, false, KMemoryManager::Pool::Application, - 0x8000000, code_size, std::addressof(m_kernel.GetAppSystemResource()), - m_resource_limit)}; + 0x8000000, code_size, std::addressof(m_kernel.GetAppSystemResource()), m_resource_limit, + m_kernel.System().ApplicationMemory())}; result.IsError()) { R_RETURN(result); } @@ -592,8 +592,7 @@ Result KProcess::DeleteThreadLocalRegion(KProcessAddress addr) { R_SUCCEED(); } -bool KProcess::InsertWatchpoint(Core::System& system, KProcessAddress addr, u64 size, - DebugWatchpointType type) { +bool KProcess::InsertWatchpoint(KProcessAddress addr, u64 size, DebugWatchpointType type) { const auto watch{std::find_if(m_watchpoints.begin(), m_watchpoints.end(), [&](const auto& wp) { return wp.type == DebugWatchpointType::None; })}; @@ -609,14 +608,13 @@ bool KProcess::InsertWatchpoint(Core::System& system, KProcessAddress addr, u64 for (KProcessAddress page = Common::AlignDown(GetInteger(addr), PageSize); page < addr + size; page += PageSize) { m_debug_page_refcounts[page]++; - system.Memory().MarkRegionDebug(page, PageSize, true); + this->GetMemory().MarkRegionDebug(page, PageSize, true); } return true; } -bool KProcess::RemoveWatchpoint(Core::System& system, KProcessAddress addr, u64 size, - DebugWatchpointType type) { +bool KProcess::RemoveWatchpoint(KProcessAddress addr, u64 size, DebugWatchpointType type) { const auto watch{std::find_if(m_watchpoints.begin(), m_watchpoints.end(), [&](const auto& wp) { return wp.start_address == addr && wp.end_address == addr + size && wp.type == type; })}; @@ -633,7 +631,7 @@ bool KProcess::RemoveWatchpoint(Core::System& system, KProcessAddress addr, u64 page += PageSize) { m_debug_page_refcounts[page]--; if (!m_debug_page_refcounts[page]) { - system.Memory().MarkRegionDebug(page, PageSize, false); + this->GetMemory().MarkRegionDebug(page, PageSize, false); } } @@ -646,8 +644,7 @@ void KProcess::LoadModule(CodeSet code_set, KProcessAddress base_addr) { m_page_table.SetProcessMemoryPermission(segment.addr + base_addr, segment.size, permission); }; - m_kernel.System().Memory().WriteBlock(*this, base_addr, code_set.memory.data(), - code_set.memory.size()); + this->GetMemory().WriteBlock(base_addr, code_set.memory.data(), code_set.memory.size()); ReprotectSegment(code_set.CodeSegment(), Svc::MemoryPermission::ReadExecute); ReprotectSegment(code_set.RODataSegment(), Svc::MemoryPermission::Read); @@ -706,4 +703,9 @@ Result KProcess::AllocateMainThreadStack(std::size_t stack_size) { R_SUCCEED(); } +Core::Memory::Memory& KProcess::GetMemory() const { + // TODO: per-process memory + return m_kernel.System().ApplicationMemory(); +} + } // namespace Kernel diff --git a/src/core/hle/kernel/k_process.h b/src/core/hle/kernel/k_process.h index 04b6bbb86..925981d06 100644 --- a/src/core/hle/kernel/k_process.h +++ b/src/core/hle/kernel/k_process.h @@ -22,8 +22,12 @@ #include "core/hle/result.h" namespace Core { +namespace Memory { +class Memory; +}; + class System; -} +} // namespace Core namespace FileSys { class ProgramMetadata; @@ -135,6 +139,9 @@ public: return m_handle_table; } + /// Gets a reference to process's memory. + Core::Memory::Memory& GetMemory() const; + Result SignalToAddress(KProcessAddress address) { return m_condition_var.SignalToAddress(address); } @@ -397,12 +404,10 @@ public: // Debug watchpoint management // Attempts to insert a watchpoint into a free slot. Returns false if none are available. - bool InsertWatchpoint(Core::System& system, KProcessAddress addr, u64 size, - DebugWatchpointType type); + bool InsertWatchpoint(KProcessAddress addr, u64 size, DebugWatchpointType type); // Attempts to remove the watchpoint specified by the given parameters. - bool RemoveWatchpoint(Core::System& system, KProcessAddress addr, u64 size, - DebugWatchpointType type); + bool RemoveWatchpoint(KProcessAddress addr, u64 size, DebugWatchpointType type); const std::array<DebugWatchpoint, Core::Hardware::NUM_WATCHPOINTS>& GetWatchpoints() const { return m_watchpoints; diff --git a/src/core/hle/kernel/k_server_session.cpp b/src/core/hle/kernel/k_server_session.cpp index 2288ee435..c66aff501 100644 --- a/src/core/hle/kernel/k_server_session.cpp +++ b/src/core/hle/kernel/k_server_session.cpp @@ -222,7 +222,7 @@ Result KServerSession::SendReply(bool is_hle) { // HLE servers write directly to a pointer to the thread command buffer. Therefore // the reply has already been written in this case. } else { - Core::Memory::Memory& memory{m_kernel.System().Memory()}; + Core::Memory::Memory& memory{client_thread->GetOwnerProcess()->GetMemory()}; KThread* server_thread{GetCurrentThreadPointer(m_kernel)}; UNIMPLEMENTED_IF(server_thread->GetOwnerProcess() != client_thread->GetOwnerProcess()); @@ -319,7 +319,7 @@ Result KServerSession::ReceiveRequest(std::shared_ptr<Service::HLERequestContext // bool recv_list_broken = false; // Receive the message. - Core::Memory::Memory& memory{m_kernel.System().Memory()}; + Core::Memory::Memory& memory{client_thread->GetOwnerProcess()->GetMemory()}; if (out_context != nullptr) { // HLE request. u32* cmd_buf{reinterpret_cast<u32*>(memory.GetPointer(client_message))}; diff --git a/src/core/hle/kernel/k_thread.cpp b/src/core/hle/kernel/k_thread.cpp index 9d101c640..70480b725 100644 --- a/src/core/hle/kernel/k_thread.cpp +++ b/src/core/hle/kernel/k_thread.cpp @@ -546,7 +546,7 @@ u16 KThread::GetUserDisableCount() const { return {}; } - auto& memory = m_kernel.System().Memory(); + auto& memory = this->GetOwnerProcess()->GetMemory(); return memory.Read16(m_tls_address + offsetof(ThreadLocalRegion, disable_count)); } @@ -556,7 +556,7 @@ void KThread::SetInterruptFlag() { return; } - auto& memory = m_kernel.System().Memory(); + auto& memory = this->GetOwnerProcess()->GetMemory(); memory.Write16(m_tls_address + offsetof(ThreadLocalRegion, interrupt_flag), 1); } @@ -566,7 +566,7 @@ void KThread::ClearInterruptFlag() { return; } - auto& memory = m_kernel.System().Memory(); + auto& memory = this->GetOwnerProcess()->GetMemory(); memory.Write16(m_tls_address + offsetof(ThreadLocalRegion, interrupt_flag), 0); } @@ -1422,6 +1422,11 @@ s32 GetCurrentCoreId(KernelCore& kernel) { return GetCurrentThread(kernel).GetCurrentCore(); } +Core::Memory::Memory& GetCurrentMemory(KernelCore& kernel) { + // TODO: per-process memory + return kernel.System().ApplicationMemory(); +} + KScopedDisableDispatch::~KScopedDisableDispatch() { // If we are shutting down the kernel, none of this is relevant anymore. if (m_kernel.IsShuttingDown()) { diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h index 0fa9672bf..9c1a41128 100644 --- a/src/core/hle/kernel/k_thread.h +++ b/src/core/hle/kernel/k_thread.h @@ -34,6 +34,9 @@ class Fiber; } namespace Core { +namespace Memory { +class Memory; +} class ARM_Interface; class System; } // namespace Core @@ -113,6 +116,7 @@ KThread& GetCurrentThread(KernelCore& kernel); KProcess* GetCurrentProcessPointer(KernelCore& kernel); KProcess& GetCurrentProcess(KernelCore& kernel); s32 GetCurrentCoreId(KernelCore& kernel); +Core::Memory::Memory& GetCurrentMemory(KernelCore& kernel); class KThread final : public KAutoObjectWithSlabHeapAndContainer<KThread, KWorkerTask>, public boost::intrusive::list_base_hook<>, diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 29809b2c5..4f3366c9d 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -102,7 +102,7 @@ struct KernelCore::Impl { void InitializeCores() { for (u32 core_id = 0; core_id < Core::Hardware::NUM_CPU_CORES; core_id++) { cores[core_id]->Initialize((*application_process).Is64BitProcess()); - system.Memory().SetCurrentPageTable(*application_process, core_id); + system.ApplicationMemory().SetCurrentPageTable(*application_process, core_id); } } @@ -206,7 +206,7 @@ struct KernelCore::Impl { void InitializePhysicalCores() { exclusive_monitor = - Core::MakeExclusiveMonitor(system.Memory(), Core::Hardware::NUM_CPU_CORES); + Core::MakeExclusiveMonitor(system.ApplicationMemory(), Core::Hardware::NUM_CPU_CORES); for (u32 i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) { const s32 core{static_cast<s32>(i)}; diff --git a/src/core/hle/kernel/svc/svc_cache.cpp b/src/core/hle/kernel/svc/svc_cache.cpp index 1779832d3..082942dab 100644 --- a/src/core/hle/kernel/svc/svc_cache.cpp +++ b/src/core/hle/kernel/svc/svc_cache.cpp @@ -46,7 +46,7 @@ Result FlushProcessDataCache(Core::System& system, Handle process_handle, u64 ad R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory); // Perform the operation. - R_RETURN(system.Memory().FlushDataCache(*process, address, size)); + R_RETURN(GetCurrentMemory(system.Kernel()).FlushDataCache(address, size)); } void FlushEntireDataCache64(Core::System& system) { diff --git a/src/core/hle/kernel/svc/svc_debug_string.cpp b/src/core/hle/kernel/svc/svc_debug_string.cpp index 8771d2b01..4c14ce668 100644 --- a/src/core/hle/kernel/svc/svc_debug_string.cpp +++ b/src/core/hle/kernel/svc/svc_debug_string.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "core/core.h" +#include "core/hle/kernel/k_thread.h" #include "core/hle/kernel/svc.h" #include "core/memory.h" @@ -12,7 +13,7 @@ Result OutputDebugString(Core::System& system, u64 address, u64 len) { R_SUCCEED_IF(len == 0); std::string str(len, '\0'); - system.Memory().ReadBlock(address, str.data(), str.size()); + GetCurrentMemory(system.Kernel()).ReadBlock(address, str.data(), str.size()); LOG_DEBUG(Debug_Emulated, "{}", str); R_SUCCEED(); diff --git a/src/core/hle/kernel/svc/svc_exception.cpp b/src/core/hle/kernel/svc/svc_exception.cpp index 4ab5f471f..580cf2f75 100644 --- a/src/core/hle/kernel/svc/svc_exception.cpp +++ b/src/core/hle/kernel/svc/svc_exception.cpp @@ -25,7 +25,7 @@ void Break(Core::System& system, BreakReason reason, u64 info1, u64 info2) { return; } - auto& memory = system.Memory(); + auto& memory = GetCurrentMemory(system.Kernel()); // This typically is an error code so we're going to assume this is the case if (sz == sizeof(u32)) { diff --git a/src/core/hle/kernel/svc/svc_ipc.cpp b/src/core/hle/kernel/svc/svc_ipc.cpp index 2a8c09a79..ea03068aa 100644 --- a/src/core/hle/kernel/svc/svc_ipc.cpp +++ b/src/core/hle/kernel/svc/svc_ipc.cpp @@ -41,12 +41,12 @@ Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_ad auto& handle_table = GetCurrentProcess(kernel).GetHandleTable(); R_UNLESS(0 <= num_handles && num_handles <= ArgumentHandleCountMax, ResultOutOfRange); - R_UNLESS(system.Memory().IsValidVirtualAddressRange( + R_UNLESS(GetCurrentMemory(kernel).IsValidVirtualAddressRange( handles_addr, static_cast<u64>(sizeof(Handle) * num_handles)), ResultInvalidPointer); std::vector<Handle> handles(num_handles); - system.Memory().ReadBlock(handles_addr, handles.data(), sizeof(Handle) * num_handles); + GetCurrentMemory(kernel).ReadBlock(handles_addr, handles.data(), sizeof(Handle) * num_handles); // Convert handle list to object table. std::vector<KSynchronizationObject*> objs(num_handles); diff --git a/src/core/hle/kernel/svc/svc_port.cpp b/src/core/hle/kernel/svc/svc_port.cpp index c6eb70422..abba757c7 100644 --- a/src/core/hle/kernel/svc/svc_port.cpp +++ b/src/core/hle/kernel/svc/svc_port.cpp @@ -14,7 +14,8 @@ namespace Kernel::Svc { Result ConnectToNamedPort(Core::System& system, Handle* out, u64 user_name) { // Copy the provided name from user memory to kernel memory. - auto string_name = system.Memory().ReadCString(user_name, KObjectName::NameLengthMax); + auto string_name = + GetCurrentMemory(system.Kernel()).ReadCString(user_name, KObjectName::NameLengthMax); std::array<char, KObjectName::NameLengthMax> name{}; std::strncpy(name.data(), string_name.c_str(), KObjectName::NameLengthMax - 1); @@ -62,7 +63,8 @@ Result ConnectToPort(Core::System& system, Handle* out_handle, Handle port) { Result ManageNamedPort(Core::System& system, Handle* out_server_handle, uint64_t user_name, int32_t max_sessions) { // Copy the provided name from user memory to kernel memory. - auto string_name = system.Memory().ReadCString(user_name, KObjectName::NameLengthMax); + auto string_name = + GetCurrentMemory(system.Kernel()).ReadCString(user_name, KObjectName::NameLengthMax); // Copy the provided name from user memory to kernel memory. std::array<char, KObjectName::NameLengthMax> name{}; diff --git a/src/core/hle/kernel/svc/svc_process.cpp b/src/core/hle/kernel/svc/svc_process.cpp index 3c3579947..619ed16a3 100644 --- a/src/core/hle/kernel/svc/svc_process.cpp +++ b/src/core/hle/kernel/svc/svc_process.cpp @@ -73,7 +73,7 @@ Result GetProcessList(Core::System& system, s32* out_num_processes, u64 out_proc R_THROW(ResultInvalidCurrentMemory); } - auto& memory = system.Memory(); + auto& memory = GetCurrentMemory(kernel); const auto& process_list = kernel.GetProcessList(); const auto num_processes = process_list.size(); const auto copy_amount = diff --git a/src/core/hle/kernel/svc/svc_query_memory.cpp b/src/core/hle/kernel/svc/svc_query_memory.cpp index 5db5611f0..4d9fcd25f 100644 --- a/src/core/hle/kernel/svc/svc_query_memory.cpp +++ b/src/core/hle/kernel/svc/svc_query_memory.cpp @@ -30,10 +30,10 @@ Result QueryProcessMemory(Core::System& system, uint64_t out_memory_info, PageIn R_THROW(ResultInvalidHandle); } - auto& memory{system.Memory()}; + auto& current_memory{GetCurrentMemory(system.Kernel())}; const auto memory_info{process->PageTable().QueryInfo(address).GetSvcMemoryInfo()}; - memory.WriteBlock(out_memory_info, std::addressof(memory_info), sizeof(memory_info)); + current_memory.WriteBlock(out_memory_info, std::addressof(memory_info), sizeof(memory_info)); //! This is supposed to be part of the QueryInfo call. *out_page_info = {}; diff --git a/src/core/hle/kernel/svc/svc_synchronization.cpp b/src/core/hle/kernel/svc/svc_synchronization.cpp index e490a13ae..04d65f0bd 100644 --- a/src/core/hle/kernel/svc/svc_synchronization.cpp +++ b/src/core/hle/kernel/svc/svc_synchronization.cpp @@ -90,7 +90,8 @@ Result WaitSynchronization(Core::System& system, int32_t* out_index, u64 user_ha std::vector<Handle> handles(num_handles); if (num_handles > 0) { - system.Memory().ReadBlock(user_handles, handles.data(), num_handles * sizeof(Handle)); + GetCurrentMemory(system.Kernel()) + .ReadBlock(user_handles, handles.data(), num_handles * sizeof(Handle)); } R_RETURN(WaitSynchronization(system, out_index, handles.data(), num_handles, timeout_ns)); diff --git a/src/core/hle/kernel/svc/svc_thread.cpp b/src/core/hle/kernel/svc/svc_thread.cpp index 0be4858a2..37b54079c 100644 --- a/src/core/hle/kernel/svc/svc_thread.cpp +++ b/src/core/hle/kernel/svc/svc_thread.cpp @@ -178,7 +178,7 @@ Result GetThreadContext3(Core::System& system, u64 out_context, Handle thread_ha R_TRY(thread->GetThreadContext3(context)); // Copy the thread context to user space. - system.Memory().WriteBlock(out_context, context.data(), context.size()); + GetCurrentMemory(kernel).WriteBlock(out_context, context.data(), context.size()); R_SUCCEED(); } @@ -242,7 +242,7 @@ Result GetThreadList(Core::System& system, s32* out_num_threads, u64 out_thread_ R_THROW(ResultInvalidCurrentMemory); } - auto& memory = system.Memory(); + auto& memory = GetCurrentMemory(system.Kernel()); const auto& thread_list = current_process->GetThreadList(); const auto num_threads = thread_list.size(); const auto copy_amount = std::min(static_cast<std::size_t>(out_thread_ids_size), num_threads); |