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

Function malloc_usable_size

freebsd/kern/kern_malloc.c:1037–1068  ·  view source on GitHub ↗

* malloc_usable_size: returns the usable size of the allocation. */

Source from the content-addressed store, hash-verified

1035 * malloc_usable_size: returns the usable size of the allocation.
1036 */
1037size_t
1038malloc_usable_size(const void *addr)
1039{
1040#ifndef DEBUG_REDZONE
1041 uma_zone_t zone;
1042 uma_slab_t slab;
1043#endif
1044 u_long size;
1045
1046 if (addr == NULL)
1047 return (0);
1048
1049#ifdef DEBUG_MEMGUARD
1050 if (is_memguard_addr(__DECONST(void *, addr)))
1051 return (memguard_get_req_size(addr));
1052#endif
1053
1054#ifdef DEBUG_REDZONE
1055 size = redzone_get_size(__DECONST(void *, addr));
1056#else
1057 vtozoneslab((vm_offset_t)addr & (~UMA_SLAB_MASK), &zone, &slab);
1058 if (slab == NULL)
1059 panic("malloc_usable_size: address %p(%p) is not allocated.\n",
1060 addr, (void *)((u_long)addr & (~UMA_SLAB_MASK)));
1061
1062 if (!malloc_large_slab(slab))
1063 size = zone->uz_size;
1064 else
1065 size = malloc_large_size(slab);
1066#endif
1067 return (size);
1068}
1069
1070CTASSERT(VM_KMEM_SIZE_SCALE >= 1);
1071

Callers 4

thd_startFunction · 0.85
TEST_BEGINFunction · 0.85
TEST_BEGINFunction · 0.85
malloc_mus_freeFunction · 0.85

Calls 7

is_memguard_addrFunction · 0.85
memguard_get_req_sizeFunction · 0.85
redzone_get_sizeFunction · 0.85
malloc_large_slabFunction · 0.85
malloc_large_sizeFunction · 0.85
panicFunction · 0.70
vtozoneslabFunction · 0.50

Tested by 4

thd_startFunction · 0.68
TEST_BEGINFunction · 0.68
TEST_BEGINFunction · 0.68
malloc_mus_freeFunction · 0.68