From b1e27890e8728c19ceef404aa6352cd6f2913ded Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 12 Feb 2021 17:38:40 -0800 Subject: hle: kernel: Migrate MemoryManager to KMemoryManager. --- src/core/CMakeLists.txt | 4 +- src/core/hle/kernel/k_memory_manager.cpp | 176 ++++++++++++++++++++++++++ src/core/hle/kernel/k_memory_manager.h | 121 ++++++++++++++++++ src/core/hle/kernel/kernel.cpp | 16 +-- src/core/hle/kernel/kernel.h | 16 +-- src/core/hle/kernel/memory/memory_manager.cpp | 176 -------------------------- src/core/hle/kernel/memory/memory_manager.h | 121 ------------------ src/core/hle/kernel/memory/page_table.cpp | 2 +- src/core/hle/kernel/memory/page_table.h | 6 +- src/core/hle/kernel/process.cpp | 9 +- 10 files changed, 324 insertions(+), 323 deletions(-) create mode 100644 src/core/hle/kernel/k_memory_manager.cpp create mode 100644 src/core/hle/kernel/k_memory_manager.h delete mode 100644 src/core/hle/kernel/memory/memory_manager.cpp delete mode 100644 src/core/hle/kernel/memory/memory_manager.h (limited to 'src') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 70dab3f74..2976187c0 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -170,6 +170,8 @@ add_library(core STATIC hle/kernel/k_memory_block_manager.cpp hle/kernel/k_memory_block_manager.h hle/kernel/k_memory_layout.h + hle/kernel/k_memory_manager.cpp + hle/kernel/k_memory_manager.h hle/kernel/k_page_bitmap.h hle/kernel/k_page_linked_list.h hle/kernel/k_priority_queue.h @@ -200,8 +202,6 @@ add_library(core STATIC hle/kernel/kernel.cpp hle/kernel/kernel.h hle/kernel/memory_types.h - hle/kernel/memory/memory_manager.cpp - hle/kernel/memory/memory_manager.h hle/kernel/memory/page_heap.cpp hle/kernel/memory/page_heap.h hle/kernel/memory/page_table.cpp diff --git a/src/core/hle/kernel/k_memory_manager.cpp b/src/core/hle/kernel/k_memory_manager.cpp new file mode 100644 index 000000000..5ea11a918 --- /dev/null +++ b/src/core/hle/kernel/k_memory_manager.cpp @@ -0,0 +1,176 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include + +#include "common/alignment.h" +#include "common/assert.h" +#include "common/common_types.h" +#include "common/scope_exit.h" +#include "core/hle/kernel/k_memory_manager.h" +#include "core/hle/kernel/k_page_linked_list.h" +#include "core/hle/kernel/svc_results.h" + +namespace Kernel { + +std::size_t KMemoryManager::Impl::Initialize(Pool new_pool, u64 start_address, u64 end_address) { + const auto size{end_address - start_address}; + + // Calculate metadata sizes + const auto ref_count_size{(size / PageSize) * sizeof(u16)}; + const auto optimize_map_size{(Common::AlignUp((size / PageSize), 64) / 64) * sizeof(u64)}; + const auto manager_size{Common::AlignUp(optimize_map_size + ref_count_size, PageSize)}; + const auto page_heap_size{Memory::PageHeap::CalculateManagementOverheadSize(size)}; + const auto total_metadata_size{manager_size + page_heap_size}; + ASSERT(manager_size <= total_metadata_size); + ASSERT(Common::IsAligned(total_metadata_size, PageSize)); + + // Setup region + pool = new_pool; + + // Initialize the manager's KPageHeap + heap.Initialize(start_address, size, page_heap_size); + + // Free the memory to the heap + heap.Free(start_address, size / PageSize); + + // Update the heap's used size + heap.UpdateUsedSize(); + + return total_metadata_size; +} + +void KMemoryManager::InitializeManager(Pool pool, u64 start_address, u64 end_address) { + ASSERT(pool < Pool::Count); + managers[static_cast(pool)].Initialize(pool, start_address, end_address); +} + +VAddr KMemoryManager::AllocateAndOpenContinuous(std::size_t num_pages, std::size_t align_pages, + u32 option) { + // Early return if we're allocating no pages + if (num_pages == 0) { + return {}; + } + + // Lock the pool that we're allocating from + const auto [pool, dir] = DecodeOption(option); + const auto pool_index{static_cast(pool)}; + std::lock_guard lock{pool_locks[pool_index]}; + + // Choose a heap based on our page size request + const s32 heap_index{Memory::PageHeap::GetAlignedBlockIndex(num_pages, align_pages)}; + + // Loop, trying to iterate from each block + // TODO (bunnei): Support multiple managers + Impl& chosen_manager{managers[pool_index]}; + VAddr allocated_block{chosen_manager.AllocateBlock(heap_index, false)}; + + // If we failed to allocate, quit now + if (!allocated_block) { + return {}; + } + + // If we allocated more than we need, free some + const auto allocated_pages{Memory::PageHeap::GetBlockNumPages(heap_index)}; + if (allocated_pages > num_pages) { + chosen_manager.Free(allocated_block + num_pages * PageSize, allocated_pages - num_pages); + } + + return allocated_block; +} + +ResultCode KMemoryManager::Allocate(KPageLinkedList& page_list, std::size_t num_pages, Pool pool, + Direction dir) { + ASSERT(page_list.GetNumPages() == 0); + + // Early return if we're allocating no pages + if (num_pages == 0) { + return RESULT_SUCCESS; + } + + // Lock the pool that we're allocating from + const auto pool_index{static_cast(pool)}; + std::lock_guard lock{pool_locks[pool_index]}; + + // Choose a heap based on our page size request + const s32 heap_index{Memory::PageHeap::GetBlockIndex(num_pages)}; + if (heap_index < 0) { + return ResultOutOfMemory; + } + + // TODO (bunnei): Support multiple managers + Impl& chosen_manager{managers[pool_index]}; + + // Ensure that we don't leave anything un-freed + auto group_guard = detail::ScopeExit([&] { + for (const auto& it : page_list.Nodes()) { + const auto min_num_pages{std::min( + it.GetNumPages(), (chosen_manager.GetEndAddress() - it.GetAddress()) / PageSize)}; + chosen_manager.Free(it.GetAddress(), min_num_pages); + } + }); + + // Keep allocating until we've allocated all our pages + for (s32 index{heap_index}; index >= 0 && num_pages > 0; index--) { + const auto pages_per_alloc{Memory::PageHeap::GetBlockNumPages(index)}; + + while (num_pages >= pages_per_alloc) { + // Allocate a block + VAddr allocated_block{chosen_manager.AllocateBlock(index, false)}; + if (!allocated_block) { + break; + } + + // Safely add it to our group + { + auto block_guard = detail::ScopeExit( + [&] { chosen_manager.Free(allocated_block, pages_per_alloc); }); + + if (const ResultCode result{page_list.AddBlock(allocated_block, pages_per_alloc)}; + result.IsError()) { + return result; + } + + block_guard.Cancel(); + } + + num_pages -= pages_per_alloc; + } + } + + // Only succeed if we allocated as many pages as we wanted + if (num_pages) { + return ResultOutOfMemory; + } + + // We succeeded! + group_guard.Cancel(); + return RESULT_SUCCESS; +} + +ResultCode KMemoryManager::Free(KPageLinkedList& page_list, std::size_t num_pages, Pool pool, + Direction dir) { + // Early return if we're freeing no pages + if (!num_pages) { + return RESULT_SUCCESS; + } + + // Lock the pool that we're freeing from + const auto pool_index{static_cast(pool)}; + std::lock_guard lock{pool_locks[pool_index]}; + + // TODO (bunnei): Support multiple managers + Impl& chosen_manager{managers[pool_index]}; + + // Free all of the pages + for (const auto& it : page_list.Nodes()) { + const auto min_num_pages{std::min( + it.GetNumPages(), (chosen_manager.GetEndAddress() - it.GetAddress()) / PageSize)}; + chosen_manager.Free(it.GetAddress(), min_num_pages); + } + + return RESULT_SUCCESS; +} + +} // namespace Kernel diff --git a/src/core/hle/kernel/k_memory_manager.h b/src/core/hle/kernel/k_memory_manager.h new file mode 100644 index 000000000..377f642d8 --- /dev/null +++ b/src/core/hle/kernel/k_memory_manager.h @@ -0,0 +1,121 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include + +#include "common/common_funcs.h" +#include "common/common_types.h" +#include "core/hle/kernel/memory/page_heap.h" +#include "core/hle/result.h" + +namespace Kernel { +class KPageLinkedList; +} + +namespace Kernel { + +class KMemoryManager final : NonCopyable { +public: + enum class Pool : u32 { + Application = 0, + Applet = 1, + System = 2, + SystemNonSecure = 3, + + Count, + + Shift = 4, + Mask = (0xF << Shift), + }; + + enum class Direction : u32 { + FromFront = 0, + FromBack = 1, + + Shift = 0, + Mask = (0xF << Shift), + }; + + KMemoryManager() = default; + + constexpr std::size_t GetSize(Pool pool) const { + return managers[static_cast(pool)].GetSize(); + } + + void InitializeManager(Pool pool, u64 start_address, u64 end_address); + + VAddr AllocateAndOpenContinuous(size_t num_pages, size_t align_pages, u32 option); + ResultCode Allocate(KPageLinkedList& page_list, std::size_t num_pages, Pool pool, + Direction dir = Direction::FromFront); + ResultCode Free(KPageLinkedList& page_list, std::size_t num_pages, Pool pool, + Direction dir = Direction::FromFront); + + static constexpr std::size_t MaxManagerCount = 10; + +public: + static constexpr u32 EncodeOption(Pool pool, Direction dir) { + return (static_cast(pool) << static_cast(Pool::Shift)) | + (static_cast(dir) << static_cast(Direction::Shift)); + } + + static constexpr Pool GetPool(u32 option) { + return static_cast((static_cast(option) & static_cast(Pool::Mask)) >> + static_cast(Pool::Shift)); + } + + static constexpr Direction GetDirection(u32 option) { + return static_cast( + (static_cast(option) & static_cast(Direction::Mask)) >> + static_cast(Direction::Shift)); + } + + static constexpr std::tuple DecodeOption(u32 option) { + return std::make_tuple(GetPool(option), GetDirection(option)); + } + +private: + class Impl final : NonCopyable { + private: + using RefCount = u16; + + private: + Memory::PageHeap heap; + Pool pool{}; + + public: + Impl() = default; + + std::size_t Initialize(Pool new_pool, u64 start_address, u64 end_address); + + VAddr AllocateBlock(s32 index, bool random) { + return heap.AllocateBlock(index, random); + } + + void Free(VAddr addr, std::size_t num_pages) { + heap.Free(addr, num_pages); + } + + constexpr std::size_t GetSize() const { + return heap.GetSize(); + } + + constexpr VAddr GetAddress() const { + return heap.GetAddress(); + } + + constexpr VAddr GetEndAddress() const { + return heap.GetEndAddress(); + } + }; + +private: + std::array(Pool::Count)> pool_locks; + std::array managers; +}; + +} // namespace Kernel diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index eab73c46c..453695545 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -28,13 +28,13 @@ #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_memory_manager.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_slab_heap.h" #include "core/hle/kernel/k_thread.h" #include "core/hle/kernel/kernel.h" -#include "core/hle/kernel/memory/memory_manager.h" #include "core/hle/kernel/physical_core.h" #include "core/hle/kernel/process.h" #include "core/hle/kernel/service_thread.h" @@ -277,14 +277,14 @@ struct KernelCore::Impl { constexpr PAddr time_addr{layout.System().StartAddress() + hid_size + font_size + irs_size}; // Initialize memory manager - memory_manager = std::make_unique(); - memory_manager->InitializeManager(Memory::MemoryManager::Pool::Application, + memory_manager = std::make_unique(); + memory_manager->InitializeManager(KMemoryManager::Pool::Application, layout.Application().StartAddress(), layout.Application().EndAddress()); - memory_manager->InitializeManager(Memory::MemoryManager::Pool::Applet, + memory_manager->InitializeManager(KMemoryManager::Pool::Applet, layout.Applet().StartAddress(), layout.Applet().EndAddress()); - memory_manager->InitializeManager(Memory::MemoryManager::Pool::System, + memory_manager->InitializeManager(KMemoryManager::Pool::System, layout.System().StartAddress(), layout.System().EndAddress()); @@ -348,7 +348,7 @@ struct KernelCore::Impl { std::atomic next_host_thread_id{Core::Hardware::NUM_CPU_CORES}; // Kernel memory management - std::unique_ptr memory_manager; + std::unique_ptr memory_manager; std::unique_ptr> user_slab_heap_pages; // Shared memory for services @@ -573,11 +573,11 @@ KThread* KernelCore::GetCurrentEmuThread() const { return impl->GetCurrentEmuThread(); } -Memory::MemoryManager& KernelCore::MemoryManager() { +KMemoryManager& KernelCore::MemoryManager() { return *impl->memory_manager; } -const Memory::MemoryManager& KernelCore::MemoryManager() const { +const KMemoryManager& KernelCore::MemoryManager() const { return *impl->memory_manager; } diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 498f94417..56906f2da 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -27,22 +27,18 @@ struct EventType; namespace Kernel { -namespace Memory { -class MemoryManager; - -} // namespace Memory - class ClientPort; class GlobalSchedulerContext; class HandleTable; -class PhysicalCore; -class Process; +class KMemoryManager; class KResourceLimit; class KScheduler; class KSharedMemory; +class KThread; +class PhysicalCore; +class Process; class ServiceThread; class Synchronization; -class KThread; class TimeManager; template @@ -180,10 +176,10 @@ public: void RegisterHostThread(); /// Gets the virtual memory manager for the kernel. - Memory::MemoryManager& MemoryManager(); + KMemoryManager& MemoryManager(); /// Gets the virtual memory manager for the kernel. - const Memory::MemoryManager& MemoryManager() const; + const KMemoryManager& MemoryManager() const; /// Gets the slab heap allocated for user space pages. KSlabHeap& GetUserSlabHeapPages(); diff --git a/src/core/hle/kernel/memory/memory_manager.cpp b/src/core/hle/kernel/memory/memory_manager.cpp deleted file mode 100644 index 00d5b15f3..000000000 --- a/src/core/hle/kernel/memory/memory_manager.cpp +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright 2020 yuzu Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include - -#include "common/alignment.h" -#include "common/assert.h" -#include "common/common_types.h" -#include "common/scope_exit.h" -#include "core/hle/kernel/k_page_linked_list.h" -#include "core/hle/kernel/memory/memory_manager.h" -#include "core/hle/kernel/svc_results.h" - -namespace Kernel::Memory { - -std::size_t MemoryManager::Impl::Initialize(Pool new_pool, u64 start_address, u64 end_address) { - const auto size{end_address - start_address}; - - // Calculate metadata sizes - const auto ref_count_size{(size / PageSize) * sizeof(u16)}; - const auto optimize_map_size{(Common::AlignUp((size / PageSize), 64) / 64) * sizeof(u64)}; - const auto manager_size{Common::AlignUp(optimize_map_size + ref_count_size, PageSize)}; - const auto page_heap_size{PageHeap::CalculateManagementOverheadSize(size)}; - const auto total_metadata_size{manager_size + page_heap_size}; - ASSERT(manager_size <= total_metadata_size); - ASSERT(Common::IsAligned(total_metadata_size, PageSize)); - - // Setup region - pool = new_pool; - - // Initialize the manager's KPageHeap - heap.Initialize(start_address, size, page_heap_size); - - // Free the memory to the heap - heap.Free(start_address, size / PageSize); - - // Update the heap's used size - heap.UpdateUsedSize(); - - return total_metadata_size; -} - -void MemoryManager::InitializeManager(Pool pool, u64 start_address, u64 end_address) { - ASSERT(pool < Pool::Count); - managers[static_cast(pool)].Initialize(pool, start_address, end_address); -} - -VAddr MemoryManager::AllocateAndOpenContinuous(std::size_t num_pages, std::size_t align_pages, - u32 option) { - // Early return if we're allocating no pages - if (num_pages == 0) { - return {}; - } - - // Lock the pool that we're allocating from - const auto [pool, dir] = DecodeOption(option); - const auto pool_index{static_cast(pool)}; - std::lock_guard lock{pool_locks[pool_index]}; - - // Choose a heap based on our page size request - const s32 heap_index{PageHeap::GetAlignedBlockIndex(num_pages, align_pages)}; - - // Loop, trying to iterate from each block - // TODO (bunnei): Support multiple managers - Impl& chosen_manager{managers[pool_index]}; - VAddr allocated_block{chosen_manager.AllocateBlock(heap_index, false)}; - - // If we failed to allocate, quit now - if (!allocated_block) { - return {}; - } - - // If we allocated more than we need, free some - const auto allocated_pages{PageHeap::GetBlockNumPages(heap_index)}; - if (allocated_pages > num_pages) { - chosen_manager.Free(allocated_block + num_pages * PageSize, allocated_pages - num_pages); - } - - return allocated_block; -} - -ResultCode MemoryManager::Allocate(KPageLinkedList& page_list, std::size_t num_pages, Pool pool, - Direction dir) { - ASSERT(page_list.GetNumPages() == 0); - - // Early return if we're allocating no pages - if (num_pages == 0) { - return RESULT_SUCCESS; - } - - // Lock the pool that we're allocating from - const auto pool_index{static_cast(pool)}; - std::lock_guard lock{pool_locks[pool_index]}; - - // Choose a heap based on our page size request - const s32 heap_index{PageHeap::GetBlockIndex(num_pages)}; - if (heap_index < 0) { - return ResultOutOfMemory; - } - - // TODO (bunnei): Support multiple managers - Impl& chosen_manager{managers[pool_index]}; - - // Ensure that we don't leave anything un-freed - auto group_guard = detail::ScopeExit([&] { - for (const auto& it : page_list.Nodes()) { - const auto min_num_pages{std::min( - it.GetNumPages(), (chosen_manager.GetEndAddress() - it.GetAddress()) / PageSize)}; - chosen_manager.Free(it.GetAddress(), min_num_pages); - } - }); - - // Keep allocating until we've allocated all our pages - for (s32 index{heap_index}; index >= 0 && num_pages > 0; index--) { - const auto pages_per_alloc{PageHeap::GetBlockNumPages(index)}; - - while (num_pages >= pages_per_alloc) { - // Allocate a block - VAddr allocated_block{chosen_manager.AllocateBlock(index, false)}; - if (!allocated_block) { - break; - } - - // Safely add it to our group - { - auto block_guard = detail::ScopeExit( - [&] { chosen_manager.Free(allocated_block, pages_per_alloc); }); - - if (const ResultCode result{page_list.AddBlock(allocated_block, pages_per_alloc)}; - result.IsError()) { - return result; - } - - block_guard.Cancel(); - } - - num_pages -= pages_per_alloc; - } - } - - // Only succeed if we allocated as many pages as we wanted - if (num_pages) { - return ResultOutOfMemory; - } - - // We succeeded! - group_guard.Cancel(); - return RESULT_SUCCESS; -} - -ResultCode MemoryManager::Free(KPageLinkedList& page_list, std::size_t num_pages, Pool pool, - Direction dir) { - // Early return if we're freeing no pages - if (!num_pages) { - return RESULT_SUCCESS; - } - - // Lock the pool that we're freeing from - const auto pool_index{static_cast(pool)}; - std::lock_guard lock{pool_locks[pool_index]}; - - // TODO (bunnei): Support multiple managers - Impl& chosen_manager{managers[pool_index]}; - - // Free all of the pages - for (const auto& it : page_list.Nodes()) { - const auto min_num_pages{std::min( - it.GetNumPages(), (chosen_manager.GetEndAddress() - it.GetAddress()) / PageSize)}; - chosen_manager.Free(it.GetAddress(), min_num_pages); - } - - return RESULT_SUCCESS; -} - -} // namespace Kernel::Memory diff --git a/src/core/hle/kernel/memory/memory_manager.h b/src/core/hle/kernel/memory/memory_manager.h deleted file mode 100644 index d090979bd..000000000 --- a/src/core/hle/kernel/memory/memory_manager.h +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2020 yuzu Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include -#include -#include - -#include "common/common_funcs.h" -#include "common/common_types.h" -#include "core/hle/kernel/memory/page_heap.h" -#include "core/hle/result.h" - -namespace Kernel { -class KPageLinkedList; -} - -namespace Kernel::Memory { - -class MemoryManager final : NonCopyable { -public: - enum class Pool : u32 { - Application = 0, - Applet = 1, - System = 2, - SystemNonSecure = 3, - - Count, - - Shift = 4, - Mask = (0xF << Shift), - }; - - enum class Direction : u32 { - FromFront = 0, - FromBack = 1, - - Shift = 0, - Mask = (0xF << Shift), - }; - - MemoryManager() = default; - - constexpr std::size_t GetSize(Pool pool) const { - return managers[static_cast(pool)].GetSize(); - } - - void InitializeManager(Pool pool, u64 start_address, u64 end_address); - - VAddr AllocateAndOpenContinuous(size_t num_pages, size_t align_pages, u32 option); - ResultCode Allocate(KPageLinkedList& page_list, std::size_t num_pages, Pool pool, - Direction dir = Direction::FromFront); - ResultCode Free(KPageLinkedList& page_list, std::size_t num_pages, Pool pool, - Direction dir = Direction::FromFront); - - static constexpr std::size_t MaxManagerCount = 10; - -public: - static constexpr u32 EncodeOption(Pool pool, Direction dir) { - return (static_cast(pool) << static_cast(Pool::Shift)) | - (static_cast(dir) << static_cast(Direction::Shift)); - } - - static constexpr Pool GetPool(u32 option) { - return static_cast((static_cast(option) & static_cast(Pool::Mask)) >> - static_cast(Pool::Shift)); - } - - static constexpr Direction GetDirection(u32 option) { - return static_cast( - (static_cast(option) & static_cast(Direction::Mask)) >> - static_cast(Direction::Shift)); - } - - static constexpr std::tuple DecodeOption(u32 option) { - return std::make_tuple(GetPool(option), GetDirection(option)); - } - -private: - class Impl final : NonCopyable { - private: - using RefCount = u16; - - private: - PageHeap heap; - Pool pool{}; - - public: - Impl() = default; - - std::size_t Initialize(Pool new_pool, u64 start_address, u64 end_address); - - VAddr AllocateBlock(s32 index, bool random) { - return heap.AllocateBlock(index, random); - } - - void Free(VAddr addr, std::size_t num_pages) { - heap.Free(addr, num_pages); - } - - constexpr std::size_t GetSize() const { - return heap.GetSize(); - } - - constexpr VAddr GetAddress() const { - return heap.GetAddress(); - } - - constexpr VAddr GetEndAddress() const { - return heap.GetEndAddress(); - } - }; - -private: - std::array(Pool::Count)> pool_locks; - std::array managers; -}; - -} // namespace Kernel::Memory diff --git a/src/core/hle/kernel/memory/page_table.cpp b/src/core/hle/kernel/memory/page_table.cpp index c1efc23de..ef9d97413 100644 --- a/src/core/hle/kernel/memory/page_table.cpp +++ b/src/core/hle/kernel/memory/page_table.cpp @@ -62,7 +62,7 @@ PageTable::PageTable(Core::System& system) : system{system} {} ResultCode PageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_type, bool enable_aslr, VAddr code_addr, std::size_t code_size, - Memory::MemoryManager::Pool pool) { + KMemoryManager::Pool pool) { const auto GetSpaceStart = [this](KAddressSpaceInfo::Type type) { return KAddressSpaceInfo::GetAddressSpaceStart(address_space_width, type); diff --git a/src/core/hle/kernel/memory/page_table.h b/src/core/hle/kernel/memory/page_table.h index 736583b81..a9e850e01 100644 --- a/src/core/hle/kernel/memory/page_table.h +++ b/src/core/hle/kernel/memory/page_table.h @@ -11,7 +11,7 @@ #include "common/page_table.h" #include "core/file_sys/program_metadata.h" #include "core/hle/kernel/k_memory_block.h" -#include "core/hle/kernel/memory/memory_manager.h" +#include "core/hle/kernel/k_memory_manager.h" #include "core/hle/result.h" namespace Core { @@ -30,7 +30,7 @@ public: ResultCode InitializeForProcess(FileSys::ProgramAddressSpaceType as_type, bool enable_aslr, VAddr code_addr, std::size_t code_size, - Memory::MemoryManager::Pool pool); + KMemoryManager::Pool pool); ResultCode MapProcessCode(VAddr addr, std::size_t pages_count, KMemoryState state, KMemoryPermission perm); ResultCode MapProcessCodeMemory(VAddr dst_addr, VAddr src_addr, std::size_t size); @@ -271,7 +271,7 @@ private: bool is_kernel{}; bool is_aslr_enabled{}; - MemoryManager::Pool memory_pool{MemoryManager::Pool::Application}; + KMemoryManager::Pool memory_pool{KMemoryManager::Pool::Application}; Common::PageTable page_table_impl; diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index f83977a8e..e0359eb3c 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -274,7 +274,7 @@ ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, // Set initial resource limits resource_limit->SetLimitValue( LimitableResource::PhysicalMemory, - kernel.MemoryManager().GetSize(Memory::MemoryManager::Pool::Application)); + kernel.MemoryManager().GetSize(KMemoryManager::Pool::Application)); KScopedResourceReservation memory_reservation(resource_limit, LimitableResource::PhysicalMemory, code_size + system_resource_size); if (!memory_reservation.Succeeded()) { @@ -285,7 +285,7 @@ ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, // Initialize proces address space if (const ResultCode result{ page_table->InitializeForProcess(metadata.GetAddressSpaceType(), false, 0x8000000, - code_size, Memory::MemoryManager::Pool::Application)}; + code_size, KMemoryManager::Pool::Application)}; result.IsError()) { return result; } @@ -323,6 +323,11 @@ ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, UNREACHABLE(); } + // Set initial resource limits + resource_limit->SetLimitValue( + LimitableResource::PhysicalMemory, + kernel.MemoryManager().GetSize(KMemoryManager::Pool::Application)); + resource_limit->SetLimitValue(LimitableResource::Threads, 608); resource_limit->SetLimitValue(LimitableResource::Events, 700); resource_limit->SetLimitValue(LimitableResource::TransferMemory, 128); -- cgit v1.2.3