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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // | 62 // |
63 // NOTE FOR C USERS: If you want to use malloc_hook functionality from | 63 // NOTE FOR C USERS: If you want to use malloc_hook functionality from |
64 // a C program, #include malloc_hook_c.h instead of this file. | 64 // a C program, #include malloc_hook_c.h instead of this file. |
65 | 65 |
66 #ifndef _MALLOC_HOOK_H_ | 66 #ifndef _MALLOC_HOOK_H_ |
67 #define _MALLOC_HOOK_H_ | 67 #define _MALLOC_HOOK_H_ |
68 | 68 |
69 #include <stddef.h> | 69 #include <stddef.h> |
70 #include <sys/types.h> | 70 #include <sys/types.h> |
71 extern "C" { | 71 extern "C" { |
72 #include <google/malloc_hook_c.h> // a C version of the malloc_hook interface | 72 #include <gperftools/malloc_hook_c.h> // a C version of the malloc_hook interfa
ce |
73 } | 73 } |
74 | 74 |
75 // Annoying stuff for windows -- makes sure clients can import these functions | 75 // Annoying stuff for windows -- makes sure clients can import these functions |
76 #ifndef PERFTOOLS_DLL_DECL | 76 #ifndef PERFTOOLS_DLL_DECL |
77 # ifdef _WIN32 | 77 # ifdef _WIN32 |
78 # define PERFTOOLS_DLL_DECL __declspec(dllimport) | 78 # define PERFTOOLS_DLL_DECL __declspec(dllimport) |
79 # else | 79 # else |
80 # define PERFTOOLS_DLL_DECL | 80 # define PERFTOOLS_DLL_DECL |
81 # endif | 81 # endif |
82 #endif | 82 #endif |
83 | 83 |
| 84 // The C++ methods below call the C version (MallocHook_*), and thus |
| 85 // convert between an int and a bool. Windows complains about this |
| 86 // (a "performance warning") which we don't care about, so we suppress. |
| 87 #ifdef _MSC_VER |
| 88 #pragma warning(push) |
| 89 #pragma warning(disable:4800) |
| 90 #endif |
| 91 |
84 // Note: malloc_hook_c.h defines MallocHook_*Hook and | 92 // Note: malloc_hook_c.h defines MallocHook_*Hook and |
85 // MallocHook_{Add,Remove}*Hook. The version of these inside the MallocHook | 93 // MallocHook_{Add,Remove}*Hook. The version of these inside the MallocHook |
86 // class are defined in terms of the malloc_hook_c version. See malloc_hook_c.h | 94 // class are defined in terms of the malloc_hook_c version. See malloc_hook_c.h |
87 // for details of these types/functions. | 95 // for details of these types/functions. |
88 | 96 |
89 class PERFTOOLS_DLL_DECL MallocHook { | 97 class PERFTOOLS_DLL_DECL MallocHook { |
90 public: | 98 public: |
91 // The NewHook is invoked whenever an object is allocated. | 99 // The NewHook is invoked whenever an object is allocated. |
92 // It may be passed NULL if the allocator returned NULL. | 100 // It may be passed NULL if the allocator returned NULL. |
93 typedef MallocHook_NewHook NewHook; | 101 typedef MallocHook_NewHook NewHook; |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 static void InvokeMremapHookSlow(const void* result, | 343 static void InvokeMremapHookSlow(const void* result, |
336 const void* old_addr, | 344 const void* old_addr, |
337 size_t old_size, | 345 size_t old_size, |
338 size_t new_size, | 346 size_t new_size, |
339 int flags, | 347 int flags, |
340 const void* new_addr); | 348 const void* new_addr); |
341 static void InvokePreSbrkHookSlow(std::ptrdiff_t increment); | 349 static void InvokePreSbrkHookSlow(std::ptrdiff_t increment); |
342 static void InvokeSbrkHookSlow(const void* result, std::ptrdiff_t increment); | 350 static void InvokeSbrkHookSlow(const void* result, std::ptrdiff_t increment); |
343 }; | 351 }; |
344 | 352 |
| 353 #ifdef _MSC_VER |
| 354 #pragma warning(pop) |
| 355 #endif |
| 356 |
| 357 |
345 #endif /* _MALLOC_HOOK_H_ */ | 358 #endif /* _MALLOC_HOOK_H_ */ |
OLD | NEW |