1*8e33eff8Schristos #ifndef JEMALLOC_H_ 2*8e33eff8Schristos #define JEMALLOC_H_ 3*8e33eff8Schristos #ifdef __cplusplus 4*8e33eff8Schristos extern "C" { 5*8e33eff8Schristos #endif 6*8e33eff8Schristos 7*8e33eff8Schristos /* Defined if __attribute__((...)) syntax is supported. */ 8*8e33eff8Schristos #define JEMALLOC_HAVE_ATTR 9*8e33eff8Schristos 10*8e33eff8Schristos /* Defined if alloc_size attribute is supported. */ 11*8e33eff8Schristos #define JEMALLOC_HAVE_ATTR_ALLOC_SIZE 12*8e33eff8Schristos 13*8e33eff8Schristos /* Defined if format(gnu_printf, ...) attribute is supported. */ 14*8e33eff8Schristos #ifndef __clang__ 15*8e33eff8Schristos #define JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF 16*8e33eff8Schristos #endif 17*8e33eff8Schristos 18*8e33eff8Schristos /* Defined if format(printf, ...) attribute is supported. */ 19*8e33eff8Schristos #define JEMALLOC_HAVE_ATTR_FORMAT_PRINTF 20*8e33eff8Schristos 21*8e33eff8Schristos /* 22*8e33eff8Schristos * Define overrides for non-standard allocator-related functions if they are 23*8e33eff8Schristos * present on the system. 24*8e33eff8Schristos */ 25*8e33eff8Schristos /* #undef JEMALLOC_OVERRIDE_MEMALIGN */ 26*8e33eff8Schristos #define JEMALLOC_OVERRIDE_VALLOC 27*8e33eff8Schristos 28*8e33eff8Schristos /* 29*8e33eff8Schristos * At least Linux omits the "const" in: 30*8e33eff8Schristos * 31*8e33eff8Schristos * size_t malloc_usable_size(const void *ptr); 32*8e33eff8Schristos * 33*8e33eff8Schristos * Match the operating system's prototype. 34*8e33eff8Schristos */ 35*8e33eff8Schristos #define JEMALLOC_USABLE_SIZE_CONST const 36*8e33eff8Schristos 37*8e33eff8Schristos /* 38*8e33eff8Schristos * If defined, specify throw() for the public function prototypes when compiling 39*8e33eff8Schristos * with C++. The only justification for this is to match the prototypes that 40*8e33eff8Schristos * glibc defines. 41*8e33eff8Schristos */ 42*8e33eff8Schristos /* #undef JEMALLOC_USE_CXX_THROW */ 43*8e33eff8Schristos 44*8e33eff8Schristos #ifdef _MSC_VER 45*8e33eff8Schristos # ifdef _WIN64 46*8e33eff8Schristos # define LG_SIZEOF_PTR_WIN 3 47*8e33eff8Schristos # else 48*8e33eff8Schristos # define LG_SIZEOF_PTR_WIN 2 49*8e33eff8Schristos # endif 50*8e33eff8Schristos #endif 51*8e33eff8Schristos 52*8e33eff8Schristos /* sizeof(void *) == 2^LG_SIZEOF_PTR. */ 53*8e33eff8Schristos #ifdef _LP64 54*8e33eff8Schristos #define LG_SIZEOF_PTR 3 55*8e33eff8Schristos #else 56*8e33eff8Schristos #define LG_SIZEOF_PTR 2 57*8e33eff8Schristos #endif 58*8e33eff8Schristos 59*8e33eff8Schristos /* 60*8e33eff8Schristos * Name mangling for public symbols is controlled by --with-mangling and 61*8e33eff8Schristos * --with-jemalloc-prefix. With default settings the je_ prefix is stripped by 62*8e33eff8Schristos * these macro definitions. 63*8e33eff8Schristos */ 64*8e33eff8Schristos #ifndef JEMALLOC_NO_RENAME 65*8e33eff8Schristos # define je_aligned_alloc aligned_alloc 66*8e33eff8Schristos # define je_calloc calloc 67*8e33eff8Schristos # define je_free free 68*8e33eff8Schristos # define je_malloc malloc 69*8e33eff8Schristos # define je_posix_memalign posix_memalign 70*8e33eff8Schristos # define je_realloc realloc 71*8e33eff8Schristos # define je_valloc valloc 72*8e33eff8Schristos 73*8e33eff8Schristos # ifndef JEMALLOC_PROTECT_NOSTD 74*8e33eff8Schristos # define je_dallocx dallocx 75*8e33eff8Schristos # define je_mallctl mallctl 76*8e33eff8Schristos # define je_mallctlbymib mallctlbymib 77*8e33eff8Schristos # define je_mallctlnametomib mallctlnametomib 78*8e33eff8Schristos # define je_malloc_conf malloc_conf 79*8e33eff8Schristos # define je_malloc_conf_get malloc_conf_get 80*8e33eff8Schristos # define je_malloc_conf_set malloc_conf_set 81*8e33eff8Schristos # define je_malloc_message malloc_message 82*8e33eff8Schristos # define je_malloc_message_get malloc_message_get 83*8e33eff8Schristos # define je_malloc_message_set malloc_message_set 84*8e33eff8Schristos # define je_malloc_stats_print malloc_stats_print 85*8e33eff8Schristos # define je_malloc_usable_size malloc_usable_size 86*8e33eff8Schristos # define je_mallocx mallocx 87*8e33eff8Schristos # define je_nallocx nallocx 88*8e33eff8Schristos # define je_rallocx rallocx 89*8e33eff8Schristos # define je_sallocx sallocx 90*8e33eff8Schristos # define je_sdallocx sdallocx 91*8e33eff8Schristos # define je_xallocx xallocx 92*8e33eff8Schristos # else 93*8e33eff8Schristos # define je_dallocx __je_dallocx 94*8e33eff8Schristos # define je_mallctl __je_mallctl 95*8e33eff8Schristos # define je_mallctlbymib __je_mallctlbymib 96*8e33eff8Schristos # define je_mallctlnametomib __je_mallctlnametomib 97*8e33eff8Schristos # define je_malloc_conf __je_malloc_conf 98*8e33eff8Schristos # define je_malloc_conf_get __je_malloc_conf_get 99*8e33eff8Schristos # define je_malloc_conf_set __je_malloc_conf_set 100*8e33eff8Schristos # define je_malloc_message __je_malloc_message 101*8e33eff8Schristos # define je_malloc_message_get __je_malloc_message_get 102*8e33eff8Schristos # define je_malloc_message_set __je_malloc_message_set 103*8e33eff8Schristos # define je_malloc_stats_print __je_malloc_stats_print 104*8e33eff8Schristos # define je_malloc_usable_size __je_malloc_usable_size 105*8e33eff8Schristos # define je_mallocx __je_mallocx 106*8e33eff8Schristos # define je_nallocx __je_nallocx 107*8e33eff8Schristos # define je_rallocx __je_rallocx 108*8e33eff8Schristos # define je_sallocx __je_sallocx 109*8e33eff8Schristos # define je_sdallocx __je_sdallocx 110*8e33eff8Schristos # define je_xallocx __je_xallocx 111*8e33eff8Schristos # endif 112*8e33eff8Schristos #endif 113*8e33eff8Schristos 114*8e33eff8Schristos #include <stdlib.h> 115*8e33eff8Schristos #include <stdbool.h> 116*8e33eff8Schristos #include <stdint.h> 117*8e33eff8Schristos #include <limits.h> 118*8e33eff8Schristos #include <strings.h> 119*8e33eff8Schristos 120*8e33eff8Schristos #define JEMALLOC_VERSION "5.1.0-0-g61efbda7098de6fe64c362d309824864308c36d4" 121*8e33eff8Schristos #define JEMALLOC_VERSION_MAJOR 5 122*8e33eff8Schristos #define JEMALLOC_VERSION_MINOR 1 123*8e33eff8Schristos #define JEMALLOC_VERSION_BUGFIX 0 124*8e33eff8Schristos #define JEMALLOC_VERSION_NREV 0 125*8e33eff8Schristos #define JEMALLOC_VERSION_GID "61efbda7098de6fe64c362d309824864308c36d4" 126*8e33eff8Schristos 127*8e33eff8Schristos #define MALLOCX_LG_ALIGN(la) ((int)(la)) 128*8e33eff8Schristos #if LG_SIZEOF_PTR == 2 129*8e33eff8Schristos # define MALLOCX_ALIGN(a) ((int)(ffs((int)(a))-1)) 130*8e33eff8Schristos #else 131*8e33eff8Schristos # define MALLOCX_ALIGN(a) \ 132*8e33eff8Schristos ((int)(((size_t)(a) < (size_t)INT_MAX) ? ffs((int)(a))-1 : \ 133*8e33eff8Schristos ffs((int)(((size_t)(a))>>32))+31)) 134*8e33eff8Schristos #endif 135*8e33eff8Schristos #define MALLOCX_ZERO ((int)0x40) 136*8e33eff8Schristos /* 137*8e33eff8Schristos * Bias tcache index bits so that 0 encodes "automatic tcache management", and 1 138*8e33eff8Schristos * encodes MALLOCX_TCACHE_NONE. 139*8e33eff8Schristos */ 140*8e33eff8Schristos #define MALLOCX_TCACHE(tc) ((int)(((tc)+2) << 8)) 141*8e33eff8Schristos #define MALLOCX_TCACHE_NONE MALLOCX_TCACHE(-1) 142*8e33eff8Schristos /* 143*8e33eff8Schristos * Bias arena index bits so that 0 encodes "use an automatically chosen arena". 144*8e33eff8Schristos */ 145*8e33eff8Schristos #define MALLOCX_ARENA(a) ((((int)(a))+1) << 20) 146*8e33eff8Schristos 147*8e33eff8Schristos /* 148*8e33eff8Schristos * Use as arena index in "arena.<i>.{purge,decay,dss}" and 149*8e33eff8Schristos * "stats.arenas.<i>.*" mallctl interfaces to select all arenas. This 150*8e33eff8Schristos * definition is intentionally specified in raw decimal format to support 151*8e33eff8Schristos * cpp-based string concatenation, e.g. 152*8e33eff8Schristos * 153*8e33eff8Schristos * #define STRINGIFY_HELPER(x) #x 154*8e33eff8Schristos * #define STRINGIFY(x) STRINGIFY_HELPER(x) 155*8e33eff8Schristos * 156*8e33eff8Schristos * mallctl("arena." STRINGIFY(MALLCTL_ARENAS_ALL) ".purge", NULL, NULL, NULL, 157*8e33eff8Schristos * 0); 158*8e33eff8Schristos */ 159*8e33eff8Schristos #define MALLCTL_ARENAS_ALL 4096 160*8e33eff8Schristos /* 161*8e33eff8Schristos * Use as arena index in "stats.arenas.<i>.*" mallctl interfaces to select 162*8e33eff8Schristos * destroyed arenas. 163*8e33eff8Schristos */ 164*8e33eff8Schristos #define MALLCTL_ARENAS_DESTROYED 4097 165*8e33eff8Schristos 166*8e33eff8Schristos #if defined(__cplusplus) && defined(JEMALLOC_USE_CXX_THROW) 167*8e33eff8Schristos # define JEMALLOC_CXX_THROW throw() 168*8e33eff8Schristos #else 169*8e33eff8Schristos # define JEMALLOC_CXX_THROW 170*8e33eff8Schristos #endif 171*8e33eff8Schristos 172*8e33eff8Schristos #if defined(_MSC_VER) 173*8e33eff8Schristos # define JEMALLOC_ATTR(s) 174*8e33eff8Schristos # define JEMALLOC_ALIGNED(s) __declspec(align(s)) 175*8e33eff8Schristos # define JEMALLOC_NORETURN 176*8e33eff8Schristos # define JEMALLOC_ALLOC_SIZE(s) 177*8e33eff8Schristos # define JEMALLOC_ALLOC_SIZE2(s1, s2) 178*8e33eff8Schristos # ifndef JEMALLOC_EXPORT 179*8e33eff8Schristos # ifdef DLLEXPORT 180*8e33eff8Schristos # define JEMALLOC_EXPORT __declspec(dllexport) 181*8e33eff8Schristos # else 182*8e33eff8Schristos # define JEMALLOC_EXPORT __declspec(dllimport) 183*8e33eff8Schristos # endif 184*8e33eff8Schristos # endif 185*8e33eff8Schristos # define JEMALLOC_FORMAT_PRINTF(s, i) 186*8e33eff8Schristos # define JEMALLOC_NOINLINE __declspec(noinline) 187*8e33eff8Schristos # ifdef __cplusplus 188*8e33eff8Schristos # define JEMALLOC_NOTHROW __declspec(nothrow) 189*8e33eff8Schristos # else 190*8e33eff8Schristos # define JEMALLOC_NOTHROW 191*8e33eff8Schristos # endif 192*8e33eff8Schristos # define JEMALLOC_SECTION(s) __declspec(allocate(s)) 193*8e33eff8Schristos # define JEMALLOC_RESTRICT_RETURN __declspec(restrict) 194*8e33eff8Schristos # if _MSC_VER >= 1900 && !defined(__EDG__) 195*8e33eff8Schristos # define JEMALLOC_ALLOCATOR __declspec(allocator) 196*8e33eff8Schristos # else 197*8e33eff8Schristos # define JEMALLOC_ALLOCATOR 198*8e33eff8Schristos # endif 199*8e33eff8Schristos #elif defined(JEMALLOC_HAVE_ATTR) 200*8e33eff8Schristos # define JEMALLOC_ATTR(s) __attribute__((s)) 201*8e33eff8Schristos # define JEMALLOC_ALIGNED(s) JEMALLOC_ATTR(aligned(s)) 202*8e33eff8Schristos # define JEMALLOC_NORETURN JEMALLOC_ATTR(__noreturn__) 203*8e33eff8Schristos # ifdef JEMALLOC_HAVE_ATTR_ALLOC_SIZE 204*8e33eff8Schristos # define JEMALLOC_ALLOC_SIZE(s) JEMALLOC_ATTR(alloc_size(s)) 205*8e33eff8Schristos # define JEMALLOC_ALLOC_SIZE2(s1, s2) JEMALLOC_ATTR(alloc_size(s1, s2)) 206*8e33eff8Schristos # else 207*8e33eff8Schristos # define JEMALLOC_ALLOC_SIZE(s) 208*8e33eff8Schristos # define JEMALLOC_ALLOC_SIZE2(s1, s2) 209*8e33eff8Schristos # endif 210*8e33eff8Schristos # ifndef JEMALLOC_EXPORT 211*8e33eff8Schristos # define JEMALLOC_EXPORT JEMALLOC_ATTR(visibility("default")) 212*8e33eff8Schristos # endif 213*8e33eff8Schristos # ifdef JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF 214*8e33eff8Schristos # define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(gnu_printf, s, i)) 215*8e33eff8Schristos # elif defined(JEMALLOC_HAVE_ATTR_FORMAT_PRINTF) 216*8e33eff8Schristos # define JEMALLOC_FORMAT_PRINTF(s, i) JEMALLOC_ATTR(format(printf, s, i)) 217*8e33eff8Schristos # else 218*8e33eff8Schristos # define JEMALLOC_FORMAT_PRINTF(s, i) 219*8e33eff8Schristos # endif 220*8e33eff8Schristos # define JEMALLOC_NOINLINE JEMALLOC_ATTR(noinline) 221*8e33eff8Schristos # define JEMALLOC_NOTHROW JEMALLOC_ATTR(nothrow) 222*8e33eff8Schristos # define JEMALLOC_SECTION(s) JEMALLOC_ATTR(section(s)) 223*8e33eff8Schristos # define JEMALLOC_RESTRICT_RETURN 224*8e33eff8Schristos # define JEMALLOC_ALLOCATOR 225*8e33eff8Schristos #else 226*8e33eff8Schristos # define JEMALLOC_ATTR(s) 227*8e33eff8Schristos # define JEMALLOC_ALIGNED(s) 228*8e33eff8Schristos # define JEMALLOC_ALLOC_SIZE(s) 229*8e33eff8Schristos # define JEMALLOC_ALLOC_SIZE2(s1, s2) 230*8e33eff8Schristos # define JEMALLOC_EXPORT 231*8e33eff8Schristos # define JEMALLOC_FORMAT_PRINTF(s, i) 232*8e33eff8Schristos # define JEMALLOC_NOINLINE 233*8e33eff8Schristos # define JEMALLOC_NOTHROW 234*8e33eff8Schristos # define JEMALLOC_SECTION(s) 235*8e33eff8Schristos # define JEMALLOC_RESTRICT_RETURN 236*8e33eff8Schristos # define JEMALLOC_ALLOCATOR 237*8e33eff8Schristos #endif 238*8e33eff8Schristos 239*8e33eff8Schristos /* 240*8e33eff8Schristos * The je_ prefix on the following public symbol declarations is an artifact 241*8e33eff8Schristos * of namespace management, and should be omitted in application code unless 242*8e33eff8Schristos * JEMALLOC_NO_DEMANGLE is defined (see jemalloc_mangle.h). 243*8e33eff8Schristos */ 244*8e33eff8Schristos extern JEMALLOC_EXPORT const char *je_malloc_conf; 245*8e33eff8Schristos extern JEMALLOC_EXPORT void (*je_malloc_message)(void *cbopaque, 246*8e33eff8Schristos const char *s); 247*8e33eff8Schristos extern JEMALLOC_EXPORT const char *je_malloc_conf_get(void); 248*8e33eff8Schristos extern JEMALLOC_EXPORT void je_malloc_conf_set(const char *); 249*8e33eff8Schristos extern JEMALLOC_EXPORT void (*je_malloc_message_get(void)) 250*8e33eff8Schristos (void *cbopaque, const char *s); 251*8e33eff8Schristos extern JEMALLOC_EXPORT void je_malloc_message_set( 252*8e33eff8Schristos void (*)(void *cbopaque, const char *s)); 253*8e33eff8Schristos 254*8e33eff8Schristos JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 255*8e33eff8Schristos void JEMALLOC_NOTHROW *je_malloc(size_t size) 256*8e33eff8Schristos JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE(1); 257*8e33eff8Schristos JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 258*8e33eff8Schristos void JEMALLOC_NOTHROW *je_calloc(size_t num, size_t size) 259*8e33eff8Schristos JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE2(1, 2); 260*8e33eff8Schristos JEMALLOC_EXPORT int JEMALLOC_NOTHROW je_posix_memalign(void **memptr, 261*8e33eff8Schristos size_t alignment, size_t size) JEMALLOC_CXX_THROW JEMALLOC_ATTR(nonnull(1)); 262*8e33eff8Schristos JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 263*8e33eff8Schristos void JEMALLOC_NOTHROW *je_aligned_alloc(size_t alignment, 264*8e33eff8Schristos size_t size) JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc) 265*8e33eff8Schristos JEMALLOC_ALLOC_SIZE(2); 266*8e33eff8Schristos JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 267*8e33eff8Schristos void JEMALLOC_NOTHROW *je_realloc(void *ptr, size_t size) 268*8e33eff8Schristos JEMALLOC_CXX_THROW JEMALLOC_ALLOC_SIZE(2); 269*8e33eff8Schristos JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_free(void *ptr) 270*8e33eff8Schristos JEMALLOC_CXX_THROW; 271*8e33eff8Schristos 272*8e33eff8Schristos JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 273*8e33eff8Schristos void JEMALLOC_NOTHROW *je_mallocx(size_t size, int flags) 274*8e33eff8Schristos JEMALLOC_ATTR(malloc) JEMALLOC_ALLOC_SIZE(1); 275*8e33eff8Schristos JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 276*8e33eff8Schristos void JEMALLOC_NOTHROW *je_rallocx(void *ptr, size_t size, 277*8e33eff8Schristos int flags) JEMALLOC_ALLOC_SIZE(2); 278*8e33eff8Schristos JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_xallocx(void *ptr, size_t size, 279*8e33eff8Schristos size_t extra, int flags); 280*8e33eff8Schristos JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_sallocx(const void *ptr, 281*8e33eff8Schristos int flags) JEMALLOC_ATTR(pure); 282*8e33eff8Schristos JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_dallocx(void *ptr, int flags); 283*8e33eff8Schristos JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_sdallocx(void *ptr, size_t size, 284*8e33eff8Schristos int flags); 285*8e33eff8Schristos JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_nallocx(size_t size, int flags) 286*8e33eff8Schristos JEMALLOC_ATTR(pure); 287*8e33eff8Schristos 288*8e33eff8Schristos JEMALLOC_EXPORT int JEMALLOC_NOTHROW je_mallctl(const char *name, 289*8e33eff8Schristos void *oldp, size_t *oldlenp, void *newp, size_t newlen); 290*8e33eff8Schristos JEMALLOC_EXPORT int JEMALLOC_NOTHROW je_mallctlnametomib(const char *name, 291*8e33eff8Schristos size_t *mibp, size_t *miblenp); 292*8e33eff8Schristos JEMALLOC_EXPORT int JEMALLOC_NOTHROW je_mallctlbymib(const size_t *mib, 293*8e33eff8Schristos size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen); 294*8e33eff8Schristos JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_malloc_stats_print( 295*8e33eff8Schristos void (*write_cb)(void *, const char *), void *je_cbopaque, 296*8e33eff8Schristos const char *opts); 297*8e33eff8Schristos JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_malloc_usable_size( 298*8e33eff8Schristos JEMALLOC_USABLE_SIZE_CONST void *ptr) JEMALLOC_CXX_THROW; 299*8e33eff8Schristos 300*8e33eff8Schristos #ifdef JEMALLOC_OVERRIDE_MEMALIGN 301*8e33eff8Schristos JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 302*8e33eff8Schristos void JEMALLOC_NOTHROW *je_memalign(size_t alignment, size_t size) 303*8e33eff8Schristos JEMALLOC_CXX_THROW JEMALLOC_ATTR(malloc); 304*8e33eff8Schristos #endif 305*8e33eff8Schristos 306*8e33eff8Schristos #ifdef JEMALLOC_OVERRIDE_VALLOC 307*8e33eff8Schristos JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN 308*8e33eff8Schristos void JEMALLOC_NOTHROW *je_valloc(size_t size) JEMALLOC_CXX_THROW 309*8e33eff8Schristos JEMALLOC_ATTR(malloc); 310*8e33eff8Schristos #endif 311*8e33eff8Schristos 312*8e33eff8Schristos typedef struct extent_hooks_s extent_hooks_t; 313*8e33eff8Schristos 314*8e33eff8Schristos /* 315*8e33eff8Schristos * void * 316*8e33eff8Schristos * extent_alloc(extent_hooks_t *extent_hooks, void *new_addr, size_t size, 317*8e33eff8Schristos * size_t alignment, bool *zero, bool *commit, unsigned arena_ind); 318*8e33eff8Schristos */ 319*8e33eff8Schristos typedef void *(extent_alloc_t)(extent_hooks_t *, void *, size_t, size_t, bool *, 320*8e33eff8Schristos bool *, unsigned); 321*8e33eff8Schristos 322*8e33eff8Schristos /* 323*8e33eff8Schristos * bool 324*8e33eff8Schristos * extent_dalloc(extent_hooks_t *extent_hooks, void *addr, size_t size, 325*8e33eff8Schristos * bool committed, unsigned arena_ind); 326*8e33eff8Schristos */ 327*8e33eff8Schristos typedef bool (extent_dalloc_t)(extent_hooks_t *, void *, size_t, bool, 328*8e33eff8Schristos unsigned); 329*8e33eff8Schristos 330*8e33eff8Schristos /* 331*8e33eff8Schristos * void 332*8e33eff8Schristos * extent_destroy(extent_hooks_t *extent_hooks, void *addr, size_t size, 333*8e33eff8Schristos * bool committed, unsigned arena_ind); 334*8e33eff8Schristos */ 335*8e33eff8Schristos typedef void (extent_destroy_t)(extent_hooks_t *, void *, size_t, bool, 336*8e33eff8Schristos unsigned); 337*8e33eff8Schristos 338*8e33eff8Schristos /* 339*8e33eff8Schristos * bool 340*8e33eff8Schristos * extent_commit(extent_hooks_t *extent_hooks, void *addr, size_t size, 341*8e33eff8Schristos * size_t offset, size_t length, unsigned arena_ind); 342*8e33eff8Schristos */ 343*8e33eff8Schristos typedef bool (extent_commit_t)(extent_hooks_t *, void *, size_t, size_t, size_t, 344*8e33eff8Schristos unsigned); 345*8e33eff8Schristos 346*8e33eff8Schristos /* 347*8e33eff8Schristos * bool 348*8e33eff8Schristos * extent_decommit(extent_hooks_t *extent_hooks, void *addr, size_t size, 349*8e33eff8Schristos * size_t offset, size_t length, unsigned arena_ind); 350*8e33eff8Schristos */ 351*8e33eff8Schristos typedef bool (extent_decommit_t)(extent_hooks_t *, void *, size_t, size_t, 352*8e33eff8Schristos size_t, unsigned); 353*8e33eff8Schristos 354*8e33eff8Schristos /* 355*8e33eff8Schristos * bool 356*8e33eff8Schristos * extent_purge(extent_hooks_t *extent_hooks, void *addr, size_t size, 357*8e33eff8Schristos * size_t offset, size_t length, unsigned arena_ind); 358*8e33eff8Schristos */ 359*8e33eff8Schristos typedef bool (extent_purge_t)(extent_hooks_t *, void *, size_t, size_t, size_t, 360*8e33eff8Schristos unsigned); 361*8e33eff8Schristos 362*8e33eff8Schristos /* 363*8e33eff8Schristos * bool 364*8e33eff8Schristos * extent_split(extent_hooks_t *extent_hooks, void *addr, size_t size, 365*8e33eff8Schristos * size_t size_a, size_t size_b, bool committed, unsigned arena_ind); 366*8e33eff8Schristos */ 367*8e33eff8Schristos typedef bool (extent_split_t)(extent_hooks_t *, void *, size_t, size_t, size_t, 368*8e33eff8Schristos bool, unsigned); 369*8e33eff8Schristos 370*8e33eff8Schristos /* 371*8e33eff8Schristos * bool 372*8e33eff8Schristos * extent_merge(extent_hooks_t *extent_hooks, void *addr_a, size_t size_a, 373*8e33eff8Schristos * void *addr_b, size_t size_b, bool committed, unsigned arena_ind); 374*8e33eff8Schristos */ 375*8e33eff8Schristos typedef bool (extent_merge_t)(extent_hooks_t *, void *, size_t, void *, size_t, 376*8e33eff8Schristos bool, unsigned); 377*8e33eff8Schristos 378*8e33eff8Schristos struct extent_hooks_s { 379*8e33eff8Schristos extent_alloc_t *alloc; 380*8e33eff8Schristos extent_dalloc_t *dalloc; 381*8e33eff8Schristos extent_destroy_t *destroy; 382*8e33eff8Schristos extent_commit_t *commit; 383*8e33eff8Schristos extent_decommit_t *decommit; 384*8e33eff8Schristos extent_purge_t *purge_lazy; 385*8e33eff8Schristos extent_purge_t *purge_forced; 386*8e33eff8Schristos extent_split_t *split; 387*8e33eff8Schristos extent_merge_t *merge; 388*8e33eff8Schristos }; 389*8e33eff8Schristos 390*8e33eff8Schristos /* 391*8e33eff8Schristos * By default application code must explicitly refer to mangled symbol names, 392*8e33eff8Schristos * so that it is possible to use jemalloc in conjunction with another allocator 393*8e33eff8Schristos * in the same application. Define JEMALLOC_MANGLE in order to cause automatic 394*8e33eff8Schristos * name mangling that matches the API prefixing that happened as a result of 395*8e33eff8Schristos * --with-mangling and/or --with-jemalloc-prefix configuration settings. 396*8e33eff8Schristos */ 397*8e33eff8Schristos #ifdef JEMALLOC_MANGLE 398*8e33eff8Schristos # ifndef JEMALLOC_NO_DEMANGLE 399*8e33eff8Schristos # define JEMALLOC_NO_DEMANGLE 400*8e33eff8Schristos # endif 401*8e33eff8Schristos # define aligned_alloc je_aligned_alloc 402*8e33eff8Schristos # define calloc je_calloc 403*8e33eff8Schristos # define dallocx je_dallocx 404*8e33eff8Schristos # define free je_free 405*8e33eff8Schristos # define mallctl je_mallctl 406*8e33eff8Schristos # define mallctlbymib je_mallctlbymib 407*8e33eff8Schristos # define mallctlnametomib je_mallctlnametomib 408*8e33eff8Schristos # define malloc je_malloc 409*8e33eff8Schristos # define malloc_conf je_malloc_conf 410*8e33eff8Schristos # define malloc_message je_malloc_message 411*8e33eff8Schristos # define malloc_stats_print je_malloc_stats_print 412*8e33eff8Schristos # define malloc_usable_size je_malloc_usable_size 413*8e33eff8Schristos # define mallocx je_mallocx 414*8e33eff8Schristos # define nallocx je_nallocx 415*8e33eff8Schristos # define posix_memalign je_posix_memalign 416*8e33eff8Schristos # define rallocx je_rallocx 417*8e33eff8Schristos # define realloc je_realloc 418*8e33eff8Schristos # define sallocx je_sallocx 419*8e33eff8Schristos # define sdallocx je_sdallocx 420*8e33eff8Schristos # define xallocx je_xallocx 421*8e33eff8Schristos # define valloc je_valloc 422*8e33eff8Schristos #endif 423*8e33eff8Schristos 424*8e33eff8Schristos /* 425*8e33eff8Schristos * The je_* macros can be used as stable alternative names for the 426*8e33eff8Schristos * public jemalloc API if JEMALLOC_NO_DEMANGLE is defined. This is primarily 427*8e33eff8Schristos * meant for use in jemalloc itself, but it can be used by application code to 428*8e33eff8Schristos * provide isolation from the name mangling specified via --with-mangling 429*8e33eff8Schristos * and/or --with-jemalloc-prefix. 430*8e33eff8Schristos */ 431*8e33eff8Schristos #ifndef JEMALLOC_NO_DEMANGLE 432*8e33eff8Schristos # undef je_aligned_alloc 433*8e33eff8Schristos # undef je_calloc 434*8e33eff8Schristos # undef je_dallocx 435*8e33eff8Schristos # undef je_free 436*8e33eff8Schristos # undef je_mallctl 437*8e33eff8Schristos # undef je_mallctlbymib 438*8e33eff8Schristos # undef je_mallctlnametomib 439*8e33eff8Schristos # undef je_malloc 440*8e33eff8Schristos # undef je_malloc_conf 441*8e33eff8Schristos # undef je_malloc_message 442*8e33eff8Schristos # undef je_malloc_stats_print 443*8e33eff8Schristos # undef je_malloc_usable_size 444*8e33eff8Schristos # undef je_mallocx 445*8e33eff8Schristos # undef je_nallocx 446*8e33eff8Schristos # undef je_posix_memalign 447*8e33eff8Schristos # undef je_rallocx 448*8e33eff8Schristos # undef je_realloc 449*8e33eff8Schristos # undef je_sallocx 450*8e33eff8Schristos # undef je_sdallocx 451*8e33eff8Schristos # undef je_xallocx 452*8e33eff8Schristos # undef je_valloc 453*8e33eff8Schristos #endif 454*8e33eff8Schristos 455*8e33eff8Schristos #ifdef __cplusplus 456*8e33eff8Schristos } 457*8e33eff8Schristos #endif 458*8e33eff8Schristos #endif /* JEMALLOC_H_ */ 459