1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:27:44 +00:00

Kernel: Always observe the return value of Region::map and remap

We have seen cases where the map fails, but we return the region
to the caller, causing them to page fault later on when they touch
the region.

The fix is to always observe the return code of map/remap.
This commit is contained in:
Brian Gianforcaro 2021-08-24 12:53:47 -07:00 committed by Andreas Kling
parent 0ae5de8c3c
commit 485f51690d
5 changed files with 28 additions and 12 deletions

View file

@ -80,7 +80,10 @@ KResult AddressSpace::unmap_mmap_range(VirtualAddress addr, size_t size)
// And finally we map the new region(s) using our page directory (they were just allocated and don't have one).
for (auto* new_region : new_regions) {
new_region->map(page_directory());
// TODO: Ideally we should do this in a way that can be rolled back on failure, as failing here
// leaves the caller in an undefined state.
if (!new_region->map(page_directory()))
return ENOMEM;
}
PerformanceManager::add_unmap_perf_event(Process::current(), range_to_unmap);
@ -130,7 +133,10 @@ KResult AddressSpace::unmap_mmap_range(VirtualAddress addr, size_t size)
// And finally map the new region(s) into our page directory.
for (auto* new_region : new_regions) {
new_region->map(page_directory());
// TODO: Ideally we should do this in a way that can be rolled back on failure, as failing here
// leaves the caller in an undefined state.
if (!new_region->map(page_directory()))
return ENOMEM;
}
PerformanceManager::add_unmap_perf_event(Process::current(), range_to_unmap);