diff options
author | csilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50> | 2008-06-14 02:30:53 +0000 |
---|---|---|
committer | csilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50> | 2008-06-14 02:30:53 +0000 |
commit | 100e657c5092bc274424286a728db5116a4bbc54 (patch) | |
tree | 3a688677e9366e218b25651d0a75567e8ecacf4f /src/pagemap.h | |
parent | 7ec719093b1c9fda979ba0d07eed288e2a7c3c9b (diff) | |
download | gperftools-100e657c5092bc274424286a728db5116a4bbc54.tar.gz |
Mon Jun 9 16:47:03 2008 Google Inc. <opensource@google.com>
* google-perftools: version 0.98 release
* Add ProfilerStartWithOptions() (cgd)
* Change tcmalloc_minimal to not do any stack-tracing at all (csilvers)
* Prefer mmap to sbrk for 64-buit debug mode (sanjay)
* Fix accounting for some tcmalloc stats (sanjay)
* Use setrlimit() to keep unittests from killing the machine (odo)
* Fix a bug when sbrk-ing near address 4G (csilvers)
* Make MallocHook thread-safe (jyasskin)
* Fix windows build for MemoryBarrier (jyasskin)
* Fix CPU-profiler docs to mention correct libs (csilvers)
* Fix for GetHeapProfile() when heap-profiling is off (maxim)
* Avoid realloc resizing ping-pongs using hysteresis (csilvers)
* Add --callgrind output support to pprof (klimek)
* Fix profiler.h and heap-profiler.h to be C-compatible (csilvers)
* Break malloc_hook.h into two parts to reduce dependencies (csilvers)
* Better handle systems that don't implement mmap (csilvers)
* PORTING: disable system_alloc_unittest for msvc (csilvers)
* PORTING: Makefile tweaks to build better on cygwin (csilvers)
git-svn-id: http://gperftools.googlecode.com/svn/trunk@52 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
Diffstat (limited to 'src/pagemap.h')
-rw-r--r-- | src/pagemap.h | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/pagemap.h b/src/pagemap.h index 1fdde99..6393ffc 100644 --- a/src/pagemap.h +++ b/src/pagemap.h @@ -42,8 +42,8 @@ // a page number. E.g., with 32 bit pointers and 4K pages (i.e., // page offset fits in lower 12 bits), BITS == 20. -#ifndef TCMALLOC_PAGEMAP_H__ -#define TCMALLOC_PAGEMAP_H__ +#ifndef TCMALLOC_PAGEMAP_H_ +#define TCMALLOC_PAGEMAP_H_ #include "config.h" #if defined HAVE_STDINT_H @@ -59,6 +59,8 @@ template <int BITS> class TCMalloc_PageMap1 { private: + static const int LENGTH = 1 << BITS; + void** array_; public: @@ -72,8 +74,11 @@ class TCMalloc_PageMap1 { // Ensure that the map contains initialized entries "x .. x+n-1". // Returns true if successful, false if we could not allocate memory. bool Ensure(Number x, size_t n) { - // Nothing to do since flat array was allocate at start - return true; + // Nothing to do since flat array was allocated at start. All + // that's left is to check for overflow (that is, we don't want to + // ensure a number y where array_[y] would be an out-of-bounds + // access). + return n <= LENGTH - x; // an overflow-free way to do "x + n <= LENGTH" } void PreallocateMoreMemory() {} @@ -141,6 +146,10 @@ class TCMalloc_PageMap2 { for (Number key = start; key <= start + n - 1; ) { const Number i1 = key >> LEAF_BITS; + // Check for overflow + if (i1 >= ROOT_LENGTH) + return false; + // Make 2nd level node if necessary if (root_[i1] == NULL) { Leaf* leaf = reinterpret_cast<Leaf*>((*allocator_)(sizeof(Leaf))); @@ -223,6 +232,10 @@ class TCMalloc_PageMap3 { const Number i1 = key >> (LEAF_BITS + INTERIOR_BITS); const Number i2 = (key >> LEAF_BITS) & (INTERIOR_LENGTH-1); + // Check for overflow + if (i1 >= INTERIOR_LENGTH || i2 >= INTERIOR_LENGTH) + return false; + // Make 2nd level node if necessary if (root_->ptrs[i1] == NULL) { Node* n = NewNode(); @@ -248,4 +261,4 @@ class TCMalloc_PageMap3 { } }; -#endif // TCMALLOC_PAGEMAP_H__ +#endif // TCMALLOC_PAGEMAP_H_ |