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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 // memory-allocation call. It may be useful in memory-limited contexts, | 230 // memory-allocation call. It may be useful in memory-limited contexts, |
231 // to catch allocations that will exceed the limit and take outside | 231 // to catch allocations that will exceed the limit and take outside |
232 // actions to increase such a limit. | 232 // actions to increase such a limit. |
233 typedef MallocHook_PreSbrkHook PreSbrkHook; | 233 typedef MallocHook_PreSbrkHook PreSbrkHook; |
234 inline static bool AddPreSbrkHook(PreSbrkHook hook) { | 234 inline static bool AddPreSbrkHook(PreSbrkHook hook) { |
235 return MallocHook_AddPreSbrkHook(hook); | 235 return MallocHook_AddPreSbrkHook(hook); |
236 } | 236 } |
237 inline static bool RemovePreSbrkHook(PreSbrkHook hook) { | 237 inline static bool RemovePreSbrkHook(PreSbrkHook hook) { |
238 return MallocHook_RemovePreSbrkHook(hook); | 238 return MallocHook_RemovePreSbrkHook(hook); |
239 } | 239 } |
240 inline static void InvokePreSbrkHook(ptrdiff_t increment); | 240 inline static void InvokePreSbrkHook(std::ptrdiff_t increment); |
241 | 241 |
242 // The SbrkHook is invoked whenever sbrk is called -- except when | 242 // The SbrkHook is invoked whenever sbrk is called -- except when |
243 // the increment is 0. This is because sbrk(0) is often called | 243 // the increment is 0. This is because sbrk(0) is often called |
244 // to get the top of the memory stack, and is not actually a | 244 // to get the top of the memory stack, and is not actually a |
245 // memory-allocation call. | 245 // memory-allocation call. |
246 typedef MallocHook_SbrkHook SbrkHook; | 246 typedef MallocHook_SbrkHook SbrkHook; |
247 inline static bool AddSbrkHook(SbrkHook hook) { | 247 inline static bool AddSbrkHook(SbrkHook hook) { |
248 return MallocHook_AddSbrkHook(hook); | 248 return MallocHook_AddSbrkHook(hook); |
249 } | 249 } |
250 inline static bool RemoveSbrkHook(SbrkHook hook) { | 250 inline static bool RemoveSbrkHook(SbrkHook hook) { |
251 return MallocHook_RemoveSbrkHook(hook); | 251 return MallocHook_RemoveSbrkHook(hook); |
252 } | 252 } |
253 inline static void InvokeSbrkHook(const void* result, ptrdiff_t increment); | 253 inline static void InvokeSbrkHook(const void* result, std::ptrdiff_t increment
); |
254 | 254 |
255 // Get the current stack trace. Try to skip all routines up to and | 255 // Get the current stack trace. Try to skip all routines up to and |
256 // and including the caller of MallocHook::Invoke*. | 256 // and including the caller of MallocHook::Invoke*. |
257 // Use "skip_count" (similarly to GetStackTrace from stacktrace.h) | 257 // Use "skip_count" (similarly to GetStackTrace from stacktrace.h) |
258 // as a hint about how many routines to skip if better information | 258 // as a hint about how many routines to skip if better information |
259 // is not available. | 259 // is not available. |
260 inline static int GetCallerStackTrace(void** result, int max_depth, | 260 inline static int GetCallerStackTrace(void** result, int max_depth, |
261 int skip_count) { | 261 int skip_count) { |
262 return MallocHook_GetCallerStackTrace(result, max_depth, skip_count); | 262 return MallocHook_GetCallerStackTrace(result, max_depth, skip_count); |
263 } | 263 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 static void InvokeMunmapHookSlow(const void* p, size_t size); | 339 static void InvokeMunmapHookSlow(const void* p, size_t size); |
340 static bool InvokeMunmapReplacementSlow(const void* p, | 340 static bool InvokeMunmapReplacementSlow(const void* p, |
341 size_t size, | 341 size_t size, |
342 int* result); | 342 int* result); |
343 static void InvokeMremapHookSlow(const void* result, | 343 static void InvokeMremapHookSlow(const void* result, |
344 const void* old_addr, | 344 const void* old_addr, |
345 size_t old_size, | 345 size_t old_size, |
346 size_t new_size, | 346 size_t new_size, |
347 int flags, | 347 int flags, |
348 const void* new_addr); | 348 const void* new_addr); |
349 static void InvokePreSbrkHookSlow(ptrdiff_t increment); | 349 static void InvokePreSbrkHookSlow(std::ptrdiff_t increment); |
350 static void InvokeSbrkHookSlow(const void* result, ptrdiff_t increment); | 350 static void InvokeSbrkHookSlow(const void* result, std::ptrdiff_t increment); |
351 }; | 351 }; |
352 | 352 |
353 #ifdef _MSC_VER | 353 #ifdef _MSC_VER |
354 #pragma warning(pop) | 354 #pragma warning(pop) |
355 #endif | 355 #endif |
356 | 356 |
357 | 357 |
358 #endif /* _MALLOC_HOOK_H_ */ | 358 #endif /* _MALLOC_HOOK_H_ */ |
OLD | NEW |