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

Unified Diff: src/spaces.cc

Issue 7379004: Add guard pages in front of platform allocations (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 5 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
« src/platform-cygwin.cc ('K') | « src/spaces.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/spaces.cc
===================================================================
--- src/spaces.cc (revision 8657)
+++ src/spaces.cc (working copy)
@@ -407,7 +407,8 @@
if (isolate_->code_range()->contains(static_cast<Address>(mem))) {
isolate_->code_range()->FreeRawMemory(mem, length);
} else {
- OS::Free(mem, length);
+ size_t guardsize = (executable == EXECUTABLE) ? Page::kPageSize : 0;
+ OS::Free(static_cast<char*>(mem) - guardsize, length + guardsize);
Mads Ager (chromium) 2011/07/17 09:47:53 This looks nasty to me. Doesn't this mean that to
Cris Neckar 2011/07/18 23:55:12 Done.
}
isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(length));
size_ -= static_cast<int>(length);
@@ -503,6 +504,11 @@
if (chunk == NULL) return Page::FromAddress(NULL);
LOG(isolate_, NewEvent("PagedChunk", chunk, chunk_size));
+ if (owner->executable() == EXECUTABLE) {
+ OS::Guard(chunk, Page::kPageSize);
+ chunk_size -= Page::kPageSize;
+ chunk = static_cast<Address>(chunk) + Page::kPageSize;
+ }
*allocated_pages = PagesInChunk(static_cast<Address>(chunk), chunk_size);
// We may 'lose' a page due to alignment.
ASSERT(*allocated_pages >= kPagesPerChunk - 1);
@@ -2672,9 +2678,10 @@
Executability executable) {
size_t requested = ChunkSizeFor(size_in_bytes);
size_t size;
+ size_t guardsize = (executable == EXECUTABLE) ? Page::kPageSize : 0;
Isolate* isolate = Isolate::Current();
void* mem = isolate->memory_allocator()->AllocateRawMemory(
- requested, &size, executable);
+ requested + guardsize, &size, executable);
if (mem == NULL) return NULL;
// The start of the chunk may be overlayed with a page so we have to
@@ -2684,11 +2691,17 @@
LOG(isolate, NewEvent("LargeObjectChunk", mem, size));
if (size < requested) {
Mads Ager (chromium) 2011/07/17 09:47:53 Shouldn't you add guardsize to requested before yo
Cris Neckar 2011/07/18 23:55:12 Done.
isolate->memory_allocator()->FreeRawMemory(
- mem, size, executable);
+ static_cast<Address>(mem) - guardsize, size + guardsize, executable);
Mads Ager (chromium) 2011/07/17 09:47:53 I'm getting confused here. Does this add up? FreeR
Cris Neckar 2011/07/18 23:55:12 Yeah this was a mistake, I had initially planned t
LOG(isolate, DeleteEvent("LargeObjectChunk", mem));
return NULL;
}
+ if (guardsize != 0) {
+ OS::Guard(mem, guardsize);
+ size -= guardsize;
+ mem = static_cast<Address>(mem) + guardsize;
+ }
+
ObjectSpace space = (executable == EXECUTABLE)
? kObjectSpaceCodeSpace
: kObjectSpaceLoSpace;
« src/platform-cygwin.cc ('K') | « src/spaces.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698