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

Side by Side Diff: src/platform-linux.cc

Issue 7352007: Add guard pages in front of platform allocations (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/platform-macos.cc » ('j') | src/platform-win32.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 return sysconf(_SC_PAGESIZE); 363 return sysconf(_SC_PAGESIZE);
364 } 364 }
365 365
366 366
367 void* OS::Allocate(const size_t requested, 367 void* OS::Allocate(const size_t requested,
368 size_t* allocated, 368 size_t* allocated,
369 bool is_executable) { 369 bool is_executable) {
370 // TODO(805): Port randomization of allocated executable memory to Linux. 370 // TODO(805): Port randomization of allocated executable memory to Linux.
371 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE)); 371 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE));
372 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 372 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
373 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 373 void* mbase = mmap(NULL, msize + Page::kPageSize, prot,
Vyacheslav Egorov (Chromium) 2011/07/12 23:23:29 V8 uses "one argument per line" convention.
Cris Neckar 2011/07/14 17:32:28 Done.
374 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
374 if (mbase == MAP_FAILED) { 375 if (mbase == MAP_FAILED) {
375 LOG(i::Isolate::Current(), 376 LOG(i::Isolate::Current(),
376 StringEvent("OS::Allocate", "mmap failed")); 377 StringEvent("OS::Allocate", "mmap failed"));
377 return NULL; 378 return NULL;
378 } 379 }
379 *allocated = msize; 380 *allocated = msize;
381 mprotect(mbase, Page::kPageSize, PROT_NONE);
382 mbase += Page::kPageSize;
Vyacheslav Egorov (Chromium) 2011/07/12 23:23:29 I am a bit concerned that we are spreading (and du
Cris Neckar 2011/07/14 17:32:28 Done.
380 UpdateAllocatedSpaceLimits(mbase, msize); 383 UpdateAllocatedSpaceLimits(mbase, msize);
381 return mbase; 384 return mbase;
382 } 385 }
383 386
384 387
385 void OS::Free(void* address, const size_t size) { 388 void OS::Free(void* address, const size_t size) {
386 // TODO(1240712): munmap has a return value which is ignored here. 389 // TODO(1240712): munmap has a return value which is ignored here.
387 int result = munmap(address, size); 390 int result = munmap(address - Page::kPageSize, size + Page::kPageSize);
388 USE(result); 391 USE(result);
389 ASSERT(result == 0); 392 ASSERT(result == 0);
390 } 393 }
391 394
392 395
393 #ifdef ENABLE_HEAP_PROTECTION 396 #ifdef ENABLE_HEAP_PROTECTION
394 397
395 void OS::Protect(void* address, size_t size) { 398 void OS::Protect(void* address, size_t size) {
396 // TODO(1240712): mprotect has a return value which is ignored here. 399 // TODO(1240712): mprotect has a return value which is ignored here.
397 mprotect(address, size, PROT_READ); 400 mprotect(address, size, PROT_READ);
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 1147
1145 void Sampler::Stop() { 1148 void Sampler::Stop() {
1146 ASSERT(IsActive()); 1149 ASSERT(IsActive());
1147 SignalSender::RemoveActiveSampler(this); 1150 SignalSender::RemoveActiveSampler(this);
1148 SetActive(false); 1151 SetActive(false);
1149 } 1152 }
1150 1153
1151 #endif // ENABLE_LOGGING_AND_PROFILING 1154 #endif // ENABLE_LOGGING_AND_PROFILING
1152 1155
1153 } } // namespace v8::internal 1156 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/platform-macos.cc » ('j') | src/platform-win32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698