MCPcopy Create free account
hub / github.com/beefytech/Beef / do_rallocx

Function do_rallocx

BeefRT/JEMalloc/src/jemalloc.c:3492–3568  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3490}
3491
3492static void *
3493do_rallocx(void *ptr, size_t size, int flags, bool is_realloc) {
3494 void *p;
3495 tsd_t *tsd;
3496 size_t usize;
3497 size_t old_usize;
3498 size_t alignment = MALLOCX_ALIGN_GET(flags);
3499 arena_t *arena;
3500
3501 assert(ptr != NULL);
3502 assert(size != 0);
3503 assert(malloc_initialized() || IS_INITIALIZER);
3504 tsd = tsd_fetch();
3505 check_entry_exit_locking(tsd_tsdn(tsd));
3506
3507 bool zero = zero_get(MALLOCX_ZERO_GET(flags), /* slow */ true);
3508
3509 unsigned arena_ind = mallocx_arena_get(flags);
3510 if (arena_get_from_ind(tsd, arena_ind, &arena)) {
3511 goto label_oom;
3512 }
3513
3514 unsigned tcache_ind = mallocx_tcache_get(flags);
3515 tcache_t *tcache = tcache_get_from_ind(tsd, tcache_ind,
3516 /* slow */ true, /* is_alloc */ true);
3517
3518 emap_alloc_ctx_t alloc_ctx;
3519 emap_alloc_ctx_lookup(tsd_tsdn(tsd), &arena_emap_global, ptr,
3520 &alloc_ctx);
3521 assert(alloc_ctx.szind != SC_NSIZES);
3522 old_usize = sz_index2size(alloc_ctx.szind);
3523 assert(old_usize == isalloc(tsd_tsdn(tsd), ptr));
3524 if (aligned_usize_get(size, alignment, &usize, NULL, false)) {
3525 goto label_oom;
3526 }
3527
3528 hook_ralloc_args_t hook_args = {is_realloc, {(uintptr_t)ptr, size,
3529 flags, 0}};
3530 if (config_prof && opt_prof) {
3531 p = irallocx_prof(tsd, ptr, old_usize, size, alignment, usize,
3532 zero, tcache, arena, &alloc_ctx, &hook_args);
3533 if (unlikely(p == NULL)) {
3534 goto label_oom;
3535 }
3536 } else {
3537 p = iralloct(tsd_tsdn(tsd), ptr, old_usize, size, alignment,
3538 zero, tcache, arena, &hook_args);
3539 if (unlikely(p == NULL)) {
3540 goto label_oom;
3541 }
3542 assert(usize == isalloc(tsd_tsdn(tsd), p));
3543 }
3544 assert(alignment == 0 || ((uintptr_t)p & (alignment - 1)) == ZU(0));
3545 thread_alloc_event(tsd, usize);
3546 thread_dalloc_event(tsd, old_usize);
3547
3548 UTRACE(ptr, size, p);
3549 check_entry_exit_locking(tsd_tsdn(tsd));

Callers 2

jemalloc.cFile · 0.85
do_realloc_nonnull_zeroFunction · 0.85

Calls 15

malloc_initializedFunction · 0.85
tsd_fetchFunction · 0.85
check_entry_exit_lockingFunction · 0.85
tsd_tsdnFunction · 0.85
zero_getFunction · 0.85
mallocx_arena_getFunction · 0.85
arena_get_from_indFunction · 0.85
mallocx_tcache_getFunction · 0.85
tcache_get_from_indFunction · 0.85
emap_alloc_ctx_lookupFunction · 0.85
sz_index2sizeFunction · 0.85
isallocFunction · 0.85

Tested by

no test coverage detected