mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +00:00
Kernel: Use TRY() in Memory::AddressSpace
This commit is contained in:
parent
8cd4879946
commit
5ba10c6017
1 changed files with 6 additions and 17 deletions
|
@ -41,10 +41,7 @@ KResult AddressSpace::unmap_mmap_range(VirtualAddress addr, size_t size)
|
||||||
if (!size)
|
if (!size)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
auto range_or_error = VirtualRange::expand_to_page_boundaries(addr.get(), size);
|
auto range_to_unmap = TRY(VirtualRange::expand_to_page_boundaries(addr.get(), size));
|
||||||
if (range_or_error.is_error())
|
|
||||||
return range_or_error.error();
|
|
||||||
auto range_to_unmap = range_or_error.value();
|
|
||||||
|
|
||||||
if (!is_user_range(range_to_unmap))
|
if (!is_user_range(range_to_unmap))
|
||||||
return EFAULT;
|
return EFAULT;
|
||||||
|
@ -70,10 +67,7 @@ KResult AddressSpace::unmap_mmap_range(VirtualAddress addr, size_t size)
|
||||||
// We manually unmap the old region here, specifying that we *don't* want the VM deallocated.
|
// We manually unmap the old region here, specifying that we *don't* want the VM deallocated.
|
||||||
region->unmap(Region::ShouldDeallocateVirtualRange::No);
|
region->unmap(Region::ShouldDeallocateVirtualRange::No);
|
||||||
|
|
||||||
auto new_regions_or_error = try_split_region_around_range(*region, range_to_unmap);
|
auto new_regions = TRY(try_split_region_around_range(*region, range_to_unmap));
|
||||||
if (new_regions_or_error.is_error())
|
|
||||||
return new_regions_or_error.error();
|
|
||||||
auto& new_regions = new_regions_or_error.value();
|
|
||||||
|
|
||||||
// Instead we give back the unwanted VM manually.
|
// Instead we give back the unwanted VM manually.
|
||||||
page_directory().range_allocator().deallocate(range_to_unmap);
|
page_directory().range_allocator().deallocate(range_to_unmap);
|
||||||
|
@ -120,11 +114,8 @@ KResult AddressSpace::unmap_mmap_range(VirtualAddress addr, size_t size)
|
||||||
region->unmap(Region::ShouldDeallocateVirtualRange::No);
|
region->unmap(Region::ShouldDeallocateVirtualRange::No);
|
||||||
|
|
||||||
// Otherwise, split the regions and collect them for future mapping.
|
// Otherwise, split the regions and collect them for future mapping.
|
||||||
auto split_regions_or_error = try_split_region_around_range(*region, range_to_unmap);
|
auto split_regions = TRY(try_split_region_around_range(*region, range_to_unmap));
|
||||||
if (split_regions_or_error.is_error())
|
if (new_regions.try_extend(split_regions))
|
||||||
return split_regions_or_error.error();
|
|
||||||
|
|
||||||
if (new_regions.try_extend(split_regions_or_error.value()))
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,10 +302,8 @@ KResultOr<Vector<Region*, 2>> AddressSpace::try_split_region_around_range(const
|
||||||
};
|
};
|
||||||
Vector<Region*, 2> new_regions;
|
Vector<Region*, 2> new_regions;
|
||||||
for (auto& new_range : remaining_ranges_after_unmap) {
|
for (auto& new_range : remaining_ranges_after_unmap) {
|
||||||
auto new_region_or_error = try_make_replacement_region(new_range);
|
auto new_region = TRY(try_make_replacement_region(new_range));
|
||||||
if (new_region_or_error.is_error())
|
new_regions.unchecked_append(new_region);
|
||||||
return new_region_or_error.error();
|
|
||||||
new_regions.unchecked_append(new_region_or_error.value());
|
|
||||||
}
|
}
|
||||||
return new_regions;
|
return new_regions;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue