1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:18:11 +00:00

Kernel: Wrap RegionTree objects in SpinlockProtected

This makes locking them much more straightforward, and we can remove
a bunch of confusing use of AddressSpace::m_lock. That lock will also
be converted to use of SpinlockProtected in a subsequent patch.
This commit is contained in:
Andreas Kling 2022-08-23 12:28:04 +02:00
parent 352d6545a9
commit dc9d2c1b10
9 changed files with 251 additions and 234 deletions

View file

@ -124,17 +124,21 @@ ErrorOr<FlatPtr> Process::sys$fork(RegisterState& regs)
#endif
{
SpinlockLocker lock(address_space().get_lock());
for (auto& region : address_space().regions()) {
dbgln_if(FORK_DEBUG, "fork: cloning Region '{}' @ {}", region.name(), region.vaddr());
auto region_clone = TRY(region.try_clone());
TRY(region_clone->map(child->address_space().page_directory(), Memory::ShouldFlushTLB::No));
TRY(child->address_space().region_tree().place_specifically(*region_clone, region.range()));
auto* child_region = region_clone.leak_ptr();
TRY(address_space().region_tree().with([&](auto& parent_region_tree) -> ErrorOr<void> {
return child->address_space().region_tree().with([&](auto& child_region_tree) -> ErrorOr<void> {
for (auto& region : parent_region_tree.regions()) {
dbgln_if(FORK_DEBUG, "fork: cloning Region '{}' @ {}", region.name(), region.vaddr());
auto region_clone = TRY(region.try_clone());
TRY(region_clone->map(child->address_space().page_directory(), Memory::ShouldFlushTLB::No));
TRY(child_region_tree.place_specifically(*region_clone, region.range()));
auto* child_region = region_clone.leak_ptr();
if (&region == m_master_tls_region.unsafe_ptr())
child->m_master_tls_region = TRY(child_region->try_make_weak_ptr());
}
if (&region == m_master_tls_region.unsafe_ptr())
child->m_master_tls_region = TRY(child_region->try_make_weak_ptr());
}
return {};
});
}));
}
thread_finalizer_guard.disarm();
@ -151,5 +155,4 @@ ErrorOr<FlatPtr> Process::sys$fork(RegisterState& regs)
return child_pid;
}
}