Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Unified Diff: src/platform-linux.cc

Issue 7865025: Move aligned allocation to the platform files. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Match the VirtualFree return type and arguments. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/platform.h ('k') | src/platform-macos.cc » ('j') | src/platform-win32.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform-linux.cc
diff --git a/src/platform-linux.cc b/src/platform-linux.cc
index 00852baeebf66cd3be61a51ee10ade941bc98603..da5d81bd45fae5001a2bf7074bc38cc3a7e490ba 100644
--- a/src/platform-linux.cc
+++ b/src/platform-linux.cc
@@ -650,6 +650,34 @@ void* VirtualMemory::ReserveRegion(size_t size) {
}
+void* VirtualMemory::ReserveAlignedRegion(size_t size, size_t alignment) {
+ ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment())));
+ size_t request_size = RoundUp(size + alignment,
+ static_cast<intptr_t>(OS::AllocateAlignment()));
+ void* reservation = mmap(GetRandomMmapAddr(),
+ request_size,
+ PROT_NONE,
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
+ kMmapFd,
+ kMmapFdOffset);
+ if (reservation == MAP_FAILED) return NULL;
+ Address base = static_cast<Address>(reservation);
+ Address aligned_base = RoundUp(base, alignment);
+ ASSERT(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 (static_cast<size_t>(aligned_base - base) < request_size - size) {
+ munmap(aligned_base + size, request_size - size - bytes_prior);
+ }
+
+ return static_cast<void*>(aligned_base);
+}
+
+
bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
if (MAP_FAILED == mmap(base,
« no previous file with comments | « src/platform.h ('k') | src/platform-macos.cc » ('j') | src/platform-win32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698