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