Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F143836717
D46101.id141316.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D46101.id141316.diff
View Options
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -920,15 +920,8 @@
}
#endif
-/*
- * free:
- *
- * Free a block of memory allocated by malloc.
- *
- * This routine may not block.
- */
-void
-free(void *addr, struct malloc_type *mtp)
+static __always_inline void
+_free(void *addr, struct malloc_type *mtp, bool dozero)
{
uma_zone_t zone;
uma_slab_t slab;
@@ -944,8 +937,8 @@
vtozoneslab((vm_offset_t)addr & (~UMA_SLAB_MASK), &zone, &slab);
if (slab == NULL)
- panic("free: address %p(%p) has not been allocated",
- addr, (void *)((u_long)addr & (~UMA_SLAB_MASK)));
+ panic("%s(%d): address %p(%p) has not been allocated", __func__,
+ dozero, addr, (void *)((uintptr_t)addr & (~UMA_SLAB_MASK)));
switch (GET_SLAB_COOKIE(slab)) {
case __predict_true(SLAB_COOKIE_SLAB_PTR):
@@ -953,79 +946,54 @@
#if defined(INVARIANTS) && !defined(KASAN)
free_save_type(addr, mtp, size);
#endif
+ if (dozero) {
+ kasan_mark(addr, size, size, 0);
+ explicit_bzero(addr, size);
+ }
uma_zfree_arg(zone, addr, slab);
break;
case SLAB_COOKIE_MALLOC_LARGE:
size = malloc_large_size(slab);
+ if (dozero) {
+ kasan_mark(addr, size, size, 0);
+ explicit_bzero(addr, size);
+ }
free_large(addr, size);
break;
case SLAB_COOKIE_CONTIG_MALLOC:
- size = contigmalloc_size(slab);
+ size = round_page(contigmalloc_size(slab));
+ if (dozero)
+ explicit_bzero(addr, size);
kmem_free(addr, size);
- size = round_page(size);
break;
default:
- panic("%s: addr %p slab %p with unknown cookie %d", __func__,
- addr, slab, GET_SLAB_COOKIE(slab));
+ panic("%s(%d): addr %p slab %p with unknown cookie %d",
+ __func__, dozero, addr, slab, GET_SLAB_COOKIE(slab));
/* NOTREACHED */
}
malloc_type_freed(mtp, size);
}
/*
- * zfree:
- *
- * Zero then free a block of memory allocated by malloc.
- *
+ * free:
+ * Free a block of memory allocated by malloc/contigmalloc.
* This routine may not block.
*/
void
-zfree(void *addr, struct malloc_type *mtp)
+free(void *addr, struct malloc_type *mtp)
{
- uma_zone_t zone;
- uma_slab_t slab;
- u_long size;
-
-#ifdef MALLOC_DEBUG
- if (free_dbg(&addr, mtp) != 0)
- return;
-#endif
- /* free(NULL, ...) does nothing */
- if (addr == NULL)
- return;
-
- vtozoneslab((vm_offset_t)addr & (~UMA_SLAB_MASK), &zone, &slab);
- if (slab == NULL)
- panic("free: address %p(%p) has not been allocated",
- addr, (void *)((u_long)addr & (~UMA_SLAB_MASK)));
+ _free(addr, mtp, false);
+}
- switch (GET_SLAB_COOKIE(slab)) {
- case __predict_true(SLAB_COOKIE_SLAB_PTR):
- size = zone->uz_size;
-#if defined(INVARIANTS) && !defined(KASAN)
- free_save_type(addr, mtp, size);
-#endif
- kasan_mark(addr, size, size, 0);
- explicit_bzero(addr, size);
- uma_zfree_arg(zone, addr, slab);
- break;
- case SLAB_COOKIE_MALLOC_LARGE:
- size = malloc_large_size(slab);
- kasan_mark(addr, size, size, 0);
- explicit_bzero(addr, size);
- free_large(addr, size);
- break;
- case SLAB_COOKIE_CONTIG_MALLOC:
- size = round_page(contigmalloc_size(slab));
- explicit_bzero(addr, size);
- kmem_free(addr, size);
- break;
- default:
- panic("%s: addr %p slab %p with unknown cookie %d", __func__,
- addr, slab, GET_SLAB_COOKIE(slab));
- /* NOTREACHED */
- }
- malloc_type_freed(mtp, size);
+/*
+ * zfree:
+ * Zero then free a block of memory allocated by malloc/contigmalloc.
+ * This routine may not block.
+ */
+void
+zfree(void *addr, struct malloc_type *mtp)
+{
+ _free(addr, mtp, true);
}
/*
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Feb 1, 7:26 PM (9 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28406568
Default Alt Text
D46101.id141316.diff (3 KB)
Attached To
Mode
D46101: kern_malloc: fold free and zfree together into one __always_inline func
Attached
Detach File
Event Timeline
Log In to Comment