Blame memkind-1.10.1/jemalloc/include/jemalloc/internal/jemalloc_internal_inlines_c.h

Packit Service 7f3b24
#ifndef JEMALLOC_INTERNAL_INLINES_C_H
Packit Service 7f3b24
#define JEMALLOC_INTERNAL_INLINES_C_H
Packit Service 7f3b24
Packit Service 7f3b24
#include "jemalloc/internal/hook.h"
Packit Service 7f3b24
#include "jemalloc/internal/jemalloc_internal_types.h"
Packit Service 7f3b24
#include "jemalloc/internal/sz.h"
Packit Service 7f3b24
#include "jemalloc/internal/witness.h"
Packit Service 7f3b24
Packit Service 7f3b24
/*
Packit Service 7f3b24
 * Translating the names of the 'i' functions:
Packit Service 7f3b24
 *   Abbreviations used in the first part of the function name (before
Packit Service 7f3b24
 *   alloc/dalloc) describe what that function accomplishes:
Packit Service 7f3b24
 *     a: arena (query)
Packit Service 7f3b24
 *     s: size (query, or sized deallocation)
Packit Service 7f3b24
 *     e: extent (query)
Packit Service 7f3b24
 *     p: aligned (allocates)
Packit Service 7f3b24
 *     vs: size (query, without knowing that the pointer is into the heap)
Packit Service 7f3b24
 *     r: rallocx implementation
Packit Service 7f3b24
 *     x: xallocx implementation
Packit Service 7f3b24
 *   Abbreviations used in the second part of the function name (after
Packit Service 7f3b24
 *   alloc/dalloc) describe the arguments it takes
Packit Service 7f3b24
 *     z: whether to return zeroed memory
Packit Service 7f3b24
 *     t: accepts a tcache_t * parameter
Packit Service 7f3b24
 *     m: accepts an arena_t * parameter
Packit Service 7f3b24
 */
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE arena_t *
Packit Service 7f3b24
iaalloc(tsdn_t *tsdn, const void *ptr) {
Packit Service 7f3b24
	assert(ptr != NULL);
Packit Service 7f3b24
Packit Service 7f3b24
	return arena_aalloc(tsdn, ptr);
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE size_t
Packit Service 7f3b24
isalloc(tsdn_t *tsdn, const void *ptr) {
Packit Service 7f3b24
	assert(ptr != NULL);
Packit Service 7f3b24
Packit Service 7f3b24
	return arena_salloc(tsdn, ptr);
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE void *
Packit Service 7f3b24
iallocztm(tsdn_t *tsdn, size_t size, szind_t ind, bool zero, tcache_t *tcache,
Packit Service 7f3b24
    bool is_internal, arena_t *arena, bool slow_path) {
Packit Service 7f3b24
	void *ret;
Packit Service 7f3b24
Packit Service 7f3b24
	assert(!is_internal || tcache == NULL);
Packit Service 7f3b24
	assert(!is_internal || arena == NULL || arena_is_auto(arena));
Packit Service 7f3b24
	if (!tsdn_null(tsdn) && tsd_reentrancy_level_get(tsdn_tsd(tsdn)) == 0) {
Packit Service 7f3b24
		witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
Packit Service 7f3b24
		    WITNESS_RANK_CORE, 0);
Packit Service 7f3b24
	}
Packit Service 7f3b24
Packit Service 7f3b24
	ret = arena_malloc(tsdn, arena, size, ind, zero, tcache, slow_path);
Packit Service 7f3b24
	if (config_stats && is_internal && likely(ret != NULL)) {
Packit Service 7f3b24
		arena_internal_add(iaalloc(tsdn, ret), isalloc(tsdn, ret));
Packit Service 7f3b24
	}
Packit Service 7f3b24
	return ret;
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE void *
Packit Service 7f3b24
ialloc(tsd_t *tsd, size_t size, szind_t ind, bool zero, bool slow_path) {
Packit Service 7f3b24
	return iallocztm(tsd_tsdn(tsd), size, ind, zero, tcache_get(tsd), false,
Packit Service 7f3b24
	    NULL, slow_path);
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE void *
Packit Service 7f3b24
ipallocztm(tsdn_t *tsdn, size_t usize, size_t alignment, bool zero,
Packit Service 7f3b24
    tcache_t *tcache, bool is_internal, arena_t *arena) {
Packit Service 7f3b24
	void *ret;
Packit Service 7f3b24
Packit Service 7f3b24
	assert(usize != 0);
Packit Service 7f3b24
	assert(usize == sz_sa2u(usize, alignment));
Packit Service 7f3b24
	assert(!is_internal || tcache == NULL);
Packit Service 7f3b24
	assert(!is_internal || arena == NULL || arena_is_auto(arena));
Packit Service 7f3b24
	witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
Packit Service 7f3b24
	    WITNESS_RANK_CORE, 0);
Packit Service 7f3b24
Packit Service 7f3b24
	ret = arena_palloc(tsdn, arena, usize, alignment, zero, tcache);
Packit Service 7f3b24
	assert(ALIGNMENT_ADDR2BASE(ret, alignment) == ret);
Packit Service 7f3b24
	if (config_stats && is_internal && likely(ret != NULL)) {
Packit Service 7f3b24
		arena_internal_add(iaalloc(tsdn, ret), isalloc(tsdn, ret));
Packit Service 7f3b24
	}
Packit Service 7f3b24
	return ret;
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE void *
Packit Service 7f3b24
ipalloct(tsdn_t *tsdn, size_t usize, size_t alignment, bool zero,
Packit Service 7f3b24
    tcache_t *tcache, arena_t *arena) {
Packit Service 7f3b24
	return ipallocztm(tsdn, usize, alignment, zero, tcache, false, arena);
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE void *
Packit Service 7f3b24
ipalloc(tsd_t *tsd, size_t usize, size_t alignment, bool zero) {
Packit Service 7f3b24
	return ipallocztm(tsd_tsdn(tsd), usize, alignment, zero,
Packit Service 7f3b24
	    tcache_get(tsd), false, NULL);
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE size_t
Packit Service 7f3b24
ivsalloc(tsdn_t *tsdn, const void *ptr) {
Packit Service 7f3b24
	return arena_vsalloc(tsdn, ptr);
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE void
Packit Service 7f3b24
idalloctm(tsdn_t *tsdn, void *ptr, tcache_t *tcache, alloc_ctx_t *alloc_ctx,
Packit Service 7f3b24
    bool is_internal, bool slow_path) {
Packit Service 7f3b24
	assert(ptr != NULL);
Packit Service 7f3b24
	assert(!is_internal || tcache == NULL);
Packit Service 7f3b24
	assert(!is_internal || arena_is_auto(iaalloc(tsdn, ptr)));
Packit Service 7f3b24
	witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
Packit Service 7f3b24
	    WITNESS_RANK_CORE, 0);
Packit Service 7f3b24
	if (config_stats && is_internal) {
Packit Service 7f3b24
		arena_internal_sub(iaalloc(tsdn, ptr), isalloc(tsdn, ptr));
Packit Service 7f3b24
	}
Packit Service 7f3b24
	if (!is_internal && !tsdn_null(tsdn) &&
Packit Service 7f3b24
	    tsd_reentrancy_level_get(tsdn_tsd(tsdn)) != 0) {
Packit Service 7f3b24
		assert(tcache == NULL);
Packit Service 7f3b24
	}
Packit Service 7f3b24
	arena_dalloc(tsdn, ptr, tcache, alloc_ctx, slow_path);
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE void
Packit Service 7f3b24
idalloc(tsd_t *tsd, void *ptr) {
Packit Service 7f3b24
	idalloctm(tsd_tsdn(tsd), ptr, tcache_get(tsd), NULL, false, true);
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE void
Packit Service 7f3b24
isdalloct(tsdn_t *tsdn, void *ptr, size_t size, tcache_t *tcache,
Packit Service 7f3b24
    alloc_ctx_t *alloc_ctx, bool slow_path) {
Packit Service 7f3b24
	witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
Packit Service 7f3b24
	    WITNESS_RANK_CORE, 0);
Packit Service 7f3b24
	arena_sdalloc(tsdn, ptr, size, tcache, alloc_ctx, slow_path);
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE void *
Packit Service 7f3b24
iralloct_realign(tsdn_t *tsdn, void *ptr, size_t oldsize, size_t size,
Packit Service 7f3b24
    size_t alignment, bool zero, tcache_t *tcache, arena_t *arena,
Packit Service 7f3b24
    hook_ralloc_args_t *hook_args) {
Packit Service 7f3b24
	witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
Packit Service 7f3b24
	    WITNESS_RANK_CORE, 0);
Packit Service 7f3b24
	void *p;
Packit Service 7f3b24
	size_t usize, copysize;
Packit Service 7f3b24
Packit Service 7f3b24
	usize = sz_sa2u(size, alignment);
Packit Service 7f3b24
	if (unlikely(usize == 0 || usize > SC_LARGE_MAXCLASS)) {
Packit Service 7f3b24
		return NULL;
Packit Service 7f3b24
	}
Packit Service 7f3b24
	p = ipalloct(tsdn, usize, alignment, zero, tcache, arena);
Packit Service 7f3b24
	if (p == NULL) {
Packit Service 7f3b24
		return NULL;
Packit Service 7f3b24
	}
Packit Service 7f3b24
	/*
Packit Service 7f3b24
	 * Copy at most size bytes (not size+extra), since the caller has no
Packit Service 7f3b24
	 * expectation that the extra bytes will be reliably preserved.
Packit Service 7f3b24
	 */
Packit Service 7f3b24
	copysize = (size < oldsize) ? size : oldsize;
Packit Service 7f3b24
	memcpy(p, ptr, copysize);
Packit Service 7f3b24
	hook_invoke_alloc(hook_args->is_realloc
Packit Service 7f3b24
	    ? hook_alloc_realloc : hook_alloc_rallocx, p, (uintptr_t)p,
Packit Service 7f3b24
	    hook_args->args);
Packit Service 7f3b24
	hook_invoke_dalloc(hook_args->is_realloc
Packit Service 7f3b24
	    ? hook_dalloc_realloc : hook_dalloc_rallocx, ptr, hook_args->args);
Packit Service 7f3b24
	isdalloct(tsdn, ptr, oldsize, tcache, NULL, true);
Packit Service 7f3b24
	return p;
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
/*
Packit Service 7f3b24
 * is_realloc threads through the knowledge of whether or not this call comes
Packit Service 7f3b24
 * from je_realloc (as opposed to je_rallocx); this ensures that we pass the
Packit Service 7f3b24
 * correct entry point into any hooks.
Packit Service 7f3b24
 * Note that these functions are all force-inlined, so no actual bool gets
Packit Service 7f3b24
 * passed-around anywhere.
Packit Service 7f3b24
 */
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE void *
Packit Service 7f3b24
iralloct(tsdn_t *tsdn, void *ptr, size_t oldsize, size_t size, size_t alignment,
Packit Service 7f3b24
    bool zero, tcache_t *tcache, arena_t *arena, hook_ralloc_args_t *hook_args)
Packit Service 7f3b24
{
Packit Service 7f3b24
	assert(ptr != NULL);
Packit Service 7f3b24
	assert(size != 0);
Packit Service 7f3b24
	witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
Packit Service 7f3b24
	    WITNESS_RANK_CORE, 0);
Packit Service 7f3b24
Packit Service 7f3b24
	if (alignment != 0 && ((uintptr_t)ptr & ((uintptr_t)alignment-1))
Packit Service 7f3b24
	    != 0) {
Packit Service 7f3b24
		/*
Packit Service 7f3b24
		 * Existing object alignment is inadequate; allocate new space
Packit Service 7f3b24
		 * and copy.
Packit Service 7f3b24
		 */
Packit Service 7f3b24
		return iralloct_realign(tsdn, ptr, oldsize, size, alignment,
Packit Service 7f3b24
		    zero, tcache, arena, hook_args);
Packit Service 7f3b24
	}
Packit Service 7f3b24
Packit Service 7f3b24
	return arena_ralloc(tsdn, arena, ptr, oldsize, size, alignment, zero,
Packit Service 7f3b24
	    tcache, hook_args);
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE void *
Packit Service 7f3b24
iralloc(tsd_t *tsd, void *ptr, size_t oldsize, size_t size, size_t alignment,
Packit Service 7f3b24
    bool zero, hook_ralloc_args_t *hook_args) {
Packit Service 7f3b24
	return iralloct(tsd_tsdn(tsd), ptr, oldsize, size, alignment, zero,
Packit Service 7f3b24
	    tcache_get(tsd), NULL, hook_args);
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
JEMALLOC_ALWAYS_INLINE bool
Packit Service 7f3b24
ixalloc(tsdn_t *tsdn, void *ptr, size_t oldsize, size_t size, size_t extra,
Packit Service 7f3b24
    size_t alignment, bool zero, size_t *newsize) {
Packit Service 7f3b24
	assert(ptr != NULL);
Packit Service 7f3b24
	assert(size != 0);
Packit Service 7f3b24
	witness_assert_depth_to_rank(tsdn_witness_tsdp_get(tsdn),
Packit Service 7f3b24
	    WITNESS_RANK_CORE, 0);
Packit Service 7f3b24
Packit Service 7f3b24
	if (alignment != 0 && ((uintptr_t)ptr & ((uintptr_t)alignment-1))
Packit Service 7f3b24
	    != 0) {
Packit Service 7f3b24
		/* Existing object alignment is inadequate. */
Packit Service 7f3b24
		*newsize = oldsize;
Packit Service 7f3b24
		return true;
Packit Service 7f3b24
	}
Packit Service 7f3b24
Packit Service 7f3b24
	return arena_ralloc_no_move(tsdn, ptr, oldsize, size, extra, zero,
Packit Service 7f3b24
	    newsize);
Packit Service 7f3b24
}
Packit Service 7f3b24
Packit Service 7f3b24
#endif /* JEMALLOC_INTERNAL_INLINES_C_H */