summaryrefslogtreecommitdiff
path: root/Kernel/Memory
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-11-29 21:18:59 +0200
committerIdan Horowitz <idan.horowitz@gmail.com>2021-12-01 21:44:11 +0200
commitff6b43734c9750b1319e62f60bae170df5313771 (patch)
treeca22184e2b3f6db27b118cf1a34ef61ed47332a5 /Kernel/Memory
parent5f95a1a7b71164a238a70a5c71420d1803850440 (diff)
downloadserenity-ff6b43734c9750b1319e62f60bae170df5313771.zip
Kernel: Add Region::clear_to_zero
This helper method can be used to quickly and efficiently zero out a region.
Diffstat (limited to 'Kernel/Memory')
-rw-r--r--Kernel/Memory/Region.cpp13
-rw-r--r--Kernel/Memory/Region.h2
2 files changed, 15 insertions, 0 deletions
diff --git a/Kernel/Memory/Region.cpp b/Kernel/Memory/Region.cpp
index 1e89f8dd84..8bb78447af 100644
--- a/Kernel/Memory/Region.cpp
+++ b/Kernel/Memory/Region.cpp
@@ -293,6 +293,19 @@ void Region::remap()
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)
{
auto page_index_in_region = page_index_from_address(fault.vaddr());
diff --git a/Kernel/Memory/Region.h b/Kernel/Memory/Region.h
index 2f1f8af8e0..8a86317b40 100644
--- a/Kernel/Memory/Region.h
+++ b/Kernel/Memory/Region.h
@@ -182,6 +182,8 @@ public:
void remap();
+ void clear_to_zero();
+
[[nodiscard]] bool is_syscall_region() const { return m_syscall_region; }
void set_syscall_region(bool b) { m_syscall_region = b; }