From aec49b06efd518437143ea082ebc3444b205f905 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 21 Sep 2010 01:09:11 +0000 Subject: Add assertwaitok(9) to declare code paths that assume they can sleep. Currently only checks that we're not in an interrupt context, but will soon check that we're not holding any mutexes either. Update malloc(9) and pool(9) to use assertwaitok(9) as appropriate. "i like it" art@, oga@, marco@; "i see no harm" deraadt@; too trivial for me to bother prying actual oks from people. --- sys/kern/kern_malloc.c | 5 ++++- sys/kern/subr_pool.c | 4 ++-- sys/kern/subr_xxx.c | 11 ++++++++++- sys/sys/systm.h | 4 +++- 4 files changed, 19 insertions(+), 5 deletions(-) (limited to 'sys') diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index e3bf091a885..986ec8f26d6 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_malloc.c,v 1.84 2010/07/22 06:30:13 matthew Exp $ */ +/* $OpenBSD: kern_malloc.c,v 1.85 2010/09/21 01:09:10 matthew Exp $ */ /* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */ /* @@ -191,6 +191,9 @@ malloc(unsigned long size, int type, int flags) panic("malloc - bogus type"); #endif + if ((flags & M_NOWAIT) == 0) + assertwaitok(); + #ifdef MALLOC_DEBUG if (debug_malloc(size, type, flags, (void **)&va)) { if ((flags & M_ZERO) && va != NULL) diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c index 4516c2c1bc9..5b9a354e423 100644 --- a/sys/kern/subr_pool.c +++ b/sys/kern/subr_pool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_pool.c,v 1.96 2010/07/03 03:04:55 tedu Exp $ */ +/* $OpenBSD: subr_pool.c,v 1.97 2010/09/21 01:09:10 matthew Exp $ */ /* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */ /*- @@ -455,7 +455,7 @@ pool_get(struct pool *pp, int flags) #ifdef DIAGNOSTIC if ((flags & PR_WAITOK) != 0) - splassert(IPL_NONE); + assertwaitok(); #endif /* DIAGNOSTIC */ mtx_enter(&pp->pr_mtx); diff --git a/sys/kern/subr_xxx.c b/sys/kern/subr_xxx.c index 5197f29505a..cb894042b9f 100644 --- a/sys/kern/subr_xxx.c +++ b/sys/kern/subr_xxx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_xxx.c,v 1.9 2005/12/09 09:09:52 jsg Exp $ */ +/* $OpenBSD: subr_xxx.c,v 1.10 2010/09/21 01:09:10 matthew Exp $ */ /* $NetBSD: subr_xxx.c,v 1.10 1996/02/04 02:16:51 christos Exp $ */ /* @@ -152,3 +152,12 @@ blktochr(dev_t dev) return (makedev(i, minor(dev))); return (NODEV); } + +/* + * Check that we're in a context where it's okay to sleep. + */ +void +assertwaitok(void) +{ + splassert(IPL_NONE); +} diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 5324713b381..89f1b1cda5a 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: systm.h,v 1.85 2010/09/07 16:21:47 deraadt Exp $ */ +/* $OpenBSD: systm.h,v 1.86 2010/09/21 01:09:10 matthew Exp $ */ /* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */ /*- @@ -179,6 +179,8 @@ void ttyprintf(struct tty *, const char *, ...) void splassert_fail(int, int, const char *); extern int splassert_ctl; +void assertwaitok(void); + void tablefull(const char *); int kcopy(const void *, void *, size_t) -- cgit v1.2.3