From 3a8d8a979cb0ebed5e960a8b4cc80cc87a5f5715 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 16 Feb 2023 12:35:33 +0100 Subject: [PATCH] Fix KiGetOrPutUserData --- source/function_replacements.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/source/function_replacements.cpp b/source/function_replacements.cpp index dfa0d29..90c49f7 100644 --- a/source/function_replacements.cpp +++ b/source/function_replacements.cpp @@ -56,17 +56,22 @@ DECL_FUNCTION(uint32_t, KiIsEffectiveRangeValid, uint32_t addressSpace, uint32_t // clang-format on DECL_FUNCTION(uint32_t, KiGetOrPutUserData, void *src, uint32_t size, void *dst, bool isRead) { - // - if (isRead && MemoryMapping_EffectiveToPhysical((uint32_t) src) > 0) { - k_memcpy(dst, src, size); - return 1; - } else if (!isRead && MemoryMapping_EffectiveToPhysical((uint32_t) dst) > 0) { - // src and dst are swapped here - k_memcpy(src, dst, size); + if (real_KiGetOrPutUserData(src, size, dst, isRead)) { return 1; } - return real_KiGetOrPutUserData(src, size, dst, isRead); + // check if the src (src is the destication for writes) buffer is valid + if (MemoryMapping_EffectiveToPhysical((uint32_t) src) == 0) { + return 0; + } + + if (isRead) { + k_memcpy(dst, src, size); + } else if (!isRead && MemoryMapping_EffectiveToPhysical((uint32_t) src) > 0) { + // src and dst are swapped here + k_memcpy(src, dst, size); + } + return 1; } DECL_FUNCTION(MEMHeapHandle, MEMFindContainHeap, void *block) {