summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorGravatar Liam2023-12-13 15:32:25 -0500
committerGravatar Liam2023-12-14 23:44:33 -0500
commit8ad5f2c50648c333c3c46f89533e200a39bf6ca8 (patch)
tree00cfb8d70b13db1016006a8a9de99137a9736c08 /src/core/hle/kernel
parentMerge pull request #12354 from liamwhite/mackage-panager (diff)
downloadyuzu-8ad5f2c50648c333c3c46f89533e200a39bf6ca8.tar.gz
yuzu-8ad5f2c50648c333c3c46f89533e200a39bf6ca8.tar.xz
yuzu-8ad5f2c50648c333c3c46f89533e200a39bf6ca8.zip
common: use memory holepunching when clearing memory
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/k_memory_manager.cpp5
-rw-r--r--src/core/hle/kernel/k_page_table_base.cpp14
2 files changed, 11 insertions, 8 deletions
diff --git a/src/core/hle/kernel/k_memory_manager.cpp b/src/core/hle/kernel/k_memory_manager.cpp
index 0a973ec8c..d6bd27296 100644
--- a/src/core/hle/kernel/k_memory_manager.cpp
+++ b/src/core/hle/kernel/k_memory_manager.cpp
@@ -421,8 +421,9 @@ Result KMemoryManager::AllocateForProcess(KPageGroup* out, size_t num_pages, u32
421 } else { 421 } else {
422 // Set all the allocated memory. 422 // Set all the allocated memory.
423 for (const auto& block : *out) { 423 for (const auto& block : *out) {
424 std::memset(m_system.DeviceMemory().GetPointer<void>(block.GetAddress()), fill_pattern, 424 m_system.DeviceMemory().buffer.ClearBackingRegion(GetInteger(block.GetAddress()) -
425 block.GetSize()); 425 Core::DramMemoryMap::Base,
426 block.GetSize(), fill_pattern);
426 } 427 }
427 } 428 }
428 429
diff --git a/src/core/hle/kernel/k_page_table_base.cpp b/src/core/hle/kernel/k_page_table_base.cpp
index 4c416d809..423289145 100644
--- a/src/core/hle/kernel/k_page_table_base.cpp
+++ b/src/core/hle/kernel/k_page_table_base.cpp
@@ -81,6 +81,11 @@ void InvalidateInstructionCache(KernelCore& kernel, AddressType addr, u64 size)
81 } 81 }
82} 82}
83 83
84void ClearBackingRegion(Core::System& system, KPhysicalAddress addr, u64 size, u32 fill_value) {
85 system.DeviceMemory().buffer.ClearBackingRegion(GetInteger(addr) - Core::DramMemoryMap::Base,
86 size, fill_value);
87}
88
84template <typename AddressType> 89template <typename AddressType>
85Result InvalidateDataCache(AddressType addr, u64 size) { 90Result InvalidateDataCache(AddressType addr, u64 size) {
86 R_SUCCEED(); 91 R_SUCCEED();
@@ -1363,8 +1368,7 @@ Result KPageTableBase::MapInsecureMemory(KProcessAddress address, size_t size) {
1363 1368
1364 // Clear all the newly allocated pages. 1369 // Clear all the newly allocated pages.
1365 for (const auto& it : pg) { 1370 for (const auto& it : pg) {
1366 std::memset(GetHeapVirtualPointer(m_kernel, it.GetAddress()), 1371 ClearBackingRegion(m_system, it.GetAddress(), it.GetSize(), m_heap_fill_value);
1367 static_cast<u32>(m_heap_fill_value), it.GetSize());
1368 } 1372 }
1369 1373
1370 // Lock the table. 1374 // Lock the table.
@@ -1570,8 +1574,7 @@ Result KPageTableBase::AllocateAndMapPagesImpl(PageLinkedList* page_list, KProce
1570 1574
1571 // Clear all pages. 1575 // Clear all pages.
1572 for (const auto& it : pg) { 1576 for (const auto& it : pg) {
1573 std::memset(GetHeapVirtualPointer(m_kernel, it.GetAddress()), 1577 ClearBackingRegion(m_system, it.GetAddress(), it.GetSize(), m_heap_fill_value);
1574 static_cast<u32>(m_heap_fill_value), it.GetSize());
1575 } 1578 }
1576 1579
1577 // Map the pages. 1580 // Map the pages.
@@ -2159,8 +2162,7 @@ Result KPageTableBase::SetHeapSize(KProcessAddress* out, size_t size) {
2159 2162
2160 // Clear all the newly allocated pages. 2163 // Clear all the newly allocated pages.
2161 for (const auto& it : pg) { 2164 for (const auto& it : pg) {
2162 std::memset(GetHeapVirtualPointer(m_kernel, it.GetAddress()), m_heap_fill_value, 2165 ClearBackingRegion(m_system, it.GetAddress(), it.GetSize(), m_heap_fill_value);
2163 it.GetSize());
2164 } 2166 }
2165 2167
2166 // Map the pages. 2168 // Map the pages.