summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authoreivind <eivind@FreeBSD.org>1999-01-08 17:31:30 +0000
committereivind <eivind@FreeBSD.org>1999-01-08 17:31:30 +0000
commita8dc66f457be84eefbe16e70c901ceb11137ba65 (patch)
treee5747f527c552fa90334c779c047697b372582fb /sys
parent1c69824749ed0aa6efce159d39ab3f17fc9e25f2 (diff)
downloadFreeBSD-src-a8dc66f457be84eefbe16e70c901ceb11137ba65.zip
FreeBSD-src-a8dc66f457be84eefbe16e70c901ceb11137ba65.tar.gz
Split DIAGNOSTIC -> DIAGNOSTIC, INVARIANTS, and INVARIANT_SUPPORT as
discussed on -hackers. Introduce 'KASSERT(assertion, ("panic message", args))' for simple check + panic. Reviewed by: msmith
Diffstat (limited to 'sys')
-rw-r--r--sys/conf/NOTES22
-rw-r--r--sys/conf/options8
-rw-r--r--sys/dev/snp/snp.c11
-rw-r--r--sys/i386/conf/LINT22
-rw-r--r--sys/i386/conf/NOTES22
-rw-r--r--sys/kern/kern_descrip.c4
-rw-r--r--sys/kern/kern_lock.c11
-rw-r--r--sys/kern/kern_malloc.c43
-rw-r--r--sys/kern/kern_proc.c24
-rw-r--r--sys/kern/kern_sig.c14
-rw-r--r--sys/kern/kern_subr.c24
-rw-r--r--sys/kern/kern_synch.c41
-rw-r--r--sys/kern/subr_autoconf.c8
-rw-r--r--sys/kern/subr_rlist.c16
-rw-r--r--sys/kern/tty.c8
-rw-r--r--sys/kern/tty_snoop.c11
-rw-r--r--sys/kern/uipc_socket.c19
-rw-r--r--sys/kern/vfs_bio.c50
-rw-r--r--sys/kern/vfs_cluster.c27
-rw-r--r--sys/kern/vfs_export.c41
-rw-r--r--sys/kern/vfs_lookup.c31
-rw-r--r--sys/kern/vfs_subr.c41
-rw-r--r--sys/sys/systm.h8
-rw-r--r--sys/vm/device_pager.c7
-rw-r--r--sys/vm/swap_pager.c12
-rw-r--r--sys/vm/vm_fault.c8
-rw-r--r--sys/vm/vm_object.c34
-rw-r--r--sys/vm/vm_page.c29
-rw-r--r--sys/vm/vm_page.h8
-rw-r--r--sys/vm/vm_zone.c10
-rw-r--r--sys/vm/vm_zone.h8
31 files changed, 253 insertions, 369 deletions
diff --git a/sys/conf/NOTES b/sys/conf/NOTES
index dca3ca3..27f1cea 100644
--- a/sys/conf/NOTES
+++ b/sys/conf/NOTES
@@ -2,7 +2,7 @@
# LINT -- config file for checking all the sources, tries to pull in
# as much of the source tree as it can.
#
-# $Id: LINT,v 1.526 1999/01/01 08:09:57 peter Exp $
+# $Id: LINT,v 1.527 1999/01/08 16:04:18 eivind Exp $
#
# NB: You probably don't want to try running a kernel built from this
# file. Instead, you should start from GENERIC, and add options from
@@ -291,12 +291,29 @@ options GDB_REMOTE_CHAT
options KTRACE #kernel tracing
#
-# The DIAGNOSTIC option is used in a number of source files to enable
+# The INVARIANTS option is used in a number of source files to enable
# extra sanity checking of internal structures. This support is not
# enabled by default because of the extra time it would take to check
# for these conditions, which can only occur as a result of
# programming errors.
#
+options INVARIANTS
+
+#
+# The INVARIANT_SUPPORT option makes us compile in support for
+# verifying some of the internal structures. It is a prerequisite for
+# 'INVARIANTS', as enabling 'INVARIANTS' will make these functions be
+# called. The intent is that you can set 'INVARIANTS' for single
+# source files (by changing the source file or specifying it on the
+# command line) if you have 'INVARIANT_SUPPORT' enabled.
+#
+options INVARIANT_SUPPORT
+
+#
+# The DIAGNOSTIC option is used to enable extra debugging information
+# from some parts of the kernel. As this makes everything more noisy,
+# it is disabled by default.
+#
options DIAGNOSTIC
#
@@ -1867,6 +1884,7 @@ options SHMSEG=9
options SI_DEBUG
options SIMPLELOCK_DEBUG
options SPX_HACK
+options VFS_BIO_DEBUG
# The 'dpt' driver provides support for DPT controllers (http://www.dpt.com/).
# These have hardware RAID-{0,1,5} support, and do multi-initiator I/O.
diff --git a/sys/conf/options b/sys/conf/options
index c9c76fd..8e593d9 100644
--- a/sys/conf/options
+++ b/sys/conf/options
@@ -1,4 +1,4 @@
-# $Id: options,v 1.112 1998/12/19 23:07:16 msmith Exp $
+# $Id: options,v 1.113 1998/12/28 16:31:26 peter Exp $
#
# On the handling of kernel options
#
@@ -249,9 +249,13 @@ SI_DEBUG opt_debug_si.h
# These cause changes all over the kernel
DEBUG opt_global.h
+DEBUG_VFS_LOCKS opt_global.h
DIAGNOSTIC opt_global.h
-SIMPLELOCK_DEBUG opt_global.h
ENABLE_VFS_IOOPT opt_global.h
+INVARIANT_SUPPORT opt_global.h
+INVARIANTS opt_global.h
+SIMPLELOCK_DEBUG opt_global.h
+VFS_BIO_DEBUG opt_global.h
# These are VM related options
VM_KMEM_SIZE opt_vm.h
diff --git a/sys/dev/snp/snp.c b/sys/dev/snp/snp.c
index c4b13e5..06f17dd 100644
--- a/sys/dev/snp/snp.c
+++ b/sys/dev/snp/snp.c
@@ -135,10 +135,8 @@ snpread(dev, uio, flag)
caddr_t from;
char *nbuf;
-#ifdef DIAGNOSTIC
- if ((snp->snp_len + snp->snp_base) > snp->snp_blen)
- panic("snoop buffer error");
-#endif
+ KASSERT(snp->snp_len + snp->snp_base <= snp->snp_blen,
+ ("snoop buffer error"));
if (snp->snp_tty == NULL)
return (EIO);
@@ -212,10 +210,9 @@ snpin(snp, buf, n)
if (n == 0)
return 0;
-#ifdef DIAGNOSTIC
- if (n < 0)
- panic("bad snoop char count");
+ KASSERT(n > 0, ("negative snoop char count"));
+#ifdef DIAGNOSTIC
if (!(snp->snp_flags & SNOOP_OPEN)) {
printf("Snoop: data coming to closed device.\n");
return 0;
diff --git a/sys/i386/conf/LINT b/sys/i386/conf/LINT
index dca3ca3..27f1cea 100644
--- a/sys/i386/conf/LINT
+++ b/sys/i386/conf/LINT
@@ -2,7 +2,7 @@
# LINT -- config file for checking all the sources, tries to pull in
# as much of the source tree as it can.
#
-# $Id: LINT,v 1.526 1999/01/01 08:09:57 peter Exp $
+# $Id: LINT,v 1.527 1999/01/08 16:04:18 eivind Exp $
#
# NB: You probably don't want to try running a kernel built from this
# file. Instead, you should start from GENERIC, and add options from
@@ -291,12 +291,29 @@ options GDB_REMOTE_CHAT
options KTRACE #kernel tracing
#
-# The DIAGNOSTIC option is used in a number of source files to enable
+# The INVARIANTS option is used in a number of source files to enable
# extra sanity checking of internal structures. This support is not
# enabled by default because of the extra time it would take to check
# for these conditions, which can only occur as a result of
# programming errors.
#
+options INVARIANTS
+
+#
+# The INVARIANT_SUPPORT option makes us compile in support for
+# verifying some of the internal structures. It is a prerequisite for
+# 'INVARIANTS', as enabling 'INVARIANTS' will make these functions be
+# called. The intent is that you can set 'INVARIANTS' for single
+# source files (by changing the source file or specifying it on the
+# command line) if you have 'INVARIANT_SUPPORT' enabled.
+#
+options INVARIANT_SUPPORT
+
+#
+# The DIAGNOSTIC option is used to enable extra debugging information
+# from some parts of the kernel. As this makes everything more noisy,
+# it is disabled by default.
+#
options DIAGNOSTIC
#
@@ -1867,6 +1884,7 @@ options SHMSEG=9
options SI_DEBUG
options SIMPLELOCK_DEBUG
options SPX_HACK
+options VFS_BIO_DEBUG
# The 'dpt' driver provides support for DPT controllers (http://www.dpt.com/).
# These have hardware RAID-{0,1,5} support, and do multi-initiator I/O.
diff --git a/sys/i386/conf/NOTES b/sys/i386/conf/NOTES
index dca3ca3..27f1cea 100644
--- a/sys/i386/conf/NOTES
+++ b/sys/i386/conf/NOTES
@@ -2,7 +2,7 @@
# LINT -- config file for checking all the sources, tries to pull in
# as much of the source tree as it can.
#
-# $Id: LINT,v 1.526 1999/01/01 08:09:57 peter Exp $
+# $Id: LINT,v 1.527 1999/01/08 16:04:18 eivind Exp $
#
# NB: You probably don't want to try running a kernel built from this
# file. Instead, you should start from GENERIC, and add options from
@@ -291,12 +291,29 @@ options GDB_REMOTE_CHAT
options KTRACE #kernel tracing
#
-# The DIAGNOSTIC option is used in a number of source files to enable
+# The INVARIANTS option is used in a number of source files to enable
# extra sanity checking of internal structures. This support is not
# enabled by default because of the extra time it would take to check
# for these conditions, which can only occur as a result of
# programming errors.
#
+options INVARIANTS
+
+#
+# The INVARIANT_SUPPORT option makes us compile in support for
+# verifying some of the internal structures. It is a prerequisite for
+# 'INVARIANTS', as enabling 'INVARIANTS' will make these functions be
+# called. The intent is that you can set 'INVARIANTS' for single
+# source files (by changing the source file or specifying it on the
+# command line) if you have 'INVARIANT_SUPPORT' enabled.
+#
+options INVARIANT_SUPPORT
+
+#
+# The DIAGNOSTIC option is used to enable extra debugging information
+# from some parts of the kernel. As this makes everything more noisy,
+# it is disabled by default.
+#
options DIAGNOSTIC
#
@@ -1867,6 +1884,7 @@ options SHMSEG=9
options SI_DEBUG
options SIMPLELOCK_DEBUG
options SPX_HACK
+options VFS_BIO_DEBUG
# The 'dpt' driver provides support for DPT controllers (http://www.dpt.com/).
# These have hardware RAID-{0,1,5} support, and do multi-initiator I/O.
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 8fc26b2..1d18a86 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94
- * $Id: kern_descrip.c,v 1.56 1998/11/11 10:03:54 truckman Exp $
+ * $Id: kern_descrip.c,v 1.57 1998/11/11 10:55:56 truckman Exp $
*/
#include "opt_compat.h"
@@ -845,7 +845,7 @@ ffree(fp)
{
LIST_REMOVE(fp, f_list);
crfree(fp->f_cred);
-#ifdef DIAGNOSTIC
+#if defined(DIAGNOSTIC) || defined(INVARIANTS)
fp->f_count = 0;
#endif
nfiles--;
diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c
index f411f14..0bf31d0 100644
--- a/sys/kern/kern_lock.c
+++ b/sys/kern/kern_lock.c
@@ -38,7 +38,7 @@
* SUCH DAMAGE.
*
* @(#)kern_lock.c 8.18 (Berkeley) 5/21/95
- * $Id: kern_lock.c,v 1.19 1998/04/17 04:53:44 bde Exp $
+ * $Id: kern_lock.c,v 1.20 1998/11/26 18:50:23 eivind Exp $
*/
#include "opt_lint.h"
@@ -83,14 +83,7 @@ sharelock(struct lock *lkp, int incr) {
static LOCK_INLINE void
shareunlock(struct lock *lkp, int decr) {
-#if defined(DIAGNOSTIC)
- if (lkp->lk_sharecount < decr)
-#if defined(DDB)
- Debugger("shareunlock: count < decr");
-#else
- panic("shareunlock: count < decr");
-#endif
-#endif
+ KASSERT(lkp->lk_sharecount >= decr, ("shareunlock: count < decr"));
if (lkp->lk_sharecount == decr) {
lkp->lk_flags &= ~LK_SHARE_NONZERO;
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 1ced96a..4cd7b73 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)kern_malloc.c 8.3 (Berkeley) 1/4/94
- * $Id: kern_malloc.c,v 1.48 1998/10/25 17:44:51 phk Exp $
+ * $Id: kern_malloc.c,v 1.49 1998/11/10 08:46:24 peter Exp $
*/
#include "opt_vm.h"
@@ -64,7 +64,7 @@ static char *kmembase;
static char *kmemlimit;
static int vm_kmem_size;
-#ifdef DIAGNOSTIC
+#if defined(INVARIANTS)
/*
* This structure provides a set of masks to catch unaligned frees.
*/
@@ -94,11 +94,11 @@ struct freelist {
long spare1;
caddr_t next;
};
-#else /* !DIAGNOSTIC */
+#else /* !INVARIANTS */
struct freelist {
caddr_t next;
};
-#endif /* DIAGNOSTIC */
+#endif /* INVARIANTS */
/*
* Allocate a block of memory
@@ -115,7 +115,7 @@ malloc(size, type, flags)
long indx, npg, allocsize;
int s;
caddr_t va, cp, savedlist;
-#ifdef DIAGNOSTIC
+#ifdef INVARIANTS
long *end, *lp;
int copysize;
char *savedtype;
@@ -138,7 +138,7 @@ malloc(size, type, flags)
tsleep((caddr_t)ksp, PSWP+2, type->ks_shortdesc, 0);
}
ksp->ks_size |= 1 << indx;
-#ifdef DIAGNOSTIC
+#ifdef INVARIANTS
copysize = 1 << indx < MAX_COPY ? 1 << indx : MAX_COPY;
#endif
if (kbp->kb_next == NULL) {
@@ -174,7 +174,7 @@ malloc(size, type, flags)
kbp->kb_next = cp = va + (npg * PAGE_SIZE) - allocsize;
for (;;) {
freep = (struct freelist *)cp;
-#ifdef DIAGNOSTIC
+#ifdef INVARIANTS
/*
* Copy in known text to detect modification
* after freeing.
@@ -183,7 +183,7 @@ malloc(size, type, flags)
for (lp = (long *)cp; lp < end; lp++)
*lp = WEIRD_ADDR;
freep->type = M_FREE;
-#endif /* DIAGNOSTIC */
+#endif /* INVARIANTS */
if (cp <= va)
break;
cp -= allocsize;
@@ -195,7 +195,7 @@ malloc(size, type, flags)
}
va = kbp->kb_next;
kbp->kb_next = ((struct freelist *)va)->next;
-#ifdef DIAGNOSTIC
+#ifdef INVARIANTS
freep = (struct freelist *)va;
savedtype = (char *) type->ks_shortdesc;
#if BYTE_ORDER == BIG_ENDIAN
@@ -219,7 +219,7 @@ malloc(size, type, flags)
break;
}
freep->spare0 = 0;
-#endif /* DIAGNOSTIC */
+#endif /* INVARIANTS */
kup = btokup(va);
if (kup->ku_indx != indx)
panic("malloc: wrong bucket");
@@ -251,7 +251,7 @@ free(addr, type)
register struct freelist *freep;
long size;
int s;
-#ifdef DIAGNOSTIC
+#ifdef INVARIANTS
struct freelist *fp;
long *end, *lp, alloc, copysize;
#endif
@@ -260,16 +260,13 @@ free(addr, type)
if (!type->ks_next)
panic("freeing with unknown type (%s)", type->ks_shortdesc);
-#ifdef DIAGNOSTIC
- if ((char *)addr < kmembase || (char *)addr >= kmemlimit) {
- panic("free: address %p out of range", (void *)addr);
- }
-#endif
+ KASSERT(kmembase <= (char *)addr && (char *)addr < kmemlimit,
+ ("free: address %p out of range", (void *)addr));
kup = btokup(addr);
size = 1 << kup->ku_indx;
kbp = &bucket[kup->ku_indx];
s = splmem();
-#ifdef DIAGNOSTIC
+#ifdef INVARIANTS
/*
* Check for returns of data that do not point to the
* beginning of the allocation.
@@ -281,7 +278,7 @@ free(addr, type)
if (((uintptr_t)(void *)addr & alloc) != 0)
panic("free: unaligned addr %p, size %ld, type %s, mask %ld",
(void *)addr, size, type->ks_shortdesc, alloc);
-#endif /* DIAGNOSTIC */
+#endif /* INVARIANTS */
if (size > MAXALLOCSAVE) {
kmem_free(kmem_map, (vm_offset_t)addr, ctob(kup->ku_pagecnt));
size = kup->ku_pagecnt << PAGE_SHIFT;
@@ -297,7 +294,7 @@ free(addr, type)
return;
}
freep = (struct freelist *)addr;
-#ifdef DIAGNOSTIC
+#ifdef INVARIANTS
/*
* Check for multiple frees. Use a quick check to see if
* it looks free before laboriously searching the freelist.
@@ -306,11 +303,9 @@ free(addr, type)
fp = (struct freelist *)kbp->kb_next;
while (fp) {
if (fp->spare0 != WEIRD_ADDR) {
- printf("trashed free item %p\n", fp);
- panic("free: free item modified");
+ panic("free: free item %p modified", fp);
} else if (addr == (caddr_t)fp) {
- printf("multiple freed item %p\n", addr);
- panic("free: multiple free");
+ panic("free: multiple freed item %p", addr);
}
fp = (struct freelist *)fp->next;
}
@@ -326,7 +321,7 @@ free(addr, type)
for (lp = (long *)addr; lp < end; lp++)
*lp = WEIRD_ADDR;
freep->type = type;
-#endif /* DIAGNOSTIC */
+#endif /* INVARIANTS */
kup->ku_freecnt++;
if (kup->ku_freecnt >= kbp->kb_elmpercl)
if (kup->ku_freecnt > kbp->kb_elmpercl)
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 9f046a3..313a9e7 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)kern_proc.c 8.7 (Berkeley) 2/14/95
- * $Id: kern_proc.c,v 1.39 1998/11/11 10:03:55 truckman Exp $
+ * $Id: kern_proc.c,v 1.40 1998/11/11 10:55:56 truckman Exp $
*/
#include <sys/param.h>
@@ -195,22 +195,18 @@ enterpgrp(p, pgid, mksess)
{
register struct pgrp *pgrp = pgfind(pgid);
-#ifdef DIAGNOSTIC
- if (pgrp != NULL && mksess) /* firewalls */
- panic("enterpgrp: setsid into non-empty pgrp");
- if (SESS_LEADER(p))
- panic("enterpgrp: session leader attempted setpgrp");
-#endif
+ KASSERT(pgrp == NULL || !mksess,
+ ("enterpgrp: setsid into non-empty pgrp"));
+ KASSERT(!SESS_LEADER(p),
+ ("enterpgrp: session leader attempted setpgrp"));
if (pgrp == NULL) {
pid_t savepid = p->p_pid;
struct proc *np;
/*
* new process group
*/
-#ifdef DIAGNOSTIC
- if (p->p_pid != pgid)
- panic("enterpgrp: new pgrp and pid != pgid");
-#endif
+ KASSERT(p->p_pid == pgid,
+ ("enterpgrp: new pgrp and pid != pgid"));
MALLOC(pgrp, struct pgrp *, sizeof(struct pgrp), M_PGRP,
M_WAITOK);
if ((np = pfind(savepid)) == NULL || np != p)
@@ -232,10 +228,8 @@ enterpgrp(p, pgid, mksess)
sizeof(sess->s_login));
p->p_flag &= ~P_CONTROLT;
pgrp->pg_session = sess;
-#ifdef DIAGNOSTIC
- if (p != curproc)
- panic("enterpgrp: mksession and p != curproc");
-#endif
+ KASSERT(p == curproc,
+ ("enterpgrp: mksession and p != curproc"));
} else {
pgrp->pg_session = p->p_session;
pgrp->pg_session->s_count++;
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index dd4a431..e9a51d4 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
- * $Id: kern_sig.c,v 1.50 1998/12/02 01:53:48 eivind Exp $
+ * $Id: kern_sig.c,v 1.51 1998/12/19 02:55:33 julian Exp $
*/
#include "opt_compat.h"
@@ -1183,10 +1183,8 @@ postsig(signum)
register sig_t action;
int code, mask, returnmask;
-#ifdef DIAGNOSTIC
- if (signum == 0)
- panic("postsig");
-#endif
+ KASSERT(signum != 0, ("postsig"));
+
mask = sigmask(signum);
p->p_siglist &= ~mask;
action = ps->ps_sigact[signum];
@@ -1214,10 +1212,8 @@ postsig(signum)
/*
* If we get here, the signal must be caught.
*/
-#ifdef DIAGNOSTIC
- if (action == SIG_IGN || (p->p_sigmask & mask))
- panic("postsig action");
-#endif
+ KASSERT(action != SIG_IGN && (p->p_sigmask & mask) == 0,
+ ("postsig action"));
/*
* Set the new mask value and also defer further
* occurences of this signal.
diff --git a/sys/kern/kern_subr.c b/sys/kern/kern_subr.c
index 548cd20..d775d97 100644
--- a/sys/kern/kern_subr.c
+++ b/sys/kern/kern_subr.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)kern_subr.c 8.3 (Berkeley) 1/21/94
- * $Id: kern_subr.c,v 1.21 1998/07/15 02:32:10 bde Exp $
+ * $Id: kern_subr.c,v 1.22 1998/08/04 09:21:04 phk Exp $
*/
#include <sys/param.h>
@@ -61,12 +61,11 @@ uiomove(cp, n, uio)
u_int cnt;
int error;
-#ifdef DIAGNOSTIC
- if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
- panic("uiomove: mode");
- if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc)
- panic("uiomove proc");
-#endif
+ KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE,
+ ("uiomove: mode"));
+ KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_procp == curproc,
+ ("uiomove proc"));
+
while (n > 0 && uio->uio_resid) {
iov = uio->uio_iov;
cnt = iov->iov_len;
@@ -120,12 +119,11 @@ uiomoveco(cp, n, uio, obj)
u_int cnt;
int error;
-#ifdef DIAGNOSTIC
- if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
- panic("uiomove: mode");
- if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc)
- panic("uiomove proc");
-#endif
+ KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE,
+ ("uiomoveco: mode"));
+ KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_procp == curproc,
+ ("uiomoveco proc"));
+
while (n > 0 && uio->uio_resid) {
iov = uio->uio_iov;
cnt = iov->iov_len;
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index 17b2a94..3a9391d 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)kern_synch.c 8.9 (Berkeley) 5/19/95
- * $Id: kern_synch.c,v 1.69 1998/11/27 11:44:22 dg Exp $
+ * $Id: kern_synch.c,v 1.70 1998/12/21 07:41:51 dillon Exp $
*/
#include "opt_ktrace.h"
@@ -401,20 +401,11 @@ tsleep(ident, priority, wmesg, timo)
splx(s);
return (0);
}
-#ifdef DIAGNOSTIC
- if(p == NULL)
- panic("tsleep1");
- if (ident == NULL || p->p_stat != SRUN)
- panic("tsleep");
- /* XXX This is not exhaustive, just the most common case */
-#ifdef NOTDEF
- /*
- * This can happen legitimately now with asleep()/await()
- */
- if ((p->p_procq.tqe_prev != NULL) && (*p->p_procq.tqe_prev == p))
- panic("sleeping process already on another queue");
-#endif
-#endif
+
+ KASSERT(p != NULL, ("tsleep1"));
+ KASSERT(ident != NULL && p->p_stat == SRUN,
+ ("tsleep"));
+
/*
* Process may be sitting on a slpque if asleep() was called, remove
* it before re-adding.
@@ -706,16 +697,6 @@ wakeup(ident)
qp = &slpque[LOOKUP(ident)];
restart:
for (p = qp->tqh_first; p != NULL; p = p->p_procq.tqe_next) {
-#ifdef DIAGNOSTIC
-#ifdef NOTDEF
- /*
- * The process can legitimately be running now with
- * asleep()/await().
- */
- if (p->p_stat != SSLEEP && p->p_stat != SSTOP)
- panic("wakeup");
-#endif
-#endif
if (p->p_wchan == ident) {
TAILQ_REMOVE(qp, p, p_procq);
p->p_wchan = 0;
@@ -757,16 +738,6 @@ wakeup_one(ident)
qp = &slpque[LOOKUP(ident)];
for (p = qp->tqh_first; p != NULL; p = p->p_procq.tqe_next) {
-#ifdef DIAGNOSTIC
-#ifdef NOTDEF
- /*
- * The process can legitimately be running now with
- * asleep()/await().
- */
- if (p->p_stat != SSLEEP && p->p_stat != SSTOP)
- panic("wakeup_one");
-#endif
-#endif
if (p->p_wchan == ident) {
TAILQ_REMOVE(qp, p, p_procq);
p->p_wchan = 0;
diff --git a/sys/kern/subr_autoconf.c b/sys/kern/subr_autoconf.c
index 8dfba39..9234732 100644
--- a/sys/kern/subr_autoconf.c
+++ b/sys/kern/subr_autoconf.c
@@ -41,7 +41,7 @@
*
* @(#)subr_autoconf.c 8.1 (Berkeley) 6/10/93
*
- * $Id: subr_autoconf.c,v 1.6 1997/11/18 12:43:41 bde Exp $
+ * $Id: subr_autoconf.c,v 1.7 1998/12/04 22:54:51 archie Exp $
*/
#include <sys/param.h>
@@ -334,10 +334,8 @@ evcnt_attach(dev, name, ev)
{
static struct evcnt **nextp = &allevents;
-#ifdef DIAGNOSTIC
- if (strlen(name) >= sizeof(ev->ev_name))
- panic("evcnt_attach");
-#endif
+ KASSERT(strlen(name) < sizeof(ev->ev_name), ("evcnt_attach"));
+
/* ev->ev_next = NULL; */
ev->ev_dev = dev;
/* ev->ev_count = 0; */
diff --git a/sys/kern/subr_rlist.c b/sys/kern/subr_rlist.c
index 33ac632..c3fdabf 100644
--- a/sys/kern/subr_rlist.c
+++ b/sys/kern/subr_rlist.c
@@ -54,7 +54,7 @@
* functioning of this software, nor does the author assume any responsibility
* for damages incurred with its use.
*
- * $Id: subr_rlist.c,v 1.26 1998/04/15 17:46:25 bde Exp $
+ * $Id: subr_rlist.c,v 1.27 1998/08/05 14:06:04 dg Exp $
*/
#include <sys/param.h>
@@ -137,16 +137,14 @@ rlist_free(rlh, start, end)
while (cur_rlp != NULL) {
if (start < cur_rlp->rl_start)
break;
-#ifdef DIAGNOSTIC
if (prev_rlp) {
- if (prev_rlp->rl_end + 1 == cur_rlp->rl_start)
- panic("rlist_free: missed coalesce opportunity");
- if (prev_rlp->rl_end == cur_rlp->rl_start)
- panic("rlist_free: entries overlap");
- if (prev_rlp->rl_end > cur_rlp->rl_start)
- panic("entries out of order");
+ KASSERT(prev_rlp->rl_end + 1 != cur_rlp->rl_start,
+ ("rlist_free: missed coalesce opportunity"));
+ KASSERT(prev_rlp->rl_end != cur_rlp->rl_start,
+ ("rlist_free: entries overlap"));
+ KASSERT(prev_rlp->rl_end <= cur_rlp->rl_start,
+ ("entries out of order"));
}
-#endif
prev_rlp = cur_rlp;
cur_rlp = cur_rlp->rl_next;
}
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index 4d7dfac..1adf784 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)tty.c 8.8 (Berkeley) 1/21/94
- * $Id: tty.c,v 1.109 1998/12/07 07:59:20 ache Exp $
+ * $Id: tty.c,v 1.110 1998/12/08 10:22:07 bde Exp $
*/
/*-
@@ -1310,10 +1310,8 @@ ttrstrt(tp_arg)
struct tty *tp;
int s;
-#ifdef DIAGNOSTIC
- if (tp_arg == NULL)
- panic("ttrstrt");
-#endif
+ KASSERT(tp_arg != NULL, ("ttrstrt"));
+
tp = tp_arg;
s = spltty();
diff --git a/sys/kern/tty_snoop.c b/sys/kern/tty_snoop.c
index c4b13e5..06f17dd 100644
--- a/sys/kern/tty_snoop.c
+++ b/sys/kern/tty_snoop.c
@@ -135,10 +135,8 @@ snpread(dev, uio, flag)
caddr_t from;
char *nbuf;
-#ifdef DIAGNOSTIC
- if ((snp->snp_len + snp->snp_base) > snp->snp_blen)
- panic("snoop buffer error");
-#endif
+ KASSERT(snp->snp_len + snp->snp_base <= snp->snp_blen,
+ ("snoop buffer error"));
if (snp->snp_tty == NULL)
return (EIO);
@@ -212,10 +210,9 @@ snpin(snp, buf, n)
if (n == 0)
return 0;
-#ifdef DIAGNOSTIC
- if (n < 0)
- panic("bad snoop char count");
+ KASSERT(n > 0, ("negative snoop char count"));
+#ifdef DIAGNOSTIC
if (!(snp->snp_flags & SNOOP_OPEN)) {
printf("Snoop: data coming to closed device.\n");
return 0;
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index b1f64fe..f7fe5a7 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94
- * $Id: uipc_socket.c,v 1.46 1998/11/11 10:03:56 truckman Exp $
+ * $Id: uipc_socket.c,v 1.47 1998/12/07 21:58:29 archie Exp $
*/
#include <sys/param.h>
@@ -637,10 +637,7 @@ restart:
(so->so_rcv.sb_cc < so->so_rcv.sb_lowat ||
((flags & MSG_WAITALL) && uio->uio_resid <= so->so_rcv.sb_hiwat)) &&
m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0)) {
-#ifdef DIAGNOSTIC
- if (m == 0 && so->so_rcv.sb_cc)
- panic("receive 1");
-#endif
+ KASSERT(m != 0 || !so->so_rcv.sb_cc, ("receive 1"));
if (so->so_error) {
if (m)
goto dontblock;
@@ -683,10 +680,7 @@ dontblock:
uio->uio_procp->p_stats->p_ru.ru_msgrcv++;
nextrecord = m->m_nextpkt;
if (pr->pr_flags & PR_ADDR) {
-#ifdef DIAGNOSTIC
- if (m->m_type != MT_SONAME)
- panic("receive 1a");
-#endif
+ KASSERT(m->m_type == MT_SONAME, ("receive 1a"));
orig_resid = 0;
if (psa)
*psa = dup_sockaddr(mtod(m, struct sockaddr *),
@@ -740,10 +734,9 @@ dontblock:
break;
} else if (type == MT_OOBDATA)
break;
-#ifdef DIAGNOSTIC
- else if (m->m_type != MT_DATA && m->m_type != MT_HEADER)
- panic("receive 3");
-#endif
+ else
+ KASSERT(m->m_type == MT_DATA || m->m_type == MT_HEADER,
+ ("receive 3"));
so->so_state &= ~SS_RCVATMARK;
len = uio->uio_resid;
if (so->so_oobmark && len > so->so_oobmark - offset)
diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c
index a84f063..28d8a03 100644
--- a/sys/kern/vfs_bio.c
+++ b/sys/kern/vfs_bio.c
@@ -11,7 +11,7 @@
* 2. Absolutely no warranty of function or purpose is made by the author
* John S. Dyson.
*
- * $Id: vfs_bio.c,v 1.188 1998/12/22 14:43:58 luoqi Exp $
+ * $Id: vfs_bio.c,v 1.189 1998/12/22 18:57:30 dillon Exp $
*/
/*
@@ -692,10 +692,7 @@ brelse(struct buf * bp)
int poffset = foff & PAGE_MASK;
int presid = resid > (PAGE_SIZE - poffset) ?
(PAGE_SIZE - poffset) : resid;
-#ifdef DIAGNOSTIC
- if (presid < 0)
- panic("brelse: extra page");
-#endif
+ KASSERT(presid >= 0, ("brelse: extra page"));
vm_page_set_invalid(m, poffset, presid);
}
resid -= PAGE_SIZE - (foff & PAGE_MASK);
@@ -1002,11 +999,8 @@ trytofreespace:
return (0);
}
-#if defined(DIAGNOSTIC)
- if (bp->b_flags & B_BUSY) {
- panic("getnewbuf: busy buffer on free list\n");
- }
-#endif
+ KASSERT(!(bp->b_flags & B_BUSY),
+ ("getnewbuf: busy buffer on free list\n"));
/*
* We are fairly aggressive about freeing VMIO buffers, but since
@@ -1460,10 +1454,8 @@ loop:
}
}
-#ifdef DIAGNOSTIC
- if (bp->b_offset == NOOFFSET)
- panic("getblk: no buffer offset");
-#endif
+ KASSERT(bp->b_offset != NOOFFSET,
+ ("getblk: no buffer offset"));
/*
* Check that the constituted buffer really deserves for the
@@ -1711,10 +1703,8 @@ allocbuf(struct buf * bp, int size)
* is the responsibility of vnode_pager_setsize
*/
m = bp->b_pages[i];
-#if defined(DIAGNOSTIC)
- if (m == bogus_page)
- panic("allocbuf: bogus page found");
-#endif
+ KASSERT(m != bogus_page,
+ ("allocbuf: bogus page found"));
vm_page_sleep(m, "biodep", &m->busy);
bp->b_pages[i] = NULL;
@@ -1747,10 +1737,8 @@ allocbuf(struct buf * bp, int size)
tinc = PAGE_SIZE;
off = bp->b_offset;
-#ifdef DIAGNOSTIC
- if (bp->b_offset == NOOFFSET)
- panic("allocbuf: no buffer offset");
-#endif
+ KASSERT(bp->b_offset != NOOFFSET,
+ ("allocbuf: no buffer offset"));
curbpnpages = bp->b_npages;
doretry:
@@ -1938,10 +1926,8 @@ biodone(register struct buf * bp)
#endif
foff = bp->b_offset;
-#ifdef DIAGNOSTIC
- if (bp->b_offset == NOOFFSET)
- panic("biodone: no buffer offset");
-#endif
+ KASSERT(bp->b_offset != NOOFFSET,
+ ("biodone: no buffer offset"));
#if !defined(MAX_PERF)
if (!obj) {
@@ -2213,10 +2199,8 @@ vfs_busy_pages(struct buf * bp, int clear_modify)
vm_ooffset_t foff;
foff = bp->b_offset;
-#ifdef DIAGNOSTIC
- if (bp->b_offset == NOOFFSET)
- panic("vfs_busy_pages: no buffer offset");
-#endif
+ KASSERT(bp->b_offset != NOOFFSET,
+ ("vfs_busy_pages: no buffer offset"));
vfs_setdirty(bp);
@@ -2266,10 +2250,8 @@ vfs_clean_pages(struct buf * bp)
vm_ooffset_t foff;
foff = bp->b_offset;
-#ifdef DIAGNOSTIC
- if (bp->b_offset == NOOFFSET)
- panic("vfs_clean_pages: no buffer offset");
-#endif
+ KASSERT(bp->b_offset != NOOFFSET,
+ ("vfs_clean_pages: no buffer offset"));
for (i = 0; i < bp->b_npages; i++) {
vm_page_t m = bp->b_pages[i];
diff --git a/sys/kern/vfs_cluster.c b/sys/kern/vfs_cluster.c
index 1e4d7b8..07434ce 100644
--- a/sys/kern/vfs_cluster.c
+++ b/sys/kern/vfs_cluster.c
@@ -33,7 +33,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_cluster.c 8.7 (Berkeley) 2/13/94
- * $Id: vfs_cluster.c,v 1.74 1998/11/17 00:31:12 mckusick Exp $
+ * $Id: vfs_cluster.c,v 1.75 1998/12/05 06:12:14 mckusick Exp $
*/
#include "opt_debug_cluster.h"
@@ -168,10 +168,8 @@ cluster_read(vp, filesize, lblkno, size, cred, totread, seqcount, bpp)
} else {
off_t firstread;
firstread = bp->b_offset;
-#ifdef DIAGNOSTIC
- if (bp->b_offset == NOOFFSET)
- panic("cluster_read: no buffer offset");
-#endif
+ KASSERT(bp->b_offset != NOOFFSET,
+ ("cluster_read: no buffer offset"));
if (firstread + totread > filesize)
totread = filesize - firstread;
if (totread > size) {
@@ -312,11 +310,9 @@ cluster_rbuild(vp, filesize, lbn, blkno, size, run, fbp)
daddr_t bn;
int i, inc, j;
-#ifdef DIAGNOSTIC
- if (size != vp->v_mount->mnt_stat.f_iosize)
- panic("cluster_rbuild: size %ld != filesize %ld\n",
- size, vp->v_mount->mnt_stat.f_iosize);
-#endif
+ KASSERT(size == vp->v_mount->mnt_stat.f_iosize,
+ ("cluster_rbuild: size %ld != filesize %ld\n",
+ size, vp->v_mount->mnt_stat.f_iosize));
/*
* avoid a division
*/
@@ -350,10 +346,8 @@ cluster_rbuild(vp, filesize, lbn, blkno, size, run, fbp)
bp->b_blkno = blkno;
bp->b_lblkno = lbn;
bp->b_offset = tbp->b_offset;
-#ifdef DIAGNOSTIC
- if (bp->b_offset == NOOFFSET)
- panic("cluster_rbuild: no buffer offset");
-#endif
+ KASSERT(bp->b_offset != NOOFFSET,
+ ("cluster_rbuild: no buffer offset"));
pbgetvp(vp, bp);
TAILQ_INIT(&bp->b_cluster.cluster_head);
@@ -517,10 +511,7 @@ cluster_write(bp, filesize)
}
lbn = bp->b_lblkno;
-#ifdef DIAGNOSTIC
- if (bp->b_offset == NOOFFSET)
- panic("cluster_write: no buffer offset");
-#endif
+ KASSERT(bp->b_offset != NOOFFSET, ("cluster_write: no buffer offset"));
/* Initialize vnode to beginning of file. */
if (lbn == 0)
diff --git a/sys/kern/vfs_export.c b/sys/kern/vfs_export.c
index 0d5bbdc..92a8710 100644
--- a/sys/kern/vfs_export.c
+++ b/sys/kern/vfs_export.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95
- * $Id: vfs_subr.c,v 1.179 1999/01/05 18:12:29 eivind Exp $
+ * $Id: vfs_subr.c,v 1.180 1999/01/05 18:49:53 eivind Exp $
*/
/*
@@ -466,7 +466,7 @@ getnewvnode(tag, mp, vops, vpp)
simple_unlock(&vp->v_interlock);
}
-#ifdef DIAGNOSTIC
+#ifdef INVARIANTS
{
int s;
@@ -796,10 +796,7 @@ bgetvp(vp, bp)
{
int s;
-#if defined(DIAGNOSTIC)
- if (bp->b_vp)
- panic("bgetvp: not free");
-#endif
+ KASSERT(bp->b_vp == NULL, ("bgetvp: not free"));
vhold(vp);
bp->b_vp = vp;
if (vp->v_type == VBLK || vp->v_type == VCHR)
@@ -827,10 +824,7 @@ brelvp(bp)
struct buflists *listheadp;
int s;
-#if defined(DIAGNOSTIC)
- if (bp->b_vp == (struct vnode *) 0)
- panic("brelvp: NULL");
-#endif
+ KASSERT(bp->b_vp != NULL, ("brelvp: NULL"));
/*
* Delete from old vnode list, if on one.
@@ -996,10 +990,8 @@ pbgetvp(vp, bp)
register struct vnode *vp;
register struct buf *bp;
{
-#if defined(DIAGNOSTIC)
- if (bp->b_vp)
- panic("pbgetvp: not free");
-#endif
+ KASSERT(bp->b_vp == NULL, ("pbgetvp: not free"));
+
bp->b_vp = vp;
if (vp->v_type == VBLK || vp->v_type == VCHR)
bp->b_dev = vp->v_rdev;
@@ -1015,10 +1007,7 @@ pbrelvp(bp)
register struct buf *bp;
{
-#if defined(DIAGNOSTIC)
- if (bp->b_vp == (struct vnode *) 0)
- panic("pbrelvp: NULL");
-#endif
+ KASSERT(bp->b_vp != NULL, ("pbrelvp: NULL"));
bp->b_vp = (struct vnode *) 0;
}
@@ -1313,10 +1302,8 @@ vrele(vp)
{
struct proc *p = curproc; /* XXX */
-#ifdef DIAGNOSTIC
- if (vp == NULL)
- panic("vrele: null vp");
-#endif
+ KASSERT(vp, ("vrele: null vp"));
+
simple_lock(&vp->v_interlock);
if (vp->v_usecount > 1) {
@@ -1356,10 +1343,7 @@ vput(vp)
{
struct proc *p = curproc; /* XXX */
-#ifdef DIAGNOSTIC
- if (vp == NULL)
- panic("vput: null vp");
-#endif
+ KASSERT(vp != NULL, ("vput: null vp"));
simple_lock(&vp->v_interlock);
@@ -1646,10 +1630,7 @@ vop_revoke(ap)
struct vnode *vp, *vq;
struct proc *p = curproc; /* XXX */
-#ifdef DIAGNOSTIC
- if ((ap->a_flags & REVOKEALL) == 0)
- panic("vop_revoke");
-#endif
+ KASSERT((ap->a_flags & REVOKEALL) != 0, ("vop_revoke"));
vp = ap->a_vp;
simple_lock(&vp->v_interlock);
diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c
index 3a00557..e6e8a6f 100644
--- a/sys/kern/vfs_lookup.c
+++ b/sys/kern/vfs_lookup.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_lookup.c 8.4 (Berkeley) 2/16/94
- * $Id: vfs_lookup.c,v 1.28 1998/06/07 17:11:45 dfr Exp $
+ * $Id: vfs_lookup.c,v 1.29 1999/01/05 18:49:52 eivind Exp $
*/
#include "opt_ktrace.h"
@@ -89,14 +89,11 @@ namei(ndp)
struct proc *p = cnp->cn_proc;
ndp->ni_cnd.cn_cred = ndp->ni_cnd.cn_proc->p_ucred;
-#ifdef DIAGNOSTIC
- if (!cnp->cn_cred || !cnp->cn_proc)
- panic ("namei: bad cred/proc");
- if (cnp->cn_nameiop & (~OPMASK))
- panic ("namei: nameiop contaminated with flags");
- if (cnp->cn_flags & OPMASK)
- panic ("namei: flags contaminated with nameiops");
-#endif
+ KASSERT(cnp->cn_cred && cnp->cn_proc, ("namei: bad cred/proc"));
+ KASSERT((cnp->cn_nameiop & (~OPMASK)) == 0,
+ ("namei: nameiop contaminated with flags"));
+ KASSERT((cnp->cn_flags & OPMASK) == 0,
+ ("namei: flags contaminated with nameiops"));
fdp = cnp->cn_proc->p_fd;
/*
@@ -418,10 +415,7 @@ unionlookup:
ndp->ni_vp = NULL;
ASSERT_VOP_LOCKED(dp, "lookup");
if (error = VOP_LOOKUP(dp, &ndp->ni_vp, cnp)) {
-#ifdef DIAGNOSTIC
- if (ndp->ni_vp != NULL)
- panic("leaf should be empty");
-#endif
+ KASSERT(ndp->ni_vp == NULL, ("leaf should be empty"));
#ifdef NAMEI_DIAGNOSTIC
printf("not found\n");
#endif
@@ -649,10 +643,7 @@ relookup(dvp, vpp, cnp)
* We now have a segment name to search for, and a directory to search.
*/
if (error = VOP_LOOKUP(dp, vpp, cnp)) {
-#ifdef DIAGNOSTIC
- if (*vpp != NULL)
- panic("leaf should be empty");
-#endif
+ KASSERT(*vpp == NULL, ("leaf should be empty"));
if (error != EJUSTRETURN)
goto bad;
/*
@@ -675,13 +666,11 @@ relookup(dvp, vpp, cnp)
}
dp = *vpp;
-#ifdef DIAGNOSTIC
/*
* Check for symbolic link
*/
- if (dp->v_type == VLNK && (cnp->cn_flags & FOLLOW))
- panic ("relookup: symlink found.\n");
-#endif
+ KASSERT(dp->v_type != VLNK || !(cnp->cn_flags & FOLLOW),
+ ("relookup: symlink found.\n"));
/*
* Disallow directory write attempts on read-only file systems.
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 0d5bbdc..92a8710 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95
- * $Id: vfs_subr.c,v 1.179 1999/01/05 18:12:29 eivind Exp $
+ * $Id: vfs_subr.c,v 1.180 1999/01/05 18:49:53 eivind Exp $
*/
/*
@@ -466,7 +466,7 @@ getnewvnode(tag, mp, vops, vpp)
simple_unlock(&vp->v_interlock);
}
-#ifdef DIAGNOSTIC
+#ifdef INVARIANTS
{
int s;
@@ -796,10 +796,7 @@ bgetvp(vp, bp)
{
int s;
-#if defined(DIAGNOSTIC)
- if (bp->b_vp)
- panic("bgetvp: not free");
-#endif
+ KASSERT(bp->b_vp == NULL, ("bgetvp: not free"));
vhold(vp);
bp->b_vp = vp;
if (vp->v_type == VBLK || vp->v_type == VCHR)
@@ -827,10 +824,7 @@ brelvp(bp)
struct buflists *listheadp;
int s;
-#if defined(DIAGNOSTIC)
- if (bp->b_vp == (struct vnode *) 0)
- panic("brelvp: NULL");
-#endif
+ KASSERT(bp->b_vp != NULL, ("brelvp: NULL"));
/*
* Delete from old vnode list, if on one.
@@ -996,10 +990,8 @@ pbgetvp(vp, bp)
register struct vnode *vp;
register struct buf *bp;
{
-#if defined(DIAGNOSTIC)
- if (bp->b_vp)
- panic("pbgetvp: not free");
-#endif
+ KASSERT(bp->b_vp == NULL, ("pbgetvp: not free"));
+
bp->b_vp = vp;
if (vp->v_type == VBLK || vp->v_type == VCHR)
bp->b_dev = vp->v_rdev;
@@ -1015,10 +1007,7 @@ pbrelvp(bp)
register struct buf *bp;
{
-#if defined(DIAGNOSTIC)
- if (bp->b_vp == (struct vnode *) 0)
- panic("pbrelvp: NULL");
-#endif
+ KASSERT(bp->b_vp != NULL, ("pbrelvp: NULL"));
bp->b_vp = (struct vnode *) 0;
}
@@ -1313,10 +1302,8 @@ vrele(vp)
{
struct proc *p = curproc; /* XXX */
-#ifdef DIAGNOSTIC
- if (vp == NULL)
- panic("vrele: null vp");
-#endif
+ KASSERT(vp, ("vrele: null vp"));
+
simple_lock(&vp->v_interlock);
if (vp->v_usecount > 1) {
@@ -1356,10 +1343,7 @@ vput(vp)
{
struct proc *p = curproc; /* XXX */
-#ifdef DIAGNOSTIC
- if (vp == NULL)
- panic("vput: null vp");
-#endif
+ KASSERT(vp != NULL, ("vput: null vp"));
simple_lock(&vp->v_interlock);
@@ -1646,10 +1630,7 @@ vop_revoke(ap)
struct vnode *vp, *vq;
struct proc *p = curproc; /* XXX */
-#ifdef DIAGNOSTIC
- if ((ap->a_flags & REVOKEALL) == 0)
- panic("vop_revoke");
-#endif
+ KASSERT((ap->a_flags & REVOKEALL) != 0, ("vop_revoke"));
vp = ap->a_vp;
simple_lock(&vp->v_interlock);
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index 222d14b..158fa1d 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)systm.h 8.7 (Berkeley) 3/29/95
- * $Id: systm.h,v 1.79 1998/12/03 04:45:57 archie Exp $
+ * $Id: systm.h,v 1.80 1998/12/21 07:41:50 dillon Exp $
*/
#ifndef _SYS_SYSTM_H_
@@ -76,6 +76,12 @@ extern struct vnode *swapdev_vp;/* vnode for swap device */
extern int boothowto; /* reboot flags, from console subsystem */
extern int bootverbose; /* nonzero to print verbose messages */
+#ifdef INVARIANTS /* The option is always available */
+#define KASSERT(exp,msg) do { if (!(exp)) panic msg; } while(0)
+#else
+#define KASSERT(exp,msg)
+#endif
+
/*
* General function declarations.
*/
diff --git a/sys/vm/device_pager.c b/sys/vm/device_pager.c
index 4459b4c..a200b9c 100644
--- a/sys/vm/device_pager.c
+++ b/sys/vm/device_pager.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)device_pager.c 8.1 (Berkeley) 6/11/93
- * $Id: device_pager.c,v 1.35 1998/11/08 12:39:07 dfr Exp $
+ * $Id: device_pager.c,v 1.36 1998/12/07 21:58:50 archie Exp $
*/
#include <sys/param.h>
@@ -208,10 +208,7 @@ dev_pager_getpages(object, m, count, reqpage)
panic("dev_pager_getpage: no map function");
paddr = pmap_phys_address((*mapfunc) ((dev_t) dev, (vm_offset_t) offset << PAGE_SHIFT, prot));
-#ifdef DIAGNOSTIC
- if (paddr == -1)
- panic("dev_pager_getpage: map function returns error");
-#endif
+ KASSERT(paddr != -1,("dev_pager_getpage: map function returns error"));
/*
* Replace the passed in reqpage page with our own fake page and free up the
* all of the original pages.
diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c
index 3e2d0de..dff0490 100644
--- a/sys/vm/swap_pager.c
+++ b/sys/vm/swap_pager.c
@@ -39,7 +39,7 @@
* from: Utah $Hdr: swap_pager.c 1.4 91/04/30$
*
* @(#)swap_pager.c 8.9 (Berkeley) 3/21/94
- * $Id: swap_pager.c,v 1.104 1998/11/19 06:20:42 bde Exp $
+ * $Id: swap_pager.c,v 1.105 1998/12/29 22:53:51 dt Exp $
*/
/*
@@ -1297,7 +1297,7 @@ swap_pager_putpages(object, m, count, sync, rtvals)
swb[i]->swb_locked--;
}
-#if defined(DIAGNOSTIC)
+#if defined(INVARIANTS)
for (i = firstidx; i < lastidx; i++) {
if (reqaddr[i] == SWB_EMPTY) {
printf("I/O to empty block???? -- pindex: %d, i: %d\n",
@@ -1348,11 +1348,9 @@ swap_pager_putpages(object, m, count, sync, rtvals)
}
spc = TAILQ_FIRST(&swap_pager_free);
-#if defined(DIAGNOSTIC)
- if (spc == NULL)
- panic("swap_pager_putpages: free queue is empty, %d expected\n",
- swap_pager_free_count);
-#endif
+ KASSERT(spc,
+ ("swap_pager_putpages: free queue is empty, %d expected\n",
+ swap_pager_free_count));
TAILQ_REMOVE(&swap_pager_free, spc, spc_list);
swap_pager_free_count--;
diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c
index 886833a..f1456b6 100644
--- a/sys/vm/vm_fault.c
+++ b/sys/vm/vm_fault.c
@@ -66,7 +66,7 @@
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*
- * $Id: vm_fault.c,v 1.90 1998/10/28 13:37:02 dg Exp $
+ * $Id: vm_fault.c,v 1.91 1998/11/25 07:40:49 dg Exp $
*/
/*
@@ -528,10 +528,8 @@ readrest:
}
}
-#if defined(DIAGNOSTIC)
- if ((fs.m->flags & PG_BUSY) == 0)
- panic("vm_fault: not busy after main loop");
-#endif
+ KASSERT((fs.m->flags & PG_BUSY) != 0,
+ ("vm_fault: not busy after main loop"));
/*
* PAGE HAS BEEN FOUND. [Loop invariant still holds -- the object lock
diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c
index a79bb1b..a00e995 100644
--- a/sys/vm/vm_object.c
+++ b/sys/vm/vm_object.c
@@ -61,7 +61,7 @@
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*
- * $Id: vm_object.c,v 1.135 1998/11/05 14:28:26 dg Exp $
+ * $Id: vm_object.c,v 1.136 1999/01/02 11:34:57 bde Exp $
*/
/*
@@ -242,10 +242,8 @@ vm_object_reference(object)
if (object == NULL)
return;
-#if defined(DIAGNOSTIC)
- if (object->flags & OBJ_DEAD)
- panic("vm_object_reference: attempting to reference dead obj");
-#endif
+ KASSERT(!(object->flags & OBJ_DEAD),
+ ("vm_object_reference: attempting to reference dead obj"));
object->ref_count++;
if (object->type == OBJT_VNODE) {
@@ -262,11 +260,10 @@ vm_object_vndeallocate(object)
vm_object_t object;
{
struct vnode *vp = (struct vnode *) object->handle;
-#if defined(DIAGNOSTIC)
- if (object->type != OBJT_VNODE)
- panic("vm_object_vndeallocate: not a vnode object");
- if (vp == NULL)
- panic("vm_object_vndeallocate: missing vp");
+ KASSERT(object->type == OBJT_VNODE,
+ ("vm_object_vndeallocate: not a vnode object"));
+ KASSERT(vp, ("vm_object_vndeallocate: missing vp"));
+#if defined(INVARIANTS)
if (object->ref_count == 0) {
vprint("vm_object_vndeallocate", vp);
panic("vm_object_vndeallocate: bad object reference count");
@@ -328,12 +325,11 @@ vm_object_deallocate(object)
vm_object_t robject;
robject = TAILQ_FIRST(&object->shadow_head);
-#if defined(DIAGNOSTIC)
- if (robject == NULL)
- panic("vm_object_deallocate: ref_count: %d,"
- " shadow_count: %d",
- object->ref_count, object->shadow_count);
-#endif
+ KASSERT(robject != NULL,
+ ("vm_object_deallocate: ref_count: %d,"
+ " shadow_count: %d",
+ object->ref_count,
+ object->shadow_count));
if ((robject->handle == NULL) &&
(robject->type == OBJT_DEFAULT ||
robject->type == OBJT_SWAP)) {
@@ -418,10 +414,8 @@ vm_object_terminate(object)
*/
vm_object_pip_wait(object, "objtrm");
-#if defined(DIAGNOSTIC)
- if (object->paging_in_progress != 0)
- panic("vm_object_terminate: pageout in progress");
-#endif
+ KASSERT(!object->paging_in_progress,
+ ("vm_object_terminate: pageout in progress"));
/*
* Clean and free the pages, as appropriate. All references to the
diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c
index dec8452..08bfc60 100644
--- a/sys/vm/vm_page.c
+++ b/sys/vm/vm_page.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)vm_page.c 7.4 (Berkeley) 5/7/91
- * $Id: vm_page.c,v 1.113 1998/11/11 15:07:57 dg Exp $
+ * $Id: vm_page.c,v 1.114 1998/12/23 01:52:47 dillon Exp $
*/
/*
@@ -870,11 +870,8 @@ vm_page_alloc(object, pindex, page_req)
int queue, qtype;
int s;
-#ifdef DIAGNOSTIC
- m = vm_page_lookup(object, pindex);
- if (m)
- panic("vm_page_alloc: page already allocated");
-#endif
+ KASSERT(!vm_page_lookup(object, pindex),
+ ("vm_page_alloc: page already allocated"));
if ((curproc == pageproc) && (page_req != VM_ALLOC_INTERRUPT)) {
page_req = VM_ALLOC_SYSTEM;
@@ -887,10 +884,7 @@ vm_page_alloc(object, pindex, page_req)
case VM_ALLOC_NORMAL:
if (cnt.v_free_count >= cnt.v_free_reserved) {
m = vm_page_select_free(object, pindex, PQ_FREE);
-#if defined(DIAGNOSTIC)
- if (m == NULL)
- panic("vm_page_alloc(NORMAL): missing page on free queue\n");
-#endif
+ KASSERT(m, ("vm_page_alloc(NORMAL): missing page on free queue\n"));
} else {
m = vm_page_select_cache(object, pindex);
if (m == NULL) {
@@ -909,10 +903,7 @@ vm_page_alloc(object, pindex, page_req)
case VM_ALLOC_ZERO:
if (cnt.v_free_count >= cnt.v_free_reserved) {
m = vm_page_select_free(object, pindex, PQ_ZERO);
-#if defined(DIAGNOSTIC)
- if (m == NULL)
- panic("vm_page_alloc(ZERO): missing page on free queue\n");
-#endif
+ KASSERT(m, ("vm_page_alloc(ZERO): missing page on free queue\n"));
} else {
m = vm_page_select_cache(object, pindex);
if (m == NULL) {
@@ -933,10 +924,7 @@ vm_page_alloc(object, pindex, page_req)
((cnt.v_cache_count == 0) &&
(cnt.v_free_count >= cnt.v_interrupt_free_min))) {
m = vm_page_select_free(object, pindex, PQ_FREE);
-#if defined(DIAGNOSTIC)
- if (m == NULL)
- panic("vm_page_alloc(SYSTEM): missing page on free queue\n");
-#endif
+ KASSERT(m, ("vm_page_alloc(SYSTEM): missing page on free queue\n"));
} else {
m = vm_page_select_cache(object, pindex);
if (m == NULL) {
@@ -955,10 +943,7 @@ vm_page_alloc(object, pindex, page_req)
case VM_ALLOC_INTERRUPT:
if (cnt.v_free_count > 0) {
m = vm_page_select_free(object, pindex, PQ_FREE);
-#if defined(DIAGNOSTIC)
- if (m == NULL)
- panic("vm_page_alloc(INTERRUPT): missing page on free queue\n");
-#endif
+ KASSERT(m, ("vm_page_alloc(INTERRUPT): missing page on free queue\n"));
} else {
splx(s);
vm_pageout_deficit++;
diff --git a/sys/vm/vm_page.h b/sys/vm/vm_page.h
index 26231a2..3149391 100644
--- a/sys/vm/vm_page.h
+++ b/sys/vm/vm_page.h
@@ -61,7 +61,7 @@
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*
- * $Id: vm_page.h,v 1.47 1998/10/21 14:46:42 dg Exp $
+ * $Id: vm_page.h,v 1.48 1998/10/28 13:37:02 dg Exp $
*/
/*
@@ -391,12 +391,8 @@ vm_page_hold(vm_page_t mem)
static __inline void
vm_page_unhold(vm_page_t mem)
{
-#ifdef DIAGNOSTIC
- if (--mem->hold_count < 0)
- panic("vm_page_unhold: hold count < 0!!!");
-#else
--mem->hold_count;
-#endif
+ KASSERT(mem->hold_count >= 0, ("vm_page_unhold: hold count < 0!!!"));
}
static __inline void
diff --git a/sys/vm/vm_zone.c b/sys/vm/vm_zone.c
index 3c52819..d90784e 100644
--- a/sys/vm/vm_zone.c
+++ b/sys/vm/vm_zone.c
@@ -11,7 +11,7 @@
* 2. Absolutely no warranty of function or purpose is made by the author
* John S. Dyson.
*
- * $Id: vm_zone.c,v 1.23 1998/10/31 17:21:31 peter Exp $
+ * $Id: vm_zone.c,v 1.24 1998/12/04 22:54:57 archie Exp $
*/
#include <sys/param.h>
@@ -194,7 +194,7 @@ zbootinit(vm_zone_t z, char *name, int size, void *item, int nitems)
z->zitems = NULL;
for (i = 0; i < nitems; i++) {
((void **) item)[0] = z->zitems;
-#if defined(DIAGNOSTIC)
+#if defined(INVARIANTS)
((void **) item)[1] = (void *) ZENTRY_FREE;
#endif
z->zitems = item;
@@ -357,7 +357,7 @@ _zget(vm_zone_t z)
nitems -= 1;
for (i = 0; i < nitems; i++) {
((void **) item)[0] = z->zitems;
-#if defined(DIAGNOSTIC)
+#if defined(INVARIANTS)
((void **) item)[1] = (void *) ZENTRY_FREE;
#endif
z->zitems = item;
@@ -367,7 +367,7 @@ _zget(vm_zone_t z)
} else if (z->zfreecnt > 0) {
item = z->zitems;
z->zitems = ((void **) item)[0];
-#if defined(DIAGNOSTIC)
+#if defined(INVARIANTS)
if (((void **) item)[1] != (void *) ZENTRY_FREE)
zerror(ZONE_ERROR_NOTFREE);
((void **) item)[1] = 0;
@@ -432,7 +432,7 @@ sysctl_vm_zone SYSCTL_HANDLER_ARGS
return (0);
}
-#if defined(DIAGNOSTIC)
+#if defined(INVARIANT_SUPPORT)
void
zerror(int error)
{
diff --git a/sys/vm/vm_zone.h b/sys/vm/vm_zone.h
index 55c54d3..6b322f5 100644
--- a/sys/vm/vm_zone.h
+++ b/sys/vm/vm_zone.h
@@ -11,7 +11,7 @@
* 2. Absolutely no warranty of function or purpose is made by the author
* John S. Dyson.
*
- * $Id: vm_zone.c,v 1.20 1998/04/15 17:47:40 bde Exp $
+ * $Id: vm_zone.h,v 1.10 1998/04/25 04:50:03 dyson Exp $
*/
#if !defined(_SYS_ZONE_H)
@@ -76,7 +76,7 @@ _zalloc(vm_zone_t z)
{
void *item;
-#if defined(DIAGNOSTIC)
+#if defined(INVARIANTS)
if (z == 0)
zerror(ZONE_ERROR_INVALID);
#endif
@@ -86,7 +86,7 @@ _zalloc(vm_zone_t z)
item = z->zitems;
z->zitems = ((void **) item)[0];
-#if defined(DIAGNOSTIC)
+#if defined(INVARIANTS)
if (((void **) item)[1] != (void *) ZENTRY_FREE)
zerror(ZONE_ERROR_NOTFREE);
((void **) item)[1] = 0;
@@ -101,7 +101,7 @@ static __inline__ void
_zfree(vm_zone_t z, void *item)
{
((void **) item)[0] = z->zitems;
-#if defined(DIAGNOSTIC)
+#if defined(INVARIANTS)
if (((void **) item)[1] == (void *) ZENTRY_FREE)
zerror(ZONE_ERROR_ALREADYFREE);
((void **) item)[1] = (void *) ZENTRY_FREE;
OpenPOWER on IntegriCloud