Index: src/platform-linux.cc |
diff --git a/src/platform-linux.cc b/src/platform-linux.cc |
index 2d6160e473f12c89f67693e44759622b9a538bc6..855ebf78e16fe14beba51d616c84a83bd03df9f3 100644 |
--- a/src/platform-linux.cc |
+++ b/src/platform-linux.cc |
@@ -477,7 +477,7 @@ OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, |
PosixMemoryMappedFile::~PosixMemoryMappedFile() { |
- if (memory_) munmap(memory_, size_); |
+ if (memory_) OS::Free(memory_, size_); |
fclose(file_); |
} |
@@ -559,7 +559,7 @@ void OS::SignalCodeMovingGC() { |
void* addr = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_PRIVATE, |
fileno(f), 0); |
ASSERT(addr != MAP_FAILED); |
- munmap(addr, size); |
+ OS::Free(addr, size); |
fclose(f); |
} |
@@ -621,21 +621,31 @@ VirtualMemory::VirtualMemory(size_t size, size_t alignment) |
kMmapFd, |
kMmapFdOffset); |
if (reservation == MAP_FAILED) return; |
+ |
Address base = static_cast<Address>(reservation); |
Address aligned_base = RoundUp(base, alignment); |
- ASSERT(base <= aligned_base); |
+ ASSERT_LE(base, aligned_base); |
// Unmap extra memory reserved before and after the desired block. |
- size_t bytes_prior = static_cast<size_t>(aligned_base - base); |
- if (bytes_prior > 0) { |
- munmap(base, bytes_prior); |
+ if (aligned_base != base) { |
+ size_t prefix_size = static_cast<size_t>(aligned_base - base); |
+ OS::Free(base, prefix_size); |
+ request_size -= prefix_size; |
} |
- if (static_cast<size_t>(aligned_base - base) < request_size - size) { |
- munmap(aligned_base + size, request_size - size - bytes_prior); |
+ |
+ size_t aligned_size = RoundUp(size, OS::AllocateAlignment()); |
+ ASSERT_LE(aligned_size, request_size); |
+ |
+ if (aligned_size != request_size) { |
+ size_t suffix_size = request_size - aligned_size; |
+ OS::Free(aligned_base + aligned_size, suffix_size); |
+ request_size -= suffix_size; |
} |
+ ASSERT(aligned_size == request_size); |
+ |
address_ = static_cast<void*>(aligned_base); |
- size_ = size; |
+ size_ = aligned_size; |
} |