OLD | NEW |
1 // Copyright (c) 2007, Google Inc. | 1 /* Copyright (c) 2003, 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 |
11 // copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 // in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 // distribution. | 13 * distribution. |
14 // * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 // contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 // this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 // | 17 * |
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 * |
| 30 * --- |
| 31 * Author: Sanjay Ghemawat <opensource@google.com> |
| 32 * .h file by Craig Silverstein <opensource@google.com> |
| 33 */ |
29 | 34 |
30 // --- | 35 #ifndef TCMALLOC_TCMALLOC_H_ |
31 // Author: Craig Silverstein <opensource@google.com> | 36 #define TCMALLOC_TCMALLOC_H_ |
32 // | |
33 // Some obscure memory-allocation routines may not be declared on all | |
34 // systems. In those cases, we'll just declare them ourselves. | |
35 // This file is meant to be used only internally, for unittests. | |
36 | 37 |
37 #include <config.h> | 38 #include <stddef.h> // for size_t |
38 | 39 #ifdef HAVE_SYS_CDEFS_H |
39 #ifndef _XOPEN_SOURCE | 40 #include <sys/cdefs.h> // where glibc defines __THROW |
40 # define _XOPEN_SOURCE 600 // for posix_memalign | |
41 #endif | |
42 #include <stdlib.h> // for posix_memalign | |
43 // FreeBSD has malloc.h, but complains if you use it | |
44 #if defined(HAVE_MALLOC_H) && !defined(__FreeBSD__) | |
45 #include <malloc.h> // for memalign, valloc, pvalloc | |
46 #endif | 41 #endif |
47 | 42 |
48 // __THROW is defined in glibc systems. It means, counter-intuitively, | 43 // __THROW is defined in glibc systems. It means, counter-intuitively, |
49 // "This function will never throw an exception." It's an optional | 44 // "This function will never throw an exception." It's an optional |
50 // optimization tool, but we may need to use it to match glibc prototypes. | 45 // optimization tool, but we may need to use it to match glibc prototypes. |
51 #ifndef __THROW // I guess we're not on a glibc system | 46 #ifndef __THROW /* I guess we're not on a glibc system */ |
52 # define __THROW // __THROW is just an optimization, so ok to make it "" | 47 # define __THROW /* __THROW is just an optimization, so ok to make it "" */ |
53 #endif | 48 #endif |
54 | 49 |
55 #if !HAVE_CFREE_SYMBOL | 50 // Define the version number so folks can check against it |
56 extern "C" void cfree(void* ptr) __THROW; | 51 #define TC_VERSION_MAJOR 1 |
| 52 #define TC_VERSION_MINOR 8 |
| 53 #define TC_VERSION_PATCH "" |
| 54 #define TC_VERSION_STRING "google-perftools 1.8" |
| 55 |
| 56 |
| 57 #include <stdlib.h> // for struct mallinfo, if it's defined |
| 58 |
| 59 // Annoying stuff for windows -- makes sure clients can import these functions |
| 60 #ifndef PERFTOOLS_DLL_DECL |
| 61 # ifdef _WIN32 |
| 62 # define PERFTOOLS_DLL_DECL __declspec(dllimport) |
| 63 # else |
| 64 # define PERFTOOLS_DLL_DECL |
| 65 # endif |
57 #endif | 66 #endif |
58 #if !HAVE_POSIX_MEMALIGN_SYMBOL | 67 |
59 extern "C" int posix_memalign(void** ptr, size_t align, size_t size) __THROW; | 68 #ifdef __cplusplus |
| 69 namespace std { |
| 70 struct nothrow_t; |
| 71 } |
| 72 |
| 73 extern "C" { |
60 #endif | 74 #endif |
61 #if !HAVE_MEMALIGN_SYMBOL | 75 // Returns a human-readable version string. If major, minor, |
62 extern "C" void* memalign(size_t __alignment, size_t __size) __THROW; | 76 // and/or patch are not NULL, they are set to the major version, |
| 77 // minor version, and patch-code (a string, usually ""). |
| 78 PERFTOOLS_DLL_DECL const char* tc_version(int* major, int* minor, |
| 79 const char** patch) __THROW; |
| 80 |
| 81 PERFTOOLS_DLL_DECL void* tc_malloc(size_t size) __THROW; |
| 82 PERFTOOLS_DLL_DECL void tc_free(void* ptr) __THROW; |
| 83 PERFTOOLS_DLL_DECL void* tc_realloc(void* ptr, size_t size) __THROW; |
| 84 PERFTOOLS_DLL_DECL void* tc_calloc(size_t nmemb, size_t size) __THROW; |
| 85 PERFTOOLS_DLL_DECL void tc_cfree(void* ptr) __THROW; |
| 86 |
| 87 PERFTOOLS_DLL_DECL void* tc_memalign(size_t __alignment, |
| 88 size_t __size) __THROW; |
| 89 PERFTOOLS_DLL_DECL int tc_posix_memalign(void** ptr, |
| 90 size_t align, size_t size) __THROW; |
| 91 PERFTOOLS_DLL_DECL void* tc_valloc(size_t __size) __THROW; |
| 92 PERFTOOLS_DLL_DECL void* tc_pvalloc(size_t __size) __THROW; |
| 93 |
| 94 PERFTOOLS_DLL_DECL void tc_malloc_stats(void) __THROW; |
| 95 PERFTOOLS_DLL_DECL int tc_mallopt(int cmd, int value) __THROW; |
| 96 #if HAVE_STRUCT_MALLINFO |
| 97 PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) __THROW; |
63 #endif | 98 #endif |
64 #if !HAVE_VALLOC_SYMBOL | 99 |
65 extern "C" void* valloc(size_t __size) __THROW; | 100 // This is an alias for MallocExtension::instance()->GetAllocatedSize(). |
| 101 // It is equivalent to |
| 102 // OS X: malloc_size() |
| 103 // glibc: malloc_usable_size() |
| 104 // Windows: _msize() |
| 105 PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW; |
| 106 |
| 107 #ifdef __cplusplus |
| 108 PERFTOOLS_DLL_DECL int tc_set_new_mode(int flag) __THROW; |
| 109 PERFTOOLS_DLL_DECL void* tc_new(size_t size); |
| 110 PERFTOOLS_DLL_DECL void* tc_new_nothrow(size_t size, |
| 111 const std::nothrow_t&) __THROW; |
| 112 PERFTOOLS_DLL_DECL void tc_delete(void* p) __THROW; |
| 113 PERFTOOLS_DLL_DECL void tc_delete_nothrow(void* p, |
| 114 const std::nothrow_t&) __THROW; |
| 115 PERFTOOLS_DLL_DECL void* tc_newarray(size_t size); |
| 116 PERFTOOLS_DLL_DECL void* tc_newarray_nothrow(size_t size, |
| 117 const std::nothrow_t&) __THROW; |
| 118 PERFTOOLS_DLL_DECL void tc_deletearray(void* p) __THROW; |
| 119 PERFTOOLS_DLL_DECL void tc_deletearray_nothrow(void* p, |
| 120 const std::nothrow_t&) __THROW; |
| 121 } |
66 #endif | 122 #endif |
67 #if !HAVE_PVALLOC_SYMBOL | 123 |
68 extern "C" void* pvalloc(size_t __size) __THROW; | 124 #endif // #ifndef TCMALLOC_TCMALLOC_H_ |
69 #endif | |
OLD | NEW |