• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdlib.h>
2 #include "meta.h"
3 
4 #ifdef USE_JEMALLOC
5 extern size_t je_malloc_usable_size(void *p);
6 #endif
7 
8 #ifndef HOOK_ENABLE
malloc_usable_size(void * p)9 size_t malloc_usable_size(void *p)
10 #else
11 size_t __libc_malloc_usable_size(void *p)
12 #endif
13 {
14 #ifdef USE_JEMALLOC
15 	return je_malloc_usable_size(p);
16 #endif
17 	if (!p) return 0;
18 	struct meta *g = get_meta(p);
19 	int idx = get_slot_index(p);
20 	size_t stride = get_stride(g);
21 	unsigned char *start = g->mem->storage + stride*idx;
22 	unsigned char *end = start + stride - IB;
23 	return get_nominal_size(p, end);
24 }
25