diff --git a/runtime/vm/virtual_memory_posix.cc b/runtime/vm/virtual_memory_posix.cc index 9ae49f6a536..dd07c76a44c 100644 --- a/runtime/vm/virtual_memory_posix.cc +++ b/runtime/vm/virtual_memory_posix.cc @@ -76,10 +76,18 @@ intptr_t VirtualMemory::CalculatePageSize() { void VirtualMemory::Init() { #if defined(DART_COMPRESSED_POINTERS) if (VirtualMemoryCompressedHeap::GetRegion() == nullptr) { - VirtualMemoryCompressedHeap::Init(GenericMapAligned( + void* address = GenericMapAligned( PROT_READ | PROT_WRITE, kCompressedHeapSize, kCompressedHeapAlignment, kCompressedHeapSize + kCompressedHeapAlignment, - MAP_PRIVATE | MAP_ANONYMOUS)); + MAP_PRIVATE | MAP_ANONYMOUS); + if (address == nullptr) { + int error = errno; + const int kBufferSize = 1024; + char error_buf[kBufferSize]; + FATAL2("Failed to reserve region for compressed heap: %d (%s)", error, + Utils::StrError(error, error_buf, kBufferSize)); + } + VirtualMemoryCompressedHeap::Init(address); } #endif // defined(DART_COMPRESSED_POINTERS) @@ -328,7 +336,7 @@ VirtualMemory* VirtualMemory::AllocateAligned(intptr_t size, #endif // defined(HOST_OS_MACOS) void* address = GenericMapAligned(prot, size, alignment, allocated_size, map_flags); - if (address == MAP_FAILED) { + if (address == nullptr) { return nullptr; } diff --git a/runtime/vm/virtual_memory_win.cc b/runtime/vm/virtual_memory_win.cc index f7322fbc6b9..994833dbd40 100644 --- a/runtime/vm/virtual_memory_win.cc +++ b/runtime/vm/virtual_memory_win.cc @@ -55,9 +55,20 @@ void VirtualMemory::Init() { page_size_ = CalculatePageSize(); #if defined(DART_COMPRESSED_POINTERS) - VirtualMemoryCompressedHeap::Init(AllocateAlignedImpl( - kCompressedHeapSize, kCompressedHeapAlignment, - kCompressedHeapSize + kCompressedHeapAlignment, PAGE_READWRITE, nullptr)); + if (VirtualMemoryCompressedHeap::GetRegion() == nullptr) { + void* address = + AllocateAlignedImpl(kCompressedHeapSize, kCompressedHeapAlignment, + kCompressedHeapSize + kCompressedHeapAlignment, + PAGE_READWRITE, nullptr); + if (address == nullptr) { + int error = GetLastError(); + const int kBufferSize = 1024; + char error_buf[kBufferSize]; + FATAL2("Failed to reserve region for compressed heap: %d (%s)", error, + Utils::StrError(error, error_buf, kBufferSize)); + } + VirtualMemoryCompressedHeap::Init(address); + } #endif // defined(DART_COMPRESSED_POINTERS) }