Gracefully handle OOM in BoundedPageAllocator

Changing the protections of a kNoAccess region to something different
can fail due to OOM. We should handle this properly.

Bug: chromium:1240062
Change-Id: I35e8837a57d66930390067eb0d1ab4bc76709948
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3099685
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Samuel Groß <saelo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76342}
This commit is contained in:
Samuel Groß 2021-08-17 11:57:19 +02:00 committed by V8 LUCI CQ
parent df2b169b3f
commit 14c3e2d6c6

View File

@ -45,9 +45,15 @@ void* BoundedPageAllocator::AllocatePages(void* hint, size_t size,
if (address == RegionAllocator::kAllocationFailure) {
return nullptr;
}
CHECK(page_allocator_->SetPermissions(reinterpret_cast<void*>(address), size,
access));
return reinterpret_cast<void*>(address);
void* ptr = reinterpret_cast<void*>(address);
if (!page_allocator_->SetPermissions(ptr, size, access)) {
// This most likely means that we ran out of memory.
CHECK_EQ(region_allocator_.FreeRegion(address), size);
return nullptr;
}
return ptr;
}
bool BoundedPageAllocator::AllocatePagesAt(Address address, size_t size,
@ -64,8 +70,13 @@ bool BoundedPageAllocator::AllocatePagesAt(Address address, size_t size,
}
}
CHECK(page_allocator_->SetPermissions(reinterpret_cast<void*>(address), size,
access));
void* ptr = reinterpret_cast<void*>(address);
if (!page_allocator_->SetPermissions(ptr, size, access)) {
// This most likely means that we ran out of memory.
CHECK_EQ(region_allocator_.FreeRegion(address), size);
return false;
}
return true;
}