summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2020-11-05 16:21:21 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2020-11-05 16:21:21 +0000
commit16b971ed6dcef9a0b0903a686ed882d506708ee7 (patch)
tree8b798c935c7fab8fd03a0aff0b1d0e99aaec04f6
parent870d4ba3ff3b8026d20cf456f05f16ecf1dbc3ce (diff)
Notes
-rw-r--r--sys/kern/kern_malloc.c17
-rw-r--r--sys/sys/malloc.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 5f9074918e52..335b4251b410 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -1031,6 +1031,23 @@ reallocf(void *addr, size_t size, struct malloc_type *mtp, int flags)
}
/*
+ * malloc_size: returns the number of bytes allocated for a request of the
+ * specified size
+ */
+size_t
+malloc_size(size_t size)
+{
+ int indx;
+
+ if (size > kmem_zmax)
+ return (0);
+ if (size & KMEM_ZMASK)
+ size = (size & ~KMEM_ZMASK) + KMEM_ZBASE;
+ indx = kmemsize[size >> KMEM_ZSHIFT];
+ return (kmemzones[indx].kz_size);
+}
+
+/*
* malloc_usable_size: returns the usable size of the allocation.
*/
size_t
diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h
index c13ebaacbf6e..a793b1d77797 100644
--- a/sys/sys/malloc.h
+++ b/sys/sys/malloc.h
@@ -250,6 +250,7 @@ void malloc_type_allocated(struct malloc_type *type, unsigned long size);
void malloc_type_freed(struct malloc_type *type, unsigned long size);
void malloc_type_list(malloc_type_list_func_t *, void *);
void malloc_uninit(void *);
+size_t malloc_size(size_t);
size_t malloc_usable_size(const void *);
void *realloc(void *addr, size_t size, struct malloc_type *type, int flags)
__result_use_check __alloc_size(2);