OLD | NEW |
1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // the increment is 0. This is because sbrk(0) is often called | 162 // the increment is 0. This is because sbrk(0) is often called |
163 // to get the top of the memory stack, and is not actually a | 163 // to get the top of the memory stack, and is not actually a |
164 // memory-allocation call. It may be useful in memory-limited contexts, | 164 // memory-allocation call. It may be useful in memory-limited contexts, |
165 // to catch allocations that will exceed the limit and take outside | 165 // to catch allocations that will exceed the limit and take outside |
166 // actions to increase such a limit. | 166 // actions to increase such a limit. |
167 typedef MallocHook_PreSbrkHook PreSbrkHook; | 167 typedef MallocHook_PreSbrkHook PreSbrkHook; |
168 inline static PreSbrkHook GetPreSbrkHook(); | 168 inline static PreSbrkHook GetPreSbrkHook(); |
169 inline static PreSbrkHook SetPreSbrkHook(PreSbrkHook hook) { | 169 inline static PreSbrkHook SetPreSbrkHook(PreSbrkHook hook) { |
170 return MallocHook_SetPreSbrkHook(hook); | 170 return MallocHook_SetPreSbrkHook(hook); |
171 } | 171 } |
172 inline static void InvokePreSbrkHook(ptrdiff_t increment); | 172 inline static void InvokePreSbrkHook(std::ptrdiff_t increment); |
173 | 173 |
174 // The SbrkHook is invoked whenever sbrk is called -- except when | 174 // The SbrkHook is invoked whenever sbrk is called -- except when |
175 // the increment is 0. This is because sbrk(0) is often called | 175 // the increment is 0. This is because sbrk(0) is often called |
176 // to get the top of the memory stack, and is not actually a | 176 // to get the top of the memory stack, and is not actually a |
177 // memory-allocation call. | 177 // memory-allocation call. |
178 typedef MallocHook_SbrkHook SbrkHook; | 178 typedef MallocHook_SbrkHook SbrkHook; |
179 inline static SbrkHook GetSbrkHook(); | 179 inline static SbrkHook GetSbrkHook(); |
180 inline static SbrkHook SetSbrkHook(SbrkHook hook) { | 180 inline static SbrkHook SetSbrkHook(SbrkHook hook) { |
181 return MallocHook_SetSbrkHook(hook); | 181 return MallocHook_SetSbrkHook(hook); |
182 } | 182 } |
183 inline static void InvokeSbrkHook(const void* result, ptrdiff_t increment); | 183 inline static void InvokeSbrkHook(const void* result, std::ptrdiff_t increment
); |
184 | 184 |
185 // Get the current stack trace. Try to skip all routines up to and | 185 // Get the current stack trace. Try to skip all routines up to and |
186 // and including the caller of MallocHook::Invoke*. | 186 // and including the caller of MallocHook::Invoke*. |
187 // Use "skip_count" (similarly to GetStackTrace from stacktrace.h) | 187 // Use "skip_count" (similarly to GetStackTrace from stacktrace.h) |
188 // as a hint about how many routines to skip if better information | 188 // as a hint about how many routines to skip if better information |
189 // is not available. | 189 // is not available. |
190 inline static int GetCallerStackTrace(void** result, int max_depth, | 190 inline static int GetCallerStackTrace(void** result, int max_depth, |
191 int skip_count) { | 191 int skip_count) { |
192 return MallocHook_GetCallerStackTrace(result, max_depth, skip_count); | 192 return MallocHook_GetCallerStackTrace(result, max_depth, skip_count); |
193 } | 193 } |
194 | 194 |
195 // Unhooked versions of mmap() and munmap(). These should be used | 195 // Unhooked versions of mmap() and munmap(). These should be used |
196 // only by experts, since they bypass heapchecking, etc. | 196 // only by experts, since they bypass heapchecking, etc. |
197 static void* UnhookedMMap(void *start, size_t length, int prot, int flags, | 197 static void* UnhookedMMap(void *start, size_t length, int prot, int flags, |
198 int fd, off_t offset); | 198 int fd, off_t offset); |
199 static int UnhookedMUnmap(void *start, size_t length); | 199 static int UnhookedMUnmap(void *start, size_t length); |
200 }; | 200 }; |
201 | 201 |
202 #endif /* _MALLOC_HOOK_H_ */ | 202 #endif /* _MALLOC_HOOK_H_ */ |
OLD | NEW |