Commit a7194874 authored by Hao Xu's avatar Hao Xu Committed by V8 LUCI CQ

[sparkplug] Implement OS::GetFreeMemoryRangesWithin() for Windows

Search for free memory ranges within the +/- 2GB boundary to the
embedded builtins. So that code range can be allocated close to the
binary to enable short builtin calls when pointer compression is
disabled.

Bug: v8:12045, v8:11527
Change-Id: I4698625882c3c7c39aff73b0bc874ddcfc990881
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3212466
Commit-Queue: Hao A Xu <hao.a.xu@intel.com>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77465}
parent 8da845df
......@@ -1443,7 +1443,39 @@ void OS::AdjustSchedulingParams() {}
std::vector<OS::MemoryRange> OS::GetFreeMemoryRangesWithin(
OS::Address boundary_start, OS::Address boundary_end, size_t minimum_size,
size_t alignment) {
return {};
std::vector<OS::MemoryRange> result = {};
// Search for the virtual memory (vm) ranges within the boundary.
// If a range is free and larger than {minimum_size}, then push it to the
// returned vector.
uintptr_t vm_start = RoundUp(boundary_start, alignment);
uintptr_t vm_end = 0;
MEMORY_BASIC_INFORMATION mi;
// This loop will terminate once the scanning reaches the higher address
// to the end of boundary or the function VirtualQuery fails.
while (vm_start < boundary_end &&
VirtualQuery(reinterpret_cast<LPCVOID>(vm_start), &mi, sizeof(mi)) !=
0) {
vm_start = reinterpret_cast<uintptr_t>(mi.BaseAddress);
vm_end = vm_start + mi.RegionSize;
if (mi.State == MEM_FREE) {
// The available area is the overlap of the virtual memory range and
// boundary. Push the overlapped memory range to the vector if there is
// enough space.
const uintptr_t overlap_start =
RoundUp(std::max(vm_start, boundary_start), alignment);
const uintptr_t overlap_end =
RoundDown(std::min(vm_end, boundary_end), alignment);
if (overlap_start < overlap_end &&
overlap_end - overlap_start >= minimum_size) {
result.push_back({overlap_start, overlap_end});
}
}
// Continue to visit the next virtual memory range.
vm_start = vm_end;
}
return result;
}
// static
......
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