mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:47:45 +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:
parent
0ae5de8c3c
commit
485f51690d
5 changed files with 28 additions and 12 deletions
|
@ -347,7 +347,7 @@ KResultOr<FlatPtr> Process::sys$mprotect(Userspace<void*> addr, size_t size, int
|
|||
}
|
||||
|
||||
// Remove the old region from our regions tree, since were going to add another region
|
||||
// with the exact same start address, but dont deallocate it yet
|
||||
// with the exact same start address, but do not deallocate it yet
|
||||
auto region = address_space().take_region(*old_region);
|
||||
|
||||
// Unmap the old region here, specifying that we *don't* want the VM deallocated.
|
||||
|
@ -371,9 +371,11 @@ KResultOr<FlatPtr> Process::sys$mprotect(Userspace<void*> addr, size_t size, int
|
|||
|
||||
// Map the new regions using our page directory (they were just allocated and don't have one).
|
||||
for (auto* adjacent_region : adjacent_regions) {
|
||||
adjacent_region->map(address_space().page_directory());
|
||||
if (!adjacent_region->map(address_space().page_directory()))
|
||||
return ENOMEM;
|
||||
}
|
||||
new_region.map(address_space().page_directory());
|
||||
if (!new_region.map(address_space().page_directory()))
|
||||
return ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -438,9 +440,11 @@ KResultOr<FlatPtr> Process::sys$mprotect(Userspace<void*> addr, size_t size, int
|
|||
|
||||
// Map the new region using our page directory (they were just allocated and don't have one) if any.
|
||||
if (adjacent_regions.size())
|
||||
adjacent_regions[0]->map(address_space().page_directory());
|
||||
if (!adjacent_regions[0]->map(address_space().page_directory()))
|
||||
return ENOMEM;
|
||||
|
||||
new_region.map(address_space().page_directory());
|
||||
if (!new_region.map(address_space().page_directory()))
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue