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