summaryrefslogtreecommitdiff
path: root/Kernel/SharedBuffer.cpp
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-11-22 15:25:48 -0700
committerAndreas Kling <kling@serenityos.org>2020-11-23 09:39:32 +0100
commita89648e15988471f3854c99f41ab0e47f131032a (patch)
tree966a03ebf958fff9592b351b62b783ad3a27004c /Kernel/SharedBuffer.cpp
parent48369194d22b5d042c1c7b0d61e86ba5389149ed (diff)
downloadserenity-a89648e15988471f3854c99f41ab0e47f131032a.zip
Kernel: Inherit shared buffers when forking
We need to create a reference for the new PID for each shared buffer that the process had a reference to. If the process subsequently get replaced through exec, those references will be dropped again. But if exec for some reason fails then other code, such as global destructors could still expect having access to them. Fixes #4076
Diffstat (limited to 'Kernel/SharedBuffer.cpp')
-rw-r--r--Kernel/SharedBuffer.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/Kernel/SharedBuffer.cpp b/Kernel/SharedBuffer.cpp
index 29223bcda7..39cd8681aa 100644
--- a/Kernel/SharedBuffer.cpp
+++ b/Kernel/SharedBuffer.cpp
@@ -121,6 +121,22 @@ void SharedBuffer::share_with(ProcessID peer_pid)
sanity_check("share_with (new ref)");
}
+void SharedBuffer::share_all_shared_buffers(Process& from_process, Process& with_process)
+{
+ LOCKER(shared_buffers().lock());
+ for (auto& shbuf : shared_buffers().resource()) {
+ auto& shared_buffer = *shbuf.value;
+ if (shared_buffer.m_global)
+ continue;
+ for (auto& ref : shared_buffer.m_refs) {
+ if (ref.pid == from_process.pid()) {
+ shared_buffer.share_with(with_process.pid());
+ break;
+ }
+ }
+ }
+}
+
void SharedBuffer::deref_for_process(Process& process)
{
LOCKER(shared_buffers().lock());