diff options
Diffstat (limited to '')
-rw-r--r-- | src/core/arm/arm_interface.h | 6 | ||||
-rw-r--r-- | src/core/file_sys/vfs.h | 18 | ||||
-rw-r--r-- | src/core/hid/emulated_console.h | 1 | ||||
-rw-r--r-- | src/core/hid/emulated_controller.h | 2 | ||||
-rw-r--r-- | src/core/hid/hid_core.h | 1 | ||||
-rw-r--r-- | src/core/hle/kernel/k_auto_object.h | 7 | ||||
-rw-r--r-- | src/core/hle/kernel/k_auto_object_container.h | 4 | ||||
-rw-r--r-- | src/core/hle/kernel/k_handle_table.h | 3 | ||||
-rw-r--r-- | src/core/hle/kernel/k_memory_manager.h | 42 | ||||
-rw-r--r-- | src/core/hle/kernel/k_memory_region.h | 80 | ||||
-rw-r--r-- | src/core/hle/kernel/k_page_heap.h | 90 | ||||
-rw-r--r-- | src/core/hle/kernel/k_page_table.cpp | 67 | ||||
-rw-r--r-- | src/core/hle/kernel/k_page_table.h | 22 | ||||
-rw-r--r-- | src/core/hle/kernel/k_slab_heap.h | 13 | ||||
-rw-r--r-- | src/core/hle/kernel/svc.cpp | 2 | ||||
-rw-r--r-- | src/core/hle/service/vi/display/vi_display.h | 2 | ||||
-rw-r--r-- | src/core/loader/loader.h | 6 |
17 files changed, 215 insertions, 151 deletions
diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index 689e3ceb5..c60322442 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h @@ -6,6 +6,7 @@ #include <array> #include <vector> +#include "common/common_funcs.h" #include "common/common_types.h" #include "core/hardware_properties.h" @@ -24,8 +25,11 @@ class CPUInterruptHandler; using CPUInterrupts = std::array<CPUInterruptHandler, Core::Hardware::NUM_CPU_CORES>; /// Generic ARMv8 CPU interface -class ARM_Interface : NonCopyable { +class ARM_Interface { public: + YUZU_NON_COPYABLE(ARM_Interface); + YUZU_NON_MOVEABLE(ARM_Interface); + explicit ARM_Interface(System& system_, CPUInterrupts& interrupt_handlers_, bool uses_wall_clock_) : system{system_}, interrupt_handlers{interrupt_handlers_}, uses_wall_clock{ diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index 3e625fad6..1b9365853 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h @@ -12,6 +12,7 @@ #include <type_traits> #include <vector> +#include "common/common_funcs.h" #include "common/common_types.h" #include "core/file_sys/vfs_types.h" @@ -29,8 +30,11 @@ enum class VfsEntryType { // A class representing an abstract filesystem. A default implementation given the root VirtualDir // is provided for convenience, but if the Vfs implementation has any additional state or // functionality, they will need to override. -class VfsFilesystem : NonCopyable { +class VfsFilesystem { public: + YUZU_NON_COPYABLE(VfsFilesystem); + YUZU_NON_MOVEABLE(VfsFilesystem); + explicit VfsFilesystem(VirtualDir root); virtual ~VfsFilesystem(); @@ -77,8 +81,12 @@ protected: }; // A class representing a file in an abstract filesystem. -class VfsFile : NonCopyable { +class VfsFile { public: + YUZU_NON_COPYABLE(VfsFile); + YUZU_NON_MOVEABLE(VfsFile); + + VfsFile() = default; virtual ~VfsFile(); // Retrieves the file name. @@ -176,8 +184,12 @@ public: }; // A class representing a directory in an abstract filesystem. -class VfsDirectory : NonCopyable { +class VfsDirectory { public: + YUZU_NON_COPYABLE(VfsDirectory); + YUZU_NON_MOVEABLE(VfsDirectory); + + VfsDirectory() = default; virtual ~VfsDirectory(); // Retrives the file located at path as if the current directory was root. Returns nullptr if diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h index 707419102..5eb170823 100644 --- a/src/core/hid/emulated_console.h +++ b/src/core/hid/emulated_console.h @@ -10,6 +10,7 @@ #include <mutex> #include <unordered_map> +#include "common/common_funcs.h" #include "common/common_types.h" #include "common/input.h" #include "common/param_package.h" diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index a63a83cce..d8642c5b3 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h @@ -13,8 +13,6 @@ #include "common/common_types.h" #include "common/input.h" #include "common/param_package.h" -#include "common/point.h" -#include "common/quaternion.h" #include "common/settings.h" #include "common/vector_math.h" #include "core/hid/hid_types.h" diff --git a/src/core/hid/hid_core.h b/src/core/hid/hid_core.h index 837f7de49..717f605e7 100644 --- a/src/core/hid/hid_core.h +++ b/src/core/hid/hid_core.h @@ -6,6 +6,7 @@ #include <memory> +#include "common/common_funcs.h" #include "core/hid/hid_types.h" namespace Core::HID { diff --git a/src/core/hle/kernel/k_auto_object.h b/src/core/hle/kernel/k_auto_object.h index 165b76747..05779f2d5 100644 --- a/src/core/hle/kernel/k_auto_object.h +++ b/src/core/hle/kernel/k_auto_object.h @@ -20,8 +20,6 @@ class KernelCore; class KProcess; #define KERNEL_AUTOOBJECT_TRAITS(CLASS, BASE_CLASS) \ - YUZU_NON_COPYABLE(CLASS); \ - YUZU_NON_MOVEABLE(CLASS); \ \ private: \ friend class ::Kernel::KClassTokenGenerator; \ @@ -32,6 +30,9 @@ private: } \ \ public: \ + YUZU_NON_COPYABLE(CLASS); \ + YUZU_NON_MOVEABLE(CLASS); \ + \ using BaseClass = BASE_CLASS; \ static constexpr TypeObj GetStaticTypeObj() { \ constexpr ClassTokenType Token = ClassToken(); \ @@ -224,9 +225,9 @@ private: template <typename T> class KScopedAutoObject { +public: YUZU_NON_COPYABLE(KScopedAutoObject); -public: constexpr KScopedAutoObject() = default; constexpr KScopedAutoObject(T* o) : m_obj(o) { diff --git a/src/core/hle/kernel/k_auto_object_container.h b/src/core/hle/kernel/k_auto_object_container.h index 4eadfe99d..697cc4289 100644 --- a/src/core/hle/kernel/k_auto_object_container.h +++ b/src/core/hle/kernel/k_auto_object_container.h @@ -16,13 +16,12 @@ class KernelCore; class KProcess; class KAutoObjectWithListContainer { +public: YUZU_NON_COPYABLE(KAutoObjectWithListContainer); YUZU_NON_MOVEABLE(KAutoObjectWithListContainer); -public: using ListType = boost::intrusive::rbtree<KAutoObjectWithList>; -public: class ListAccessor : public KScopedLightLock { public: explicit ListAccessor(KAutoObjectWithListContainer* container) @@ -48,7 +47,6 @@ public: friend class ListAccessor; -public: KAutoObjectWithListContainer(KernelCore& kernel) : m_lock(kernel), m_object_list() {} void Initialize() {} diff --git a/src/core/hle/kernel/k_handle_table.h b/src/core/hle/kernel/k_handle_table.h index 4b114ec2f..87004a0f9 100644 --- a/src/core/hle/kernel/k_handle_table.h +++ b/src/core/hle/kernel/k_handle_table.h @@ -22,13 +22,12 @@ namespace Kernel { class KernelCore; class KHandleTable { +public: YUZU_NON_COPYABLE(KHandleTable); YUZU_NON_MOVEABLE(KHandleTable); -public: static constexpr size_t MaxTableSize = 1024; -public: explicit KHandleTable(KernelCore& kernel_); ~KHandleTable(); diff --git a/src/core/hle/kernel/k_memory_manager.h b/src/core/hle/kernel/k_memory_manager.h index abd6c8ace..17c7690f1 100644 --- a/src/core/hle/kernel/k_memory_manager.h +++ b/src/core/hle/kernel/k_memory_manager.h @@ -8,6 +8,7 @@ #include <mutex> #include <tuple> +#include "common/common_funcs.h" #include "common/common_types.h" #include "core/hle/kernel/k_page_heap.h" #include "core/hle/result.h" @@ -20,8 +21,11 @@ namespace Kernel { class KPageLinkedList; -class KMemoryManager final : NonCopyable { +class KMemoryManager final { public: + YUZU_NON_COPYABLE(KMemoryManager); + YUZU_NON_MOVEABLE(KMemoryManager); + enum class Pool : u32 { Application = 0, Applet = 1, @@ -88,26 +92,13 @@ public: } private: - class Impl final : NonCopyable { - private: - using RefCount = u16; - - private: - KPageHeap heap; - Pool pool{}; - + class Impl final { public: - static std::size_t CalculateManagementOverheadSize(std::size_t region_size); - - static constexpr std::size_t CalculateOptimizedProcessOverheadSize( - std::size_t region_size) { - return (Common::AlignUp((region_size / PageSize), Common::BitSize<u64>()) / - Common::BitSize<u64>()) * - sizeof(u64); - } + YUZU_NON_COPYABLE(Impl); + YUZU_NON_MOVEABLE(Impl); - public: Impl() = default; + ~Impl() = default; std::size_t Initialize(Pool new_pool, u64 start_address, u64 end_address); @@ -130,6 +121,21 @@ private: constexpr VAddr GetEndAddress() const { return heap.GetEndAddress(); } + + static std::size_t CalculateManagementOverheadSize(std::size_t region_size); + + static constexpr std::size_t CalculateOptimizedProcessOverheadSize( + std::size_t region_size) { + return (Common::AlignUp((region_size / PageSize), Common::BitSize<u64>()) / + Common::BitSize<u64>()) * + sizeof(u64); + } + + private: + using RefCount = u16; + + KPageHeap heap; + Pool pool{}; }; private: diff --git a/src/core/hle/kernel/k_memory_region.h b/src/core/hle/kernel/k_memory_region.h index 90ab8fd62..e9bdf4e59 100644 --- a/src/core/hle/kernel/k_memory_region.h +++ b/src/core/hle/kernel/k_memory_region.h @@ -5,6 +5,7 @@ #pragma once #include "common/assert.h" +#include "common/common_funcs.h" #include "common/common_types.h" #include "common/intrusive_red_black_tree.h" #include "core/hle/kernel/k_memory_region_type.h" @@ -13,11 +14,13 @@ namespace Kernel { class KMemoryRegionAllocator; -class KMemoryRegion final : public Common::IntrusiveRedBlackTreeBaseNode<KMemoryRegion>, - NonCopyable { +class KMemoryRegion final : public Common::IntrusiveRedBlackTreeBaseNode<KMemoryRegion> { friend class KMemoryRegionTree; public: + YUZU_NON_COPYABLE(KMemoryRegion); + YUZU_NON_MOVEABLE(KMemoryRegion); + constexpr KMemoryRegion() = default; constexpr KMemoryRegion(u64 address_, u64 last_address_) : address{address_}, last_address{last_address_} {} @@ -29,6 +32,8 @@ public: : KMemoryRegion(address_, last_address_, std::numeric_limits<u64>::max(), attributes_, type_id_) {} + ~KMemoryRegion() = default; + static constexpr int Compare(const KMemoryRegion& lhs, const KMemoryRegion& rhs) { if (lhs.GetAddress() < rhs.GetAddress()) { return -1; @@ -39,16 +44,6 @@ public: } } -private: - constexpr void Reset(u64 a, u64 la, u64 p, u32 r, u32 t) { - address = a; - pair_address = p; - last_address = la; - attributes = r; - type_id = t; - } - -public: constexpr u64 GetAddress() const { return address; } @@ -108,6 +103,14 @@ public: } private: + constexpr void Reset(u64 a, u64 la, u64 p, u32 r, u32 t) { + address = a; + pair_address = p; + last_address = la; + attributes = r; + type_id = t; + } + u64 address{}; u64 last_address{}; u64 pair_address{}; @@ -115,8 +118,25 @@ private: u32 type_id{}; }; -class KMemoryRegionTree final : NonCopyable { +class KMemoryRegionTree final { +private: + using TreeType = + Common::IntrusiveRedBlackTreeBaseTraits<KMemoryRegion>::TreeType<KMemoryRegion>; + public: + YUZU_NON_COPYABLE(KMemoryRegionTree); + YUZU_NON_MOVEABLE(KMemoryRegionTree); + + using value_type = TreeType::value_type; + using size_type = TreeType::size_type; + using difference_type = TreeType::difference_type; + using pointer = TreeType::pointer; + using const_pointer = TreeType::const_pointer; + using reference = TreeType::reference; + using const_reference = TreeType::const_reference; + using iterator = TreeType::iterator; + using const_iterator = TreeType::const_iterator; + struct DerivedRegionExtents { const KMemoryRegion* first_region{}; const KMemoryRegion* last_region{}; @@ -140,29 +160,9 @@ public: } }; -private: - using TreeType = - Common::IntrusiveRedBlackTreeBaseTraits<KMemoryRegion>::TreeType<KMemoryRegion>; - -public: - using value_type = TreeType::value_type; - using size_type = TreeType::size_type; - using difference_type = TreeType::difference_type; - using pointer = TreeType::pointer; - using const_pointer = TreeType::const_pointer; - using reference = TreeType::reference; - using const_reference = TreeType::const_reference; - using iterator = TreeType::iterator; - using const_iterator = TreeType::const_iterator; - -private: - TreeType m_tree{}; - KMemoryRegionAllocator& memory_region_allocator; - -public: explicit KMemoryRegionTree(KMemoryRegionAllocator& memory_region_allocator_); + ~KMemoryRegionTree() = default; -public: KMemoryRegion* FindModifiable(u64 address) { if (auto it = this->find(KMemoryRegion(address, address, 0, 0)); it != this->end()) { return std::addressof(*it); @@ -241,7 +241,6 @@ public: return GetDerivedRegionExtents(static_cast<KMemoryRegionType>(type_id)); } -public: void InsertDirectly(u64 address, u64 last_address, u32 attr = 0, u32 type_id = 0); bool Insert(u64 address, size_t size, u32 type_id, u32 new_attr = 0, u32 old_attr = 0); @@ -252,7 +251,6 @@ public: return this->GetRandomAlignedRegion(size + 2 * guard_size, alignment, type_id) + guard_size; } -public: // Iterator accessors. iterator begin() { return m_tree.begin(); @@ -322,13 +320,21 @@ public: iterator nfind(const_reference ref) const { return m_tree.nfind(ref); } + +private: + TreeType m_tree{}; + KMemoryRegionAllocator& memory_region_allocator; }; -class KMemoryRegionAllocator final : NonCopyable { +class KMemoryRegionAllocator final { public: + YUZU_NON_COPYABLE(KMemoryRegionAllocator); + YUZU_NON_MOVEABLE(KMemoryRegionAllocator); + static constexpr size_t MaxMemoryRegions = 200; constexpr KMemoryRegionAllocator() = default; + constexpr ~KMemoryRegionAllocator() = default; template <typename... Args> KMemoryRegion* Allocate(Args&&... args) { diff --git a/src/core/hle/kernel/k_page_heap.h b/src/core/hle/kernel/k_page_heap.h index 8d9f30523..a65aa28a0 100644 --- a/src/core/hle/kernel/k_page_heap.h +++ b/src/core/hle/kernel/k_page_heap.h @@ -8,14 +8,44 @@ #include <vector> #include "common/alignment.h" +#include "common/common_funcs.h" #include "common/common_types.h" #include "core/hle/kernel/k_page_bitmap.h" #include "core/hle/kernel/memory_types.h" namespace Kernel { -class KPageHeap final : NonCopyable { +class KPageHeap final { public: + YUZU_NON_COPYABLE(KPageHeap); + YUZU_NON_MOVEABLE(KPageHeap); + + KPageHeap() = default; + ~KPageHeap() = default; + + constexpr VAddr GetAddress() const { + return heap_address; + } + constexpr std::size_t GetSize() const { + return heap_size; + } + constexpr VAddr GetEndAddress() const { + return GetAddress() + GetSize(); + } + constexpr std::size_t GetPageOffset(VAddr block) const { + return (block - GetAddress()) / PageSize; + } + + void Initialize(VAddr heap_address, std::size_t heap_size, std::size_t metadata_size); + VAddr AllocateBlock(s32 index, bool random); + void Free(VAddr addr, std::size_t num_pages); + + void UpdateUsedSize() { + used_size = heap_size - (GetNumFreePages() * PageSize); + } + + static std::size_t CalculateManagementOverheadSize(std::size_t region_size); + static constexpr s32 GetAlignedBlockIndex(std::size_t num_pages, std::size_t align_pages) { const auto target_pages{std::max(num_pages, align_pages)}; for (std::size_t i = 0; i < NumMemoryBlockPageShifts; i++) { @@ -45,21 +75,13 @@ public: } private: - static constexpr std::size_t NumMemoryBlockPageShifts{7}; - static constexpr std::array<std::size_t, NumMemoryBlockPageShifts> MemoryBlockPageShifts{ - 0xC, 0x10, 0x15, 0x16, 0x19, 0x1D, 0x1E, - }; - - class Block final : NonCopyable { - private: - KPageBitmap bitmap; - VAddr heap_address{}; - uintptr_t end_offset{}; - std::size_t block_shift{}; - std::size_t next_block_shift{}; - + class Block final { public: + YUZU_NON_COPYABLE(Block); + YUZU_NON_MOVEABLE(Block); + Block() = default; + ~Block() = default; constexpr std::size_t GetShift() const { return block_shift; @@ -129,7 +151,6 @@ private: return heap_address + (offset << GetShift()); } - public: static constexpr std::size_t CalculateManagementOverheadSize(std::size_t region_size, std::size_t cur_block_shift, std::size_t next_block_shift) { @@ -139,35 +160,15 @@ private: return KPageBitmap::CalculateManagementOverheadSize( (align * 2 + Common::AlignUp(region_size, align)) / cur_block_size); } - }; - -public: - KPageHeap() = default; - - constexpr VAddr GetAddress() const { - return heap_address; - } - constexpr std::size_t GetSize() const { - return heap_size; - } - constexpr VAddr GetEndAddress() const { - return GetAddress() + GetSize(); - } - constexpr std::size_t GetPageOffset(VAddr block) const { - return (block - GetAddress()) / PageSize; - } - void Initialize(VAddr heap_address, std::size_t heap_size, std::size_t metadata_size); - VAddr AllocateBlock(s32 index, bool random); - void Free(VAddr addr, std::size_t num_pages); - - void UpdateUsedSize() { - used_size = heap_size - (GetNumFreePages() * PageSize); - } - - static std::size_t CalculateManagementOverheadSize(std::size_t region_size); + private: + KPageBitmap bitmap; + VAddr heap_address{}; + uintptr_t end_offset{}; + std::size_t block_shift{}; + std::size_t next_block_shift{}; + }; -private: constexpr std::size_t GetNumFreePages() const { std::size_t num_free{}; @@ -180,6 +181,11 @@ private: void FreeBlock(VAddr block, s32 index); + static constexpr std::size_t NumMemoryBlockPageShifts{7}; + static constexpr std::array<std::size_t, NumMemoryBlockPageShifts> MemoryBlockPageShifts{ + 0xC, 0x10, 0x15, 0x16, 0x19, 0x1D, 0x1E, + }; + VAddr heap_address{}; std::size_t heap_size{}; std::size_t used_size{}; diff --git a/src/core/hle/kernel/k_page_table.cpp b/src/core/hle/kernel/k_page_table.cpp index 2ebbc0819..912853e5c 100644 --- a/src/core/hle/kernel/k_page_table.cpp +++ b/src/core/hle/kernel/k_page_table.cpp @@ -61,7 +61,10 @@ constexpr std::size_t GetSizeInRange(const KMemoryInfo& info, VAddr start, VAddr } // namespace -KPageTable::KPageTable(Core::System& system_) : system{system_} {} +KPageTable::KPageTable(Core::System& system_) + : general_lock{system_.Kernel()}, map_physical_memory_lock{system_.Kernel()}, system{system_} {} + +KPageTable::~KPageTable() = default; ResultCode KPageTable::InitializeForProcess(FileSys::ProgramAddressSpaceType as_type, bool enable_aslr, VAddr code_addr, @@ -282,7 +285,7 @@ ResultCode KPageTable::MapProcessCode(VAddr addr, std::size_t num_pages, KMemory R_UNLESS(this->CanContain(addr, size, state), ResultInvalidCurrentMemory); // Lock the table. - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); // Verify that the destination memory is unmapped. R_TRY(this->CheckMemoryState(addr, size, KMemoryState::All, KMemoryState::Free, @@ -300,7 +303,7 @@ ResultCode KPageTable::MapProcessCode(VAddr addr, std::size_t num_pages, KMemory } ResultCode KPageTable::MapCodeMemory(VAddr dst_addr, VAddr src_addr, std::size_t size) { - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); const std::size_t num_pages{size / PageSize}; @@ -337,7 +340,7 @@ ResultCode KPageTable::MapCodeMemory(VAddr dst_addr, VAddr src_addr, std::size_t } ResultCode KPageTable::UnmapCodeMemory(VAddr dst_addr, VAddr src_addr, std::size_t size) { - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); if (!size) { return ResultSuccess; @@ -371,7 +374,7 @@ ResultCode KPageTable::UnmapCodeMemory(VAddr dst_addr, VAddr src_addr, std::size ResultCode KPageTable::UnmapProcessMemory(VAddr dst_addr, std::size_t size, KPageTable& src_page_table, VAddr src_addr) { - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); const std::size_t num_pages{size / PageSize}; @@ -399,10 +402,10 @@ ResultCode KPageTable::UnmapProcessMemory(VAddr dst_addr, std::size_t size, ResultCode KPageTable::MapPhysicalMemory(VAddr addr, std::size_t size) { // Lock the physical memory lock. - std::lock_guard phys_lk(map_physical_memory_lock); + KScopedLightLock map_phys_mem_lk(map_physical_memory_lock); // Lock the table. - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); std::size_t mapped_size{}; const VAddr end_addr{addr + size}; @@ -478,7 +481,11 @@ ResultCode KPageTable::MapPhysicalMemory(VAddr addr, std::size_t size) { } ResultCode KPageTable::UnmapPhysicalMemory(VAddr addr, std::size_t size) { - std::lock_guard lock{page_table_lock}; + // Lock the physical memory lock. + KScopedLightLock map_phys_mem_lk(map_physical_memory_lock); + + // Lock the table. + KScopedLightLock lk(general_lock); const VAddr end_addr{addr + size}; ResultCode result{ResultSuccess}; @@ -540,7 +547,7 @@ ResultCode KPageTable::UnmapPhysicalMemory(VAddr addr, std::size_t size) { } ResultCode KPageTable::MapMemory(VAddr dst_addr, VAddr src_addr, std::size_t size) { - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); KMemoryState src_state{}; CASCADE_CODE(CheckMemoryState( @@ -579,7 +586,7 @@ ResultCode KPageTable::MapMemory(VAddr dst_addr, VAddr src_addr, std::size_t siz } ResultCode KPageTable::UnmapMemory(VAddr dst_addr, VAddr src_addr, std::size_t size) { - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); KMemoryState src_state{}; CASCADE_CODE(CheckMemoryState( @@ -622,6 +629,8 @@ ResultCode KPageTable::UnmapMemory(VAddr dst_addr, VAddr src_addr, std::size_t s ResultCode KPageTable::MapPages(VAddr addr, const KPageLinkedList& page_linked_list, KMemoryPermission perm) { + ASSERT(this->IsLockedByCurrentThread()); + VAddr cur_addr{addr}; for (const auto& node : page_linked_list.Nodes()) { @@ -650,7 +659,7 @@ ResultCode KPageTable::MapPages(VAddr address, KPageLinkedList& page_linked_list R_UNLESS(this->CanContain(address, size, state), ResultInvalidCurrentMemory); // Lock the table. - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); // Check the memory state. R_TRY(this->CheckMemoryState(address, size, KMemoryState::All, KMemoryState::Free, @@ -667,6 +676,8 @@ ResultCode KPageTable::MapPages(VAddr address, KPageLinkedList& page_linked_list } ResultCode KPageTable::UnmapPages(VAddr addr, const KPageLinkedList& page_linked_list) { + ASSERT(this->IsLockedByCurrentThread()); + VAddr cur_addr{addr}; for (const auto& node : page_linked_list.Nodes()) { @@ -691,7 +702,7 @@ ResultCode KPageTable::UnmapPages(VAddr addr, KPageLinkedList& page_linked_list, R_UNLESS(this->Contains(addr, size), ResultInvalidCurrentMemory); // Lock the table. - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); // Check the memory state. R_TRY(this->CheckMemoryState(addr, size, KMemoryState::All, state, KMemoryPermission::None, @@ -712,7 +723,7 @@ ResultCode KPageTable::SetProcessMemoryPermission(VAddr addr, std::size_t size, const size_t num_pages = size / PageSize; // Lock the table. - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); // Verify we can change the memory permission. KMemoryState old_state; @@ -766,7 +777,7 @@ ResultCode KPageTable::SetProcessMemoryPermission(VAddr addr, std::size_t size, } KMemoryInfo KPageTable::QueryInfoImpl(VAddr addr) { - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); return block_manager->FindBlock(addr).GetMemoryInfo(); } @@ -781,7 +792,7 @@ KMemoryInfo KPageTable::QueryInfo(VAddr addr) { } ResultCode KPageTable::ReserveTransferMemory(VAddr addr, std::size_t size, KMemoryPermission perm) { - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); KMemoryState state{}; KMemoryAttribute attribute{}; @@ -799,7 +810,7 @@ ResultCode KPageTable::ReserveTransferMemory(VAddr addr, std::size_t size, KMemo } ResultCode KPageTable::ResetTransferMemory(VAddr addr, std::size_t size) { - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); KMemoryState state{}; @@ -818,7 +829,7 @@ ResultCode KPageTable::SetMemoryPermission(VAddr addr, std::size_t size, const size_t num_pages = size / PageSize; // Lock the table. - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); // Verify we can change the memory permission. KMemoryState old_state; @@ -847,7 +858,7 @@ ResultCode KPageTable::SetMemoryAttribute(VAddr addr, std::size_t size, u32 mask KMemoryAttribute::SetMask); // Lock the table. - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); // Verify we can change the memory attribute. KMemoryState old_state; @@ -878,7 +889,7 @@ ResultCode KPageTable::SetMemoryAttribute(VAddr addr, std::size_t size, u32 mask ResultCode KPageTable::SetMaxHeapSize(std::size_t size) { // Lock the table. - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); // Only process page tables are allowed to set heap size. ASSERT(!this->IsKernel()); @@ -889,15 +900,15 @@ ResultCode KPageTable::SetMaxHeapSize(std::size_t size) { } ResultCode KPageTable::SetHeapSize(VAddr* out, std::size_t size) { - // Lock the physical memory lock. - std::lock_guard phys_lk(map_physical_memory_lock); + // Lock the physical memory mutex. + KScopedLightLock map_phys_mem_lk(map_physical_memory_lock); // Try to perform a reduction in heap, instead of an extension. VAddr cur_address{}; std::size_t allocation_size{}; { // Lock the table. - std::lock_guard lk(page_table_lock); + KScopedLightLock lk(general_lock); // Validate that setting heap size is possible at all. R_UNLESS(!is_kernel, ResultOutOfMemory); @@ -962,7 +973,7 @@ ResultCode KPageTable::SetHeapSize(VAddr* out, std::size_t size) { // Map the pages. { // Lock the table. - std::lock_guard lk(page_table_lock); + KScopedLightLock lk(general_lock); // Ensure that the heap hasn't changed since we began executing. ASSERT(cur_address == current_heap_end); @@ -1004,7 +1015,7 @@ ResultVal<VAddr> KPageTable::AllocateAndMapMemory(std::size_t needed_num_pages, bool is_map_only, VAddr region_start, std::size_t region_num_pages, KMemoryState state, KMemoryPermission perm, PAddr map_addr) { - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); if (!CanContain(region_start, region_num_pages * PageSize, state)) { return ResultInvalidCurrentMemory; @@ -1035,7 +1046,7 @@ ResultVal<VAddr> KPageTable::AllocateAndMapMemory(std::size_t needed_num_pages, } ResultCode KPageTable::LockForDeviceAddressSpace(VAddr addr, std::size_t size) { - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); KMemoryPermission perm{}; if (const ResultCode result{CheckMemoryState( @@ -1058,7 +1069,7 @@ ResultCode KPageTable::LockForDeviceAddressSpace(VAddr addr, std::size_t size) { } ResultCode KPageTable::UnlockForDeviceAddressSpace(VAddr addr, std::size_t size) { - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); KMemoryPermission perm{}; if (const ResultCode result{CheckMemoryState( @@ -1081,7 +1092,7 @@ ResultCode KPageTable::UnlockForDeviceAddressSpace(VAddr addr, std::size_t size) } ResultCode KPageTable::LockForCodeMemory(VAddr addr, std::size_t size) { - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); KMemoryPermission new_perm = KMemoryPermission::NotMapped | KMemoryPermission::KernelReadWrite; @@ -1108,7 +1119,7 @@ ResultCode KPageTable::LockForCodeMemory(VAddr addr, std::size_t size) { } ResultCode KPageTable::UnlockForCodeMemory(VAddr addr, std::size_t size) { - std::lock_guard lock{page_table_lock}; + KScopedLightLock lk(general_lock); KMemoryPermission new_perm = KMemoryPermission::UserReadWrite; diff --git a/src/core/hle/kernel/k_page_table.h b/src/core/hle/kernel/k_page_table.h index 60ae9b9e8..c98887d34 100644 --- a/src/core/hle/kernel/k_page_table.h +++ b/src/core/hle/kernel/k_page_table.h @@ -5,11 +5,12 @@ #pragma once #include <memory> -#include <mutex> +#include "common/common_funcs.h" #include "common/common_types.h" #include "common/page_table.h" #include "core/file_sys/program_metadata.h" +#include "core/hle/kernel/k_light_lock.h" #include "core/hle/kernel/k_memory_block.h" #include "core/hle/kernel/k_memory_manager.h" #include "core/hle/result.h" @@ -22,9 +23,13 @@ namespace Kernel { class KMemoryBlockManager; -class KPageTable final : NonCopyable { +class KPageTable final { public: + YUZU_NON_COPYABLE(KPageTable); + YUZU_NON_MOVEABLE(KPageTable); + explicit KPageTable(Core::System& system_); + ~KPageTable(); ResultCode InitializeForProcess(FileSys::ProgramAddressSpaceType as_type, bool enable_aslr, VAddr code_addr, std::size_t code_size, @@ -142,11 +147,12 @@ private: } bool IsLockedByCurrentThread() const { - return true; + return general_lock.IsLockedByCurrentThread(); } - std::recursive_mutex page_table_lock; - std::mutex map_physical_memory_lock; + mutable KLightLock general_lock; + mutable KLightLock map_physical_memory_lock; + std::unique_ptr<KMemoryBlockManager> block_manager; public: @@ -205,7 +211,7 @@ public: return alias_code_region_end - alias_code_region_start; } size_t GetNormalMemorySize() { - std::lock_guard lk(page_table_lock); + KScopedLightLock lk(general_lock); return GetHeapSize() + mapped_physical_memory_size; } constexpr std::size_t GetAddressSpaceWidth() const { @@ -247,7 +253,9 @@ public: constexpr bool IsInsideASLRRegion(VAddr address, std::size_t size) const { return !IsOutsideASLRRegion(address, size); } - constexpr PAddr GetPhysicalAddr(VAddr addr) { + + PAddr GetPhysicalAddr(VAddr addr) { + ASSERT(IsLockedByCurrentThread()); const auto backing_addr = page_table_impl.backing_addr[addr >> PageBits]; ASSERT(backing_addr); return backing_addr + addr; diff --git a/src/core/hle/kernel/k_slab_heap.h b/src/core/hle/kernel/k_slab_heap.h index 0ad74b0a0..05c0bec9c 100644 --- a/src/core/hle/kernel/k_slab_heap.h +++ b/src/core/hle/kernel/k_slab_heap.h @@ -7,6 +7,7 @@ #include <atomic> #include "common/assert.h" +#include "common/common_funcs.h" #include "common/common_types.h" namespace Kernel { @@ -15,13 +16,17 @@ class KernelCore; namespace impl { -class KSlabHeapImpl final : NonCopyable { +class KSlabHeapImpl final { public: + YUZU_NON_COPYABLE(KSlabHeapImpl); + YUZU_NON_MOVEABLE(KSlabHeapImpl); + struct Node { Node* next{}; }; constexpr KSlabHeapImpl() = default; + constexpr ~KSlabHeapImpl() = default; void Initialize(std::size_t size) { ASSERT(head == nullptr); @@ -64,9 +69,13 @@ private: } // namespace impl -class KSlabHeapBase : NonCopyable { +class KSlabHeapBase { public: + YUZU_NON_COPYABLE(KSlabHeapBase); + YUZU_NON_MOVEABLE(KSlabHeapBase); + constexpr KSlabHeapBase() = default; + constexpr ~KSlabHeapBase() = default; constexpr bool Contains(uintptr_t addr) const { return start <= addr && addr < end; diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 40bb893ac..4f7aebf3f 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -2613,7 +2613,7 @@ static const FunctionDef SVC_Table_32[] = { {0x33, SvcWrap32<GetThreadContext32>, "GetThreadContext32"}, {0x34, SvcWrap32<WaitForAddress32>, "WaitForAddress32"}, {0x35, SvcWrap32<SignalToAddress32>, "SignalToAddress32"}, - {0x36, nullptr, "Unknown"}, + {0x36, SvcWrap32<SynchronizePreemptionState>, "SynchronizePreemptionState32"}, {0x37, nullptr, "Unknown"}, {0x38, nullptr, "Unknown"}, {0x39, nullptr, "Unknown"}, diff --git a/src/core/hle/service/vi/display/vi_display.h b/src/core/hle/service/vi/display/vi_display.h index 0979fc421..329f4ba86 100644 --- a/src/core/hle/service/vi/display/vi_display.h +++ b/src/core/hle/service/vi/display/vi_display.h @@ -28,10 +28,10 @@ class Layer; /// Represents a single display type class Display { +public: YUZU_NON_COPYABLE(Display); YUZU_NON_MOVEABLE(Display); -public: /// Constructs a display with a given unique ID and name. /// /// @param id The unique ID for this display. diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 7b1bac3f7..8b6b3b68f 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -11,6 +11,7 @@ #include <utility> #include <vector> +#include "common/common_funcs.h" #include "common/common_types.h" #include "core/file_sys/control_metadata.h" #include "core/file_sys/vfs.h" @@ -139,8 +140,11 @@ std::string GetResultStatusString(ResultStatus status); std::ostream& operator<<(std::ostream& os, ResultStatus status); /// Interface for loading an application -class AppLoader : NonCopyable { +class AppLoader { public: + YUZU_NON_COPYABLE(AppLoader); + YUZU_NON_MOVEABLE(AppLoader); + struct LoadParameters { s32 main_thread_priority; u64 main_thread_stack_size; |