From 7527bc819259c99c88098ec29e1b6b827d3780db Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 5 Jun 2006 20:59:19 +0000 Subject: [PATCH] Add an INVARIANTS test in both the trap code and system call code. The system will now panic if the critical section count recorded at the beginning of a system call or trap does not match the count recorded at the end. --- sys/i386/i386/trap.c | 18 +++++++++++++++++- sys/platform/pc32/i386/trap.c | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c index c77aa3d394..0a5300e53b 100644 --- a/sys/i386/i386/trap.c +++ b/sys/i386/i386/trap.c @@ -36,7 +36,7 @@ * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 * $FreeBSD: src/sys/i386/i386/trap.c,v 1.147.2.11 2003/02/27 19:09:59 luoqi Exp $ - * $DragonFly: src/sys/i386/i386/Attic/trap.c,v 1.76 2006/05/29 03:57:19 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/trap.c,v 1.77 2006/06/05 20:59:19 dillon Exp $ */ /* @@ -383,6 +383,9 @@ trap(frame) int i = 0, ucode = 0, type, code; #ifdef SMP int have_mplock = 0; +#endif +#ifdef INVARIANTS + int crit_count = td->td_pri & ~TDPRI_MASK; #endif vm_offset_t eva; @@ -862,6 +865,11 @@ out2: ; if (have_mplock) rel_mplock(); #endif +#ifdef INVARIANTS + KASSERT(crit_count == (td->td_pri & ~TDPRI_MASK), + ("syscall: critical section count mismatch! %d/%d", + crit_count / TDPRI_CRIT, td->td_pri / TDPRI_CRIT)); +#endif } #ifdef notyet @@ -1280,6 +1288,9 @@ syscall2(struct trapframe frame) int sticks; int error; int narg; +#ifdef INVARIANTS + int crit_count = td->td_pri & ~TDPRI_MASK; +#endif #ifdef SMP int have_mplock = 0; #endif @@ -1469,6 +1480,11 @@ bad: if (have_mplock) rel_mplock(); #endif +#ifdef INVARIANTS + KASSERT(crit_count == (td->td_pri & ~TDPRI_MASK), + ("syscall: critical section count mismatch! %d/%d", + crit_count / TDPRI_CRIT, td->td_pri / TDPRI_CRIT)); +#endif } /* diff --git a/sys/platform/pc32/i386/trap.c b/sys/platform/pc32/i386/trap.c index a34c0dfee2..58391027d0 100644 --- a/sys/platform/pc32/i386/trap.c +++ b/sys/platform/pc32/i386/trap.c @@ -36,7 +36,7 @@ * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 * $FreeBSD: src/sys/i386/i386/trap.c,v 1.147.2.11 2003/02/27 19:09:59 luoqi Exp $ - * $DragonFly: src/sys/platform/pc32/i386/trap.c,v 1.76 2006/05/29 03:57:19 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/trap.c,v 1.77 2006/06/05 20:59:19 dillon Exp $ */ /* @@ -383,6 +383,9 @@ trap(frame) int i = 0, ucode = 0, type, code; #ifdef SMP int have_mplock = 0; +#endif +#ifdef INVARIANTS + int crit_count = td->td_pri & ~TDPRI_MASK; #endif vm_offset_t eva; @@ -862,6 +865,11 @@ out2: ; if (have_mplock) rel_mplock(); #endif +#ifdef INVARIANTS + KASSERT(crit_count == (td->td_pri & ~TDPRI_MASK), + ("syscall: critical section count mismatch! %d/%d", + crit_count / TDPRI_CRIT, td->td_pri / TDPRI_CRIT)); +#endif } #ifdef notyet @@ -1280,6 +1288,9 @@ syscall2(struct trapframe frame) int sticks; int error; int narg; +#ifdef INVARIANTS + int crit_count = td->td_pri & ~TDPRI_MASK; +#endif #ifdef SMP int have_mplock = 0; #endif @@ -1469,6 +1480,11 @@ bad: if (have_mplock) rel_mplock(); #endif +#ifdef INVARIANTS + KASSERT(crit_count == (td->td_pri & ~TDPRI_MASK), + ("syscall: critical section count mismatch! %d/%d", + crit_count / TDPRI_CRIT, td->td_pri / TDPRI_CRIT)); +#endif } /* -- 2.41.0