Commit cc71d5ca authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm][gc] Use SetPermissions to discard pages

On 32bit windows, DiscardSystemPages fails sometimes (see bug). We don't
have a reproducer, so this is a purely speculative fix.
{SetPermissions} has some platform-specific logic to also discard the
pages. Specifially, on windows it uses {VirtualFree} instead of
{DiscardVirtualMemory}.
{SetPermissions} is also semantically stronger, since it forbids any
further access to the pages.

R=mstarzinger@chromium.org

Bug: v8:8217, chromium:960707
Change-Id: I8b3325264c86aff8d6e7c6b01c22ae410e87faf4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1601134Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61321}
parent 56a0d001
......@@ -1369,8 +1369,18 @@ void NativeModule::FreeCode(Vector<WasmCode* const> codes) {
Address discard_end = std::min(RoundDown(merged_region.end(), page_size),
RoundUp(region.end(), page_size));
if (discard_start >= discard_end) continue;
allocator->DiscardSystemPages(reinterpret_cast<void*>(discard_start),
discard_end - discard_start);
#ifdef ENABLE_SLOW_DCHECKS
auto vmem_contains = [discard_start, discard_end](VirtualMemory& vmem) {
return vmem.InVM(discard_start, discard_end - discard_start);
};
DCHECK_EQ(1, std::count_if(owned_code_space_.begin(),
owned_code_space_.end(), vmem_contains));
#endif
// {SetPermissions} with {kNoAccess} also discards the pages in a platform
// specific way.
CHECK(allocator->SetPermissions(reinterpret_cast<void*>(discard_start),
discard_end - discard_start,
PageAllocator::kNoAccess));
}
}
......
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