[Avida-SVN] r3473 - in branches/tcmalloc-1.4: Avida.xcodeproj source/platform/tcmalloc-1.4
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Wed Oct 14 09:29:23 PDT 2009
Author: brysonda
Date: 2009-10-14 12:29:23 -0400 (Wed, 14 Oct 2009)
New Revision: 3473
Removed:
branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook-inl.h
branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook.cc
branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook.h
branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook_c.h
Modified:
branches/tcmalloc-1.4/Avida.xcodeproj/project.pbxproj
branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/tcmalloc.cc
Log:
Remove malloc hooks from tcmalloc-1.4
Modified: branches/tcmalloc-1.4/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/tcmalloc-1.4/Avida.xcodeproj/project.pbxproj 2009-10-14 15:52:40 UTC (rev 3472)
+++ branches/tcmalloc-1.4/Avida.xcodeproj/project.pbxproj 2009-10-14 16:29:23 UTC (rev 3473)
@@ -49,7 +49,6 @@
702246DE107FCA900079CD25 /* common.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702246B9107FCA590079CD25 /* common.cc */; };
702246DF107FCA900079CD25 /* internal_logging.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702246BB107FCA590079CD25 /* internal_logging.cc */; };
702246E0107FCA900079CD25 /* malloc_extension.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702246BE107FCA590079CD25 /* malloc_extension.cc */; };
- 702246E1107FCA900079CD25 /* malloc_hook.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702246C0107FCA590079CD25 /* malloc_hook.cc */; };
702246E2107FCA900079CD25 /* maybe_threads.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702246C1107FCA590079CD25 /* maybe_threads.cc */; };
702246E3107FCA900079CD25 /* memfs_malloc.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702246C3107FCA590079CD25 /* memfs_malloc.cc */; };
702246E4107FCA900079CD25 /* page_heap.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702246C6107FCA590079CD25 /* page_heap.cc */; };
@@ -498,8 +497,6 @@
702246BC107FCA590079CD25 /* internal_logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = internal_logging.h; sourceTree = "<group>"; };
702246BD107FCA590079CD25 /* linked_list.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = linked_list.h; sourceTree = "<group>"; };
702246BE107FCA590079CD25 /* malloc_extension.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = malloc_extension.cc; sourceTree = "<group>"; };
- 702246BF107FCA590079CD25 /* malloc_hook-inl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "malloc_hook-inl.h"; sourceTree = "<group>"; };
- 702246C0107FCA590079CD25 /* malloc_hook.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = malloc_hook.cc; sourceTree = "<group>"; };
702246C1107FCA590079CD25 /* maybe_threads.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = maybe_threads.cc; sourceTree = "<group>"; };
702246C2107FCA590079CD25 /* maybe_threads.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = maybe_threads.h; sourceTree = "<group>"; };
702246C3107FCA590079CD25 /* memfs_malloc.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = memfs_malloc.cc; sourceTree = "<group>"; };
@@ -535,8 +532,6 @@
702247A4108621060079CD25 /* logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = logging.h; sourceTree = "<group>"; };
702247AD108621660079CD25 /* malloc_extension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = malloc_extension.h; sourceTree = "<group>"; };
702247BF108622430079CD25 /* stacktrace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stacktrace.h; sourceTree = "<group>"; };
- 702247C5108622980079CD25 /* malloc_hook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = malloc_hook.h; sourceTree = "<group>"; };
- 702247CE108622DB0079CD25 /* malloc_hook_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = malloc_hook_c.h; sourceTree = "<group>"; };
702247D51086236F0079CD25 /* cycleclock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cycleclock.h; sourceTree = "<group>"; };
702247D61086236F0079CD25 /* spinlock_linux-inl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "spinlock_linux-inl.h"; sourceTree = "<group>"; };
702247D71086236F0079CD25 /* spinlock_posix-inl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "spinlock_posix-inl.h"; sourceTree = "<group>"; };
@@ -1204,8 +1199,6 @@
702247D61086236F0079CD25 /* spinlock_linux-inl.h */,
702247D71086236F0079CD25 /* spinlock_posix-inl.h */,
702247D81086236F0079CD25 /* spinlock_win32-inl.h */,
- 702247CE108622DB0079CD25 /* malloc_hook_c.h */,
- 702247C5108622980079CD25 /* malloc_hook.h */,
702247BF108622430079CD25 /* stacktrace.h */,
702247AD108621660079CD25 /* malloc_extension.h */,
702247A4108621060079CD25 /* logging.h */,
@@ -1231,8 +1224,6 @@
702246BC107FCA590079CD25 /* internal_logging.h */,
702246BD107FCA590079CD25 /* linked_list.h */,
702246BE107FCA590079CD25 /* malloc_extension.cc */,
- 702246BF107FCA590079CD25 /* malloc_hook-inl.h */,
- 702246C0107FCA590079CD25 /* malloc_hook.cc */,
702246C1107FCA590079CD25 /* maybe_threads.cc */,
702246C2107FCA590079CD25 /* maybe_threads.h */,
702246C3107FCA590079CD25 /* memfs_malloc.cc */,
@@ -2291,7 +2282,6 @@
702246DE107FCA900079CD25 /* common.cc in Sources */,
702246DF107FCA900079CD25 /* internal_logging.cc in Sources */,
702246E0107FCA900079CD25 /* malloc_extension.cc in Sources */,
- 702246E1107FCA900079CD25 /* malloc_hook.cc in Sources */,
702246E2107FCA900079CD25 /* maybe_threads.cc in Sources */,
702246E3107FCA900079CD25 /* memfs_malloc.cc in Sources */,
702246E4107FCA900079CD25 /* page_heap.cc in Sources */,
Deleted: branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook-inl.h
===================================================================
--- branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook-inl.h 2009-10-14 15:52:40 UTC (rev 3472)
+++ branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook-inl.h 2009-10-14 16:29:23 UTC (rev 3473)
@@ -1,188 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat
-//
-// This has the implementation details of malloc_hook that are needed
-// to use malloc-hook inside the tcmalloc system. It does not hold
-// any of the client-facing calls that are used to add new hooks.
-
-#ifndef _MALLOC_HOOK_INL_H_
-#define _MALLOC_HOOK_INL_H_
-
-#include <stddef.h>
-#include <sys/types.h>
-#include "atomicops.h"
-#include "basictypes.h"
-#include "malloc_hook.h"
-
-namespace base { namespace internal {
-
-// A simple atomic pointer class that can be initialized by the linker
-// when you define a namespace-scope variable as:
-//
-// AtomicPtr<Foo*> my_global = { &initial_value };
-//
-// This isn't suitable for a general atomic<> class because of the
-// public access to data_.
-template<typename PtrT>
-class AtomicPtr {
- public:
- COMPILE_ASSERT(sizeof(PtrT) <= sizeof(AtomicWord),
- PtrT_should_fit_in_AtomicWord);
-
- PtrT Get() const {
- // Depending on the system, Acquire_Load(AtomicWord*) may have
- // been defined to return an AtomicWord, Atomic32, or Atomic64.
- // We hide that implementation detail here with an explicit cast.
- // This prevents MSVC 2005, at least, from complaining (it has to
- // do with __wp64; AtomicWord is __wp64, but Atomic32/64 aren't).
- return reinterpret_cast<PtrT>(static_cast<AtomicWord>(
- base::subtle::Acquire_Load(&data_)));
- }
-
- // Sets the contained value to new_val and returns the old value,
- // atomically, with acquire and release semantics.
- PtrT Exchange(PtrT new_val);
-
- // Not private so that the class is an aggregate and can be
- // initialized by the linker. Don't access this directly.
- AtomicWord data_;
-};
-
-// These are initialized in malloc_hook.cc
-extern AtomicPtr<MallocHook::NewHook> new_hook_;
-extern AtomicPtr<MallocHook::DeleteHook> delete_hook_;
-extern AtomicPtr<MallocHook::PreMmapHook> premmap_hook_;
-extern AtomicPtr<MallocHook::MmapHook> mmap_hook_;
-extern AtomicPtr<MallocHook::MunmapHook> munmap_hook_;
-extern AtomicPtr<MallocHook::MremapHook> mremap_hook_;
-extern AtomicPtr<MallocHook::PreSbrkHook> presbrk_hook_;
-extern AtomicPtr<MallocHook::SbrkHook> sbrk_hook_;
-
-} } // namespace base::internal
-
-inline MallocHook::NewHook MallocHook::GetNewHook() {
- return base::internal::new_hook_.Get();
-}
-
-inline void MallocHook::InvokeNewHook(const void* p, size_t s) {
- MallocHook::NewHook hook = MallocHook::GetNewHook();
- if (hook != NULL) (*hook)(p, s);
-}
-
-inline MallocHook::DeleteHook MallocHook::GetDeleteHook() {
- return base::internal::delete_hook_.Get();
-}
-
-inline void MallocHook::InvokeDeleteHook(const void* p) {
- MallocHook::DeleteHook hook = MallocHook::GetDeleteHook();
- if (hook != NULL) (*hook)(p);
-}
-
-inline MallocHook::PreMmapHook MallocHook::GetPreMmapHook() {
- return base::internal::premmap_hook_.Get();
-}
-
-inline void MallocHook::InvokePreMmapHook(const void* start,
- size_t size,
- int protection,
- int flags,
- int fd,
- off_t offset) {
- MallocHook::PreMmapHook hook = MallocHook::GetPreMmapHook();
- if (hook != NULL) (*hook)(start, size,
- protection, flags,
- fd, offset);
-}
-
-inline MallocHook::MmapHook MallocHook::GetMmapHook() {
- return base::internal::mmap_hook_.Get();
-}
-
-inline void MallocHook::InvokeMmapHook(const void* result,
- const void* start,
- size_t size,
- int protection,
- int flags,
- int fd,
- off_t offset) {
- MallocHook::MmapHook hook = MallocHook::GetMmapHook();
- if (hook != NULL) (*hook)(result,
- start, size,
- protection, flags,
- fd, offset);
-}
-
-inline MallocHook::MunmapHook MallocHook::GetMunmapHook() {
- return base::internal::munmap_hook_.Get();
-}
-
-inline void MallocHook::InvokeMunmapHook(const void* p, size_t size) {
- MallocHook::MunmapHook hook = MallocHook::GetMunmapHook();
- if (hook != NULL) (*hook)(p, size);
-}
-
-inline MallocHook::MremapHook MallocHook::GetMremapHook() {
- return base::internal::mremap_hook_.Get();
-}
-
-inline void MallocHook::InvokeMremapHook(const void* result,
- const void* old_addr,
- size_t old_size,
- size_t new_size,
- int flags,
- const void* new_addr) {
- MallocHook::MremapHook hook = MallocHook::GetMremapHook();
- if (hook != NULL) (*hook)(result,
- old_addr, old_size,
- new_size, flags, new_addr);
-}
-
-inline MallocHook::PreSbrkHook MallocHook::GetPreSbrkHook() {
- return base::internal::presbrk_hook_.Get();
-}
-
-inline void MallocHook::InvokePreSbrkHook(ptrdiff_t increment) {
- MallocHook::PreSbrkHook hook = MallocHook::GetPreSbrkHook();
- if (hook != NULL && increment != 0) (*hook)(increment);
-}
-
-inline MallocHook::SbrkHook MallocHook::GetSbrkHook() {
- return base::internal::sbrk_hook_.Get();
-}
-
-inline void MallocHook::InvokeSbrkHook(const void* result,
- ptrdiff_t increment) {
- MallocHook::SbrkHook hook = MallocHook::GetSbrkHook();
- if (hook != NULL && increment != 0) (*hook)(result, increment);
-}
-
-#endif /* _MALLOC_HOOK_INL_H_ */
Deleted: branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook.cc
===================================================================
--- branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook.cc 2009-10-14 15:52:40 UTC (rev 3472)
+++ branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook.cc 2009-10-14 16:29:23 UTC (rev 3473)
@@ -1,504 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat <opensource at google.com>
-
-#include "tcmalloc-platform.h"
-
-// Disable the glibc prototype of mremap(), as older versions of the
-// system headers define this function with only four arguments,
-// whereas newer versions allow an optional fifth argument:
-#ifdef HAVE_MMAP
-# define mremap glibc_mremap
-# include <sys/mman.h>
-# undef mremap
-#endif
-
-#include <algorithm>
-#include "basictypes.h"
-#include "logging.h"
-#include "malloc_hook-inl.h"
-#include "malloc_hook.h"
-
-// This #ifdef should almost never be set. Set NO_TCMALLOC_SAMPLES if
-// you're porting to a system where you really can't get a stacktrace.
-#ifdef NO_TCMALLOC_SAMPLES
- // We use #define so code compiles even if you #include stacktrace.h somehow.
-# define GetStackTrace(stack, depth, skip) (0)
-#else
-# include "stacktrace.h"
-#endif
-
-// __THROW is defined in glibc systems. It means, counter-intuitively,
-// "This function will never throw an exception." It's an optional
-// optimization tool, but we may need to use it to match glibc prototypes.
-#ifndef __THROW // I guess we're not on a glibc system
-# define __THROW // __THROW is just an optimization, so ok to make it ""
-#endif
-
-using std::copy;
-
-
-// Declarations of three default weak hook functions, that can be overridden by
-// linking-in a strong definition (as heap-checker.cc does)
-//
-// These default hooks let some other library we link in
-// to define strong versions of InitialMallocHook_New, InitialMallocHook_MMap,
-// InitialMallocHook_PreMMap, InitialMallocHook_PreSbrk, and
-// InitialMallocHook_Sbrk to have a chance to hook into the very first
-// invocation of an allocation function call, mmap, or sbrk.
-//
-// These functions are declared here as weak, and defined later, rather than a
-// more straightforward simple weak definition, as a workround for an icc
-// compiler issue ((Intel reference 290819). This issue causes icc to resolve
-// weak symbols too early, at compile rather than link time. By declaring it
-// (weak) here, then defining it below after its use, we can avoid the problem.
-//
-ATTRIBUTE_WEAK
-extern void InitialMallocHook_New(const void* ptr, size_t size);
-
-ATTRIBUTE_WEAK
-extern void InitialMallocHook_PreMMap(const void* start,
- size_t size,
- int protection,
- int flags,
- int fd,
- off_t offset);
-
-ATTRIBUTE_WEAK
-extern void InitialMallocHook_MMap(const void* result,
- const void* start,
- size_t size,
- int protection,
- int flags,
- int fd,
- off_t offset);
-
-ATTRIBUTE_WEAK
-extern void InitialMallocHook_PreSbrk(ptrdiff_t increment);
-
-ATTRIBUTE_WEAK
-extern void InitialMallocHook_Sbrk(const void* result, ptrdiff_t increment);
-
-namespace base { namespace internal {
-template<typename PtrT>
-PtrT AtomicPtr<PtrT>::Exchange(PtrT new_val) {
- base::subtle::MemoryBarrier(); // Release semantics.
- // Depending on the system, NoBarrier_AtomicExchange(AtomicWord*)
- // may have been defined to return an AtomicWord, Atomic32, or
- // Atomic64. We hide that implementation detail here with an
- // explicit cast. This prevents MSVC 2005, at least, from complaining.
- PtrT old_val = reinterpret_cast<PtrT>(static_cast<AtomicWord>(
- base::subtle::NoBarrier_AtomicExchange(
- &data_,
- reinterpret_cast<AtomicWord>(new_val))));
- base::subtle::MemoryBarrier(); // And acquire semantics.
- return old_val;
-}
-
-AtomicPtr<MallocHook::NewHook> new_hook_ = {
- reinterpret_cast<AtomicWord>(InitialMallocHook_New) };
-AtomicPtr<MallocHook::DeleteHook> delete_hook_ = { 0 };
-AtomicPtr<MallocHook::PreMmapHook> premmap_hook_ = {
- reinterpret_cast<AtomicWord>(InitialMallocHook_PreMMap) };
-AtomicPtr<MallocHook::MmapHook> mmap_hook_ = {
- reinterpret_cast<AtomicWord>(InitialMallocHook_MMap) };
-AtomicPtr<MallocHook::MunmapHook> munmap_hook_ = { 0 };
-AtomicPtr<MallocHook::MremapHook> mremap_hook_ = { 0 };
-AtomicPtr<MallocHook::PreSbrkHook> presbrk_hook_ = {
- reinterpret_cast<AtomicWord>(InitialMallocHook_PreSbrk) };
-AtomicPtr<MallocHook::SbrkHook> sbrk_hook_ = {
- reinterpret_cast<AtomicWord>(InitialMallocHook_Sbrk) };
-
-} } // namespace base::internal
-
-using base::internal::new_hook_;
-using base::internal::delete_hook_;
-using base::internal::premmap_hook_;
-using base::internal::mmap_hook_;
-using base::internal::munmap_hook_;
-using base::internal::mremap_hook_;
-using base::internal::presbrk_hook_;
-using base::internal::sbrk_hook_;
-
-
-// These are available as C bindings as well as C++, hence their
-// definition outside the MallocHook class.
-extern "C"
-MallocHook_NewHook MallocHook_SetNewHook(MallocHook_NewHook hook) {
- return new_hook_.Exchange(hook);
-}
-
-extern "C"
-MallocHook_DeleteHook MallocHook_SetDeleteHook(MallocHook_DeleteHook hook) {
- return delete_hook_.Exchange(hook);
-}
-
-extern "C"
-MallocHook_PreMmapHook MallocHook_SetPreMmapHook(MallocHook_PreMmapHook hook) {
- return premmap_hook_.Exchange(hook);
-}
-
-extern "C"
-MallocHook_MmapHook MallocHook_SetMmapHook(MallocHook_MmapHook hook) {
- return mmap_hook_.Exchange(hook);
-}
-
-extern "C"
-MallocHook_MunmapHook MallocHook_SetMunmapHook(MallocHook_MunmapHook hook) {
- return munmap_hook_.Exchange(hook);
-}
-
-extern "C"
-MallocHook_MremapHook MallocHook_SetMremapHook(MallocHook_MremapHook hook) {
- return mremap_hook_.Exchange(hook);
-}
-
-extern "C"
-MallocHook_PreSbrkHook MallocHook_SetPreSbrkHook(MallocHook_PreSbrkHook hook) {
- return presbrk_hook_.Exchange(hook);
-}
-
-extern "C"
-MallocHook_SbrkHook MallocHook_SetSbrkHook(MallocHook_SbrkHook hook) {
- return sbrk_hook_.Exchange(hook);
-}
-
-
-// The definitions of weak default malloc hooks (New, MMap, and Sbrk)
-// that self deinstall on their first call. This is entirely for
-// efficiency: the default version of these functions will be called a
-// maximum of one time. If these functions were a no-op instead, they'd
-// be called every time, costing an extra function call per malloc.
-//
-// However, this 'delete self' isn't safe in general -- it's possible
-// that this function will be called via a daisy chain. That is,
-// someone else might do
-// old_hook = MallocHook::SetNewHook(&myhook);
-// void myhook(void* ptr, size_t size) {
-// do_my_stuff();
-// old_hook(ptr, size); // daisy-chain the hooks
-// }
-// If old_hook is InitialMallocHook_New(), then this is broken code! --
-// after the first run it'll deregister not only InitialMallocHook_New()
-// but also myhook. To protect against that, InitialMallocHook_New()
-// makes sure it's the 'top-level' hook before doing the deregistration.
-// This means the daisy-chain case will be less efficient because the
-// hook will be called, and do an if check, for every new. Alas.
-// TODO(csilvers): add support for removing a hook from the middle of a chain.
-
-void InitialMallocHook_New(const void* ptr, size_t size) {
- if (MallocHook::GetNewHook() == &InitialMallocHook_New)
- MallocHook::SetNewHook(NULL);
-}
-
-void InitialMallocHook_PreMMap(const void* start,
- size_t size,
- int protection,
- int flags,
- int fd,
- off_t offset) {
- if (MallocHook::GetPreMmapHook() == &InitialMallocHook_PreMMap)
- MallocHook::SetPreMmapHook(NULL);
-}
-
-void InitialMallocHook_MMap(const void* result,
- const void* start,
- size_t size,
- int protection,
- int flags,
- int fd,
- off_t offset) {
- if (MallocHook::GetMmapHook() == &InitialMallocHook_MMap)
- MallocHook::SetMmapHook(NULL);
-}
-
-void InitialMallocHook_PreSbrk(ptrdiff_t increment) {
- if (MallocHook::GetPreSbrkHook() == &InitialMallocHook_PreSbrk)
- MallocHook::SetPreSbrkHook(NULL);
-}
-
-void InitialMallocHook_Sbrk(const void* result, ptrdiff_t increment) {
- if (MallocHook::GetSbrkHook() == &InitialMallocHook_Sbrk)
- MallocHook::SetSbrkHook(NULL);
-}
-
-DEFINE_ATTRIBUTE_SECTION_VARS(google_malloc);
-DECLARE_ATTRIBUTE_SECTION_VARS(google_malloc);
- // actual functions are in debugallocation.cc or tcmalloc.cc
-DEFINE_ATTRIBUTE_SECTION_VARS(malloc_hook);
-DECLARE_ATTRIBUTE_SECTION_VARS(malloc_hook);
- // actual functions are in this file, malloc_hook.cc, and low_level_alloc.cc
-
-#define ADDR_IN_ATTRIBUTE_SECTION(addr, name) \
- (reinterpret_cast<uintptr_t>(ATTRIBUTE_SECTION_START(name)) <= \
- reinterpret_cast<uintptr_t>(addr) && \
- reinterpret_cast<uintptr_t>(addr) < \
- reinterpret_cast<uintptr_t>(ATTRIBUTE_SECTION_STOP(name)))
-
-// Return true iff 'caller' is a return address within a function
-// that calls one of our hooks via MallocHook:Invoke*.
-// A helper for GetCallerStackTrace.
-static inline bool InHookCaller(const void* caller) {
- return ADDR_IN_ATTRIBUTE_SECTION(caller, google_malloc) ||
- ADDR_IN_ATTRIBUTE_SECTION(caller, malloc_hook);
- // We can use one section for everything except tcmalloc_or_debug
- // due to its special linkage mode, which prevents merging of the sections.
-}
-
-#undef ADDR_IN_ATTRIBUTE_SECTION
-
-static bool checked_sections = false;
-
-static inline void CheckInHookCaller() {
- if (!checked_sections) {
- INIT_ATTRIBUTE_SECTION_VARS(google_malloc);
- if (ATTRIBUTE_SECTION_START(google_malloc) ==
- ATTRIBUTE_SECTION_STOP(google_malloc)) {
- RAW_LOG(ERROR, "google_malloc section is missing, "
- "thus InHookCaller is broken!");
- }
- INIT_ATTRIBUTE_SECTION_VARS(malloc_hook);
- if (ATTRIBUTE_SECTION_START(malloc_hook) ==
- ATTRIBUTE_SECTION_STOP(malloc_hook)) {
- RAW_LOG(ERROR, "malloc_hook section is missing, "
- "thus InHookCaller is broken!");
- }
- checked_sections = true;
- }
-}
-
-// We can improve behavior/compactness of this function
-// if we pass a generic test function (with a generic arg)
-// into the implementations for GetStackTrace instead of the skip_count.
-extern "C" int MallocHook_GetCallerStackTrace(void** result, int max_depth,
- int skip_count) {
-#if defined(NO_TCMALLOC_SAMPLES)
- return 0;
-#elif !defined(HAVE_ATTRIBUTE_SECTION_START)
- // Fall back to GetStackTrace and good old but fragile frame skip counts.
- // Note: this path is inaccurate when a hook is not called directly by an
- // allocation function but is daisy-chained through another hook,
- // search for MallocHook::(Get|Set|Invoke)* to find such cases.
- return GetStackTrace(result, max_depth, skip_count + int(DEBUG_MODE));
- // due to -foptimize-sibling-calls in opt mode
- // there's no need for extra frame skip here then
-#else
- CheckInHookCaller();
- // MallocHook caller determination via InHookCaller works, use it:
- static const int kMaxSkip = 32 + 6 + 3;
- // Constant tuned to do just one GetStackTrace call below in practice
- // and not get many frames that we don't actually need:
- // currently max passsed max_depth is 32,
- // max passed/needed skip_count is 6
- // and 3 is to account for some hook daisy chaining.
- static const int kStackSize = kMaxSkip + 1;
- void* stack[kStackSize];
- int depth = GetStackTrace(stack, kStackSize, 1); // skip this function frame
- if (depth == 0) // silenty propagate cases when GetStackTrace does not work
- return 0;
- for (int i = 0; i < depth; ++i) { // stack[0] is our immediate caller
- if (InHookCaller(stack[i])) {
- RAW_VLOG(4, "Found hooked allocator at %d: %p <- %p",
- i, stack[i], stack[i+1]);
- i += 1; // skip hook caller frame
- depth -= i; // correct depth
- if (depth > max_depth) depth = max_depth;
- copy(stack + i, stack + i + depth, result);
- if (depth < max_depth && depth + i == kStackSize) {
- // get frames for the missing depth
- depth +=
- GetStackTrace(result + depth, max_depth - depth, 1 + kStackSize);
- }
- return depth;
- }
- }
- RAW_LOG(WARNING, "Hooked allocator frame not found, returning empty trace");
- // If this happens try increasing kMaxSkip
- // or else something must be wrong with InHookCaller,
- // e.g. for every section used in InHookCaller
- // all functions in that section must be inside the same library.
- return 0;
-#endif
-}
-
-// On Linux/x86, we override mmap/munmap/mremap/sbrk
-// and provide support for calling the related hooks.
-//
-// We define mmap() and mmap64(), which somewhat reimplements libc's mmap
-// syscall stubs. Unfortunately libc only exports the stubs via weak symbols
-// (which we're overriding with our mmap64() and mmap() wrappers) so we can't
-// just call through to them.
-
-
-#if defined(__linux) && \
- (defined(__i386__) || defined(__x86_64__) || defined(__PPC__))
-#include <unistd.h>
-#include <syscall.h>
-#include <sys/mman.h>
-#include <errno.h>
-#include "linux_syscall_support.h"
-
-// The x86-32 case and the x86-64 case differ:
-// 32b has a mmap2() syscall, 64b does not.
-// 64b and 32b have different calling conventions for mmap().
-#if defined(__x86_64__) || defined(__PPC64__)
-
-static inline void* do_mmap64(void *start, size_t length,
- int prot, int flags,
- int fd, __off64_t offset) __THROW {
- return (void *)syscall(SYS_mmap, start, length, prot, flags, fd, offset);
-}
-
-#elif defined(__i386__) || defined(__PPC__)
-
-static inline void* do_mmap64(void *start, size_t length,
- int prot, int flags,
- int fd, __off64_t offset) __THROW {
- void *result;
-
- // Try mmap2() unless it's not supported
- static bool have_mmap2 = true;
- if (have_mmap2) {
- static int pagesize = 0;
- if (!pagesize) pagesize = getpagesize();
-
- // Check that the offset is page aligned
- if (offset & (pagesize - 1)) {
- result = MAP_FAILED;
- errno = EINVAL;
- goto out;
- }
-
- result = (void *)syscall(SYS_mmap2,
- start, length, prot, flags, fd, offset / pagesize);
- if (result != MAP_FAILED || errno != ENOSYS) goto out;
-
- // We don't have mmap2() after all - don't bother trying it in future
- have_mmap2 = false;
- }
-
- if (((off_t)offset) != offset) {
- // If we're trying to map a 64-bit offset, fail now since we don't
- // have 64-bit mmap() support.
- result = MAP_FAILED;
- errno = EINVAL;
- goto out;
- }
-
- {
- // Fall back to old 32-bit offset mmap() call
- // Old syscall interface cannot handle six args, so pass in an array
- int32 args[6] = { (int32) start, length, prot, flags, fd, (off_t) offset };
- result = (void *)syscall(SYS_mmap, args);
- }
- out:
- return result;
-}
-
-# endif
-
-// We use do_mmap64 abstraction to put MallocHook::InvokeMmapHook
-// calls right into mmap and mmap64, so that the stack frames in the caller's
-// stack are at the same offsets for all the calls of memory allocating
-// functions.
-
-// Put all callers of MallocHook::Invoke* in this module into
-// malloc_hook section,
-// so that MallocHook::GetCallerStackTrace can function accurately:
-
-// Make sure mmap doesn't get #define'd away by <sys/mman.h>
-#undef mmap
-
-extern "C" {
- void* mmap64(void *start, size_t length, int prot, int flags,
- int fd, __off64_t offset ) __THROW
- ATTRIBUTE_SECTION(malloc_hook);
- void* mmap(void *start, size_t length,int prot, int flags,
- int fd, off_t offset) __THROW
- ATTRIBUTE_SECTION(malloc_hook);
- int munmap(void* start, size_t length) __THROW
- ATTRIBUTE_SECTION(malloc_hook);
- void* mremap(void* old_addr, size_t old_size, size_t new_size,
- int flags, ...) __THROW
- ATTRIBUTE_SECTION(malloc_hook);
- void* sbrk(ptrdiff_t increment) __THROW
- ATTRIBUTE_SECTION(malloc_hook);
-}
-
-extern "C" void* mmap64(void *start, size_t length, int prot, int flags,
- int fd, __off64_t offset) __THROW {
- MallocHook::InvokePreMmapHook(start, length, prot, flags, fd, offset);
- void *result = do_mmap64(start, length, prot, flags, fd, offset);
- MallocHook::InvokeMmapHook(result, start, length, prot, flags, fd, offset);
- return result;
-}
-
-#if !defined(__USE_FILE_OFFSET64) || !defined(__REDIRECT_NTH)
-
-extern "C" void* mmap(void *start, size_t length, int prot, int flags,
- int fd, off_t offset) __THROW {
- MallocHook::InvokePreMmapHook(start, length, prot, flags, fd, offset);
- void *result = do_mmap64(start, length, prot, flags, fd,
- static_cast<size_t>(offset)); // avoid sign extension
- MallocHook::InvokeMmapHook(result, start, length, prot, flags, fd, offset);
- return result;
-}
-
-#endif
-
-extern "C" int munmap(void* start, size_t length) __THROW {
- MallocHook::InvokeMunmapHook(start, length);
- return syscall(SYS_munmap, start, length);
-}
-
-extern "C" void* mremap(void* old_addr, size_t old_size, size_t new_size,
- int flags, ...) __THROW {
- va_list ap;
- va_start(ap, flags);
- void *new_address = va_arg(ap, void *);
- va_end(ap);
- void* result = sys_mremap(old_addr, old_size, new_size, flags, new_address);
- MallocHook::InvokeMremapHook(result, old_addr, old_size, new_size, flags,
- new_address);
- return result;
-}
-
-// libc's version:
-extern "C" void* __sbrk(ptrdiff_t increment);
-
-extern "C" void* sbrk(ptrdiff_t increment) __THROW {
- MallocHook::InvokePreSbrkHook(increment);
- void *result = __sbrk(increment);
- MallocHook::InvokeSbrkHook(result, increment);
- return result;
-}
-
-#endif
Deleted: branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook.h
===================================================================
--- branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook.h 2009-10-14 15:52:40 UTC (rev 3472)
+++ branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook.h 2009-10-14 16:29:23 UTC (rev 3473)
@@ -1,196 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat
-//
-// Some of our malloc implementations can invoke the following hooks
-// whenever memory is allocated or deallocated. If the hooks are
-// NULL, they are not invoked. MallocHook is thread-safe, and things
-// you do before calling SetFooHook(MyHook) are visible to any
-// resulting calls to MyHook. Hooks must be thread-safe, and if you
-// write:
-//
-// MallocHook::NewHook old_new_hook_ = NULL;
-// ...
-// old_new_hook_ = MallocHook::SetNewHook(&MyNewHook);
-//
-// old_new_hook_ could still be NULL the first couple times MyNewHook
-// is called.
-//
-// One important user of these hooks is the heap profiler.
-//
-// CAVEAT: If you add new MallocHook::Invoke* calls (not for chaining hooks),
-// then those calls must be directly in the code of the (de)allocation
-// function that is provided to the user and that function must have
-// an ATTRIBUTE_SECTION(malloc_hook) attribute.
-//
-// Note: Get*Hook() and Invoke*Hook() functions are defined in
-// malloc_hook-inl.h. If you need to get or invoke a hook (which you
-// shouldn't unless you're part of tcmalloc), be sure to #include
-// malloc_hook-inl.h in addition to malloc_hook.h.
-//
-// NOTE FOR C USERS: If you want to use malloc_hook functionality from
-// a C program, #include malloc_hook_c.h instead of this file.
-//
-// TODO(csilvers): support a non-inlined function called
-// Assert*HookIs()? This is the context in which I normally see
-// Get*Hook() called in non-tcmalloc code.
-
-#ifndef _MALLOC_HOOK_H_
-#define _MALLOC_HOOK_H_
-
-#include <stddef.h>
-#include <sys/types.h>
-extern "C" {
-#include "malloc_hook_c.h" // a C version of the malloc_hook interface
-}
-
-// Annoying stuff for windows -- makes sure clients can import these functions
-#ifndef PERFTOOLS_DLL_DECL
-# ifdef _WIN32
-# define PERFTOOLS_DLL_DECL __declspec(dllimport)
-# else
-# define PERFTOOLS_DLL_DECL
-# endif
-#endif
-
-// Note: malloc_hook_c.h defines MallocHook_*Hook and
-// MallocHook_Set*Hook. The version of these inside the MallocHook
-// class are defined in terms of the malloc_hook_c version. See
-// malloc_hook_c.h for details of these types/functions.
-
-class PERFTOOLS_DLL_DECL MallocHook {
- public:
- // The NewHook is invoked whenever an object is allocated.
- // It may be passed NULL if the allocator returned NULL.
- typedef MallocHook_NewHook NewHook;
- inline static NewHook GetNewHook();
- inline static NewHook SetNewHook(NewHook hook) {
- return MallocHook_SetNewHook(hook);
- }
- inline static void InvokeNewHook(const void* p, size_t s);
-
- // The DeleteHook is invoked whenever an object is deallocated.
- // It may be passed NULL if the caller is trying to delete NULL.
- typedef MallocHook_DeleteHook DeleteHook;
- inline static DeleteHook GetDeleteHook();
- inline static DeleteHook SetDeleteHook(DeleteHook hook) {
- return MallocHook_SetDeleteHook(hook);
- }
- inline static void InvokeDeleteHook(const void* p);
-
- // The PreMmapHook is invoked with mmap or mmap64 arguments just
- // before the call is actually made. Such a hook may be useful
- // in memory limited contexts, to catch allocations that will exceed
- // a memory limit, and take outside actions to increase that limit.
- typedef MallocHook_PreMmapHook PreMmapHook;
- inline static PreMmapHook GetPreMmapHook();
- inline static PreMmapHook SetPreMmapHook(PreMmapHook hook) {
- return MallocHook_SetPreMmapHook(hook);
- }
- inline static void InvokePreMmapHook(const void* start,
- size_t size,
- int protection,
- int flags,
- int fd,
- off_t offset);
-
- // The MmapHook is invoked whenever a region of memory is mapped.
- // It may be passed MAP_FAILED if the mmap failed.
- typedef MallocHook_MmapHook MmapHook;
- inline static MmapHook GetMmapHook();
- inline static MmapHook SetMmapHook(MmapHook hook) {
- return MallocHook_SetMmapHook(hook);
- }
- inline static void InvokeMmapHook(const void* result,
- const void* start,
- size_t size,
- int protection,
- int flags,
- int fd,
- off_t offset);
-
- // The MunmapHook is invoked whenever a region of memory is unmapped.
- typedef MallocHook_MunmapHook MunmapHook;
- inline static MunmapHook GetMunmapHook();
- inline static MunmapHook SetMunmapHook(MunmapHook hook) {
- return MallocHook_SetMunmapHook(hook);
- }
- inline static void InvokeMunmapHook(const void* p, size_t size);
-
- // The MremapHook is invoked whenever a region of memory is remapped.
- typedef MallocHook_MremapHook MremapHook;
- inline static MremapHook GetMremapHook();
- inline static MremapHook SetMremapHook(MremapHook hook) {
- return MallocHook_SetMremapHook(hook);
- }
- inline static void InvokeMremapHook(const void* result,
- const void* old_addr,
- size_t old_size,
- size_t new_size,
- int flags,
- const void* new_addr);
-
- // The PreSbrkHook is invoked just before sbrk is called -- except when
- // the increment is 0. This is because sbrk(0) is often called
- // to get the top of the memory stack, and is not actually a
- // memory-allocation call. It may be useful in memory-limited contexts,
- // to catch allocations that will exceed the limit and take outside
- // actions to increase such a limit.
- typedef MallocHook_PreSbrkHook PreSbrkHook;
- inline static PreSbrkHook GetPreSbrkHook();
- inline static PreSbrkHook SetPreSbrkHook(PreSbrkHook hook) {
- return MallocHook_SetPreSbrkHook(hook);
- }
- inline static void InvokePreSbrkHook(ptrdiff_t increment);
-
- // The SbrkHook is invoked whenever sbrk is called -- except when
- // the increment is 0. This is because sbrk(0) is often called
- // to get the top of the memory stack, and is not actually a
- // memory-allocation call.
- typedef MallocHook_SbrkHook SbrkHook;
- inline static SbrkHook GetSbrkHook();
- inline static SbrkHook SetSbrkHook(SbrkHook hook) {
- return MallocHook_SetSbrkHook(hook);
- }
- inline static void InvokeSbrkHook(const void* result, ptrdiff_t increment);
-
- // Get the current stack trace. Try to skip all routines up to and
- // and including the caller of MallocHook::Invoke*.
- // Use "skip_count" (similarly to GetStackTrace from stacktrace.h)
- // as a hint about how many routines to skip if better information
- // is not available.
- inline static int GetCallerStackTrace(void** result, int max_depth,
- int skip_count) {
- return MallocHook_GetCallerStackTrace(result, max_depth, skip_count);
- }
-};
-
-#endif /* _MALLOC_HOOK_H_ */
Deleted: branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook_c.h
===================================================================
--- branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook_c.h 2009-10-14 15:52:40 UTC (rev 3472)
+++ branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/malloc_hook_c.h 2009-10-14 16:29:23 UTC (rev 3473)
@@ -1,93 +0,0 @@
-/* Copyright (c) 2008, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * --
- * Author: Craig Silverstein
- *
- * C shims for the C++ malloc_hook.h. See malloc_hook.h for details
- * on how to use these.
- */
-
-#ifndef _MALLOC_HOOK_C_H_
-#define _MALLOC_HOOK_C_H_
-
-#include <stddef.h>
-#include <sys/types.h>
-
-/* Get the current stack trace. Try to skip all routines up to and
- * and including the caller of MallocHook::Invoke*.
- * Use "skip_count" (similarly to GetStackTrace from stacktrace.h)
- * as a hint about how many routines to skip if better information
- * is not available.
- */
-int MallocHook_GetCallerStackTrace(void** result, int max_depth,
- int skip_count);
-
-
-typedef void (*MallocHook_NewHook)(const void* ptr, size_t size);
-MallocHook_NewHook MallocHook_SetNewHook(MallocHook_NewHook hook);
-
-typedef void (*MallocHook_DeleteHook)(const void* ptr);
-MallocHook_DeleteHook MallocHook_SetDeleteHook(MallocHook_DeleteHook hook);
-
-typedef void (*MallocHook_PreMmapHook)(const void *start,
- size_t size,
- int protection,
- int flags,
- int fd,
- off_t offset);
-MallocHook_PreMmapHook MallocHook_SetPreMmapHook(MallocHook_PreMmapHook hook);
-
-typedef void (*MallocHook_MmapHook)(const void* result,
- const void* start,
- size_t size,
- int protection,
- int flags,
- int fd,
- off_t offset);
-MallocHook_MmapHook MallocHook_SetMmapHook(MallocHook_MmapHook hook);
-
-typedef void (*MallocHook_MunmapHook)(const void* ptr, size_t size);
-MallocHook_MunmapHook MallocHook_SetMunmapHook(MallocHook_MunmapHook hook);
-
-typedef void (*MallocHook_MremapHook)(const void* result,
- const void* old_addr,
- size_t old_size,
- size_t new_size,
- int flags,
- const void* new_addr);
-MallocHook_MremapHook MallocHook_SetMremapHook(MallocHook_MremapHook hook);
-
-typedef void (*MallocHook_PreSbrkHook)(ptrdiff_t increment);
-MallocHook_PreSbrkHook MallocHook_SetPreSbrkHook(MallocHook_PreSbrkHook hook);
-
-typedef void (*MallocHook_SbrkHook)(const void* result, ptrdiff_t increment);
-MallocHook_SbrkHook MallocHook_SetSbrkHook(MallocHook_SbrkHook hook);
-
-#endif /* _MALLOC_HOOK_C_H_ */
Modified: branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/tcmalloc.cc
===================================================================
--- branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/tcmalloc.cc 2009-10-14 15:52:40 UTC (rev 3472)
+++ branches/tcmalloc-1.4/source/platform/tcmalloc-1.4/tcmalloc.cc 2009-10-14 16:29:23 UTC (rev 3473)
@@ -181,59 +181,6 @@
"disable reporting entirely.");
-// We already declared these functions in tcmalloc.h, but we have to
-// declare them again to give them an ATTRIBUTE_SECTION: we want to
-// put all callers of MallocHook::Invoke* in this module into
-// ATTRIBUTE_SECTION(google_malloc) section, so that
-// MallocHook::GetCallerStackTrace can function accurately.
-#ifndef _WIN32 // windows doesn't have attribute_section, so don't bother
-extern "C" {
- void* tc_malloc(size_t size) __THROW
- ATTRIBUTE_SECTION(google_malloc);
- void tc_free(void* ptr) __THROW
- ATTRIBUTE_SECTION(google_malloc);
- void* tc_realloc(void* ptr, size_t size) __THROW
- ATTRIBUTE_SECTION(google_malloc);
- void* tc_calloc(size_t nmemb, size_t size) __THROW
- ATTRIBUTE_SECTION(google_malloc);
- void tc_cfree(void* ptr) __THROW
- ATTRIBUTE_SECTION(google_malloc);
-
- void* tc_memalign(size_t __alignment, size_t __size) __THROW
- ATTRIBUTE_SECTION(google_malloc);
- int tc_posix_memalign(void** ptr, size_t align, size_t size) __THROW
- ATTRIBUTE_SECTION(google_malloc);
- void* tc_valloc(size_t __size) __THROW
- ATTRIBUTE_SECTION(google_malloc);
- void* tc_pvalloc(size_t __size) __THROW
- ATTRIBUTE_SECTION(google_malloc);
-
- void tc_malloc_stats(void) __THROW
- ATTRIBUTE_SECTION(google_malloc);
- int tc_mallopt(int cmd, int value) __THROW
- ATTRIBUTE_SECTION(google_malloc);
-#ifdef HAVE_STRUCT_MALLINFO // struct mallinfo isn't defined on freebsd
- struct mallinfo tc_mallinfo(void) __THROW
- ATTRIBUTE_SECTION(google_malloc);
-#endif
-
- void* tc_new(size_t size)
- ATTRIBUTE_SECTION(google_malloc);
- void tc_delete(void* p) __THROW
- ATTRIBUTE_SECTION(google_malloc);
- void* tc_newarray(size_t size)
- ATTRIBUTE_SECTION(google_malloc);
- void tc_deletearray(void* p) __THROW
- ATTRIBUTE_SECTION(google_malloc);
-
- // And the nothrow variants of these:
- void* tc_new_nothrow(size_t size, const std::nothrow_t&) __THROW
- ATTRIBUTE_SECTION(google_malloc);
- void* tc_newarray_nothrow(size_t size, const std::nothrow_t&) __THROW
- ATTRIBUTE_SECTION(google_malloc);
-} // extern "C"
-#endif // #ifndef _WIN32
-
// Override the libc functions to prefer our own instead. This comes
// first so code in tcmalloc.cc can use the overridden versions. One
// exception: in windows, by default, we patch our code into these
@@ -932,18 +879,13 @@
if (new_ptr == NULL) {
return NULL;
}
- MallocHook::InvokeNewHook(new_ptr, new_size);
memcpy(new_ptr, old_ptr, ((old_size < new_size) ? old_size : new_size));
- MallocHook::InvokeDeleteHook(old_ptr);
// We could use a variant of do_free() that leverages the fact
// that we already know the sizeclass of old_ptr. The benefit
// would be small, so don't bother.
do_free_with_callback(old_ptr, invalid_free_fn);
return new_ptr;
} else {
- // We still need to call hooks to report the updated size:
- MallocHook::InvokeDeleteHook(old_ptr);
- MallocHook::InvokeNewHook(old_ptr, new_size);
return old_ptr;
}
}
@@ -1138,32 +1080,20 @@
return TC_VERSION_STRING;
}
-// CAVEAT: The code structure below ensures that MallocHook methods are always
-// called from the stack frame of the invoked allocation function.
-// heap-checker.cc depends on this to start a stack trace from
-// the call to the (de)allocation function.
-
static int tc_new_mode = 0; // See tc_set_new_mode().
extern "C" PERFTOOLS_DLL_DECL void* tc_malloc(size_t size) __THROW {
- void* result = (tc_new_mode ? cpp_alloc(size, false) : do_malloc(size));
- MallocHook::InvokeNewHook(result, size);
- return result;
+ return (tc_new_mode ? cpp_alloc(size, false) : do_malloc(size));
}
extern "C" PERFTOOLS_DLL_DECL void tc_free(void* ptr) __THROW {
- MallocHook::InvokeDeleteHook(ptr);
do_free(ptr);
}
-extern "C" PERFTOOLS_DLL_DECL void* tc_calloc(size_t n,
- size_t elem_size) __THROW {
- void* result = do_calloc(n, elem_size);
- MallocHook::InvokeNewHook(result, n * elem_size);
- return result;
+extern "C" PERFTOOLS_DLL_DECL void* tc_calloc(size_t n, size_t elem_size) __THROW {
+ return do_calloc(n, elem_size);
}
extern "C" PERFTOOLS_DLL_DECL void tc_cfree(void* ptr) __THROW {
- MallocHook::InvokeDeleteHook(ptr);
do_free(ptr);
}
@@ -1171,11 +1101,9 @@
size_t new_size) __THROW {
if (old_ptr == NULL) {
void* result = do_malloc(new_size);
- MallocHook::InvokeNewHook(result, new_size);
return result;
}
if (new_size == 0) {
- MallocHook::InvokeDeleteHook(old_ptr);
do_free(old_ptr);
return NULL;
}
@@ -1183,60 +1111,34 @@
}
extern "C" PERFTOOLS_DLL_DECL void* tc_new(size_t size) {
- void* p = cpp_alloc(size, false);
- // We keep this next instruction out of cpp_alloc for a reason: when
- // it's in, and new just calls cpp_alloc, the optimizer may fold the
- // new call into cpp_alloc, which messes up our whole section-based
- // stacktracing (see ATTRIBUTE_SECTION, above). This ensures cpp_alloc
- // isn't the last thing this fn calls, and prevents the folding.
- MallocHook::InvokeNewHook(p, size);
- return p;
+ return cpp_alloc(size, false);
}
-extern "C" PERFTOOLS_DLL_DECL void* tc_new_nothrow(
- size_t size, const std::nothrow_t&) __THROW {
- void* p = cpp_alloc(size, true);
- MallocHook::InvokeNewHook(p, size);
- return p;
+extern "C" PERFTOOLS_DLL_DECL void* tc_new_nothrow(size_t size, const std::nothrow_t&) __THROW {
+ return cpp_alloc(size, true);
}
extern "C" PERFTOOLS_DLL_DECL void tc_delete(void* p) __THROW {
- MallocHook::InvokeDeleteHook(p);
do_free(p);
}
extern "C" PERFTOOLS_DLL_DECL void* tc_newarray(size_t size) {
- void* p = cpp_alloc(size, false);
- // We keep this next instruction out of cpp_alloc for a reason: when
- // it's in, and new just calls cpp_alloc, the optimizer may fold the
- // new call into cpp_alloc, which messes up our whole section-based
- // stacktracing (see ATTRIBUTE_SECTION, above). This ensures cpp_alloc
- // isn't the last thing this fn calls, and prevents the folding.
- MallocHook::InvokeNewHook(p, size);
- return p;
+ return cpp_alloc(size, false);
}
-extern "C" PERFTOOLS_DLL_DECL void* tc_newarray_nothrow(
- size_t size, const std::nothrow_t&) __THROW {
- void* p = cpp_alloc(size, true);
- MallocHook::InvokeNewHook(p, size);
- return p;
+extern "C" PERFTOOLS_DLL_DECL void* tc_newarray_nothrow(size_t size, const std::nothrow_t&) __THROW {
+ return cpp_alloc(size, true);
}
extern "C" PERFTOOLS_DLL_DECL void tc_deletearray(void* p) __THROW {
- MallocHook::InvokeDeleteHook(p);
do_free(p);
}
-extern "C" PERFTOOLS_DLL_DECL void* tc_memalign(size_t align,
- size_t size) __THROW {
- void* result = do_memalign(align, size);
- MallocHook::InvokeNewHook(result, size);
- return result;
+extern "C" PERFTOOLS_DLL_DECL void* tc_memalign(size_t align, size_t size) __THROW {
+ return do_memalign(align, size);
}
-extern "C" PERFTOOLS_DLL_DECL int tc_posix_memalign(
- void** result_ptr, size_t align, size_t size) __THROW {
+extern "C" PERFTOOLS_DLL_DECL int tc_posix_memalign(void** result_ptr, size_t align, size_t size) __THROW {
if (((align % sizeof(void*)) != 0) ||
((align & (align - 1)) != 0) ||
(align == 0)) {
@@ -1244,7 +1146,6 @@
}
void* result = do_memalign(align, size);
- MallocHook::InvokeNewHook(result, size);
if (result == NULL) {
return ENOMEM;
} else {
@@ -1258,9 +1159,7 @@
extern "C" PERFTOOLS_DLL_DECL void* tc_valloc(size_t size) __THROW {
// Allocate page-aligned object of length >= size bytes
if (pagesize == 0) pagesize = getpagesize();
- void* result = do_memalign(pagesize, size);
- MallocHook::InvokeNewHook(result, size);
- return result;
+ return do_memalign(pagesize, size);
}
extern "C" PERFTOOLS_DLL_DECL void* tc_pvalloc(size_t size) __THROW {
@@ -1270,9 +1169,7 @@
size = pagesize; // http://man.free4web.biz/man3/libmpatrol.3.html
}
size = (size + pagesize - 1) & ~(pagesize - 1);
- void* result = do_memalign(pagesize, size);
- MallocHook::InvokeNewHook(result, size);
- return result;
+ return do_memalign(pagesize, size);
}
extern "C" PERFTOOLS_DLL_DECL void tc_malloc_stats(void) __THROW {
@@ -1309,14 +1206,10 @@
// from the stack frame of the allocation function;
// heap-checker handles this special case explicitly.
#ifndef TCMALLOC_FOR_DEBUGALLOCATION
-static void *MemalignOverride(size_t align, size_t size, const void *caller)
- __THROW ATTRIBUTE_SECTION(google_malloc);
+static void *MemalignOverride(size_t align, size_t size, const void *caller) __THROW ATTRIBUTE_SECTION(google_malloc);
-static void *MemalignOverride(size_t align, size_t size, const void *caller)
- __THROW {
- void* result = do_memalign(align, size);
- MallocHook::InvokeNewHook(result, size);
- return result;
+static void *MemalignOverride(size_t align, size_t size, const void *caller) __THROW {
+ return do_memalign(align, size);
}
void *(*__memalign_hook)(size_t, size_t, const void *) = MemalignOverride;
#endif // #ifndef TCMALLOC_FOR_DEBUGALLOCATION
More information about the Avida-cvs
mailing list