* malloc_usable_size: returns the usable size of the allocation. */
| 1035 | * malloc_usable_size: returns the usable size of the allocation. |
| 1036 | */ |
| 1037 | size_t |
| 1038 | malloc_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 | |
| 1070 | CTASSERT(VM_KMEM_SIZE_SCALE >= 1); |
| 1071 |