Commit cbdc8337 authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

[wasm] Decommit unneeded memory

The {WasmCodeManager::Decommit} method is called for ranges that do not
contain any live code any more. Instead of setting permissions to
{kNoAccess} and discarding the pages, do actually decommit them. The
difference is subtle, but decommitting tries harder to actually free the
underlying physical pages (whereas discarding is more a hint to the
operating system).

After both operations, the memory is not accessible afterwards, so any
further access results in a signal, and thus a crash of the process.

R=jkummerow@chromium.org, mlippautz@chromium.org

Change-Id: Iddeda5c4ed864682c4df589b6ea6e359bf03847a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3427459Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78916}
parent 6c3001fa
......@@ -1942,15 +1942,10 @@ void WasmCodeManager::Decommit(base::AddressRegion region) {
size_t old_committed = total_committed_code_space_.fetch_sub(region.size());
DCHECK_LE(region.size(), old_committed);
USE(old_committed);
TRACE_HEAP("Discarding system pages 0x%" PRIxPTR ":0x%" PRIxPTR "\n",
TRACE_HEAP("Decommitting system pages 0x%" PRIxPTR ":0x%" PRIxPTR "\n",
region.begin(), region.end());
if (MemoryProtectionKeysEnabled()) {
CHECK(SetPermissionsAndMemoryProtectionKey(
allocator, region, PageAllocator::kNoAccess, kNoMemoryProtectionKey));
} else {
CHECK(SetPermissions(allocator, region.begin(), region.size(),
PageAllocator::kNoAccess));
}
CHECK(allocator->DecommitPages(reinterpret_cast<void*>(region.begin()),
region.size()));
}
void WasmCodeManager::AssignRange(base::AddressRegion region,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment