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 |
(...skipping 22 matching lines...) Expand all Loading... |
33 * C shims for the C++ malloc_hook.h. See malloc_hook.h for details | 33 * C shims for the C++ malloc_hook.h. See malloc_hook.h for details |
34 * on how to use these. | 34 * on how to use these. |
35 */ | 35 */ |
36 | 36 |
37 #ifndef _MALLOC_HOOK_C_H_ | 37 #ifndef _MALLOC_HOOK_C_H_ |
38 #define _MALLOC_HOOK_C_H_ | 38 #define _MALLOC_HOOK_C_H_ |
39 | 39 |
40 #include <stddef.h> | 40 #include <stddef.h> |
41 #include <sys/types.h> | 41 #include <sys/types.h> |
42 | 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 |
43 /* Get the current stack trace. Try to skip all routines up to and | 56 /* Get the current stack trace. Try to skip all routines up to and |
44 * and including the caller of MallocHook::Invoke*. | 57 * and including the caller of MallocHook::Invoke*. |
45 * Use "skip_count" (similarly to GetStackTrace from stacktrace.h) | 58 * Use "skip_count" (similarly to GetStackTrace from stacktrace.h) |
46 * as a hint about how many routines to skip if better information | 59 * as a hint about how many routines to skip if better information |
47 * is not available. | 60 * is not available. |
48 */ | 61 */ |
| 62 PERFTOOLS_DLL_DECL |
49 int MallocHook_GetCallerStackTrace(void** result, int max_depth, | 63 int MallocHook_GetCallerStackTrace(void** result, int max_depth, |
50 int skip_count); | 64 int skip_count); |
51 | 65 |
| 66 /* The MallocHook_{Add,Remove}*Hook functions return 1 on success and 0 on |
| 67 * failure. |
| 68 */ |
52 | 69 |
53 typedef void (*MallocHook_NewHook)(const void* ptr, size_t size); | 70 typedef void (*MallocHook_NewHook)(const void* ptr, size_t size); |
54 MallocHook_NewHook MallocHook_SetNewHook(MallocHook_NewHook hook); | 71 PERFTOOLS_DLL_DECL |
| 72 int MallocHook_AddNewHook(MallocHook_NewHook hook); |
| 73 PERFTOOLS_DLL_DECL |
| 74 int MallocHook_RemoveNewHook(MallocHook_NewHook hook); |
55 | 75 |
56 typedef void (*MallocHook_DeleteHook)(const void* ptr); | 76 typedef void (*MallocHook_DeleteHook)(const void* ptr); |
57 MallocHook_DeleteHook MallocHook_SetDeleteHook(MallocHook_DeleteHook hook); | 77 PERFTOOLS_DLL_DECL |
| 78 int MallocHook_AddDeleteHook(MallocHook_DeleteHook hook); |
| 79 PERFTOOLS_DLL_DECL |
| 80 int MallocHook_RemoveDeleteHook(MallocHook_DeleteHook hook); |
58 | 81 |
59 typedef void (*MallocHook_PreMmapHook)(const void *start, | 82 typedef void (*MallocHook_PreMmapHook)(const void *start, |
60 size_t size, | 83 size_t size, |
61 int protection, | 84 int protection, |
62 int flags, | 85 int flags, |
63 int fd, | 86 int fd, |
64 off_t offset); | 87 off_t offset); |
65 MallocHook_PreMmapHook MallocHook_SetPreMmapHook(MallocHook_PreMmapHook hook); | 88 PERFTOOLS_DLL_DECL |
| 89 int MallocHook_AddPreMmapHook(MallocHook_PreMmapHook hook); |
| 90 PERFTOOLS_DLL_DECL |
| 91 int MallocHook_RemovePreMmapHook(MallocHook_PreMmapHook hook); |
66 | 92 |
67 typedef void (*MallocHook_MmapHook)(const void* result, | 93 typedef void (*MallocHook_MmapHook)(const void* result, |
68 const void* start, | 94 const void* start, |
69 size_t size, | 95 size_t size, |
70 int protection, | 96 int protection, |
71 int flags, | 97 int flags, |
72 int fd, | 98 int fd, |
73 off_t offset); | 99 off_t offset); |
74 MallocHook_MmapHook MallocHook_SetMmapHook(MallocHook_MmapHook hook); | 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); |
75 | 114 |
76 typedef void (*MallocHook_MunmapHook)(const void* ptr, size_t size); | 115 typedef void (*MallocHook_MunmapHook)(const void* ptr, size_t size); |
77 MallocHook_MunmapHook MallocHook_SetMunmapHook(MallocHook_MunmapHook hook); | 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); |
78 | 126 |
79 typedef void (*MallocHook_MremapHook)(const void* result, | 127 typedef void (*MallocHook_MremapHook)(const void* result, |
80 const void* old_addr, | 128 const void* old_addr, |
81 size_t old_size, | 129 size_t old_size, |
82 size_t new_size, | 130 size_t new_size, |
83 int flags, | 131 int flags, |
84 const void* new_addr); | 132 const void* new_addr); |
85 MallocHook_MremapHook MallocHook_SetMremapHook(MallocHook_MremapHook hook); | 133 PERFTOOLS_DLL_DECL |
| 134 int MallocHook_AddMremapHook(MallocHook_MremapHook hook); |
| 135 PERFTOOLS_DLL_DECL |
| 136 int MallocHook_RemoveMremapHook(MallocHook_MremapHook hook); |
86 | 137 |
87 typedef void (*MallocHook_PreSbrkHook)(std::ptrdiff_t increment); | 138 typedef void (*MallocHook_PreSbrkHook)(std::ptrdiff_t increment); |
88 MallocHook_PreSbrkHook MallocHook_SetPreSbrkHook(MallocHook_PreSbrkHook hook); | 139 PERFTOOLS_DLL_DECL |
| 140 int MallocHook_AddPreSbrkHook(MallocHook_PreSbrkHook hook); |
| 141 PERFTOOLS_DLL_DECL |
| 142 int MallocHook_RemovePreSbrkHook(MallocHook_PreSbrkHook hook); |
89 | 143 |
90 typedef void (*MallocHook_SbrkHook)(const void* result, std::ptrdiff_t increment
); | 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 |
91 MallocHook_SbrkHook MallocHook_SetSbrkHook(MallocHook_SbrkHook hook); | 166 MallocHook_SbrkHook MallocHook_SetSbrkHook(MallocHook_SbrkHook hook); |
| 167 /* End of DEPRECATED functions. */ |
| 168 |
| 169 #ifdef __cplusplus |
| 170 } // extern "C" |
| 171 #endif |
92 | 172 |
93 #endif /* _MALLOC_HOOK_C_H_ */ | 173 #endif /* _MALLOC_HOOK_C_H_ */ |
OLD | NEW |