Skip to content

Commit

Permalink
Kernel: Don't treat read faults like CoW exceptions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
awesomekling committed Aug 6, 2019
1 parent af4cf01 commit 945f8eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions Kernel/Arch/i386/CPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,20 @@ class PageFault {
}

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; }
Expand Down
2 changes: 1 addition & 1 deletion Kernel/VM/MemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 945f8eb

Please sign in to comment.