OLD | NEW |
---|---|
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 Loading... | |
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) | 106 #ifdef HAVE_GETPAGESIZE |
107 // Page size is initialized on demand (only needed for mmap-based allocators) | |
108 static size_t pagesize = 0; | 107 static size_t pagesize = 0; |
109 #endif | 108 #endif |
110 | 109 |
111 // The current system allocator | 110 // The current system allocator |
112 SysAllocator* sys_alloc = NULL; | 111 SysAllocator* sys_alloc = NULL; |
113 | 112 |
114 // Configuration parameters. | 113 // Configuration parameters. |
115 DEFINE_int32(malloc_devmem_start, | 114 DEFINE_int32(malloc_devmem_start, |
116 EnvToInt("TCMALLOC_DEVMEM_START", 0), | 115 EnvToInt("TCMALLOC_DEVMEM_START", 0), |
117 "Physical memory starting location in MB for /dev/mem allocation." | 116 "Physical memory starting location in MB for /dev/mem allocation." |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 CheckAddressBits<kAddressBits>( | 476 CheckAddressBits<kAddressBits>( |
478 reinterpret_cast<uintptr_t>(result) + *actual_size - 1); | 477 reinterpret_cast<uintptr_t>(result) + *actual_size - 1); |
479 } else { | 478 } else { |
480 CheckAddressBits<kAddressBits>( | 479 CheckAddressBits<kAddressBits>( |
481 reinterpret_cast<uintptr_t>(result) + size - 1); | 480 reinterpret_cast<uintptr_t>(result) + size - 1); |
482 } | 481 } |
483 } | 482 } |
484 return result; | 483 return result; |
485 } | 484 } |
486 | 485 |
486 size_t TCMalloc_SystemAddGuard(void* start, size_t size) { | |
487 #ifdef HAVE_GETPAGESIZE | |
488 if (pagesize == 0) | |
489 pagesize = getpagesize(); | |
490 | |
491 if (size < pagesize || (reinterpret_cast<size_t>(start) % pagesize) != 0) | |
jar (doing other things)
2011/11/24 01:08:07
Perhaps you could be cautious, and check that the
jschuh
2011/11/28 18:33:36
It seems sufficient to just crash in PageAllocator
| |
492 return 0; | |
493 | |
494 if (!mprotect(start, pagesize, PROT_NONE)) | |
495 return pagesize; | |
496 #endif | |
497 | |
498 return 0; | |
499 } | |
500 | |
487 void TCMalloc_SystemRelease(void* start, size_t length) { | 501 void TCMalloc_SystemRelease(void* start, size_t length) { |
488 #ifdef MADV_DONTNEED | 502 #ifdef MADV_DONTNEED |
489 if (FLAGS_malloc_devmem_start) { | 503 if (FLAGS_malloc_devmem_start) { |
490 // It's not safe to use MADV_DONTNEED if we've been mapping | 504 // It's not safe to use MADV_DONTNEED if we've been mapping |
491 // /dev/mem for heap memory | 505 // /dev/mem for heap memory |
492 return; | 506 return; |
493 } | 507 } |
494 if (pagesize == 0) pagesize = getpagesize(); | 508 if (pagesize == 0) pagesize = getpagesize(); |
495 const size_t pagemask = pagesize - 1; | 509 const size_t pagemask = pagesize - 1; |
496 | 510 |
(...skipping 21 matching lines...) Expand all Loading... | |
518 } | 532 } |
519 } | 533 } |
520 #endif | 534 #endif |
521 } | 535 } |
522 | 536 |
523 void TCMalloc_SystemCommit(void* start, size_t length) { | 537 void TCMalloc_SystemCommit(void* start, size_t length) { |
524 // Nothing to do here. TCMalloc_SystemRelease does not alter pages | 538 // 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 | 539 // such that they need to be re-committed before they can be used by the |
526 // application. | 540 // application. |
527 } | 541 } |
OLD | NEW |