From 945f8eb22a48718012268473b8172f24fa1a98ae Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 6 Aug 2019 09:39:39 +0200 Subject: [PATCH] Kernel: Don't treat read faults like CoW exceptions I'm not sure why we would have a non-readable CoW region, but I suppose we could, so let's not Copy-on-Read in those cases. --- Kernel/Arch/i386/CPU.h | 10 ++++++++-- Kernel/VM/MemoryManager.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Kernel/Arch/i386/CPU.h b/Kernel/Arch/i386/CPU.h index 9c12fe9cd3..4d34ff64d1 100644 --- a/Kernel/Arch/i386/CPU.h +++ b/Kernel/Arch/i386/CPU.h @@ -304,14 +304,20 @@ public: } enum class Type { - PageNotPresent, - ProtectionViolation, + PageNotPresent = PageFaultFlags::NotPresent, + ProtectionViolation = PageFaultFlags::ProtectionViolation, + }; + + enum class Access { + Read = PageFaultFlags::Read, + Write = PageFaultFlags::Write, }; VirtualAddress vaddr() const { return m_vaddr; } u16 code() const { return m_code; } Type type() const { return (Type)(m_code & 1); } + Access access() const { return (Access)(m_code & 2); } bool is_not_present() const { return (m_code & 1) == PageFaultFlags::NotPresent; } bool is_protection_violation() const { return (m_code & 1) == PageFaultFlags::ProtectionViolation; } diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index f3be20a27c..178ecd1415 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -437,7 +437,7 @@ PageFaultResponse MemoryManager::handle_page_fault(const PageFault& fault) return PageFaultResponse::Continue; } ASSERT(fault.type() == PageFault::Type::ProtectionViolation); - if (region->should_cow(page_index_in_region)) { + if (fault.access() == PageFault::Access::Write && region->should_cow(page_index_in_region)) { #ifdef PAGE_FAULT_DEBUG dbgprintf("PV(cow) fault in Region{%p}[%u]\n", region, page_index_in_region); #endif