Kernel: Make AddressSpace::find_regions_intersecting OOM-fallible

This commit is contained in:
Idan Horowitz 2022-01-25 15:33:48 +02:00
parent dab73d6d23
commit a6f0ab358a
Notes: sideshowbarker 2024-07-17 20:12:10 +09:00
4 changed files with 6 additions and 6 deletions

View File

@ -81,7 +81,7 @@ ErrorOr<void> AddressSpace::unmap_mmap_range(VirtualAddress addr, size_t size)
}
// Try again while checking multiple regions at a time.
auto const& regions = find_regions_intersecting(range_to_unmap);
auto const& regions = TRY(find_regions_intersecting(range_to_unmap));
if (regions.is_empty())
return {};
@ -237,7 +237,7 @@ Region* AddressSpace::find_region_containing(VirtualRange const& range)
return (*candidate)->range().contains(range) ? candidate->ptr() : nullptr;
}
Vector<Region*> AddressSpace::find_regions_intersecting(VirtualRange const& range)
ErrorOr<Vector<Region*>> AddressSpace::find_regions_intersecting(VirtualRange const& range)
{
Vector<Region*> regions = {};
size_t total_size_collected = 0;
@ -250,7 +250,7 @@ Vector<Region*> AddressSpace::find_regions_intersecting(VirtualRange const& rang
for (auto iter = m_regions.begin_from((*found_region)->vaddr().get()); !iter.is_end(); ++iter) {
const auto& iter_range = (*iter)->range();
if (iter_range.base() < range.end() && iter_range.end() > range.base()) {
regions.append(*iter);
TRY(regions.try_append(*iter));
total_size_collected += (*iter)->size() - iter_range.intersect(range).size();
if (total_size_collected == range.size())

View File

@ -48,7 +48,7 @@ public:
Region* find_region_from_range(VirtualRange const&);
Region* find_region_containing(VirtualRange const&);
Vector<Region*> find_regions_intersecting(VirtualRange const&);
ErrorOr<Vector<Region*>> find_regions_intersecting(VirtualRange const&);
bool enforces_syscall_regions() const { return m_enforces_syscall_regions; }
void set_enforces_syscall_regions(bool b) { m_enforces_syscall_regions = b; }

View File

@ -323,7 +323,7 @@ ErrorOr<FlatPtr> Process::sys$mprotect(Userspace<void*> addr, size_t size, int p
return 0;
}
if (const auto& regions = address_space().find_regions_intersecting(range_to_mprotect); regions.size()) {
if (const auto& regions = TRY(address_space().find_regions_intersecting(range_to_mprotect)); regions.size()) {
size_t full_size_found = 0;
// Check that all intersecting regions are compatible.
for (const auto* region : regions) {

View File

@ -189,7 +189,7 @@ ErrorOr<void> Process::remap_range_as_stack(FlatPtr address, size_t size)
return {};
}
if (const auto& regions = address_space().find_regions_intersecting(range_to_remap); regions.size()) {
if (const auto& regions = TRY(address_space().find_regions_intersecting(range_to_remap)); regions.size()) {
size_t full_size_found = 0;
// Check that all intersecting regions are compatible.
for (const auto* region : regions) {