1 #ifndef JEMALLOC_H_ 2 #define JEMALLOC_H_ 3 #pragma GCC system_header 4 5 /* Defined if __attribute__((...)) syntax is supported. */ 6 #define JEMALLOC_HAVE_ATTR 7 8 /* Defined if alloc_size attribute is supported. */ 9 #define JEMALLOC_HAVE_ATTR_ALLOC_SIZE 10 11 /* Defined if format_arg(...) attribute is supported. */ 12 #define JEMALLOC_HAVE_ATTR_FORMAT_ARG 13 14 /* Defined if format(gnu_printf, ...) attribute is supported. */ 15 #ifndef __clang__ 16 #define JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF 17 #endif 18 19 /* Defined if format(printf, ...) attribute is supported. */ 20 #define JEMALLOC_HAVE_ATTR_FORMAT_PRINTF 21 22 /* Defined if fallthrough attribute is supported. */ 23 #define JEMALLOC_HAVE_ATTR_FALLTHROUGH 24 25 /* Defined if cold attribute is supported. */ 26 #define JEMALLOC_HAVE_ATTR_COLD 27 28 /* Defined if deprecated attribute is supported. */ 29 #define JEMALLOC_HAVE_ATTR_DEPRECATED 30 31 /* 32 * Define overrides for non-standard allocator-related functions if they are 33 * present on the system. 34 */ 35 /* #undef JEMALLOC_OVERRIDE_MEMALIGN */ 36 #define JEMALLOC_OVERRIDE_VALLOC 37 /* #undef JEMALLOC_OVERRIDE_PVALLOC */ 38 39 /* 40 * At least Linux omits the "const" in: 41 * 42 * size_t malloc_usable_size(const void *ptr); 43 * 44 * Match the operating system's prototype. 45 */ 46 #define JEMALLOC_USABLE_SIZE_CONST const 47 48 /* 49 * If defined, specify throw() for the public function prototypes when compiling 50 * with C++. The only justification for this is to match the prototypes that 51 * glibc defines. 52 */ 53 /* #undef JEMALLOC_USE_CXX_THROW */ 54 55 /* 56 * If undefined, disables reading configuration from environment variable or file 57 */ 58 #define JEMALLOC_CONFIG_ENV 59 #define JEMALLOC_CONFIG_FILE 60 61 /* 62 * Whether throwing operator new aborts on OOM instead of throwing 63 * std::bad_alloc. This is always defined to either 0 or 1. 64 */ 65 /* #undef JEMALLOC_INFALLIBLE_NEW */ 66 #ifndef JEMALLOC_INFALLIBLE_NEW 67 # define JEMALLOC_INFALLIBLE_NEW 0 68 #endif 69 70 #ifdef _MSC_VER 71 # ifdef _WIN64 72 # define LG_SIZEOF_PTR_WIN 3 73 # else 74 # define LG_SIZEOF_PTR_WIN 2 75 # endif 76 #endif 77 78 /* sizeof(void *) == 2^LG_SIZEOF_PTR. */ 79 #ifdef _LP64 80 #define LG_SIZEOF_PTR 3 81 #else 82 #define LG_SIZEOF_PTR 2 83 #endif 84 85 /* 86 * Name mangling for public symbols is controlled by --with-mangling and 87 * --with-jemalloc-prefix. With default settings the je_ prefix is stripped by 88 * these macro definitions. 89 */ 90 #ifndef JEMALLOC_NO_RENAME 91 # define je_aligned_alloc aligned_alloc 92 # define je_calloc calloc 93 # define je_free free 94 # define je_malloc malloc 95 # define je_posix_memalign posix_memalign 96 # define je_realloc realloc 97 # define je_valloc valloc 98 99 # ifndef JEMALLOC_PROTECT_NOSTD 100 # define je_dallocx dallocx 101 # define je_free_sized free_sized 102 # define je_free_aligned_sized free_aligned_sized 103 # define je_mallctl mallctl 104 # define je_mallctlbymib mallctlbymib 105 # define je_mallctlnametomib mallctlnametomib 106 # define je_malloc_conf malloc_conf 107 # define je_malloc_conf_get malloc_conf_get 108 # define je_malloc_conf_set malloc_conf_set 109 # define je_malloc_message_get malloc_message_get 110 # define je_malloc_message_set malloc_message_set 111 # define je_malloc_conf_2_conf_harder malloc_conf_2_conf_harder 112 # define je_malloc_message malloc_message 113 # define je_malloc_stats_print malloc_stats_print 114 # define je_malloc_usable_size malloc_usable_size 115 # define je_mallocx mallocx 116 # define je_smallocx_7a34f18502e7b222724097cdcd499b437d189acc smallocx_7a34f18502e7b222724097cdcd499b437d189acc 117 # define je_nallocx nallocx 118 # define je_realloc realloc 119 # define je_sallocx sallocx 120 # define je_sdallocx sdallocx 121 # define je_xallocx xallocx 122 #else 123 # define je_dallocx __je_dallocx 124 # define je_free_sized __je_free_sized 125 # define je_free_aligned_sized __je_free_aligned_sized 126 # define je_mallctl __je_mallctl 127 # define je_mallctlbymib __je_mallctlbymib 128 # define je_mallctlnametomib __je_mallctlnametomib 129 # define je_malloc_conf __je_malloc_conf 130 # define je_malloc_conf_get __je_malloc_conf_get 131 # define je_malloc_conf_set __je_malloc_conf_set 132 # define je_malloc_conf_2_conf_harder __je_malloc_conf_2_conf_harder 133 # define je_malloc_message __je_malloc_message 134 # define je_malloc_message_get __je_malloc_message_get 135 # define je_malloc_message_set __je_malloc_message_set 136 # define je_malloc_stats_print __je_malloc_stats_print 137 # define je_malloc_usable_size __je_malloc_usable_size 138 # define je_mallocx __je_mallocx 139 # define je_smallocx_7a34f18502e7b222724097cdcd499b437d189acc smallocx_7a34f18502e7b222724097cdcd499b437d189acc 140 # define je_nallocx __je_nallocx 141 # define je_rallocx __je_rallocx 142 # define je_sallocx __je_sallocx 143 # define je_sdallocx __je_sdallocx 144 # define je_xallocx __je_xallocx 145 #endif 146 147 #include <stdlib.h> 148 #include <stdbool.h> 149 #include <stdint.h> 150 #include <limits.h> 151 #include <strings.h> 152 153 #define JEMALLOC_VERSION "5.4.0-0-g7a34f18502e7b222724097cdcd499b437d189acc" 154 #define JEMALLOC_VERSION_MAJOR 5 155 #define JEMALLOC_VERSION_MINOR 4 156 #define JEMALLOC_VERSION_BUGFIX 0 157 #define JEMALLOC_VERSION_NREV 0 158 #define JEMALLOC_VERSION_GID "7a34f18502e7b222724097cdcd499b437d189acc" 159 #define JEMALLOC_VERSION_GID_IDENT 7a34f18502e7b222724097cdcd499b437d189acc 160 161 #define MALLOCX_LG_ALIGN(la) ((int)(la)) 162 #if LG_SIZEOF_PTR == 2 163 # define MALLOCX_ALIGN(a) ((int)(ffs((int)(a))-1)) 164 #else 165 # define MALLOCX_ALIGN(a) \ 166 ((int)(((size_t)(a) < (size_t)INT_MAX) ? ffs((int)(a))-1 : \ 167 ffs((int)(((size_t)(a))>>32))+31)) 168 #endif 169 #define MALLOCX_ZERO ((int)0x40) 170 /* 171 * Bias tcache index bits so that 0 encodes "automatic tcache management", and 1 172 * encodes MALLOCX_TCACHE_NONE. 173 */ 174 #define MALLOCX_TCACHE(tc) ((int)(((tc)+2) << 8)) 175 #define MALLOCX_TCACHE_NONE MALLOCX_TCACHE(-1) 176 /* 177 * Bias arena index bits so that 0 encodes "use an automatically chosen arena". 178 */ 179 #define MALLOCX_ARENA(a) ((((int)(a))+1) << 20) 180 181 /* 182 * Use as arena index in "arena.<i>.{purge,decay,dss}" and 183 * "stats.arenas.<i>.*" mallctl interfaces to select all arenas. This 184 * definition is intentionally specified in raw decimal format to support 185 * cpp-based string concatenation, e.g. 186 * 187 * #define STRINGIFY_HELPER(x) #x 188 * #define STRINGIFY(x) STRINGIFY_HELPER(x) 189 * 190 * mallctl("arena." STRINGIFY(MALLCTL_ARENAS_ALL) ".purge", NULL, NULL, NULL, 191 * 0); 192 */ 193 #define MALLCTL_ARENAS_ALL 4096 194 /* 195 * Use as arena index in "stats.arenas.<i>.*" mallctl interfaces to select 196 * destroyed arenas. 197 */ 198 #define MALLCTL_ARENAS_DESTROYED 4097 199 200 #if defined(__cplusplus) && defined(JEMALLOC_USE_CXX_THROW) 201 # define JEMALLOC_CXX_THROW noexcept (true) 202 #else 203 # define JEMALLOC_CXX_THROW 204 #endif 205 206 #if defined(_MSC_VER) 207 # define JEMALLOC_ATTR(s) 208 # define JEMALLOC_ALIGNED(s) __declspec(align(s)) 209 # define JEMALLOC_ALLOC_SIZE(s) 210 # define JEMALLOC_ALLOC_SIZE2(s1, s2) 211 # ifndef JEMALLOC_EXPORT 212 # ifdef DLLEXPORT 213 # define JEMALLOC_EXPORT __declspec(dllexport) 214 # else 215 # define JEMALLOC_EXPORT __declspec(dllimport) 216 # endif 217 # endif 218 # define JEMALLOC_FORMAT_ARG(i) 219 # define JEMALLOC_FORMAT_PRINTF(s, i) 220 # define JEMALLOC_FALLTHROUGH 221 # define JEMALLOC_NOINLINE __declspec(noinline) 222 # ifdef __cplusplus 223 # define JEMALLOC_NOTHROW __declspec(nothrow) 224 # else 225 # define JEMALLOC_NOTHROW 226 # endif 227 # define JEMALLOC_SECTION(s) __declspec(allocate(s)) 228 # define JEMALLOC_RESTRICT_RETURN __declspec(restrict) 229 # if _MSC_VER >= 1900 && !defined(__EDG__) 230 # define JEMALLOC_ALLOCATOR __declspec(allocator) 231 # else 232 # define JEMALLOC_ALLOCATOR 233 # endif 234 # define JEMALLOC_COLD 235 # define JEMALLOC_WARN_ON_USAGE(warning_message) 236 #elif defined(JEMALLOC_HAVE_ATTR) 237 # define JEMALLOC_ATTR(s) __attribute__((s)) 238 # define JEMALLOC_ALIGNED(s) JEMALLOC_ATTR(aligned(s)) 239 # ifdef JEMALLOC_HAVE_ATTR_ALLOC_SIZE 240 # define JEMALLOC_ALLOC_SIZE(s) JEMALLOC_ATTR(alloc_size(s)) 241 # define JEMALLOC_ALLOC_SIZE2(s1, s2) JEMALLOC_ATTR(alloc_size(s1, s2)) 242 # else 243 # define JEMALLOC_ALLOC_SIZE(s) 244 # define JEMALLOC_ALLOC_SIZE2(s1, s2) 245 # endif 246 # ifndef JEMALLOC_EXPORT 247 # define JEMALLOC_EXPORT JEMALLOC_ATTR(visibility("default")) 248 # endif 249 # ifdef JEMALLOC_HAVE_ATTR_FORMAT_ARG 250 # define JEMALLOC_FORMAT_ARG(i) JEMALLOC_ATTR(__format_arg__(3)) 251 # else 252 # define JEMALLOC_FORMAT_ARG(i) 253 # endif 254 # ifdef JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF 255 # define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(gnu_printf, s, i)) 256 # elif defined(JEMALLOC_HAVE_ATTR_FORMAT_PRINTF) 257 # define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(printf, s, i)) 258 # else 259 # define JEMALLOC_FORMAT_PRINTF(s, i) 260 # endif 261 # ifdef JEMALLOC_HAVE_ATTR_FALLTHROUGH 262 # define JEMALLOC_FALLTHROUGH JEMALLOC_ATTR(fallthrough) 263 # else 264 # define JEMALLOC_FALLTHROUGH 265 # endif 266 # define JEMALLOC_NOINLINE JEMALLOC_ATTR(noinline) 267 # define JEMALLOC_NOTHROW JEMALLOC_ATTR(nothrow) 268 # define JEMALLOC_SECTION(s) JEMALLOC_ATTR(section(s)) 269 # define JEMALLOC_RESTRICT_RETURN 270 # define JEMALLOC_ALLOCATOR 271 # ifdef JEMALLOC_HAVE_ATTR_COLD 272 # define JEMALLOC_COLD JEMALLOC_ATTR(__cold__) 273 # else 274 # define JEMALLOC_COLD 275 # endif 276 # ifdef JEMALLOC_HAVE_ATTR_DEPRECATED 277 # define JEMALLOC_WARN_ON_USAGE(warning_message) JEMALLOC_ATTR(deprecated(warning_message)) 278 # else 279 # define JEMALLOC_WARN_ON_USAGE(warning_message) 280 # endif 281 #else 282 # define JEMALLOC_ATTR(s) 283 # define JEMALLOC_ALIGNED(s) 284 # define JEMALLOC_ALLOC_SIZE(s) 285 # define JEMALLOC_ALLOC_SIZE2(s1, s2) 286 # define JEMALLOC_EXPORT 287 # define JEMALLOC_FORMAT_PRINTF(s, i) 288 # define JEMALLOC_FALLTHROUGH 289 # define JEMALLOC_NOINLINE 290 # define JEMALLOC_NOTHROW 291 # define JEMALLOC_SECTION(s) 292 # define JEMALLOC_RESTRICT_RETURN 293 # define JEMALLOC_ALLOCATOR 294 # define JEMALLOC_COLD 295 # define JEMALLOC_WARN_ON_USAGE(warning_message) 296 #endif 297 298 #if (defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__linux__) && !defined(__GLIBC__))) && !defined(JEMALLOC_NO_RENAME) 299 # define JEMALLOC_SYS_NOTHROW 300 #else 301 # define JEMALLOC_SYS_NOTHROW JEMALLOC_NOTHROW 302 #endif 303 304 /* 305 * The je_ prefix on the following public symbol declarations is an artifact 306 * of namespace management, and should be omitted in application code unless 307 * JEMALLOC_NO_DEMANGLE is defined (see jemalloc_mangle.h). 308 */ 309 #ifdef __cplusplus 310 extern "C" { 311 #endif 312 313 extern JEMALLOC_EXPORT const char *je_malloc_conf; 314 extern JEMALLOC_EXPORT const char *je_malloc_conf_2_conf_harder; 315 extern JEMALLOC_EXPORT void (*je_malloc_message)(void *cbopaque, 316 const char *s); 317 extern JEMALLOC_EXPORT const char *je_malloc_conf_get(void); 318 extern JEMALLOC_EXPORT void je_malloc_conf_set(const char *); 319 extern JEMALLOC_EXPORT void (*je_malloc_message_get(void)) 320 (void *cbopaque, const char *s); 321 extern JEMALLOC_EXPORT void je_malloc_message_set( 322 void (*)(void *cbopaque, const char *s)); 323 324 JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 325 void JEMALLOC_SYS_NOTHROW *je_malloc(size_t size) 326 JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE(1); 327 JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 328 void JEMALLOC_SYS_NOTHROW *je_calloc(size_t num, size_t size) 329 JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE2(1, 2); 330 JEMALLOC_EXPORT int JEMALLOC_SYS_NOTHROW je_posix_memalign( 331 void **memptr, size_t alignment, size_t size) JEMALLOC_CXX_THROW 332 JEMALLOC_ATTR(nonnull(1)); 333 JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 334 void JEMALLOC_SYS_NOTHROW *je_aligned_alloc(size_t alignment, 335 size_t size) JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc) 336 JEMALLOC_ALLOC_SIZE(2); 337 JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 338 void JEMALLOC_SYS_NOTHROW *je_realloc(void *ptr, size_t size) 339 JEMALLOC_CXX_THROW JEMALLOC_ALLOC_SIZE(2); 340 JEMALLOC_EXPORT void JEMALLOC_SYS_NOTHROW je_free(void *ptr) 341 JEMALLOC_CXX_THROW; 342 JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_free_sized(void *ptr, size_t size); 343 JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_free_aligned_sized( 344 void *ptr, size_t alignment, size_t size); 345 346 JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 347 void JEMALLOC_NOTHROW *je_mallocx(size_t size, int flags) 348 JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE(1); 349 JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 350 void JEMALLOC_NOTHROW *je_rallocx(void *ptr, size_t size, 351 int flags) JEMALLOC_ALLOC_SIZE(2); 352 JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_xallocx(void *ptr, size_t size, 353 size_t extra, int flags); 354 JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_sallocx(const void *ptr, 355 int flags) JEMALLOC_ATTR(pure); 356 JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_dallocx(void *ptr, int flags); 357 JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_sdallocx(void *ptr, size_t size, 358 int flags); 359 JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_nallocx(size_t size, int flags) 360 JEMALLOC_ATTR(pure); 361 362 JEMALLOC_EXPORT int JEMALLOC_NOTHROW je_mallctl(const char *name, 363 void *oldp, size_t *oldlenp, void *newp, size_t newlen); 364 JEMALLOC_EXPORT int JEMALLOC_NOTHROW je_mallctlnametomib(const char *name, 365 size_t *mibp, size_t *miblenp); 366 JEMALLOC_EXPORT int JEMALLOC_NOTHROW je_mallctlbymib(const size_t *mib, 367 size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen); 368 JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_malloc_stats_print( 369 void (*write_cb)(void *, const char *), void *je_cbopaque, 370 const char *opts); 371 JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_malloc_usable_size( 372 JEMALLOC_USABLE_SIZE_CONST void *ptr) JEMALLOC_CXX_THROW; 373 #ifdef JEMALLOC_HAVE_MALLOC_SIZE 374 JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_malloc_size( 375 const void *ptr); 376 #endif 377 378 #ifdef JEMALLOC_OVERRIDE_MEMALIGN 379 JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 380 void JEMALLOC_SYS_NOTHROW *je_memalign(size_t alignment, size_t size) 381 JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc); 382 #endif 383 384 #ifdef JEMALLOC_OVERRIDE_VALLOC 385 JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 386 void JEMALLOC_SYS_NOTHROW *je_valloc(size_t size) JEMALLOC_CXX_THROW 387 JEMALLOC_ATTR(malloc); 388 #endif 389 390 #ifdef JEMALLOC_OVERRIDE_PVALLOC 391 JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 392 void JEMALLOC_SYS_NOTHROW *je_pvalloc(size_t size) JEMALLOC_CXX_THROW 393 JEMALLOC_ATTR(malloc); 394 #endif 395 396 #ifdef __cplusplus 397 } 398 #endif 399 400 #ifdef __cplusplus 401 extern "C" { 402 #endif 403 404 typedef struct extent_hooks_s extent_hooks_t; 405 406 /* 407 * Extent alloc flags. A custom extent_alloc hook may OR these into the 408 * returned pointer; jemalloc strips the low bits before use. Safe because 409 * returned addresses are at least page-aligned (PAGE >= 256). 410 * 411 * EXTENT_ALLOC_FLAG_PINNED: backing memory is non-reclaimable. 412 * Pinned extents are excluded from decay/purging and cached separately for 413 * preferential reuse. A hook returning this flag must also set *commit to 414 * true: pinned memory bypasses jemalloc's commit/decommit machinery. 415 * 416 * The pinned attribute is per-extent: a single hook may return pinned and 417 * non-pinned extents in different calls. Pinned and non-pinned extents are 418 * never merged together (the merge would change the reclamation policy of 419 * one half), so pinned-ness is set at allocation and inherited through 420 * splits, but never changes after that. 421 * 422 * Example (HugeTLB alloc hook): 423 * void *my_alloc(extent_hooks_t *h, void *new_addr, size_t size, 424 * size_t alignment, bool *zero, bool *commit, unsigned arena_ind) { 425 * void *addr = mmap(NULL, size, PROT_READ|PROT_WRITE, 426 * MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB, -1, 0); 427 * if (addr == MAP_FAILED) return NULL; 428 * *zero = true; 429 * *commit = true; 430 * return (void *)((uintptr_t)addr | EXTENT_ALLOC_FLAG_PINNED); 431 * } 432 */ 433 #define EXTENT_ALLOC_FLAG_PINNED 0x1U 434 #define EXTENT_ALLOC_FLAG_MASK 0xFFU 435 436 /* 437 * void * 438 * extent_alloc(extent_hooks_t *extent_hooks, void *new_addr, size_t size, 439 * size_t alignment, bool *zero, bool *commit, unsigned arena_ind); 440 */ 441 typedef void *(extent_alloc_t)(extent_hooks_t *, void *, size_t, size_t, bool *, 442 bool *, unsigned); 443 444 /* 445 * bool 446 * extent_dalloc(extent_hooks_t *extent_hooks, void *addr, size_t size, 447 * bool committed, unsigned arena_ind); 448 */ 449 typedef bool (extent_dalloc_t)(extent_hooks_t *, void *, size_t, bool, 450 unsigned); 451 452 /* 453 * void 454 * extent_destroy(extent_hooks_t *extent_hooks, void *addr, size_t size, 455 * bool committed, unsigned arena_ind); 456 */ 457 typedef void (extent_destroy_t)(extent_hooks_t *, void *, size_t, bool, 458 unsigned); 459 460 /* 461 * bool 462 * extent_commit(extent_hooks_t *extent_hooks, void *addr, size_t size, 463 * size_t offset, size_t length, unsigned arena_ind); 464 */ 465 typedef bool (extent_commit_t)(extent_hooks_t *, void *, size_t, size_t, size_t, 466 unsigned); 467 468 /* 469 * bool 470 * extent_decommit(extent_hooks_t *extent_hooks, void *addr, size_t size, 471 * size_t offset, size_t length, unsigned arena_ind); 472 */ 473 typedef bool (extent_decommit_t)(extent_hooks_t *, void *, size_t, size_t, 474 size_t, unsigned); 475 476 /* 477 * bool 478 * extent_purge(extent_hooks_t *extent_hooks, void *addr, size_t size, 479 * size_t offset, size_t length, unsigned arena_ind); 480 */ 481 typedef bool (extent_purge_t)(extent_hooks_t *, void *, size_t, size_t, size_t, 482 unsigned); 483 484 /* 485 * bool 486 * extent_split(extent_hooks_t *extent_hooks, void *addr, size_t size, 487 * size_t size_a, size_t size_b, bool committed, unsigned arena_ind); 488 */ 489 typedef bool (extent_split_t)(extent_hooks_t *, void *, size_t, size_t, size_t, 490 bool, unsigned); 491 492 /* 493 * bool 494 * extent_merge(extent_hooks_t *extent_hooks, void *addr_a, size_t size_a, 495 * void *addr_b, size_t size_b, bool committed, unsigned arena_ind); 496 */ 497 typedef bool (extent_merge_t)(extent_hooks_t *, void *, size_t, void *, size_t, 498 bool, unsigned); 499 500 struct extent_hooks_s { 501 extent_alloc_t *alloc; 502 extent_dalloc_t *dalloc; 503 extent_destroy_t *destroy; 504 extent_commit_t *commit; 505 extent_decommit_t *decommit; 506 extent_purge_t *purge_lazy; 507 extent_purge_t *purge_forced; 508 extent_split_t *split; 509 extent_merge_t *merge; 510 }; 511 512 #ifdef __cplusplus 513 } 514 #endif 515 516 /* 517 * By default application code must explicitly refer to mangled symbol names, 518 * so that it is possible to use jemalloc in conjunction with another allocator 519 * in the same application. Define JEMALLOC_MANGLE in order to cause automatic 520 * name mangling that matches the API prefixing that happened as a result of 521 * --with-mangling and/or --with-jemalloc-prefix configuration settings. 522 */ 523 #ifdef JEMALLOC_MANGLE 524 # ifndef JEMALLOC_NO_DEMANGLE 525 # define JEMALLOC_NO_DEMANGLE 526 # endif 527 # define aligned_alloc je_aligned_alloc 528 # define calloc je_calloc 529 # define dallocx je_dallocx 530 # define free je_free 531 # define free_sized je_free_sized 532 # define free_aligned_sized je_free_aligned_sized 533 # define mallctl je_mallctl 534 # define mallctlbymib je_mallctlbymib 535 # define mallctlnametomib je_mallctlnametomib 536 # define malloc je_malloc 537 # define malloc_conf je_malloc_conf 538 # define malloc_conf_2_conf_harder je_malloc_conf_2_conf_harder 539 # define malloc_message je_malloc_message 540 # define malloc_stats_print je_malloc_stats_print 541 # define malloc_usable_size je_malloc_usable_size 542 # define mallocx je_mallocx 543 # define smallocx_7a34f18502e7b222724097cdcd499b437d189acc je_smallocx_7a34f18502e7b222724097cdcd499b437d189acc 544 # define nallocx je_nallocx 545 # define posix_memalign je_posix_memalign 546 # define rallocx je_rallocx 547 # define realloc je_realloc 548 # define sallocx je_sallocx 549 # define sdallocx je_sdallocx 550 # define xallocx je_xallocx 551 # define valloc je_valloc 552 # endif 553 #endif 554 555 /* 556 * The je_* macros can be used as stable alternative names for the 557 * public jemalloc API if JEMALLOC_NO_DEMANGLE is defined. This is primarily 558 * meant for use in jemalloc itself, but it can be used by application code to 559 * provide isolation from the name mangling specified via --with-mangling 560 * and/or --with-jemalloc-prefix. 561 */ 562 #ifndef JEMALLOC_NO_DEMANGLE 563 # undef je_aligned_alloc 564 # undef je_calloc 565 # undef je_dallocx 566 # undef je_free 567 # undef je_free_sized 568 # undef je_free_aligned_sized 569 # undef je_mallctl 570 # undef je_mallctlbymib 571 # undef je_mallctlnametomib 572 # undef je_malloc 573 # undef je_malloc_conf 574 # undef je_malloc_conf_2_conf_harder 575 # undef je_malloc_message 576 # undef je_malloc_stats_print 577 # undef je_malloc_usable_size 578 # undef je_mallocx 579 # undef je_smallocx_7a34f18502e7b222724097cdcd499b437d189acc 580 # undef je_nallocx 581 # undef je_posix_memalign 582 # undef je_rallocx 583 # undef je_realloc 584 # undef je_sallocx 585 # undef je_sdallocx 586 # undef je_xallocx 587 # undef je_valloc 588 #endif 589 590 #endif /* JEMALLOC_H_ */ 591