Kernel: Make Memory::Region allocation functions return KResultOr

This makes for some nicer handling of errors compared to checking an
OwnPtr for null state.
This commit is contained in:
sin-ack 2021-08-15 10:11:05 +00:00 committed by Andreas Kling
parent 4bfd6e41b9
commit 0a18425cbb
Notes: sideshowbarker 2024-07-18 05:39:28 +09:00
5 changed files with 45 additions and 38 deletions

View file

@ -96,14 +96,14 @@ KResultOr<FlatPtr> Process::sys$fork(RegisterState& regs)
ScopedSpinLock lock(address_space().get_lock());
for (auto& region : address_space().regions()) {
dbgln_if(FORK_DEBUG, "fork: cloning Region({}) '{}' @ {}", region, region->name(), region->vaddr());
auto region_clone = region->clone();
if (!region_clone) {
auto maybe_region_clone = region->try_clone();
if (maybe_region_clone.is_error()) {
dbgln("fork: Cannot clone region, insufficient memory");
// TODO: tear down new process?
return ENOMEM;
return maybe_region_clone.error();
}
auto* child_region = child->address_space().add_region(region_clone.release_nonnull());
auto* child_region = child->address_space().add_region(maybe_region_clone.release_value());
if (!child_region) {
dbgln("fork: Cannot add region, insufficient memory");
// TODO: tear down new process?