malloc_extension_c.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Copyright (c) 2008, Google Inc.
  2. * All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. * --
  31. * Author: Craig Silverstein
  32. *
  33. * C shims for the C++ malloc_extension.h. See malloc_extension.h for
  34. * details. Note these C shims always work on
  35. * MallocExtension::instance(); it is not possible to have more than
  36. * one MallocExtension object in C applications.
  37. */
  38. #ifndef _MALLOC_EXTENSION_C_H_
  39. #define _MALLOC_EXTENSION_C_H_
  40. #include <stddef.h>
  41. #include <sys/types.h>
  42. /* Annoying stuff for windows -- makes sure clients can import these fns */
  43. #ifndef PERFTOOLS_DLL_DECL
  44. # ifdef _WIN32
  45. # define PERFTOOLS_DLL_DECL __declspec(dllimport)
  46. # else
  47. # define PERFTOOLS_DLL_DECL
  48. # endif
  49. #endif
  50. #ifdef __cplusplus
  51. extern "C" {
  52. #endif
  53. #define kMallocExtensionHistogramSize 64
  54. PERFTOOLS_DLL_DECL int MallocExtension_VerifyAllMemory(void);
  55. PERFTOOLS_DLL_DECL int MallocExtension_VerifyNewMemory(const void* p);
  56. PERFTOOLS_DLL_DECL int MallocExtension_VerifyArrayNewMemory(const void* p);
  57. PERFTOOLS_DLL_DECL int MallocExtension_VerifyMallocMemory(const void* p);
  58. PERFTOOLS_DLL_DECL int MallocExtension_MallocMemoryStats(int* blocks, size_t* total,
  59. int histogram[kMallocExtensionHistogramSize]);
  60. PERFTOOLS_DLL_DECL void MallocExtension_GetStats(char* buffer, int buffer_length);
  61. /* TODO(csilvers): write a C version of these routines, that perhaps
  62. * takes a function ptr and a void *.
  63. */
  64. /* void MallocExtension_GetHeapSample(string* result); */
  65. /* void MallocExtension_GetHeapGrowthStacks(string* result); */
  66. PERFTOOLS_DLL_DECL int MallocExtension_GetNumericProperty(const char* property, size_t* value);
  67. PERFTOOLS_DLL_DECL int MallocExtension_SetNumericProperty(const char* property, size_t value);
  68. PERFTOOLS_DLL_DECL void MallocExtension_MarkThreadIdle(void);
  69. PERFTOOLS_DLL_DECL void MallocExtension_MarkThreadBusy(void);
  70. PERFTOOLS_DLL_DECL void MallocExtension_ReleaseToSystem(size_t num_bytes);
  71. PERFTOOLS_DLL_DECL void MallocExtension_ReleaseFreeMemory(void);
  72. PERFTOOLS_DLL_DECL size_t MallocExtension_GetEstimatedAllocatedSize(size_t size);
  73. PERFTOOLS_DLL_DECL size_t MallocExtension_GetAllocatedSize(const void* p);
  74. PERFTOOLS_DLL_DECL size_t MallocExtension_GetThreadCacheSize(void);
  75. PERFTOOLS_DLL_DECL void MallocExtension_MarkThreadTemporarilyIdle(void);
  76. /*
  77. * NOTE: These enum values MUST be kept in sync with the version in
  78. * malloc_extension.h
  79. */
  80. typedef enum {
  81. MallocExtension_kUnknownOwnership = 0,
  82. MallocExtension_kOwned,
  83. MallocExtension_kNotOwned
  84. } MallocExtension_Ownership;
  85. PERFTOOLS_DLL_DECL MallocExtension_Ownership MallocExtension_GetOwnership(const void* p);
  86. #ifdef __cplusplus
  87. } /* extern "C" */
  88. #endif
  89. #endif /* _MALLOC_EXTENSION_C_H_ */