From 595c6dbe8f764cd0da683aad5b34b7552ef56785 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 3 Aug 2020 18:43:38 -0700 Subject: [PATCH] kern: KPageTableBase::WriteDebugMemory stores/invalidates cache --- libraries/libmesosphere/source/kern_k_page_table_base.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/libmesosphere/source/kern_k_page_table_base.cpp b/libraries/libmesosphere/source/kern_k_page_table_base.cpp index 1daf7c67c..75e11a70e 100644 --- a/libraries/libmesosphere/source/kern_k_page_table_base.cpp +++ b/libraries/libmesosphere/source/kern_k_page_table_base.cpp @@ -2157,6 +2157,8 @@ namespace ams::kern { if (cur_size >= sizeof(u32)) { const size_t copy_size = util::AlignDown(cur_size, sizeof(u32)); R_UNLESS(UserspaceAccess::CopyMemoryFromUserAligned32Bit(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), buffer, copy_size), svc::ResultInvalidCurrentMemory()); + cpu::StoreDataCache(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), copy_size); + buffer = reinterpret_cast(reinterpret_cast(buffer) + copy_size); cur_addr += copy_size; cur_size -= copy_size; @@ -2165,6 +2167,7 @@ namespace ams::kern { /* Copy remaining data. */ if (cur_size > 0) { R_UNLESS(UserspaceAccess::CopyMemoryFromUser(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), buffer, cur_size), svc::ResultInvalidCurrentMemory()); + cpu::StoreDataCache(GetVoidPointer(GetLinearMappedVirtualAddress(cur_addr)), copy_size); } return ResultSuccess(); @@ -2200,6 +2203,9 @@ namespace ams::kern { /* Perform copy for the last block. */ R_TRY(PerformCopy()); + /* Invalidate the entire instruction cache, as this svc allows modifying executable pages. */ + cpu::InvalidateEntireInstructionCache(); + return ResultSuccess(); }