Browse Source

Kernel: Add Region::clear_to_zero

This helper method can be used to quickly and efficiently zero out a
region.
Idan Horowitz 3 năm trước cách đây
mục cha
commit
ff6b43734c
2 tập tin đã thay đổi với 15 bổ sung0 xóa
  1. 13 0
      Kernel/Memory/Region.cpp
  2. 2 0
      Kernel/Memory/Region.h

+ 13 - 0
Kernel/Memory/Region.cpp

@@ -293,6 +293,19 @@ void Region::remap()
         TODO();
         TODO();
 }
 }
 
 
+void Region::clear_to_zero()
+{
+    VERIFY(vmobject().is_anonymous());
+    SpinlockLocker locker(vmobject().m_lock);
+    for (auto i = 0u; i < page_count(); ++i) {
+        auto page = physical_page_slot(i);
+        VERIFY(page);
+        if (page->is_shared_zero_page())
+            continue;
+        page = MM.shared_zero_page();
+    }
+}
+
 PageFaultResponse Region::handle_fault(PageFault const& fault)
 PageFaultResponse Region::handle_fault(PageFault const& fault)
 {
 {
     auto page_index_in_region = page_index_from_address(fault.vaddr());
     auto page_index_in_region = page_index_from_address(fault.vaddr());

+ 2 - 0
Kernel/Memory/Region.h

@@ -182,6 +182,8 @@ public:
 
 
     void remap();
     void remap();
 
 
+    void clear_to_zero();
+
     [[nodiscard]] bool is_syscall_region() const { return m_syscall_region; }
     [[nodiscard]] bool is_syscall_region() const { return m_syscall_region; }
     void set_syscall_region(bool b) { m_syscall_region = b; }
     void set_syscall_region(bool b) { m_syscall_region = b; }