Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 1 | #ifndef JEMALLOC_H_ |
| 2 | #define JEMALLOC_H_ |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
| 7 | /* Defined if __attribute__((...)) syntax is supported. */ |
| 8 | #define JEMALLOC_HAVE_ATTR |
| 9 | |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 10 | /* Defined if alloc_size attribute is supported. */ |
Christopher Ferris | 6c1bfbf | 2015-09-15 13:24:03 -0700 | [diff] [blame] | 11 | /* #undef JEMALLOC_HAVE_ATTR_ALLOC_SIZE */ |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 12 | |
| 13 | /* Defined if format(gnu_printf, ...) attribute is supported. */ |
Colin Cross | 7027478 | 2015-12-29 16:56:11 -0800 | [diff] [blame] | 14 | #if !defined(__clang__) |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 15 | #define JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF |
Colin Cross | 7027478 | 2015-12-29 16:56:11 -0800 | [diff] [blame] | 16 | #endif |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 17 | |
| 18 | /* Defined if format(printf, ...) attribute is supported. */ |
| 19 | #define JEMALLOC_HAVE_ATTR_FORMAT_PRINTF |
| 20 | |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 21 | /* |
| 22 | * Define overrides for non-standard allocator-related functions if they are |
| 23 | * present on the system. |
| 24 | */ |
| 25 | #define JEMALLOC_OVERRIDE_MEMALIGN |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 26 | #ifndef __LP64__ |
Christopher Ferris | bf9b018 | 2016-12-08 11:56:18 -0800 | [diff] [blame] | 27 | #define JEMALLOC_OVERRIDE_VALLOC |
Christopher Ferris | 96d58c8 | 2015-04-22 06:59:40 +0000 | [diff] [blame] | 28 | #endif |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | * At least Linux omits the "const" in: |
| 32 | * |
| 33 | * size_t malloc_usable_size(const void *ptr); |
| 34 | * |
| 35 | * Match the operating system's prototype. |
| 36 | */ |
| 37 | #define JEMALLOC_USABLE_SIZE_CONST const |
| 38 | |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 39 | /* |
| 40 | * If defined, specify throw() for the public function prototypes when compiling |
| 41 | * with C++. The only justification for this is to match the prototypes that |
| 42 | * glibc defines. |
| 43 | */ |
Christopher Ferris | bf9b018 | 2016-12-08 11:56:18 -0800 | [diff] [blame] | 44 | /* #undef JEMALLOC_USE_CXX_THROW */ |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 45 | |
Christopher Ferris | 473a185 | 2016-03-02 16:24:07 -0800 | [diff] [blame] | 46 | #ifdef _MSC_VER |
| 47 | # ifdef _WIN64 |
| 48 | # define LG_SIZEOF_PTR_WIN 3 |
| 49 | # else |
| 50 | # define LG_SIZEOF_PTR_WIN 2 |
| 51 | # endif |
| 52 | #endif |
| 53 | |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 54 | /* sizeof(void *) == 2^LG_SIZEOF_PTR. */ |
Christopher Ferris | 9ebe2ac | 2014-07-01 14:34:56 -0700 | [diff] [blame] | 55 | #ifdef __LP64__ |
| 56 | #define LG_SIZEOF_PTR 3 |
| 57 | #else |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 58 | #define LG_SIZEOF_PTR 2 |
Christopher Ferris | 9ebe2ac | 2014-07-01 14:34:56 -0700 | [diff] [blame] | 59 | #endif |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 60 | |
| 61 | /* |
| 62 | * Name mangling for public symbols is controlled by --with-mangling and |
| 63 | * --with-jemalloc-prefix. With default settings the je_ prefix is stripped by |
| 64 | * these macro definitions. |
| 65 | */ |
| 66 | #ifndef JEMALLOC_NO_RENAME |
| 67 | # define je_malloc_conf je_malloc_conf |
| 68 | # define je_malloc_message je_malloc_message |
| 69 | # define je_malloc je_malloc |
| 70 | # define je_calloc je_calloc |
| 71 | # define je_posix_memalign je_posix_memalign |
| 72 | # define je_aligned_alloc je_aligned_alloc |
| 73 | # define je_realloc je_realloc |
| 74 | # define je_free je_free |
| 75 | # define je_mallocx je_mallocx |
| 76 | # define je_rallocx je_rallocx |
| 77 | # define je_xallocx je_xallocx |
| 78 | # define je_sallocx je_sallocx |
| 79 | # define je_dallocx je_dallocx |
Christopher Ferris | 96d58c8 | 2015-04-22 06:59:40 +0000 | [diff] [blame] | 80 | # define je_sdallocx je_sdallocx |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 81 | # define je_nallocx je_nallocx |
| 82 | # define je_mallctl je_mallctl |
| 83 | # define je_mallctlnametomib je_mallctlnametomib |
| 84 | # define je_mallctlbymib je_mallctlbymib |
| 85 | # define je_malloc_stats_print je_malloc_stats_print |
| 86 | # define je_malloc_usable_size je_malloc_usable_size |
| 87 | # define je_memalign je_memalign |
| 88 | # define je_valloc je_valloc |
| 89 | #endif |
| 90 | |
Christopher Ferris | 96d58c8 | 2015-04-22 06:59:40 +0000 | [diff] [blame] | 91 | #include <stdlib.h> |
| 92 | #include <stdbool.h> |
| 93 | #include <stdint.h> |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 94 | #include <limits.h> |
| 95 | #include <strings.h> |
| 96 | |
Christopher Ferris | bf9b018 | 2016-12-08 11:56:18 -0800 | [diff] [blame] | 97 | #define JEMALLOC_VERSION "4.4.0-0-gf1f76357313e7dcad7262f17a48ff0a2e005fcdc" |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 98 | #define JEMALLOC_VERSION_MAJOR 4 |
Christopher Ferris | bf9b018 | 2016-12-08 11:56:18 -0800 | [diff] [blame] | 99 | #define JEMALLOC_VERSION_MINOR 4 |
| 100 | #define JEMALLOC_VERSION_BUGFIX 0 |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 101 | #define JEMALLOC_VERSION_NREV 0 |
Christopher Ferris | bf9b018 | 2016-12-08 11:56:18 -0800 | [diff] [blame] | 102 | #define JEMALLOC_VERSION_GID "f1f76357313e7dcad7262f17a48ff0a2e005fcdc" |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 103 | |
Christopher Ferris | 473a185 | 2016-03-02 16:24:07 -0800 | [diff] [blame] | 104 | # define MALLOCX_LG_ALIGN(la) ((int)(la)) |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 105 | # if LG_SIZEOF_PTR == 2 |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 106 | # define MALLOCX_ALIGN(a) ((int)(ffs((int)(a))-1)) |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 107 | # else |
| 108 | # define MALLOCX_ALIGN(a) \ |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 109 | ((int)(((size_t)(a) < (size_t)INT_MAX) ? ffs((int)(a))-1 : \ |
| 110 | ffs((int)(((size_t)(a))>>32))+31)) |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 111 | # endif |
| 112 | # define MALLOCX_ZERO ((int)0x40) |
Christopher Ferris | 96d58c8 | 2015-04-22 06:59:40 +0000 | [diff] [blame] | 113 | /* |
| 114 | * Bias tcache index bits so that 0 encodes "automatic tcache management", and 1 |
| 115 | * encodes MALLOCX_TCACHE_NONE. |
| 116 | */ |
| 117 | # define MALLOCX_TCACHE(tc) ((int)(((tc)+2) << 8)) |
| 118 | # define MALLOCX_TCACHE_NONE MALLOCX_TCACHE(-1) |
| 119 | /* |
| 120 | * Bias arena index bits so that 0 encodes "use an automatically chosen arena". |
| 121 | */ |
Christopher Ferris | 3545247 | 2016-06-14 14:28:47 -0700 | [diff] [blame] | 122 | # define MALLOCX_ARENA(a) ((((int)(a))+1) << 20) |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 123 | |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 124 | #if defined(__cplusplus) && defined(JEMALLOC_USE_CXX_THROW) |
| 125 | # define JEMALLOC_CXX_THROW throw() |
| 126 | #else |
| 127 | # define JEMALLOC_CXX_THROW |
| 128 | #endif |
| 129 | |
Christopher Ferris | fb1f094 | 2016-11-08 14:47:48 -0800 | [diff] [blame] | 130 | #if _MSC_VER |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 131 | # define JEMALLOC_ATTR(s) |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 132 | # define JEMALLOC_ALIGNED(s) __declspec(align(s)) |
| 133 | # define JEMALLOC_ALLOC_SIZE(s) |
| 134 | # define JEMALLOC_ALLOC_SIZE2(s1, s2) |
Christopher Ferris | 96d58c8 | 2015-04-22 06:59:40 +0000 | [diff] [blame] | 135 | # ifndef JEMALLOC_EXPORT |
| 136 | # ifdef DLLEXPORT |
| 137 | # define JEMALLOC_EXPORT __declspec(dllexport) |
| 138 | # else |
| 139 | # define JEMALLOC_EXPORT __declspec(dllimport) |
| 140 | # endif |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 141 | # endif |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 142 | # define JEMALLOC_FORMAT_PRINTF(s, i) |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 143 | # define JEMALLOC_NOINLINE __declspec(noinline) |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 144 | # ifdef __cplusplus |
| 145 | # define JEMALLOC_NOTHROW __declspec(nothrow) |
| 146 | # else |
| 147 | # define JEMALLOC_NOTHROW |
| 148 | # endif |
| 149 | # define JEMALLOC_SECTION(s) __declspec(allocate(s)) |
| 150 | # define JEMALLOC_RESTRICT_RETURN __declspec(restrict) |
| 151 | # if _MSC_VER >= 1900 && !defined(__EDG__) |
| 152 | # define JEMALLOC_ALLOCATOR __declspec(allocator) |
| 153 | # else |
| 154 | # define JEMALLOC_ALLOCATOR |
| 155 | # endif |
Christopher Ferris | ad6417c | 2016-02-01 10:59:37 -0800 | [diff] [blame] | 156 | #elif defined(JEMALLOC_HAVE_ATTR) |
| 157 | # define JEMALLOC_ATTR(s) __attribute__((s)) |
| 158 | # define JEMALLOC_ALIGNED(s) JEMALLOC_ATTR(aligned(s)) |
| 159 | # ifdef JEMALLOC_HAVE_ATTR_ALLOC_SIZE |
| 160 | # define JEMALLOC_ALLOC_SIZE(s) JEMALLOC_ATTR(alloc_size(s)) |
| 161 | # define JEMALLOC_ALLOC_SIZE2(s1, s2) JEMALLOC_ATTR(alloc_size(s1, s2)) |
| 162 | # else |
| 163 | # define JEMALLOC_ALLOC_SIZE(s) |
| 164 | # define JEMALLOC_ALLOC_SIZE2(s1, s2) |
| 165 | # endif |
| 166 | # ifndef JEMALLOC_EXPORT |
| 167 | # define JEMALLOC_EXPORT JEMALLOC_ATTR(visibility("default")) |
| 168 | # endif |
| 169 | # ifdef JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF |
| 170 | # define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(gnu_printf, s, i)) |
| 171 | # elif defined(JEMALLOC_HAVE_ATTR_FORMAT_PRINTF) |
| 172 | # define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(printf, s, i)) |
| 173 | # else |
| 174 | # define JEMALLOC_FORMAT_PRINTF(s, i) |
| 175 | # endif |
| 176 | # define JEMALLOC_NOINLINE JEMALLOC_ATTR(noinline) |
| 177 | # define JEMALLOC_NOTHROW JEMALLOC_ATTR(nothrow) |
| 178 | # define JEMALLOC_SECTION(s) JEMALLOC_ATTR(section(s)) |
| 179 | # define JEMALLOC_RESTRICT_RETURN |
| 180 | # define JEMALLOC_ALLOCATOR |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 181 | #else |
| 182 | # define JEMALLOC_ATTR(s) |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 183 | # define JEMALLOC_ALIGNED(s) |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 184 | # define JEMALLOC_ALLOC_SIZE(s) |
| 185 | # define JEMALLOC_ALLOC_SIZE2(s1, s2) |
| 186 | # define JEMALLOC_EXPORT |
| 187 | # define JEMALLOC_FORMAT_PRINTF(s, i) |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 188 | # define JEMALLOC_NOINLINE |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 189 | # define JEMALLOC_NOTHROW |
| 190 | # define JEMALLOC_SECTION(s) |
| 191 | # define JEMALLOC_RESTRICT_RETURN |
| 192 | # define JEMALLOC_ALLOCATOR |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 193 | #endif |
| 194 | |
| 195 | /* |
| 196 | * The je_ prefix on the following public symbol declarations is an artifact |
| 197 | * of namespace management, and should be omitted in application code unless |
| 198 | * JEMALLOC_NO_DEMANGLE is defined (see jemalloc_mangle.h). |
| 199 | */ |
| 200 | extern JEMALLOC_EXPORT const char *je_malloc_conf; |
| 201 | extern JEMALLOC_EXPORT void (*je_malloc_message)(void *cbopaque, |
| 202 | const char *s); |
| 203 | |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 204 | JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN |
| 205 | void JEMALLOC_NOTHROW *je_malloc(size_t size) |
| 206 | JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE(1); |
| 207 | JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN |
| 208 | void JEMALLOC_NOTHROW *je_calloc(size_t num, size_t size) |
| 209 | JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE2(1, 2); |
| 210 | JEMALLOC_EXPORT int JEMALLOC_NOTHROW je_posix_memalign(void **memptr, |
| 211 | size_t alignment, size_t size) JEMALLOC_CXX_THROW JEMALLOC_ATTR(nonnull(1)); |
| 212 | JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN |
| 213 | void JEMALLOC_NOTHROW *je_aligned_alloc(size_t alignment, |
| 214 | size_t size) JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc) |
| 215 | JEMALLOC_ALLOC_SIZE(2); |
| 216 | JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN |
| 217 | void JEMALLOC_NOTHROW *je_realloc(void *ptr, size_t size) |
| 218 | JEMALLOC_CXX_THROW JEMALLOC_ALLOC_SIZE(2); |
| 219 | JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_free(void *ptr) |
| 220 | JEMALLOC_CXX_THROW; |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 221 | |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 222 | JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN |
| 223 | void JEMALLOC_NOTHROW *je_mallocx(size_t size, int flags) |
| 224 | JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE(1); |
| 225 | JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN |
| 226 | void JEMALLOC_NOTHROW *je_rallocx(void *ptr, size_t size, |
| 227 | int flags) JEMALLOC_ALLOC_SIZE(2); |
| 228 | JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_xallocx(void *ptr, size_t size, |
| 229 | size_t extra, int flags); |
| 230 | JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_sallocx(const void *ptr, |
| 231 | int flags) JEMALLOC_ATTR(pure); |
| 232 | JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_dallocx(void *ptr, int flags); |
| 233 | JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_sdallocx(void *ptr, size_t size, |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 234 | int flags); |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 235 | JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_nallocx(size_t size, int flags) |
Christopher Ferris | 96d58c8 | 2015-04-22 06:59:40 +0000 | [diff] [blame] | 236 | JEMALLOC_ATTR(pure); |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 237 | |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 238 | JEMALLOC_EXPORT int JEMALLOC_NOTHROW je_mallctl(const char *name, |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 239 | void *oldp, size_t *oldlenp, void *newp, size_t newlen); |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 240 | JEMALLOC_EXPORT int JEMALLOC_NOTHROW je_mallctlnametomib(const char *name, |
| 241 | size_t *mibp, size_t *miblenp); |
| 242 | JEMALLOC_EXPORT int JEMALLOC_NOTHROW je_mallctlbymib(const size_t *mib, |
| 243 | size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen); |
| 244 | JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_malloc_stats_print( |
| 245 | void (*write_cb)(void *, const char *), void *je_cbopaque, |
| 246 | const char *opts); |
| 247 | JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_malloc_usable_size( |
| 248 | JEMALLOC_USABLE_SIZE_CONST void *ptr) JEMALLOC_CXX_THROW; |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 249 | |
| 250 | #ifdef JEMALLOC_OVERRIDE_MEMALIGN |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 251 | JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN |
| 252 | void JEMALLOC_NOTHROW *je_memalign(size_t alignment, size_t size) |
| 253 | JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc); |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 254 | #endif |
| 255 | |
| 256 | #ifdef JEMALLOC_OVERRIDE_VALLOC |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 257 | JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN |
| 258 | void JEMALLOC_NOTHROW *je_valloc(size_t size) JEMALLOC_CXX_THROW |
| 259 | JEMALLOC_ATTR(malloc); |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 260 | #endif |
| 261 | |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 262 | /* |
| 263 | * void * |
| 264 | * chunk_alloc(void *new_addr, size_t size, size_t alignment, bool *zero, |
| 265 | * bool *commit, unsigned arena_ind); |
| 266 | */ |
| 267 | typedef void *(chunk_alloc_t)(void *, size_t, size_t, bool *, bool *, unsigned); |
| 268 | |
| 269 | /* |
| 270 | * bool |
| 271 | * chunk_dalloc(void *chunk, size_t size, bool committed, unsigned arena_ind); |
| 272 | */ |
| 273 | typedef bool (chunk_dalloc_t)(void *, size_t, bool, unsigned); |
| 274 | |
| 275 | /* |
| 276 | * bool |
| 277 | * chunk_commit(void *chunk, size_t size, size_t offset, size_t length, |
| 278 | * unsigned arena_ind); |
| 279 | */ |
| 280 | typedef bool (chunk_commit_t)(void *, size_t, size_t, size_t, unsigned); |
| 281 | |
| 282 | /* |
| 283 | * bool |
| 284 | * chunk_decommit(void *chunk, size_t size, size_t offset, size_t length, |
| 285 | * unsigned arena_ind); |
| 286 | */ |
| 287 | typedef bool (chunk_decommit_t)(void *, size_t, size_t, size_t, unsigned); |
| 288 | |
| 289 | /* |
| 290 | * bool |
| 291 | * chunk_purge(void *chunk, size_t size, size_t offset, size_t length, |
| 292 | * unsigned arena_ind); |
| 293 | */ |
| 294 | typedef bool (chunk_purge_t)(void *, size_t, size_t, size_t, unsigned); |
| 295 | |
| 296 | /* |
| 297 | * bool |
| 298 | * chunk_split(void *chunk, size_t size, size_t size_a, size_t size_b, |
| 299 | * bool committed, unsigned arena_ind); |
| 300 | */ |
| 301 | typedef bool (chunk_split_t)(void *, size_t, size_t, size_t, bool, unsigned); |
| 302 | |
| 303 | /* |
| 304 | * bool |
| 305 | * chunk_merge(void *chunk_a, size_t size_a, void *chunk_b, size_t size_b, |
| 306 | * bool committed, unsigned arena_ind); |
| 307 | */ |
| 308 | typedef bool (chunk_merge_t)(void *, size_t, void *, size_t, bool, unsigned); |
| 309 | |
| 310 | typedef struct { |
| 311 | chunk_alloc_t *alloc; |
| 312 | chunk_dalloc_t *dalloc; |
| 313 | chunk_commit_t *commit; |
| 314 | chunk_decommit_t *decommit; |
| 315 | chunk_purge_t *purge; |
| 316 | chunk_split_t *split; |
| 317 | chunk_merge_t *merge; |
| 318 | } chunk_hooks_t; |
Christopher Ferris | 9ebe2ac | 2014-07-01 14:34:56 -0700 | [diff] [blame] | 319 | |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 320 | /* |
| 321 | * By default application code must explicitly refer to mangled symbol names, |
| 322 | * so that it is possible to use jemalloc in conjunction with another allocator |
| 323 | * in the same application. Define JEMALLOC_MANGLE in order to cause automatic |
| 324 | * name mangling that matches the API prefixing that happened as a result of |
| 325 | * --with-mangling and/or --with-jemalloc-prefix configuration settings. |
| 326 | */ |
| 327 | #ifdef JEMALLOC_MANGLE |
| 328 | # ifndef JEMALLOC_NO_DEMANGLE |
| 329 | # define JEMALLOC_NO_DEMANGLE |
| 330 | # endif |
| 331 | # define malloc_conf je_malloc_conf |
| 332 | # define malloc_message je_malloc_message |
| 333 | # define malloc je_malloc |
| 334 | # define calloc je_calloc |
| 335 | # define posix_memalign je_posix_memalign |
| 336 | # define aligned_alloc je_aligned_alloc |
| 337 | # define realloc je_realloc |
| 338 | # define free je_free |
| 339 | # define mallocx je_mallocx |
| 340 | # define rallocx je_rallocx |
| 341 | # define xallocx je_xallocx |
| 342 | # define sallocx je_sallocx |
| 343 | # define dallocx je_dallocx |
Christopher Ferris | 96d58c8 | 2015-04-22 06:59:40 +0000 | [diff] [blame] | 344 | # define sdallocx je_sdallocx |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 345 | # define nallocx je_nallocx |
| 346 | # define mallctl je_mallctl |
| 347 | # define mallctlnametomib je_mallctlnametomib |
| 348 | # define mallctlbymib je_mallctlbymib |
| 349 | # define malloc_stats_print je_malloc_stats_print |
| 350 | # define malloc_usable_size je_malloc_usable_size |
| 351 | # define memalign je_memalign |
| 352 | # define valloc je_valloc |
| 353 | #endif |
| 354 | |
| 355 | /* |
| 356 | * The je_* macros can be used as stable alternative names for the |
| 357 | * public jemalloc API if JEMALLOC_NO_DEMANGLE is defined. This is primarily |
| 358 | * meant for use in jemalloc itself, but it can be used by application code to |
| 359 | * provide isolation from the name mangling specified via --with-mangling |
| 360 | * and/or --with-jemalloc-prefix. |
| 361 | */ |
| 362 | #ifndef JEMALLOC_NO_DEMANGLE |
| 363 | # undef je_malloc_conf |
| 364 | # undef je_malloc_message |
| 365 | # undef je_malloc |
| 366 | # undef je_calloc |
| 367 | # undef je_posix_memalign |
| 368 | # undef je_aligned_alloc |
| 369 | # undef je_realloc |
| 370 | # undef je_free |
| 371 | # undef je_mallocx |
| 372 | # undef je_rallocx |
| 373 | # undef je_xallocx |
| 374 | # undef je_sallocx |
| 375 | # undef je_dallocx |
Christopher Ferris | 96d58c8 | 2015-04-22 06:59:40 +0000 | [diff] [blame] | 376 | # undef je_sdallocx |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 377 | # undef je_nallocx |
| 378 | # undef je_mallctl |
| 379 | # undef je_mallctlnametomib |
| 380 | # undef je_mallctlbymib |
| 381 | # undef je_malloc_stats_print |
| 382 | # undef je_malloc_usable_size |
| 383 | # undef je_memalign |
| 384 | # undef je_valloc |
| 385 | #endif |
| 386 | |
| 387 | #ifdef __cplusplus |
Christopher Ferris | 6f50cbc | 2015-09-09 12:17:01 -0700 | [diff] [blame] | 388 | } |
Christopher Ferris | 5daf4e4 | 2014-04-22 18:52:58 -0700 | [diff] [blame] | 389 | #endif |
| 390 | #endif /* JEMALLOC_H_ */ |