summaryrefslogtreecommitdiff
path: root/src/malloc/mallocng/malloc_usable_size.c
blob: ce6a960c6f5835d5fd7f16818a139e5d9991edb4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdlib.h>
#include "meta.h"

size_t malloc_usable_size(void *p)
{
	if (!p) return 0;
	struct meta *g = get_meta(p);
	int idx = get_slot_index(p);
	size_t stride = get_stride(g);
	unsigned char *start = g->mem->storage + stride*idx;
	unsigned char *end = start + stride - IB;
	return get_nominal_size(p, end);
}