git: 580c891f5add - stable/14 - malloc: extend malloc_usable_size() for contigmalloc

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Fri, 18 Apr 2025 14:36:48 UTC
The branch stable/14 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=580c891f5addc9055f41933c72caae14e352ba4c

commit 580c891f5addc9055f41933c72caae14e352ba4c
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2025-04-12 17:11:26 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2025-04-18 14:35:56 +0000

    malloc: extend malloc_usable_size() for contigmalloc
    
    Extend malloc_usable_size() for contigmalloc;  it seems the only
    outside consumer is LinuxKPI ksize() which by itself has little to
    no consumer either.
    
    Sponsored by:   The FreeBSD Foundation
    Suggested by:   jhb (see D46657)
    Reviewed by:    jhb, markj
    Fixes:          9e6544dd6e02
    Differential Revision: https://reviews.freebsd.org/D49571
    
    (cherry picked from commit c5cf4b64f4a976f5c5d75d52816078def86bf3e4)
---
 sys/kern/kern_malloc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index f31fc2a76a07..94583288430b 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -1162,6 +1162,9 @@ malloc_usable_size(const void *addr)
 	case SLAB_COOKIE_MALLOC_LARGE:
 		size = malloc_large_size(slab);
 		break;
+	case SLAB_COOKIE_CONTIG_MALLOC:
+		size = round_page(contigmalloc_size(slab));
+		break;
 	default:
 		__assert_unreachable();
 		size = 0;