#ifndef MEMUTILS_INTERNAL_H
#define MEMUTILS_INTERNAL_H
#include "utils/memutils.h"
extern void *AllocSetAlloc(MemoryContext context, Size size, int flags);
extern void AllocSetFree(void *pointer);
extern void *AllocSetRealloc(void *pointer, Size size, int flags);
extern void AllocSetReset(MemoryContext context);
extern void AllocSetDelete(MemoryContext context);
extern MemoryContext AllocSetGetChunkContext(void *pointer);
extern Size AllocSetGetChunkSpace(void *pointer);
extern bool AllocSetIsEmpty(MemoryContext context);
extern void AllocSetStats(MemoryContext context,
MemoryStatsPrintFunc printfunc, void *passthru,
MemoryContextCounters *totals,
bool print_to_stderr);
#ifdef MEMORY_CONTEXT_CHECKING
extern void AllocSetCheck(MemoryContext context);
#endif
extern void *GenerationAlloc(MemoryContext context, Size size, int flags);
extern void GenerationFree(void *pointer);
extern void *GenerationRealloc(void *pointer, Size size, int flags);
extern void GenerationReset(MemoryContext context);
extern void GenerationDelete(MemoryContext context);
extern MemoryContext GenerationGetChunkContext(void *pointer);
extern Size GenerationGetChunkSpace(void *pointer);
extern bool GenerationIsEmpty(MemoryContext context);
extern void GenerationStats(MemoryContext context,
MemoryStatsPrintFunc printfunc, void *passthru,
MemoryContextCounters *totals,
bool print_to_stderr);
#ifdef MEMORY_CONTEXT_CHECKING
extern void GenerationCheck(MemoryContext context);
#endif
extern void *SlabAlloc(MemoryContext context, Size size, int flags);
extern void SlabFree(void *pointer);
extern void *SlabRealloc(void *pointer, Size size, int flags);
extern void SlabReset(MemoryContext context);
extern void SlabDelete(MemoryContext context);
extern MemoryContext SlabGetChunkContext(void *pointer);
extern Size SlabGetChunkSpace(void *pointer);
extern bool SlabIsEmpty(MemoryContext context);
extern void SlabStats(MemoryContext context,
MemoryStatsPrintFunc printfunc, void *passthru,
MemoryContextCounters *totals,
bool print_to_stderr);
#ifdef MEMORY_CONTEXT_CHECKING
extern void SlabCheck(MemoryContext context);
#endif
extern void AlignedAllocFree(void *pointer);
extern void *AlignedAllocRealloc(void *pointer, Size size, int flags);
extern MemoryContext AlignedAllocGetChunkContext(void *pointer);
extern Size AlignedAllocGetChunkSpace(void *pointer);
extern void *BumpAlloc(MemoryContext context, Size size, int flags);
extern void BumpFree(void *pointer);
extern void *BumpRealloc(void *pointer, Size size, int flags);
extern void BumpReset(MemoryContext context);
extern void BumpDelete(MemoryContext context);
extern MemoryContext BumpGetChunkContext(void *pointer);
extern Size BumpGetChunkSpace(void *pointer);
extern bool BumpIsEmpty(MemoryContext context);
extern void BumpStats(MemoryContext context, MemoryStatsPrintFunc printfunc,
void *passthru, MemoryContextCounters *totals,
bool print_to_stderr);
#ifdef MEMORY_CONTEXT_CHECKING
extern void BumpCheck(MemoryContext context);
#endif
#define PallocAlignedExtraBytes(alignto) \
((alignto) + (sizeof(MemoryChunk) - MAXIMUM_ALIGNOF))
typedef enum MemoryContextMethodID
{
MCTX_0_RESERVED_UNUSEDMEM_ID,
MCTX_1_RESERVED_GLIBC_ID,
MCTX_2_RESERVED_GLIBC_ID,
MCTX_ASET_ID,
MCTX_GENERATION_ID,
MCTX_SLAB_ID,
MCTX_ALIGNED_REDIRECT_ID,
MCTX_BUMP_ID,
MCTX_8_UNUSED_ID,
MCTX_9_UNUSED_ID,
MCTX_10_UNUSED_ID,
MCTX_11_UNUSED_ID,
MCTX_12_UNUSED_ID,
MCTX_13_UNUSED_ID,
MCTX_14_UNUSED_ID,
MCTX_15_RESERVED_WIPEDMEM_ID
} MemoryContextMethodID;
#define MEMORY_CONTEXT_METHODID_BITS 4
#define MEMORY_CONTEXT_METHODID_MASK \
((((uint64) 1) << MEMORY_CONTEXT_METHODID_BITS) - 1)
extern void MemoryContextCreate(MemoryContext node,
NodeTag tag,
MemoryContextMethodID method_id,
MemoryContext parent,
const char *name);
extern void *MemoryContextAllocationFailure(MemoryContext context, Size size,
int flags);
extern void MemoryContextSizeFailure(MemoryContext context, Size size,
int flags) pg_attribute_noreturn();
static inline void
MemoryContextCheckSize(MemoryContext context, Size size, int flags)
{
if (unlikely(!AllocSizeIsValid(size)))
{
if (!(flags & MCXT_ALLOC_HUGE) || !AllocHugeSizeIsValid(size))
MemoryContextSizeFailure(context, size, flags);
}
}
#endif