tcmalloc.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
  2. // Copyright (c) 2007, Google Inc.
  3. // All rights reserved.
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // ---
  31. // Author: Craig Silverstein <opensource@google.com>
  32. //
  33. // Some obscure memory-allocation routines may not be declared on all
  34. // systems. In those cases, we'll just declare them ourselves.
  35. // This file is meant to be used only internally, for unittests.
  36. #include <config.h>
  37. #ifndef _XOPEN_SOURCE
  38. # define _XOPEN_SOURCE 600 // for posix_memalign
  39. #endif
  40. #include <stdlib.h> // for posix_memalign
  41. // FreeBSD has malloc.h, but complains if you use it
  42. #if defined(HAVE_MALLOC_H) && !defined(__FreeBSD__)
  43. #include <malloc.h> // for memalign, valloc, pvalloc
  44. #endif
  45. // __THROW is defined in glibc systems. It means, counter-intuitively,
  46. // "This function will never throw an exception." It's an optional
  47. // optimization tool, but we may need to use it to match glibc prototypes.
  48. #ifndef __THROW // I guess we're not on a glibc system
  49. # define __THROW // __THROW is just an optimization, so ok to make it ""
  50. #endif
  51. #if !HAVE_CFREE_SYMBOL
  52. extern "C" void cfree(void* ptr) __THROW;
  53. #endif
  54. #if !HAVE_POSIX_MEMALIGN_SYMBOL
  55. extern "C" int posix_memalign(void** ptr, size_t align, size_t size) __THROW;
  56. #endif
  57. #if !HAVE_MEMALIGN_SYMBOL
  58. extern "C" void* memalign(size_t __alignment, size_t __size) __THROW;
  59. #endif
  60. #if !HAVE_VALLOC_SYMBOL
  61. extern "C" void* valloc(size_t __size) __THROW;
  62. #endif
  63. #if !HAVE_PVALLOC_SYMBOL
  64. extern "C" void* pvalloc(size_t __size) __THROW;
  65. #endif