Commit 4ecd70a2 authored by Igor Sheludko's avatar Igor Sheludko Committed by V8 LUCI CQ

[ext-code-space] Fix CodeRange hint logic on Windows and Linux

Windows requires additional writable page to be allocated in front of
the code range, but at the same time the code range must not cross 4 GB
boundary in order to make Code pointer compression work for Code
pointers. All these constraints make the logic of hint calculation too
dependent on what VirtualMemoryCage::InitReservation() would do with
the provided hint. This CL simplifies the hint calculation and fully
relies on VirtualMemoryCage::InitReservation() to do the right thing.

On Linux the implementation of OS::GetFreeMemoryRangesWithin() doesn't
work when Chromium sandbox is enabled, so we use the beginning of the
preferred short builtin calls region as a hint. It should be at least
as good as the fallback hint but with higher chances to point to free
address space location.

Bug: v8:11880
Change-Id: I0b6ebec98dd0cf483f67e6ba8a919deb9ce7cc25
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3380585Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78568}
parent 3e0fad5a
......@@ -53,6 +53,11 @@ Address CodeRangeAddressHint::GetAddressHint(size_t code_range_size,
CHECK(IsAligned(result, alignment));
return result;
}
// The empty memory_ranges means that GetFreeMemoryRangesWithin() API
// is not supported, so use the lowest address from the preferred region
// as a hint because it'll be at least as good as the fallback hint but
// with a higher chances to point to the free address space range.
return RoundUp(preferred_region.begin(), alignment);
}
return RoundUp(FUNCTION_ADDR(&FunctionInStaticBinaryForAddressHint),
alignment);
......@@ -124,16 +129,8 @@ bool CodeRange::InitReservation(v8::PageAllocator* page_allocator,
: VirtualMemoryCage::ReservationParams::kAnyBaseAlignment;
params.base_bias_size = RoundUp(reserved_area, allocate_page_size);
params.page_size = MemoryChunk::kPageSize;
// V8_EXTERNAL_CODE_SPACE imposes additional alignment requirement for the
// base address, so make sure the hint calculation function takes that into
// account. Otherwise the allocated reservation might be outside of the
// preferred region (see Isolate::GetShortBuiltinsCallRegion()).
const size_t hint_alignment =
V8_EXTERNAL_CODE_SPACE_BOOL
? RoundUp(params.base_alignment, allocate_page_size)
: allocate_page_size;
params.requested_start_hint =
GetCodeRangeAddressHint()->GetAddressHint(requested, hint_alignment);
GetCodeRangeAddressHint()->GetAddressHint(requested, allocate_page_size);
if (!VirtualMemoryCage::InitReservation(params)) return false;
......
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