blob: 51e40e3e4ed6357574241f35cc79b180b992fc96 [file] [log] [blame]
Brian Silvermana659aaa2022-01-02 00:19:11 -08001/* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */
Brian Silverman660d6092015-11-26 18:41:59 -05002/* Copyright (c) 2003, Google Inc.
3 * All rights reserved.
Brian Silverman20350ac2021-11-17 18:19:55 -08004 *
Brian Silverman660d6092015-11-26 18:41:59 -05005 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
Brian Silverman20350ac2021-11-17 18:19:55 -08008 *
Brian Silverman660d6092015-11-26 18:41:59 -05009 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
Brian Silverman20350ac2021-11-17 18:19:55 -080018 *
Brian Silverman660d6092015-11-26 18:41:59 -050019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * ---
32 * Author: Sanjay Ghemawat <opensource@google.com>
33 * .h file by Craig Silverstein <opensource@google.com>
34 */
35
36#ifndef TCMALLOC_TCMALLOC_H_
37#define TCMALLOC_TCMALLOC_H_
38
Brian Silverman20350ac2021-11-17 18:19:55 -080039#include <stddef.h> /* for size_t */
40#ifdef __cplusplus
41#include <new> /* for std::nothrow_t, std::align_val_t */
Brian Silverman660d6092015-11-26 18:41:59 -050042#endif
43
Brian Silverman20350ac2021-11-17 18:19:55 -080044/* Define the version number so folks can check against it */
Brian Silverman660d6092015-11-26 18:41:59 -050045#define TC_VERSION_MAJOR 2
Brian Silverman20350ac2021-11-17 18:19:55 -080046#define TC_VERSION_MINOR 9
47#define TC_VERSION_PATCH ".1"
48#define TC_VERSION_STRING "gperftools 2.9.1"
Brian Silverman660d6092015-11-26 18:41:59 -050049
Brian Silvermana659aaa2022-01-02 00:19:11 -080050/* For struct mallinfo, if it's defined. */
51#if 1
Brian Silverman660d6092015-11-26 18:41:59 -050052# include <malloc.h>
Brian Silvermana659aaa2022-01-02 00:19:11 -080053#endif
54
Brian Silverman20350ac2021-11-17 18:19:55 -080055#ifndef PERFTOOLS_NOTHROW
Austin Schuh745610d2015-09-06 18:19:50 -070056
Brian Silverman20350ac2021-11-17 18:19:55 -080057#if __cplusplus >= 201103L
58#define PERFTOOLS_NOTHROW noexcept
59#elif defined(__cplusplus)
60#define PERFTOOLS_NOTHROW throw()
61#else
62# ifdef __GNUC__
63# define PERFTOOLS_NOTHROW __attribute__((__nothrow__))
64# else
65# define PERFTOOLS_NOTHROW
Brian Silverman660d6092015-11-26 18:41:59 -050066# endif
67#endif
68
Brian Silverman20350ac2021-11-17 18:19:55 -080069#endif
70
Brian Silverman660d6092015-11-26 18:41:59 -050071#ifndef PERFTOOLS_DLL_DECL
72# ifdef _WIN32
73# define PERFTOOLS_DLL_DECL __declspec(dllimport)
74# else
75# define PERFTOOLS_DLL_DECL
76# endif
77#endif
78
79#ifdef __cplusplus
Brian Silverman660d6092015-11-26 18:41:59 -050080extern "C" {
81#endif
Brian Silverman20350ac2021-11-17 18:19:55 -080082 /*
83 * Returns a human-readable version string. If major, minor,
84 * and/or patch are not NULL, they are set to the major version,
85 * minor version, and patch-code (a string, usually "").
86 */
Brian Silverman660d6092015-11-26 18:41:59 -050087 PERFTOOLS_DLL_DECL const char* tc_version(int* major, int* minor,
Brian Silverman20350ac2021-11-17 18:19:55 -080088 const char** patch) PERFTOOLS_NOTHROW;
Brian Silverman660d6092015-11-26 18:41:59 -050089
Brian Silverman20350ac2021-11-17 18:19:55 -080090 PERFTOOLS_DLL_DECL void* tc_malloc(size_t size) PERFTOOLS_NOTHROW;
91 PERFTOOLS_DLL_DECL void* tc_malloc_skip_new_handler(size_t size) PERFTOOLS_NOTHROW;
92 PERFTOOLS_DLL_DECL void tc_free(void* ptr) PERFTOOLS_NOTHROW;
93 PERFTOOLS_DLL_DECL void tc_free_sized(void *ptr, size_t size) PERFTOOLS_NOTHROW;
94 PERFTOOLS_DLL_DECL void* tc_realloc(void* ptr, size_t size) PERFTOOLS_NOTHROW;
95 PERFTOOLS_DLL_DECL void* tc_calloc(size_t nmemb, size_t size) PERFTOOLS_NOTHROW;
96 PERFTOOLS_DLL_DECL void tc_cfree(void* ptr) PERFTOOLS_NOTHROW;
Brian Silverman660d6092015-11-26 18:41:59 -050097
98 PERFTOOLS_DLL_DECL void* tc_memalign(size_t __alignment,
Brian Silverman20350ac2021-11-17 18:19:55 -080099 size_t __size) PERFTOOLS_NOTHROW;
Brian Silverman660d6092015-11-26 18:41:59 -0500100 PERFTOOLS_DLL_DECL int tc_posix_memalign(void** ptr,
Brian Silverman20350ac2021-11-17 18:19:55 -0800101 size_t align, size_t size) PERFTOOLS_NOTHROW;
102 PERFTOOLS_DLL_DECL void* tc_valloc(size_t __size) PERFTOOLS_NOTHROW;
103 PERFTOOLS_DLL_DECL void* tc_pvalloc(size_t __size) PERFTOOLS_NOTHROW;
Brian Silverman660d6092015-11-26 18:41:59 -0500104
Brian Silverman20350ac2021-11-17 18:19:55 -0800105 PERFTOOLS_DLL_DECL void tc_malloc_stats(void) PERFTOOLS_NOTHROW;
106 PERFTOOLS_DLL_DECL int tc_mallopt(int cmd, int value) PERFTOOLS_NOTHROW;
Brian Silverman660d6092015-11-26 18:41:59 -0500107#if 1
Brian Silvermana659aaa2022-01-02 00:19:11 -0800108 PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) PERFTOOLS_NOTHROW;
Brian Silverman660d6092015-11-26 18:41:59 -0500109#endif
110
Brian Silverman20350ac2021-11-17 18:19:55 -0800111 /*
112 * This is an alias for MallocExtension::instance()->GetAllocatedSize().
113 * It is equivalent to
114 * OS X: malloc_size()
115 * glibc: malloc_usable_size()
116 * Windows: _msize()
117 */
118 PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) PERFTOOLS_NOTHROW;
Brian Silverman660d6092015-11-26 18:41:59 -0500119
120#ifdef __cplusplus
Brian Silverman20350ac2021-11-17 18:19:55 -0800121 PERFTOOLS_DLL_DECL int tc_set_new_mode(int flag) PERFTOOLS_NOTHROW;
Brian Silverman660d6092015-11-26 18:41:59 -0500122 PERFTOOLS_DLL_DECL void* tc_new(size_t size);
123 PERFTOOLS_DLL_DECL void* tc_new_nothrow(size_t size,
Brian Silverman20350ac2021-11-17 18:19:55 -0800124 const std::nothrow_t&) PERFTOOLS_NOTHROW;
125 PERFTOOLS_DLL_DECL void tc_delete(void* p) PERFTOOLS_NOTHROW;
126 PERFTOOLS_DLL_DECL void tc_delete_sized(void* p, size_t size) PERFTOOLS_NOTHROW;
Brian Silverman660d6092015-11-26 18:41:59 -0500127 PERFTOOLS_DLL_DECL void tc_delete_nothrow(void* p,
Brian Silverman20350ac2021-11-17 18:19:55 -0800128 const std::nothrow_t&) PERFTOOLS_NOTHROW;
Brian Silverman660d6092015-11-26 18:41:59 -0500129 PERFTOOLS_DLL_DECL void* tc_newarray(size_t size);
130 PERFTOOLS_DLL_DECL void* tc_newarray_nothrow(size_t size,
Brian Silverman20350ac2021-11-17 18:19:55 -0800131 const std::nothrow_t&) PERFTOOLS_NOTHROW;
132 PERFTOOLS_DLL_DECL void tc_deletearray(void* p) PERFTOOLS_NOTHROW;
133 PERFTOOLS_DLL_DECL void tc_deletearray_sized(void* p, size_t size) PERFTOOLS_NOTHROW;
Brian Silverman660d6092015-11-26 18:41:59 -0500134 PERFTOOLS_DLL_DECL void tc_deletearray_nothrow(void* p,
Brian Silverman20350ac2021-11-17 18:19:55 -0800135 const std::nothrow_t&) PERFTOOLS_NOTHROW;
136
Brian Silvermana659aaa2022-01-02 00:19:11 -0800137#if 1 && __cplusplus >= 201703L
Brian Silverman20350ac2021-11-17 18:19:55 -0800138 PERFTOOLS_DLL_DECL void* tc_new_aligned(size_t size, std::align_val_t al);
139 PERFTOOLS_DLL_DECL void* tc_new_aligned_nothrow(size_t size, std::align_val_t al,
140 const std::nothrow_t&) PERFTOOLS_NOTHROW;
141 PERFTOOLS_DLL_DECL void tc_delete_aligned(void* p, std::align_val_t al) PERFTOOLS_NOTHROW;
142 PERFTOOLS_DLL_DECL void tc_delete_sized_aligned(void* p, size_t size, std::align_val_t al) PERFTOOLS_NOTHROW;
143 PERFTOOLS_DLL_DECL void tc_delete_aligned_nothrow(void* p, std::align_val_t al,
144 const std::nothrow_t&) PERFTOOLS_NOTHROW;
145 PERFTOOLS_DLL_DECL void* tc_newarray_aligned(size_t size, std::align_val_t al);
146 PERFTOOLS_DLL_DECL void* tc_newarray_aligned_nothrow(size_t size, std::align_val_t al,
147 const std::nothrow_t&) PERFTOOLS_NOTHROW;
148 PERFTOOLS_DLL_DECL void tc_deletearray_aligned(void* p, std::align_val_t al) PERFTOOLS_NOTHROW;
149 PERFTOOLS_DLL_DECL void tc_deletearray_sized_aligned(void* p, size_t size, std::align_val_t al) PERFTOOLS_NOTHROW;
150 PERFTOOLS_DLL_DECL void tc_deletearray_aligned_nothrow(void* p, std::align_val_t al,
151 const std::nothrow_t&) PERFTOOLS_NOTHROW;
152#endif
Brian Silverman660d6092015-11-26 18:41:59 -0500153}
154#endif
155
Brian Silverman20350ac2021-11-17 18:19:55 -0800156/* We're only un-defining for public */
157#if !defined(GPERFTOOLS_CONFIG_H_)
158
159#undef PERFTOOLS_NOTHROW
160
161#endif /* GPERFTOOLS_CONFIG_H_ */
162
163#endif /* #ifndef TCMALLOC_TCMALLOC_H_ */