1#ifndef JEMALLOC_H_ 2#define JEMALLOC_H_ 3#ifdef __cplusplus 4extern "C" { 5#endif 6 7/* Defined if __attribute__((...)) syntax is supported. */ 8#define JEMALLOC_HAVE_ATTR 9 10/* 11 * Define overrides for non-standard allocator-related functions if they are 12 * present on the system. 13 */ 14#define JEMALLOC_OVERRIDE_MEMALIGN 15#if !defined(__LP64__) 16#define JEMALLOC_OVERRIDE_VALLOC 17#endif 18 19/* 20 * At least Linux omits the "const" in: 21 * 22 * size_t malloc_usable_size(const void *ptr); 23 * 24 * Match the operating system's prototype. 25 */ 26#define JEMALLOC_USABLE_SIZE_CONST const 27 28/* sizeof(void *) == 2^LG_SIZEOF_PTR. */ 29#ifdef __LP64__ 30#define LG_SIZEOF_PTR 3 31#else 32#define LG_SIZEOF_PTR 2 33#endif 34 35/* 36 * Name mangling for public symbols is controlled by --with-mangling and 37 * --with-jemalloc-prefix. With default settings the je_ prefix is stripped by 38 * these macro definitions. 39 */ 40#ifndef JEMALLOC_NO_RENAME 41# define je_malloc_conf je_malloc_conf 42# define je_malloc_message je_malloc_message 43# define je_malloc je_malloc 44# define je_calloc je_calloc 45# define je_posix_memalign je_posix_memalign 46# define je_aligned_alloc je_aligned_alloc 47# define je_realloc je_realloc 48# define je_free je_free 49# define je_mallocx je_mallocx 50# define je_rallocx je_rallocx 51# define je_xallocx je_xallocx 52# define je_sallocx je_sallocx 53# define je_dallocx je_dallocx 54# define je_sdallocx je_sdallocx 55# define je_nallocx je_nallocx 56# define je_mallctl je_mallctl 57# define je_mallctlnametomib je_mallctlnametomib 58# define je_mallctlbymib je_mallctlbymib 59# define je_malloc_stats_print je_malloc_stats_print 60# define je_malloc_usable_size je_malloc_usable_size 61# define je_memalign je_memalign 62# define je_valloc je_valloc 63#endif 64 65#include <stdlib.h> 66#include <stdbool.h> 67#include <stdint.h> 68#include <limits.h> 69#include <strings.h> 70 71#define JEMALLOC_VERSION "3.6.0-129-g3cae39166d1fc58873c5df3c0c96b45d49cb5778" 72#define JEMALLOC_VERSION_MAJOR 3 73#define JEMALLOC_VERSION_MINOR 6 74#define JEMALLOC_VERSION_BUGFIX 0 75#define JEMALLOC_VERSION_NREV 129 76#define JEMALLOC_VERSION_GID "3cae39166d1fc58873c5df3c0c96b45d49cb5778" 77 78# define MALLOCX_LG_ALIGN(la) (la) 79# if LG_SIZEOF_PTR == 2 80# define MALLOCX_ALIGN(a) (ffs(a)-1) 81# else 82# define MALLOCX_ALIGN(a) \ 83 ((a < (size_t)INT_MAX) ? ffs(a)-1 : ffs(a>>32)+31) 84# endif 85# define MALLOCX_ZERO ((int)0x40) 86/* 87 * Bias tcache index bits so that 0 encodes "automatic tcache management", and 1 88 * encodes MALLOCX_TCACHE_NONE. 89 */ 90# define MALLOCX_TCACHE(tc) ((int)(((tc)+2) << 8)) 91# define MALLOCX_TCACHE_NONE MALLOCX_TCACHE(-1) 92/* 93 * Bias arena index bits so that 0 encodes "use an automatically chosen arena". 94 */ 95# define MALLOCX_ARENA(a) ((int)(((a)+1) << 20)) 96 97#ifdef JEMALLOC_HAVE_ATTR 98# define JEMALLOC_ATTR(s) __attribute__((s)) 99# ifndef JEMALLOC_EXPORT 100# define JEMALLOC_EXPORT JEMALLOC_ATTR(visibility("default")) 101# endif 102# define JEMALLOC_ALIGNED(s) JEMALLOC_ATTR(aligned(s)) 103# define JEMALLOC_SECTION(s) JEMALLOC_ATTR(section(s)) 104# define JEMALLOC_NOINLINE JEMALLOC_ATTR(noinline) 105#elif _MSC_VER 106# define JEMALLOC_ATTR(s) 107# ifndef JEMALLOC_EXPORT 108# ifdef DLLEXPORT 109# define JEMALLOC_EXPORT __declspec(dllexport) 110# else 111# define JEMALLOC_EXPORT __declspec(dllimport) 112# endif 113# endif 114# define JEMALLOC_ALIGNED(s) __declspec(align(s)) 115# define JEMALLOC_SECTION(s) __declspec(allocate(s)) 116# define JEMALLOC_NOINLINE __declspec(noinline) 117#else 118# define JEMALLOC_ATTR(s) 119# define JEMALLOC_EXPORT 120# define JEMALLOC_ALIGNED(s) 121# define JEMALLOC_SECTION(s) 122# define JEMALLOC_NOINLINE 123#endif 124 125/* 126 * The je_ prefix on the following public symbol declarations is an artifact 127 * of namespace management, and should be omitted in application code unless 128 * JEMALLOC_NO_DEMANGLE is defined (see jemalloc_mangle.h). 129 */ 130extern JEMALLOC_EXPORT const char *je_malloc_conf; 131extern JEMALLOC_EXPORT void (*je_malloc_message)(void *cbopaque, 132 const char *s); 133 134JEMALLOC_EXPORT void *je_malloc(size_t size) JEMALLOC_ATTR(malloc); 135JEMALLOC_EXPORT void *je_calloc(size_t num, size_t size) 136 JEMALLOC_ATTR(malloc); 137JEMALLOC_EXPORT int je_posix_memalign(void **memptr, size_t alignment, 138 size_t size) JEMALLOC_ATTR(nonnull(1)); 139JEMALLOC_EXPORT void *je_aligned_alloc(size_t alignment, size_t size) 140 JEMALLOC_ATTR(malloc); 141JEMALLOC_EXPORT void *je_realloc(void *ptr, size_t size); 142JEMALLOC_EXPORT void je_free(void *ptr); 143 144JEMALLOC_EXPORT void *je_mallocx(size_t size, int flags) 145 JEMALLOC_ATTR(malloc); 146JEMALLOC_EXPORT void *je_rallocx(void *ptr, size_t size, int flags); 147JEMALLOC_EXPORT size_t je_xallocx(void *ptr, size_t size, size_t extra, 148 int flags); 149JEMALLOC_EXPORT size_t je_sallocx(const void *ptr, int flags) 150 JEMALLOC_ATTR(pure); 151JEMALLOC_EXPORT void je_dallocx(void *ptr, int flags); 152JEMALLOC_EXPORT void je_sdallocx(void *ptr, size_t size, int flags); 153JEMALLOC_EXPORT size_t je_nallocx(size_t size, int flags) 154 JEMALLOC_ATTR(pure); 155 156JEMALLOC_EXPORT int je_mallctl(const char *name, void *oldp, 157 size_t *oldlenp, void *newp, size_t newlen); 158JEMALLOC_EXPORT int je_mallctlnametomib(const char *name, size_t *mibp, 159 size_t *miblenp); 160JEMALLOC_EXPORT int je_mallctlbymib(const size_t *mib, size_t miblen, 161 void *oldp, size_t *oldlenp, void *newp, size_t newlen); 162JEMALLOC_EXPORT void je_malloc_stats_print(void (*write_cb)(void *, 163 const char *), void *je_cbopaque, const char *opts); 164JEMALLOC_EXPORT size_t je_malloc_usable_size( 165 JEMALLOC_USABLE_SIZE_CONST void *ptr); 166 167#ifdef JEMALLOC_OVERRIDE_MEMALIGN 168JEMALLOC_EXPORT void * je_memalign(size_t alignment, size_t size) 169 JEMALLOC_ATTR(malloc); 170#endif 171 172#ifdef JEMALLOC_OVERRIDE_VALLOC 173JEMALLOC_EXPORT void * je_valloc(size_t size) JEMALLOC_ATTR(malloc); 174#endif 175 176typedef void *(chunk_alloc_t)(void *, size_t, size_t, bool *, unsigned); 177typedef bool (chunk_dalloc_t)(void *, size_t, unsigned); 178typedef bool (chunk_purge_t)(void *, size_t, size_t, unsigned); 179 180/* 181 * By default application code must explicitly refer to mangled symbol names, 182 * so that it is possible to use jemalloc in conjunction with another allocator 183 * in the same application. Define JEMALLOC_MANGLE in order to cause automatic 184 * name mangling that matches the API prefixing that happened as a result of 185 * --with-mangling and/or --with-jemalloc-prefix configuration settings. 186 */ 187#ifdef JEMALLOC_MANGLE 188# ifndef JEMALLOC_NO_DEMANGLE 189# define JEMALLOC_NO_DEMANGLE 190# endif 191# define malloc_conf je_malloc_conf 192# define malloc_message je_malloc_message 193# define malloc je_malloc 194# define calloc je_calloc 195# define posix_memalign je_posix_memalign 196# define aligned_alloc je_aligned_alloc 197# define realloc je_realloc 198# define free je_free 199# define mallocx je_mallocx 200# define rallocx je_rallocx 201# define xallocx je_xallocx 202# define sallocx je_sallocx 203# define dallocx je_dallocx 204# define sdallocx je_sdallocx 205# define nallocx je_nallocx 206# define mallctl je_mallctl 207# define mallctlnametomib je_mallctlnametomib 208# define mallctlbymib je_mallctlbymib 209# define malloc_stats_print je_malloc_stats_print 210# define malloc_usable_size je_malloc_usable_size 211# define memalign je_memalign 212# define valloc je_valloc 213#endif 214 215/* 216 * The je_* macros can be used as stable alternative names for the 217 * public jemalloc API if JEMALLOC_NO_DEMANGLE is defined. This is primarily 218 * meant for use in jemalloc itself, but it can be used by application code to 219 * provide isolation from the name mangling specified via --with-mangling 220 * and/or --with-jemalloc-prefix. 221 */ 222#ifndef JEMALLOC_NO_DEMANGLE 223# undef je_malloc_conf 224# undef je_malloc_message 225# undef je_malloc 226# undef je_calloc 227# undef je_posix_memalign 228# undef je_aligned_alloc 229# undef je_realloc 230# undef je_free 231# undef je_mallocx 232# undef je_rallocx 233# undef je_xallocx 234# undef je_sallocx 235# undef je_dallocx 236# undef je_sdallocx 237# undef je_nallocx 238# undef je_mallctl 239# undef je_mallctlnametomib 240# undef je_mallctlbymib 241# undef je_malloc_stats_print 242# undef je_malloc_usable_size 243# undef je_memalign 244# undef je_valloc 245#endif 246 247#ifdef __cplusplus 248}; 249#endif 250#endif /* JEMALLOC_H_ */ 251