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

Side by Side Diff: third_party/tcmalloc/chromium/src/system-alloc.cc

Issue 8570023: Add a guard page in front of metadata allocations. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2005, Google Inc. 1 // Copyright (c) 2005, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 // Structure for discovering alignment 97 // Structure for discovering alignment
98 union MemoryAligner { 98 union MemoryAligner {
99 void* p; 99 void* p;
100 double d; 100 double d;
101 size_t s; 101 size_t s;
102 } CACHELINE_ALIGNED; 102 } CACHELINE_ALIGNED;
103 103
104 static SpinLock spinlock(SpinLock::LINKER_INITIALIZED); 104 static SpinLock spinlock(SpinLock::LINKER_INITIALIZED);
105 105
106 #if defined(HAVE_MMAP) || defined(MADV_DONTNEED)
107 // Page size is initialized on demand (only needed for mmap-based allocators)
108 static size_t pagesize = 0; 106 static size_t pagesize = 0;
jar (doing other things) 2011/11/23 23:46:14 Per your verbal comment.... "you need a guard arou
jschuh 2011/11/24 00:05:26 Done.
109 #endif
110 107
111 // The current system allocator 108 // The current system allocator
112 SysAllocator* sys_alloc = NULL; 109 SysAllocator* sys_alloc = NULL;
113 110
114 // Configuration parameters. 111 // Configuration parameters.
115 DEFINE_int32(malloc_devmem_start, 112 DEFINE_int32(malloc_devmem_start,
116 EnvToInt("TCMALLOC_DEVMEM_START", 0), 113 EnvToInt("TCMALLOC_DEVMEM_START", 0),
117 "Physical memory starting location in MB for /dev/mem allocation." 114 "Physical memory starting location in MB for /dev/mem allocation."
118 " Setting this to 0 disables /dev/mem allocation"); 115 " Setting this to 0 disables /dev/mem allocation");
119 DEFINE_int32(malloc_devmem_limit, 116 DEFINE_int32(malloc_devmem_limit,
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 CheckAddressBits<kAddressBits>( 474 CheckAddressBits<kAddressBits>(
478 reinterpret_cast<uintptr_t>(result) + *actual_size - 1); 475 reinterpret_cast<uintptr_t>(result) + *actual_size - 1);
479 } else { 476 } else {
480 CheckAddressBits<kAddressBits>( 477 CheckAddressBits<kAddressBits>(
481 reinterpret_cast<uintptr_t>(result) + size - 1); 478 reinterpret_cast<uintptr_t>(result) + size - 1);
482 } 479 }
483 } 480 }
484 return result; 481 return result;
485 } 482 }
486 483
484 size_t TCMalloc_SystemAddGuard(void* start) {
485 if (pagesize == 0) pagesize = getpagesize();
jar (doing other things) 2011/11/23 23:46:14 You'll need a wrapper here to for getpagesize avai
jschuh 2011/11/24 00:05:26 Done.
486
487 if (reinterpret_cast<size_t>(start) % pagesize != 0)
488 return 0;
489
490 if (!mprotect(start, pagesize, PROT_NONE))
491 return pagesize;
492
493 return 0;
494 }
495
487 void TCMalloc_SystemRelease(void* start, size_t length) { 496 void TCMalloc_SystemRelease(void* start, size_t length) {
488 #ifdef MADV_DONTNEED 497 #ifdef MADV_DONTNEED
489 if (FLAGS_malloc_devmem_start) { 498 if (FLAGS_malloc_devmem_start) {
490 // It's not safe to use MADV_DONTNEED if we've been mapping 499 // It's not safe to use MADV_DONTNEED if we've been mapping
491 // /dev/mem for heap memory 500 // /dev/mem for heap memory
492 return; 501 return;
493 } 502 }
494 if (pagesize == 0) pagesize = getpagesize(); 503 if (pagesize == 0) pagesize = getpagesize();
495 const size_t pagemask = pagesize - 1; 504 const size_t pagemask = pagesize - 1;
496 505
(...skipping 21 matching lines...) Expand all
518 } 527 }
519 } 528 }
520 #endif 529 #endif
521 } 530 }
522 531
523 void TCMalloc_SystemCommit(void* start, size_t length) { 532 void TCMalloc_SystemCommit(void* start, size_t length) {
524 // Nothing to do here. TCMalloc_SystemRelease does not alter pages 533 // Nothing to do here. TCMalloc_SystemRelease does not alter pages
525 // such that they need to be re-committed before they can be used by the 534 // such that they need to be re-committed before they can be used by the
526 // application. 535 // application.
527 } 536 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698