Page MenuHomeFreeBSD

D4197.diff
No OneTemporary

D4197.diff

Index: head/share/man/man9/malloc.9
===================================================================
--- head/share/man/man9/malloc.9
+++ head/share/man/man9/malloc.9
@@ -29,7 +29,7 @@
.\" $NetBSD: malloc.9,v 1.3 1996/11/11 00:05:11 lukem Exp $
.\" $FreeBSD$
.\"
-.Dd January 16, 2014
+.Dd November 19, 2015
.Dt MALLOC 9
.Os
.Sh NAME
@@ -227,6 +227,13 @@
.Dv M_WAITOK .
.Fn free
never sleeps.
+However,
+.Fn malloc ,
+.Fn realloc,
+.Fn reallocf
+and
+.Fn free
+may not be called in a critical section or while holding a spin lock.
.Pp
Any calls to
.Fn malloc
Index: head/sys/kern/kern_malloc.c
===================================================================
--- head/sys/kern/kern_malloc.c
+++ head/sys/kern/kern_malloc.c
@@ -476,6 +476,9 @@
KASSERT(curthread->td_intr_nesting_level == 0,
("malloc(M_WAITOK) in interrupt context"));
+ KASSERT(curthread->td_critnest == 0,
+ ("malloc: called with spinlock or critical section held"));
+
#ifdef DEBUG_MEMGUARD
if (memguard_cmp_mtp(mtp, size)) {
va = memguard_alloc(size, flags);
@@ -542,6 +545,9 @@
KASSERT(mtp->ks_magic == M_MAGIC, ("free: bad malloc type magic"));
+ KASSERT(curthread->td_critnest == 0,
+ ("free: called with spinlock or critical section held"));
+
/* free(NULL, ...) does nothing */
if (addr == NULL)
return;
@@ -605,6 +611,9 @@
KASSERT(mtp->ks_magic == M_MAGIC,
("realloc: bad malloc type magic"));
+ KASSERT(curthread->td_critnest == 0,
+ ("realloc: called with spinlock or critical section held"));
+
/* realloc(NULL, ...) is equivalent to malloc(...) */
if (addr == NULL)
return (malloc(size, mtp, flags));
Index: head/sys/vm/uma_core.c
===================================================================
--- head/sys/vm/uma_core.c
+++ head/sys/vm/uma_core.c
@@ -2149,6 +2149,10 @@
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
"uma_zalloc_arg: zone \"%s\"", zone->uz_name);
}
+
+ KASSERT(curthread->td_critnest == 0,
+ ("uma_zalloc_arg: called with spinlock or critical section held"));
+
#ifdef DEBUG_MEMGUARD
if (memguard_cmp_zone(zone)) {
item = memguard_alloc(zone->uz_size, flags);
@@ -2686,6 +2690,9 @@
CTR2(KTR_UMA, "uma_zfree_arg thread %x zone %s", curthread,
zone->uz_name);
+ KASSERT(curthread->td_critnest == 0,
+ ("uma_zfree_arg: called with spinlock or critical section held"));
+
/* uma_zfree(..., NULL) does nothing, to match free(9). */
if (item == NULL)
return;

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 15, 1:16 PM (11 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29684343
Default Alt Text
D4197.diff (2 KB)

Event Timeline