mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 17:35:08 +00:00
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
This commit is contained in:
parent
48369194d2
commit
a89648e159
3 changed files with 20 additions and 0 deletions
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue