summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-01-25 15:33:48 +0200
committerIdan Horowitz <idan.horowitz@gmail.com>2022-01-26 02:37:03 +0200
commita6f0ab358ad68bd4350d31423c379d4a8c198dce (patch)
tree14989a5d62bb448eee549383fcf71508af4f72fa
parentdab73d6d23fd7ee98429a73cc262a8597416c356 (diff)
downloadserenity-a6f0ab358ad68bd4350d31423c379d4a8c198dce.zip
Kernel: Make AddressSpace::find_regions_intersecting OOM-fallible
-rw-r--r--Kernel/Memory/AddressSpace.cpp6
-rw-r--r--Kernel/Memory/AddressSpace.h2
-rw-r--r--Kernel/Syscalls/mmap.cpp2
-rw-r--r--Kernel/Syscalls/sigaction.cpp2
4 files changed, 6 insertions, 6 deletions
diff --git a/Kernel/Memory/AddressSpace.cpp b/Kernel/Memory/AddressSpace.cpp
index 613842f94c..b0c8e0b66e 100644
--- a/Kernel/Memory/AddressSpace.cpp
+++ b/Kernel/Memory/AddressSpace.cpp
@@ -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())
diff --git a/Kernel/Memory/AddressSpace.h b/Kernel/Memory/AddressSpace.h
index c66f8256f5..b09f5f3d2d 100644
--- a/Kernel/Memory/AddressSpace.h
+++ b/Kernel/Memory/AddressSpace.h
@@ -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; }
diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp
index 0ac03dc0d0..776c105442 100644
--- a/Kernel/Syscalls/mmap.cpp
+++ b/Kernel/Syscalls/mmap.cpp
@@ -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) {
diff --git a/Kernel/Syscalls/sigaction.cpp b/Kernel/Syscalls/sigaction.cpp
index 411ecd99e7..79450ca974 100644
--- a/Kernel/Syscalls/sigaction.cpp
+++ b/Kernel/Syscalls/sigaction.cpp
@@ -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) {