1 #ifndef JEMALLOC_INTERNAL_H
2 #define JEMALLOC_INTERNAL_H
6 # define ENOENT ERROR_PATH_NOT_FOUND
7 # define EINVAL ERROR_BAD_ARGUMENTS
8 # define EAGAIN ERROR_OUTOFMEMORY
9 # define EPERM ERROR_WRITE_FAULT
10 # define EFAULT ERROR_INVALID_ADDRESS
11 # define ENOMEM ERROR_NOT_ENOUGH_MEMORY
13 # define ERANGE ERROR_INVALID_DATA
15 # include <sys/param.h>
16 # include <sys/mman.h>
17 # include <sys/syscall.h>
18 # if !defined(SYS_write) && defined(__NR_write)
19 # define SYS_write __NR_write
25 #include <sys/types.h>
29 # define SIZE_T_MAX SIZE_MAX
38 # define offsetof(type, member) ((size_t)&(((type *)NULL)->member))
46 typedef intptr_t ssize_t
;
47 # define PATH_MAX 1024
48 # define STDERR_FILENO 2
49 # define __func__ __FUNCTION__
50 /* Disable warnings about deprecated system functions */
51 # pragma warning(disable: 4996)
57 #define JEMALLOC_NO_DEMANGLE
58 #include "../jemalloc@install_suffix@.h"
60 #ifdef JEMALLOC_UTRACE
61 #include <sys/ktrace.h>
64 #ifdef JEMALLOC_VALGRIND
65 #include <valgrind/valgrind.h>
66 #include <valgrind/memcheck.h>
69 #include "jemalloc/internal/private_namespace.h"
71 #ifdef JEMALLOC_CC_SILENCE
72 #define UNUSED JEMALLOC_ATTR(unused)
77 static const bool config_debug
=
84 static const bool config_dss
=
91 static const bool config_fill
=
98 static const bool config_lazy_lock
=
99 #ifdef JEMALLOC_LAZY_LOCK
105 static const bool config_prof
=
112 static const bool config_prof_libgcc
=
113 #ifdef JEMALLOC_PROF_LIBGCC
119 static const bool config_prof_libunwind
=
120 #ifdef JEMALLOC_PROF_LIBUNWIND
126 static const bool config_mremap
=
127 #ifdef JEMALLOC_MREMAP
133 static const bool config_munmap
=
134 #ifdef JEMALLOC_MUNMAP
140 static const bool config_stats
=
141 #ifdef JEMALLOC_STATS
147 static const bool config_tcache
=
148 #ifdef JEMALLOC_TCACHE
154 static const bool config_tls
=
161 static const bool config_utrace
=
162 #ifdef JEMALLOC_UTRACE
168 static const bool config_valgrind
=
169 #ifdef JEMALLOC_VALGRIND
175 static const bool config_xmalloc
=
176 #ifdef JEMALLOC_XMALLOC
182 static const bool config_ivsalloc
=
183 #ifdef JEMALLOC_IVSALLOC
190 #ifdef JEMALLOC_ATOMIC9
191 #include <machine/atomic.h>
194 #if (defined(JEMALLOC_OSATOMIC) || defined(JEMALLOC_OSSPIN))
195 #include <libkern/OSAtomic.h>
199 #include <mach/mach_error.h>
200 #include <mach/mach_init.h>
201 #include <mach/vm_map.h>
202 #include <malloc/malloc.h>
206 #include "jemalloc/internal/rb.h"
207 #include "jemalloc/internal/qr.h"
208 #include "jemalloc/internal/ql.h"
211 * jemalloc can conceptually be broken into components (arena, tcache, etc.),
212 * but there are circular dependencies that cannot be broken without
213 * substantial performance degradation. In order to reduce the effect on
214 * visual code flow, read the header files in multiple passes, with one of the
215 * following cpp variables defined during each pass:
217 * JEMALLOC_H_TYPES : Preprocessor-defined constants and psuedo-opaque data
219 * JEMALLOC_H_STRUCTS : Data structures.
220 * JEMALLOC_H_EXTERNS : Extern data declarations and function prototypes.
221 * JEMALLOC_H_INLINES : Inline functions.
223 /******************************************************************************/
224 #define JEMALLOC_H_TYPES
226 #define ALLOCM_LG_ALIGN_MASK ((int)0x3f)
228 #define ZU(z) ((size_t)z)
231 # define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
234 #ifdef JEMALLOC_DEBUG
235 /* Disable inlining to make debugging easier. */
236 # define JEMALLOC_INLINE
239 # define JEMALLOC_ENABLE_INLINE
240 # define JEMALLOC_INLINE static inline
242 # define inline _inline
246 /* Smallest size class to support. */
247 #define LG_TINY_MIN 3
248 #define TINY_MIN (1U << LG_TINY_MIN)
251 * Minimum alignment of allocations is 2^LG_QUANTUM bytes (ignoring tiny size
255 # if (defined(__i386__) || defined(_M_IX86))
256 # define LG_QUANTUM 4
259 # define LG_QUANTUM 4
262 # define LG_QUANTUM 4
265 # define LG_QUANTUM 4
267 # if (defined(__amd64__) || defined(__x86_64__) || defined(_M_X64))
268 # define LG_QUANTUM 4
271 # define LG_QUANTUM 3
274 # define LG_QUANTUM 3
277 # define LG_QUANTUM 4
280 # define LG_QUANTUM 4
283 # define LG_QUANTUM 4
286 # define LG_QUANTUM 4
289 # error "No LG_QUANTUM definition for architecture; specify via CPPFLAGS"
293 #define QUANTUM ((size_t)(1U << LG_QUANTUM))
294 #define QUANTUM_MASK (QUANTUM - 1)
296 /* Return the smallest quantum multiple that is >= a. */
297 #define QUANTUM_CEILING(a) \
298 (((a) + QUANTUM_MASK) & ~QUANTUM_MASK)
300 #define LONG ((size_t)(1U << LG_SIZEOF_LONG))
301 #define LONG_MASK (LONG - 1)
303 /* Return the smallest long multiple that is >= a. */
304 #define LONG_CEILING(a) \
305 (((a) + LONG_MASK) & ~LONG_MASK)
307 #define SIZEOF_PTR (1U << LG_SIZEOF_PTR)
308 #define PTR_MASK (SIZEOF_PTR - 1)
310 /* Return the smallest (void *) multiple that is >= a. */
311 #define PTR_CEILING(a) \
312 (((a) + PTR_MASK) & ~PTR_MASK)
315 * Maximum size of L1 cache line. This is used to avoid cache line aliasing.
316 * In addition, this controls the spacing of cacheline-spaced size classes.
318 * CACHELINE cannot be based on LG_CACHELINE because __declspec(align()) can
319 * only handle raw constants.
321 #define LG_CACHELINE 6
323 #define CACHELINE_MASK (CACHELINE - 1)
325 /* Return the smallest cacheline multiple that is >= s. */
326 #define CACHELINE_CEILING(s) \
327 (((s) + CACHELINE_MASK) & ~CACHELINE_MASK)
329 /* Page size. STATIC_PAGE_SHIFT is determined by the configure script. */
333 #define LG_PAGE STATIC_PAGE_SHIFT
334 #define PAGE ((size_t)(1U << STATIC_PAGE_SHIFT))
335 #define PAGE_MASK ((size_t)(PAGE - 1))
337 /* Return the smallest pagesize multiple that is >= s. */
338 #define PAGE_CEILING(s) \
339 (((s) + PAGE_MASK) & ~PAGE_MASK)
341 /* Return the nearest aligned address at or below a. */
342 #define ALIGNMENT_ADDR2BASE(a, alignment) \
343 ((void *)((uintptr_t)(a) & (-(alignment))))
345 /* Return the offset between a and the nearest aligned address at or below a. */
346 #define ALIGNMENT_ADDR2OFFSET(a, alignment) \
347 ((size_t)((uintptr_t)(a) & (alignment - 1)))
349 /* Return the smallest alignment multiple that is >= s. */
350 #define ALIGNMENT_CEILING(s, alignment) \
351 (((s) + (alignment - 1)) & (-(alignment)))
353 /* Declare a variable length array */
354 #if __STDC_VERSION__ < 199901L
357 # define alloca _alloca
361 # define VARIABLE_ARRAY(type, name, count) \
362 type *name = alloca(sizeof(type) * count)
364 # define VARIABLE_ARRAY(type, name, count) type name[count]
367 #ifdef JEMALLOC_VALGRIND
369 * The JEMALLOC_VALGRIND_*() macros must be macros rather than functions
370 * so that when Valgrind reports errors, there are no extra stack frames
373 * The size that is reported to valgrind must be consistent through a chain of
374 * malloc..realloc..realloc calls. Request size isn't recorded anywhere in
375 * jemalloc, so it is critical that all callers of these macros provide usize
376 * rather than request size. As a result, buffer overflow detection is
377 * technically weakened for the standard API, though it is generally accepted
378 * practice to consider any extra bytes reported by malloc_usable_size() as
381 #define JEMALLOC_VALGRIND_MALLOC(cond, ptr, usize, zero) do { \
382 if (config_valgrind && opt_valgrind && cond) \
383 VALGRIND_MALLOCLIKE_BLOCK(ptr, usize, p2rz(ptr), zero); \
385 #define JEMALLOC_VALGRIND_REALLOC(ptr, usize, old_ptr, old_usize, \
386 old_rzsize, zero) do { \
387 if (config_valgrind && opt_valgrind) { \
388 size_t rzsize = p2rz(ptr); \
390 if (ptr == old_ptr) { \
391 VALGRIND_RESIZEINPLACE_BLOCK(ptr, old_usize, \
393 if (zero && old_usize < usize) { \
394 VALGRIND_MAKE_MEM_DEFINED( \
395 (void *)((uintptr_t)ptr + \
396 old_usize), usize - old_usize); \
399 if (old_ptr != NULL) { \
400 VALGRIND_FREELIKE_BLOCK(old_ptr, \
404 size_t copy_size = (old_usize < usize) \
405 ? old_usize : usize; \
406 size_t tail_size = usize - copy_size; \
407 VALGRIND_MALLOCLIKE_BLOCK(ptr, usize, \
409 if (copy_size > 0) { \
410 VALGRIND_MAKE_MEM_DEFINED(ptr, \
413 if (zero && tail_size > 0) { \
414 VALGRIND_MAKE_MEM_DEFINED( \
415 (void *)((uintptr_t)ptr + \
416 copy_size), tail_size); \
422 #define JEMALLOC_VALGRIND_FREE(ptr, rzsize) do { \
423 if (config_valgrind && opt_valgrind) \
424 VALGRIND_FREELIKE_BLOCK(ptr, rzsize); \
427 #define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed)
428 #define VALGRIND_RESIZEINPLACE_BLOCK(addr, oldSizeB, newSizeB, rzB)
429 #define VALGRIND_FREELIKE_BLOCK(addr, rzB)
430 #define VALGRIND_MAKE_MEM_UNDEFINED(_qzz_addr, _qzz_len)
431 #define VALGRIND_MAKE_MEM_DEFINED(_qzz_addr, _qzz_len)
432 #define JEMALLOC_VALGRIND_MALLOC(cond, ptr, usize, zero)
433 #define JEMALLOC_VALGRIND_REALLOC(ptr, usize, old_ptr, old_usize, \
435 #define JEMALLOC_VALGRIND_FREE(ptr, rzsize)
438 #include "jemalloc/internal/util.h"
439 #include "jemalloc/internal/atomic.h"
440 #include "jemalloc/internal/prng.h"
441 #include "jemalloc/internal/ckh.h"
442 #include "jemalloc/internal/size_classes.h"
443 #include "jemalloc/internal/stats.h"
444 #include "jemalloc/internal/ctl.h"
445 #include "jemalloc/internal/mutex.h"
446 #include "jemalloc/internal/tsd.h"
447 #include "jemalloc/internal/mb.h"
448 #include "jemalloc/internal/extent.h"
449 #include "jemalloc/internal/arena.h"
450 #include "jemalloc/internal/bitmap.h"
451 #include "jemalloc/internal/base.h"
452 #include "jemalloc/internal/chunk.h"
453 #include "jemalloc/internal/huge.h"
454 #include "jemalloc/internal/rtree.h"
455 #include "jemalloc/internal/tcache.h"
456 #include "jemalloc/internal/hash.h"
457 #include "jemalloc/internal/quarantine.h"
458 #include "jemalloc/internal/prof.h"
460 #undef JEMALLOC_H_TYPES
461 /******************************************************************************/
462 #define JEMALLOC_H_STRUCTS
464 #include "jemalloc/internal/util.h"
465 #include "jemalloc/internal/atomic.h"
466 #include "jemalloc/internal/prng.h"
467 #include "jemalloc/internal/ckh.h"
468 #include "jemalloc/internal/size_classes.h"
469 #include "jemalloc/internal/stats.h"
470 #include "jemalloc/internal/ctl.h"
471 #include "jemalloc/internal/mutex.h"
472 #include "jemalloc/internal/tsd.h"
473 #include "jemalloc/internal/mb.h"
474 #include "jemalloc/internal/bitmap.h"
475 #include "jemalloc/internal/extent.h"
476 #include "jemalloc/internal/arena.h"
477 #include "jemalloc/internal/base.h"
478 #include "jemalloc/internal/chunk.h"
479 #include "jemalloc/internal/huge.h"
480 #include "jemalloc/internal/rtree.h"
481 #include "jemalloc/internal/tcache.h"
482 #include "jemalloc/internal/hash.h"
483 #include "jemalloc/internal/quarantine.h"
484 #include "jemalloc/internal/prof.h"
488 uint64_t deallocated
;
489 } thread_allocated_t
;
491 * The JEMALLOC_CONCAT() wrapper is necessary to pass {0, 0} via a cpp macro
494 #define THREAD_ALLOCATED_INITIALIZER JEMALLOC_CONCAT({0, 0})
496 #undef JEMALLOC_H_STRUCTS
497 /******************************************************************************/
498 #define JEMALLOC_H_EXTERNS
500 extern bool opt_abort
;
501 extern bool opt_junk
;
502 extern size_t opt_quarantine
;
503 extern bool opt_redzone
;
504 extern bool opt_utrace
;
505 extern bool opt_valgrind
;
506 extern bool opt_xmalloc
;
507 extern bool opt_zero
;
508 extern size_t opt_narenas
;
510 /* Number of CPUs. */
511 extern unsigned ncpus
;
513 extern malloc_mutex_t arenas_lock
; /* Protects arenas initialization. */
515 * Arenas that are used to service external requests. Not all elements of the
516 * arenas array are necessarily used; arenas are created lazily as needed.
518 extern arena_t
**arenas
;
519 extern unsigned narenas
;
521 arena_t
*arenas_extend(unsigned ind
);
522 void arenas_cleanup(void *arg
);
523 arena_t
*choose_arena_hard(void);
524 void jemalloc_prefork(void);
525 void jemalloc_postfork_parent(void);
526 void jemalloc_postfork_child(void);
528 #include "jemalloc/internal/util.h"
529 #include "jemalloc/internal/atomic.h"
530 #include "jemalloc/internal/prng.h"
531 #include "jemalloc/internal/ckh.h"
532 #include "jemalloc/internal/size_classes.h"
533 #include "jemalloc/internal/stats.h"
534 #include "jemalloc/internal/ctl.h"
535 #include "jemalloc/internal/mutex.h"
536 #include "jemalloc/internal/tsd.h"
537 #include "jemalloc/internal/mb.h"
538 #include "jemalloc/internal/bitmap.h"
539 #include "jemalloc/internal/extent.h"
540 #include "jemalloc/internal/arena.h"
541 #include "jemalloc/internal/base.h"
542 #include "jemalloc/internal/chunk.h"
543 #include "jemalloc/internal/huge.h"
544 #include "jemalloc/internal/rtree.h"
545 #include "jemalloc/internal/tcache.h"
546 #include "jemalloc/internal/hash.h"
547 #include "jemalloc/internal/quarantine.h"
548 #include "jemalloc/internal/prof.h"
550 #undef JEMALLOC_H_EXTERNS
551 /******************************************************************************/
552 #define JEMALLOC_H_INLINES
554 #include "jemalloc/internal/util.h"
555 #include "jemalloc/internal/atomic.h"
556 #include "jemalloc/internal/prng.h"
557 #include "jemalloc/internal/ckh.h"
558 #include "jemalloc/internal/size_classes.h"
559 #include "jemalloc/internal/stats.h"
560 #include "jemalloc/internal/ctl.h"
561 #include "jemalloc/internal/mutex.h"
562 #include "jemalloc/internal/tsd.h"
563 #include "jemalloc/internal/mb.h"
564 #include "jemalloc/internal/extent.h"
565 #include "jemalloc/internal/base.h"
566 #include "jemalloc/internal/chunk.h"
567 #include "jemalloc/internal/huge.h"
569 #ifndef JEMALLOC_ENABLE_INLINE
570 malloc_tsd_protos(JEMALLOC_ATTR(unused
), arenas
, arena_t
*)
572 size_t s2u(size_t size
);
573 size_t sa2u(size_t size
, size_t alignment
);
574 arena_t
*choose_arena(arena_t
*arena
);
577 #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_C_))
579 * Map of pthread_self() --> arenas[???], used for selecting an arena to use
582 malloc_tsd_externs(arenas
, arena_t
*)
583 malloc_tsd_funcs(JEMALLOC_INLINE
, arenas
, arena_t
*, NULL
, arenas_cleanup
)
586 * Compute usable size that would result from allocating an object with the
589 JEMALLOC_INLINE
size_t
593 if (size
<= SMALL_MAXCLASS
)
594 return (arena_bin_info
[SMALL_SIZE2BIN(size
)].reg_size
);
595 if (size
<= arena_maxclass
)
596 return (PAGE_CEILING(size
));
597 return (CHUNK_CEILING(size
));
601 * Compute usable size that would result from allocating an object with the
602 * specified size and alignment.
604 JEMALLOC_INLINE
size_t
605 sa2u(size_t size
, size_t alignment
)
609 assert(alignment
!= 0 && ((alignment
- 1) & alignment
) == 0);
612 * Round size up to the nearest multiple of alignment.
614 * This done, we can take advantage of the fact that for each small
615 * size class, every object is aligned at the smallest power of two
616 * that is non-zero in the base two representation of the size. For
619 * Size | Base 2 | Minimum alignment
620 * -----+----------+------------------
622 * 144 | 10100000 | 32
623 * 192 | 11000000 | 64
625 usize
= ALIGNMENT_CEILING(size
, alignment
);
627 * (usize < size) protects against the combination of maximal
628 * alignment and size greater than maximal alignment.
631 /* size_t overflow. */
635 if (usize
<= arena_maxclass
&& alignment
<= PAGE
) {
636 if (usize
<= SMALL_MAXCLASS
)
637 return (arena_bin_info
[SMALL_SIZE2BIN(usize
)].reg_size
);
638 return (PAGE_CEILING(usize
));
643 * We can't achieve subpage alignment, so round up alignment
644 * permanently; it makes later calculations simpler.
646 alignment
= PAGE_CEILING(alignment
);
647 usize
= PAGE_CEILING(size
);
649 * (usize < size) protects against very large sizes within
650 * PAGE of SIZE_T_MAX.
652 * (usize + alignment < usize) protects against the
653 * combination of maximal alignment and usize large enough
654 * to cause overflow. This is similar to the first overflow
655 * check above, but it needs to be repeated due to the new
656 * usize value, which may now be *equal* to maximal
657 * alignment, whereas before we only detected overflow if the
658 * original size was *greater* than maximal alignment.
660 if (usize
< size
|| usize
+ alignment
< usize
) {
661 /* size_t overflow. */
666 * Calculate the size of the over-size run that arena_palloc()
667 * would need to allocate in order to guarantee the alignment.
668 * If the run wouldn't fit within a chunk, round up to a huge
671 run_size
= usize
+ alignment
- PAGE
;
672 if (run_size
<= arena_maxclass
)
673 return (PAGE_CEILING(usize
));
674 return (CHUNK_CEILING(usize
));
678 /* Choose an arena based on a per-thread value. */
679 JEMALLOC_INLINE arena_t
*
680 choose_arena(arena_t
*arena
)
687 if ((ret
= *arenas_tsd_get()) == NULL
) {
688 ret
= choose_arena_hard();
696 #include "jemalloc/internal/bitmap.h"
697 #include "jemalloc/internal/rtree.h"
699 * Include arena.h twice in order to resolve circular dependencies with
702 #define JEMALLOC_ARENA_INLINE_A
703 #include "jemalloc/internal/arena.h"
704 #undef JEMALLOC_ARENA_INLINE_A
705 #include "jemalloc/internal/tcache.h"
706 #define JEMALLOC_ARENA_INLINE_B
707 #include "jemalloc/internal/arena.h"
708 #undef JEMALLOC_ARENA_INLINE_B
709 #include "jemalloc/internal/hash.h"
710 #include "jemalloc/internal/quarantine.h"
712 #ifndef JEMALLOC_ENABLE_INLINE
713 void *imalloc(size_t size
);
714 void *icalloc(size_t size
);
715 void *ipalloc(size_t usize
, size_t alignment
, bool zero
);
716 size_t isalloc(const void *ptr
, bool demote
);
717 size_t ivsalloc(const void *ptr
, bool demote
);
718 size_t u2rz(size_t usize
);
719 size_t p2rz(const void *ptr
);
720 void idalloc(void *ptr
);
721 void iqalloc(void *ptr
);
722 void *iralloc(void *ptr
, size_t size
, size_t extra
, size_t alignment
,
723 bool zero
, bool no_move
);
724 malloc_tsd_protos(JEMALLOC_ATTR(unused
), thread_allocated
, thread_allocated_t
)
727 #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_C_))
728 JEMALLOC_INLINE
void *
734 if (size
<= arena_maxclass
)
735 return (arena_malloc(NULL
, size
, false, true));
737 return (huge_malloc(size
, false));
740 JEMALLOC_INLINE
void *
744 if (size
<= arena_maxclass
)
745 return (arena_malloc(NULL
, size
, true, true));
747 return (huge_malloc(size
, true));
750 JEMALLOC_INLINE
void *
751 ipalloc(size_t usize
, size_t alignment
, bool zero
)
756 assert(usize
== sa2u(usize
, alignment
));
758 if (usize
<= arena_maxclass
&& alignment
<= PAGE
)
759 ret
= arena_malloc(NULL
, usize
, zero
, true);
761 if (usize
<= arena_maxclass
) {
762 ret
= arena_palloc(choose_arena(NULL
), usize
, alignment
,
764 } else if (alignment
<= chunksize
)
765 ret
= huge_malloc(usize
, zero
);
767 ret
= huge_palloc(usize
, alignment
, zero
);
770 assert(ALIGNMENT_ADDR2BASE(ret
, alignment
) == ret
);
777 * size_t sz = isalloc(ptr, config_prof);
779 JEMALLOC_INLINE
size_t
780 isalloc(const void *ptr
, bool demote
)
783 arena_chunk_t
*chunk
;
786 /* Demotion only makes sense if config_prof is true. */
787 assert(config_prof
|| demote
== false);
789 chunk
= (arena_chunk_t
*)CHUNK_ADDR2BASE(ptr
);
791 ret
= arena_salloc(ptr
, demote
);
793 ret
= huge_salloc(ptr
);
798 JEMALLOC_INLINE
size_t
799 ivsalloc(const void *ptr
, bool demote
)
802 /* Return 0 if ptr is not within a chunk managed by jemalloc. */
803 if (rtree_get(chunks_rtree
, (uintptr_t)CHUNK_ADDR2BASE(ptr
)) == NULL
)
806 return (isalloc(ptr
, demote
));
809 JEMALLOC_INLINE
size_t
814 if (usize
<= SMALL_MAXCLASS
) {
815 size_t binind
= SMALL_SIZE2BIN(usize
);
816 ret
= arena_bin_info
[binind
].redzone_size
;
823 JEMALLOC_INLINE
size_t
824 p2rz(const void *ptr
)
826 size_t usize
= isalloc(ptr
, false);
828 return (u2rz(usize
));
834 arena_chunk_t
*chunk
;
838 chunk
= (arena_chunk_t
*)CHUNK_ADDR2BASE(ptr
);
840 arena_dalloc(chunk
->arena
, chunk
, ptr
, true);
842 huge_dalloc(ptr
, true);
849 if (config_fill
&& opt_quarantine
)
855 JEMALLOC_INLINE
void *
856 iralloc(void *ptr
, size_t size
, size_t extra
, size_t alignment
, bool zero
,
865 oldsize
= isalloc(ptr
, config_prof
);
867 if (alignment
!= 0 && ((uintptr_t)ptr
& ((uintptr_t)alignment
-1))
869 size_t usize
, copysize
;
872 * Existing object alignment is inadequate; allocate new space
877 usize
= sa2u(size
+ extra
, alignment
);
880 ret
= ipalloc(usize
, alignment
, zero
);
884 /* Try again, without extra this time. */
885 usize
= sa2u(size
, alignment
);
888 ret
= ipalloc(usize
, alignment
, zero
);
893 * Copy at most size bytes (not size+extra), since the caller
894 * has no expectation that the extra bytes will be reliably
897 copysize
= (size
< oldsize
) ? size
: oldsize
;
898 memcpy(ret
, ptr
, copysize
);
904 if (size
<= arena_maxclass
) {
905 return (arena_ralloc_no_move(ptr
, oldsize
, size
,
908 return (huge_ralloc_no_move(ptr
, oldsize
, size
,
912 if (size
+ extra
<= arena_maxclass
) {
913 return (arena_ralloc(ptr
, oldsize
, size
, extra
,
914 alignment
, zero
, true));
916 return (huge_ralloc(ptr
, oldsize
, size
, extra
,
922 malloc_tsd_externs(thread_allocated
, thread_allocated_t
)
923 malloc_tsd_funcs(JEMALLOC_INLINE
, thread_allocated
, thread_allocated_t
,
924 THREAD_ALLOCATED_INITIALIZER
, malloc_tsd_no_cleanup
)
927 #include "jemalloc/internal/prof.h"
929 #undef JEMALLOC_H_INLINES
930 /******************************************************************************/
931 #endif /* JEMALLOC_INTERNAL_H */