| OLD | NEW |
| 1 /* Copyright (c) 2008, Google Inc. | 1 /* Copyright (c) 2008, 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 |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 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_hook.h. See malloc_hook.h for details | |
| 34 * on how to use these. | |
| 35 */ | 29 */ |
| 36 | 30 |
| 37 #ifndef _MALLOC_HOOK_C_H_ | 31 /* The code has moved to gperftools/. Use that include-directory for |
| 38 #define _MALLOC_HOOK_C_H_ | 32 * new code. |
| 39 | |
| 40 #include <stddef.h> | |
| 41 #include <sys/types.h> | |
| 42 | |
| 43 /* Annoying stuff for windows; makes sure clients can import these functions */ | |
| 44 #ifndef PERFTOOLS_DLL_DECL | |
| 45 # ifdef _WIN32 | |
| 46 # define PERFTOOLS_DLL_DECL __declspec(dllimport) | |
| 47 # else | |
| 48 # define PERFTOOLS_DLL_DECL | |
| 49 # endif | |
| 50 #endif | |
| 51 | |
| 52 #ifdef __cplusplus | |
| 53 extern "C" { | |
| 54 #endif | |
| 55 | |
| 56 /* Get the current stack trace. Try to skip all routines up to and | |
| 57 * and including the caller of MallocHook::Invoke*. | |
| 58 * Use "skip_count" (similarly to GetStackTrace from stacktrace.h) | |
| 59 * as a hint about how many routines to skip if better information | |
| 60 * is not available. | |
| 61 */ | 33 */ |
| 62 PERFTOOLS_DLL_DECL | 34 #include <gperftools/malloc_hook_c.h> |
| 63 int MallocHook_GetCallerStackTrace(void** result, int max_depth, | |
| 64 int skip_count); | |
| 65 | |
| 66 /* The MallocHook_{Add,Remove}*Hook functions return 1 on success and 0 on | |
| 67 * failure. | |
| 68 */ | |
| 69 | |
| 70 typedef void (*MallocHook_NewHook)(const void* ptr, size_t size); | |
| 71 PERFTOOLS_DLL_DECL | |
| 72 int MallocHook_AddNewHook(MallocHook_NewHook hook); | |
| 73 PERFTOOLS_DLL_DECL | |
| 74 int MallocHook_RemoveNewHook(MallocHook_NewHook hook); | |
| 75 | |
| 76 typedef void (*MallocHook_DeleteHook)(const void* ptr); | |
| 77 PERFTOOLS_DLL_DECL | |
| 78 int MallocHook_AddDeleteHook(MallocHook_DeleteHook hook); | |
| 79 PERFTOOLS_DLL_DECL | |
| 80 int MallocHook_RemoveDeleteHook(MallocHook_DeleteHook hook); | |
| 81 | |
| 82 typedef void (*MallocHook_PreMmapHook)(const void *start, | |
| 83 size_t size, | |
| 84 int protection, | |
| 85 int flags, | |
| 86 int fd, | |
| 87 off_t offset); | |
| 88 PERFTOOLS_DLL_DECL | |
| 89 int MallocHook_AddPreMmapHook(MallocHook_PreMmapHook hook); | |
| 90 PERFTOOLS_DLL_DECL | |
| 91 int MallocHook_RemovePreMmapHook(MallocHook_PreMmapHook hook); | |
| 92 | |
| 93 typedef void (*MallocHook_MmapHook)(const void* result, | |
| 94 const void* start, | |
| 95 size_t size, | |
| 96 int protection, | |
| 97 int flags, | |
| 98 int fd, | |
| 99 off_t offset); | |
| 100 PERFTOOLS_DLL_DECL | |
| 101 int MallocHook_AddMmapHook(MallocHook_MmapHook hook); | |
| 102 PERFTOOLS_DLL_DECL | |
| 103 int MallocHook_RemoveMmapHook(MallocHook_MmapHook hook); | |
| 104 | |
| 105 typedef int (*MallocHook_MmapReplacement)(const void* start, | |
| 106 size_t size, | |
| 107 int protection, | |
| 108 int flags, | |
| 109 int fd, | |
| 110 off_t offset, | |
| 111 void** result); | |
| 112 int MallocHook_SetMmapReplacement(MallocHook_MmapReplacement hook); | |
| 113 int MallocHook_RemoveMmapReplacement(MallocHook_MmapReplacement hook); | |
| 114 | |
| 115 typedef void (*MallocHook_MunmapHook)(const void* ptr, size_t size); | |
| 116 PERFTOOLS_DLL_DECL | |
| 117 int MallocHook_AddMunmapHook(MallocHook_MunmapHook hook); | |
| 118 PERFTOOLS_DLL_DECL | |
| 119 int MallocHook_RemoveMunmapHook(MallocHook_MunmapHook hook); | |
| 120 | |
| 121 typedef int (*MallocHook_MunmapReplacement)(const void* ptr, | |
| 122 size_t size, | |
| 123 int* result); | |
| 124 int MallocHook_SetMunmapReplacement(MallocHook_MunmapReplacement hook); | |
| 125 int MallocHook_RemoveMunmapReplacement(MallocHook_MunmapReplacement hook); | |
| 126 | |
| 127 typedef void (*MallocHook_MremapHook)(const void* result, | |
| 128 const void* old_addr, | |
| 129 size_t old_size, | |
| 130 size_t new_size, | |
| 131 int flags, | |
| 132 const void* new_addr); | |
| 133 PERFTOOLS_DLL_DECL | |
| 134 int MallocHook_AddMremapHook(MallocHook_MremapHook hook); | |
| 135 PERFTOOLS_DLL_DECL | |
| 136 int MallocHook_RemoveMremapHook(MallocHook_MremapHook hook); | |
| 137 | |
| 138 typedef void (*MallocHook_PreSbrkHook)(std::ptrdiff_t increment); | |
| 139 PERFTOOLS_DLL_DECL | |
| 140 int MallocHook_AddPreSbrkHook(MallocHook_PreSbrkHook hook); | |
| 141 PERFTOOLS_DLL_DECL | |
| 142 int MallocHook_RemovePreSbrkHook(MallocHook_PreSbrkHook hook); | |
| 143 | |
| 144 typedef void (*MallocHook_SbrkHook)(const void* result, std::ptrdiff_t increment
); | |
| 145 PERFTOOLS_DLL_DECL | |
| 146 int MallocHook_AddSbrkHook(MallocHook_SbrkHook hook); | |
| 147 PERFTOOLS_DLL_DECL | |
| 148 int MallocHook_RemoveSbrkHook(MallocHook_SbrkHook hook); | |
| 149 | |
| 150 /* The following are DEPRECATED. */ | |
| 151 PERFTOOLS_DLL_DECL | |
| 152 MallocHook_NewHook MallocHook_SetNewHook(MallocHook_NewHook hook); | |
| 153 PERFTOOLS_DLL_DECL | |
| 154 MallocHook_DeleteHook MallocHook_SetDeleteHook(MallocHook_DeleteHook hook); | |
| 155 PERFTOOLS_DLL_DECL | |
| 156 MallocHook_PreMmapHook MallocHook_SetPreMmapHook(MallocHook_PreMmapHook hook); | |
| 157 PERFTOOLS_DLL_DECL | |
| 158 MallocHook_MmapHook MallocHook_SetMmapHook(MallocHook_MmapHook hook); | |
| 159 PERFTOOLS_DLL_DECL | |
| 160 MallocHook_MunmapHook MallocHook_SetMunmapHook(MallocHook_MunmapHook hook); | |
| 161 PERFTOOLS_DLL_DECL | |
| 162 MallocHook_MremapHook MallocHook_SetMremapHook(MallocHook_MremapHook hook); | |
| 163 PERFTOOLS_DLL_DECL | |
| 164 MallocHook_PreSbrkHook MallocHook_SetPreSbrkHook(MallocHook_PreSbrkHook hook); | |
| 165 PERFTOOLS_DLL_DECL | |
| 166 MallocHook_SbrkHook MallocHook_SetSbrkHook(MallocHook_SbrkHook hook); | |
| 167 /* End of DEPRECATED functions. */ | |
| 168 | |
| 169 #ifdef __cplusplus | |
| 170 } // extern "C" | |
| 171 #endif | |
| 172 | |
| 173 #endif /* _MALLOC_HOOK_C_H_ */ | |
| OLD | NEW |