MCPcopy Create free account
hub / github.com/F-Stack/f-stack / je_xallocx

Function je_xallocx

app/redis-6.2.6/deps/jemalloc/src/jemalloc.c:2828–2890  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2826}
2827
2828JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW
2829je_xallocx(void *ptr, size_t size, size_t extra, int flags) {
2830 tsd_t *tsd;
2831 size_t usize, old_usize;
2832 size_t alignment = MALLOCX_ALIGN_GET(flags);
2833 bool zero = flags & MALLOCX_ZERO;
2834
2835 LOG("core.xallocx.entry", "ptr: %p, size: %zu, extra: %zu, "
2836 "flags: %d", ptr, size, extra, flags);
2837
2838 assert(ptr != NULL);
2839 assert(size != 0);
2840 assert(SIZE_T_MAX - size >= extra);
2841 assert(malloc_initialized() || IS_INITIALIZER);
2842 tsd = tsd_fetch();
2843 check_entry_exit_locking(tsd_tsdn(tsd));
2844
2845 alloc_ctx_t alloc_ctx;
2846 rtree_ctx_t *rtree_ctx = tsd_rtree_ctx(tsd);
2847 rtree_szind_slab_read(tsd_tsdn(tsd), &extents_rtree, rtree_ctx,
2848 (uintptr_t)ptr, true, &alloc_ctx.szind, &alloc_ctx.slab);
2849 assert(alloc_ctx.szind != NSIZES);
2850 old_usize = sz_index2size(alloc_ctx.szind);
2851 assert(old_usize == isalloc(tsd_tsdn(tsd), ptr));
2852 /*
2853 * The API explicitly absolves itself of protecting against (size +
2854 * extra) numerical overflow, but we may need to clamp extra to avoid
2855 * exceeding LARGE_MAXCLASS.
2856 *
2857 * Ordinarily, size limit checking is handled deeper down, but here we
2858 * have to check as part of (size + extra) clamping, since we need the
2859 * clamped value in the above helper functions.
2860 */
2861 if (unlikely(size > LARGE_MAXCLASS)) {
2862 usize = old_usize;
2863 goto label_not_resized;
2864 }
2865 if (unlikely(LARGE_MAXCLASS - size < extra)) {
2866 extra = LARGE_MAXCLASS - size;
2867 }
2868
2869 if (config_prof && opt_prof) {
2870 usize = ixallocx_prof(tsd, ptr, old_usize, size, extra,
2871 alignment, zero, &alloc_ctx);
2872 } else {
2873 usize = ixallocx_helper(tsd_tsdn(tsd), ptr, old_usize, size,
2874 extra, alignment, zero);
2875 }
2876 if (unlikely(usize == old_usize)) {
2877 goto label_not_resized;
2878 }
2879
2880 if (config_stats) {
2881 *tsd_thread_allocatedp_get(tsd) += usize;
2882 *tsd_thread_deallocatedp_get(tsd) += old_usize;
2883 }
2884label_not_resized:
2885 UTRACE(ptr, size, ptr);

Callers

nothing calls this directly

Calls 9

malloc_initializedFunction · 0.85
tsd_fetchFunction · 0.85
check_entry_exit_lockingFunction · 0.85
tsd_tsdnFunction · 0.85
rtree_szind_slab_readFunction · 0.85
sz_index2sizeFunction · 0.85
isallocFunction · 0.85
ixallocx_profFunction · 0.85
ixallocx_helperFunction · 0.85

Tested by

no test coverage detected