From 1f894cee59814ada237a02ff49774bcce6caf9b7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 17 Nov 2021 19:35:53 +0100 Subject: [PATCH] Kernel: Automatically sync shared file mappings when unmapped To make sure we don't lose changes, shared file mappings will now be fully synced when they are unmapped, whether explicitly or implicitly (by the program exiting/crashing/etc.) This can incur a lot of work, since we don't keep track of dirty pages, but that's something we can optimize down the road. :^) --- Kernel/Memory/Region.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Kernel/Memory/Region.cpp b/Kernel/Memory/Region.cpp index b757ffee9e..0e2142051a 100644 --- a/Kernel/Memory/Region.cpp +++ b/Kernel/Memory/Region.cpp @@ -38,6 +38,11 @@ Region::Region(VirtualRange const& range, NonnullRefPtr vmobject, size Region::~Region() { + if (is_writable() && vmobject().is_shared_inode()) { + // FIXME: This is very aggressive. Find a way to do less work! + (void)static_cast(vmobject()).sync(); + } + m_vmobject->remove_region(*this); MM.unregister_region(*this);