--- //depot/vendor/freebsd/src/sys/amd64/amd64/trap.c 2006/06/20 12:46:47 +++ //depot/projects/smpng/sys/amd64/amd64/trap.c 2006/07/24 22:20:45 @@ -145,9 +145,7 @@ SYSCTL_INT(_machdep, OID_AUTO, panic_on_nmi, CTLFLAG_RW, &panic_on_nmi, 0, "Panic on NMI"); -#ifdef WITNESS extern char *syscallnames[]; -#endif /* * Exception, fault, and trap interface to the FreeBSD kernel. @@ -874,6 +872,19 @@ } /* + * Check for misbehavior. + */ + KASSERT(td->td_critnest == 0, + ("System call %s returning in a critical section", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???")); + KASSERT(td->td_locks == 0, + ("System call %s returning with %d locks held", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???", + td->td_locks)); + WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); + + /* * Handle reschedule and other end-of-syscall issues */ userret(td, &frame); @@ -894,9 +905,4 @@ STOPEVENT(p, S_SCX, code); PTRACESTOP_SC(p, td, S_PT_SCX); - - WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", - (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); - mtx_assert(&sched_lock, MA_NOTOWNED); - mtx_assert(&Giant, MA_NOTOWNED); } --- //depot/vendor/freebsd/src/sys/amd64/ia32/ia32_syscall.c 2006/02/08 08:13:37 +++ //depot/projects/smpng/sys/amd64/ia32/ia32_syscall.c 2006/07/24 21:48:42 @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -171,6 +172,9 @@ if (KTRPOINT(td, KTR_SYSCALL)) ktrsyscall(code, narg, args64); #endif + CTR4(KTR_SYSC, "syscall enter thread %p pid %d proc %s code %d", td, + td->td_proc->p_pid, td->td_proc->p_comm, code); + /* * Try to run the syscall without Giant if the syscall * is MP safe. @@ -184,6 +188,8 @@ STOPEVENT(p, S_SCE, narg); + PTRACESTOP_SC(p, td, S_PT_SCE); + AUDIT_SYSCALL_ENTER(code, td); error = (*callp->sy_call)(td, args64); AUDIT_SYSCALL_EXIT(error, td); @@ -238,10 +244,25 @@ } /* + * Check for misbehavior. + */ + KASSERT(td->td_critnest == 0, + ("System call %s returning in a critical section", + (code >= 0 && code < SYS_MAXSYSCALL) ? freebsd32_syscallnames[code] : "???")); + KASSERT(td->td_locks == 0, + ("System call %s returning with %d locks held", + (code >= 0 && code < SYS_MAXSYSCALL) ? freebsd32_syscallnames[code] : "???", + td->td_locks)); + WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", + (code >= 0 && code < SYS_MAXSYSCALL) ? freebsd32_syscallnames[code] : "???"); + + /* * Handle reschedule and other end-of-syscall issues */ userret(td, &frame); + CTR4(KTR_SYSC, "syscall exit thread %p pid %d proc %s code %d", td, + td->td_proc->p_pid, td->td_proc->p_comm, code); #ifdef KTRACE if (KTRPOINT(td, KTR_SYSRET)) ktrsysret(code, error, td->td_retval[0]); @@ -254,10 +275,7 @@ */ STOPEVENT(p, S_SCX, code); - WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", - (code >= 0 && code < SYS_MAXSYSCALL) ? freebsd32_syscallnames[code] : "???"); - mtx_assert(&sched_lock, MA_NOTOWNED); - mtx_assert(&Giant, MA_NOTOWNED); + PTRACESTOP_SC(p, td, S_PT_SCX); } --- //depot/vendor/freebsd/src/sys/arm/arm/trap.c 2006/04/09 20:22:04 +++ //depot/projects/smpng/sys/arm/arm/trap.c 2006/07/24 22:20:45 @@ -133,6 +133,7 @@ #include extern char fusubailout[]; +extern char *syscallnames[]; #ifdef DEBUG int last_fault_code; /* For the benefit of pmap_fault_fixup() */ @@ -979,8 +980,17 @@ } if (locked && (callp->sy_narg & SYF_MPSAFE) == 0) mtx_unlock(&Giant); - - + + KASSERT(td->td_critnest == 0, + ("System call %s returning in a critical section", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???")); + KASSERT(td->td_locks == 0, + ("System call %s returning with %d locks held", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???", + td->td_locks)); + WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); + userret(td, frame); CTR4(KTR_SYSC, "syscall exit thread %p pid %d proc %s code %d", td, td->td_proc->p_pid, td->td_proc->p_comm, code); @@ -991,8 +1001,6 @@ if (KTRPOINT(td, KTR_SYSRET)) ktrsysret(code, error, td->td_retval[0]); #endif - mtx_assert(&sched_lock, MA_NOTOWNED); - mtx_assert(&Giant, MA_NOTOWNED); } void --- //depot/vendor/freebsd/src/sys/conf/files 2006/07/15 20:26:09 +++ //depot/projects/smpng/sys/conf/files 2006/07/24 22:20:45 @@ -1399,7 +1399,7 @@ kern/sys_pipe.c standard kern/sys_process.c standard kern/sys_socket.c standard -kern/syscalls.c optional witness +kern/syscalls.c optional witness | invariants kern/sysv_ipc.c standard kern/sysv_msg.c optional sysvmsg kern/sysv_sem.c optional sysvsem --- //depot/vendor/freebsd/src/sys/i386/i386/trap.c 2006/06/20 12:46:47 +++ //depot/projects/smpng/sys/i386/i386/trap.c 2006/07/24 22:20:45 @@ -159,9 +159,7 @@ SYSCTL_INT(_machdep, OID_AUTO, panic_on_nmi, CTLFLAG_RW, &panic_on_nmi, 0, "Panic on NMI"); -#ifdef WITNESS extern char *syscallnames[]; -#endif /* * Exception, fault, and trap interface to the FreeBSD kernel. @@ -1065,6 +1063,19 @@ } /* + * Check for misbehavior. + */ + KASSERT(td->td_critnest == 0, + ("System call %s returning in a critical section", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???")); + KASSERT(td->td_locks == 0, + ("System call %s returning with %d locks held", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???", + td->td_locks)); + WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); + + /* * Handle reschedule and other end-of-syscall issues */ userret(td, &frame); @@ -1085,10 +1096,5 @@ STOPEVENT(p, S_SCX, code); PTRACESTOP_SC(p, td, S_PT_SCX); - - WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", - (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); - mtx_assert(&sched_lock, MA_NOTOWNED); - mtx_assert(&Giant, MA_NOTOWNED); } --- //depot/vendor/freebsd/src/sys/ia64/ia32/ia32_trap.c 2006/02/08 08:13:37 +++ //depot/projects/smpng/sys/ia64/ia32/ia32_trap.c 2006/07/24 22:20:45 @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -45,9 +46,7 @@ #include #include -#ifdef WITNESS extern char *syscallnames[]; -#endif static void ia32_syscall(struct trapframe *tf) @@ -112,6 +111,9 @@ if (KTRPOINT(td, KTR_SYSCALL)) ktrsyscall(code, narg, args64); #endif + CTR4(KTR_SYSC, "syscall enter thread %p pid %d proc %s code %d", td, + td->td_proc->p_pid, td->td_proc->p_comm, code); + /* * Try to run the syscall without Giant if the syscall * is MP safe. @@ -125,6 +127,8 @@ STOPEVENT(p, S_SCE, narg); + PTRACESTOP_SC(p, td, S_PT_SCE); + error = (*callp->sy_call)(td, args64); } @@ -176,6 +180,24 @@ trapsignal(td, &ksi); } + /* + * Check for misbehavior. + */ + KASSERT(td->td_critnest == 0, + ("System call %s returning in a critical section", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???")); + KASSERT(td->td_locks == 0, + ("System call %s returning with %d locks held", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???", + td->td_locks)); + WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); + + /* + * End of syscall tracing. + */ + CTR4(KTR_SYSC, "syscall exit thread %p pid %d proc %s code %d", td, + td->td_proc->p_pid, td->td_proc->p_comm, code); #ifdef KTRACE if (KTRPOINT(td, KTR_SYSRET)) ktrsysret(code, error, td->td_retval[0]); @@ -188,10 +210,7 @@ */ STOPEVENT(p, S_SCX, code); - WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", - (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); - mtx_assert(&sched_lock, MA_NOTOWNED); - mtx_assert(&Giant, MA_NOTOWNED); + PTRACESTOP_SC(p, td, S_PT_SCX); } /* --- //depot/vendor/freebsd/src/sys/ia64/ia64/trap.c 2006/06/29 20:01:39 +++ //depot/projects/smpng/sys/ia64/ia64/trap.c 2006/07/24 22:20:45 @@ -85,9 +85,7 @@ */ extern struct fpswa_iface *fpswa_iface; -#ifdef WITNESS extern char *syscallnames[]; -#endif static const char *ia64_vector_names[] = { "VHPT Translation", /* 0 */ @@ -1007,6 +1005,8 @@ if (KTRPOINT(td, KTR_SYSCALL)) ktrsyscall(code, (callp->sy_narg & SYF_ARGMASK), args); #endif + CTR4(KTR_SYSC, "syscall enter thread %p pid %d proc %s code %d", td, + td->td_proc->p_pid, td->td_proc->p_comm, code); td->td_retval[0] = 0; td->td_retval[1] = 0; @@ -1046,8 +1046,26 @@ } } + /* + * Check for misbehavior. + */ + KASSERT(td->td_critnest == 0, + ("System call %s returning in a critical section", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???")); + KASSERT(td->td_locks == 0, + ("System call %s returning with %d locks held", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???", + td->td_locks)); + WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); + + /* + * Handle reschedule and other end-of-syscall issues + */ userret(td, tf); + CTR4(KTR_SYSC, "syscall exit thread %p pid %d proc %s code %d", td, + td->td_proc->p_pid, td->td_proc->p_comm, code); #ifdef KTRACE if (KTRPOINT(td, KTR_SYSRET)) ktrsysret(code, error, td->td_retval[0]); @@ -1062,10 +1080,5 @@ PTRACESTOP_SC(p, td, S_PT_SCX); - WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", - (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); - mtx_assert(&sched_lock, MA_NOTOWNED); - mtx_assert(&Giant, MA_NOTOWNED); - return (error); } --- //depot/vendor/freebsd/src/sys/kern/kern_mutex.c 2006/06/03 21:16:44 +++ //depot/projects/smpng/sys/kern/kern_mutex.c 2006/07/24 19:14:57 @@ -285,6 +285,7 @@ LOCK_LOG_LOCK("LOCK", &m->mtx_object, opts, m->mtx_recurse, file, line); WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line); + curthread->td_locks++; #ifdef MUTEX_PROFILING /* don't reset the timer when/if recursing */ if (m->mtx_acqtime == 0) { @@ -304,6 +305,7 @@ KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_sleep, ("mtx_unlock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name, file, line)); + curthread->td_locks--; WITNESS_UNLOCK(&m->mtx_object, opts | LOP_EXCLUSIVE, file, line); LOCK_LOG_LOCK("UNLOCK", &m->mtx_object, opts, m->mtx_recurse, file, line); @@ -429,9 +431,11 @@ rval = _obtain_lock(m, (uintptr_t)curthread); LOCK_LOG_TRY("LOCK", &m->mtx_object, opts, rval, file, line); - if (rval) + if (rval) { WITNESS_LOCK(&m->mtx_object, opts | LOP_EXCLUSIVE | LOP_TRYLOCK, file, line); + curthread->td_locks++; + } return (rval); } --- //depot/vendor/freebsd/src/sys/kern/kern_rwlock.c 2006/04/19 21:10:17 +++ //depot/projects/smpng/sys/kern/kern_rwlock.c 2006/07/24 19:14:57 @@ -119,6 +119,7 @@ __rw_wlock(rw, curthread, file, line); LOCK_LOG_LOCK("WLOCK", &rw->rw_object, 0, 0, file, line); WITNESS_LOCK(&rw->rw_object, LOP_EXCLUSIVE, file, line); + curthread->td_locks++; } void @@ -127,6 +128,7 @@ MPASS(curthread != NULL); _rw_assert(rw, RA_WLOCKED, file, line); + curthread->td_locks--; WITNESS_UNLOCK(&rw->rw_object, LOP_EXCLUSIVE, file, line); LOCK_LOG_LOCK("WUNLOCK", &rw->rw_object, 0, 0, file, line); __rw_wunlock(rw, curthread, file, line); @@ -266,6 +268,7 @@ LOCK_LOG_LOCK("RLOCK", &rw->rw_object, 0, 0, file, line); WITNESS_LOCK(&rw->rw_object, 0, file, line); + curthread->td_locks++; } void @@ -275,6 +278,7 @@ uintptr_t x; _rw_assert(rw, RA_RLOCKED, file, line); + curthread->td_locks--; WITNESS_UNLOCK(&rw->rw_object, 0, file, line); LOCK_LOG_LOCK("RUNLOCK", &rw->rw_object, 0, 0, file, line); --- //depot/vendor/freebsd/src/sys/kern/kern_sx.c 2006/01/17 16:55:37 +++ //depot/projects/smpng/sys/kern/kern_sx.c 2006/07/24 19:14:57 @@ -128,6 +128,7 @@ LOCK_LOG_LOCK("SLOCK", &sx->sx_object, 0, 0, file, line); WITNESS_LOCK(&sx->sx_object, 0, file, line); + curthread->td_locks++; mtx_unlock(sx->sx_lock); } @@ -141,6 +142,7 @@ sx->sx_cnt++; LOCK_LOG_TRY("SLOCK", &sx->sx_object, 0, 1, file, line); WITNESS_LOCK(&sx->sx_object, LOP_TRYLOCK, file, line); + curthread->td_locks++; mtx_unlock(sx->sx_lock); return (1); } else { @@ -184,6 +186,7 @@ LOCK_LOG_LOCK("XLOCK", &sx->sx_object, 0, 0, file, line); WITNESS_LOCK(&sx->sx_object, LOP_EXCLUSIVE, file, line); + curthread->td_locks++; mtx_unlock(sx->sx_lock); } @@ -199,6 +202,7 @@ LOCK_LOG_TRY("XLOCK", &sx->sx_object, 0, 1, file, line); WITNESS_LOCK(&sx->sx_object, LOP_EXCLUSIVE | LOP_TRYLOCK, file, line); + curthread->td_locks++; mtx_unlock(sx->sx_lock); return (1); } else { @@ -215,6 +219,7 @@ _sx_assert(sx, SX_SLOCKED, file, line); mtx_lock(sx->sx_lock); + curthread->td_locks--; WITNESS_UNLOCK(&sx->sx_object, 0, file, line); /* Release. */ @@ -245,6 +250,7 @@ mtx_lock(sx->sx_lock); MPASS(sx->sx_cnt == -1); + curthread->td_locks--; WITNESS_UNLOCK(&sx->sx_object, LOP_EXCLUSIVE, file, line); /* Release. */ --- //depot/vendor/freebsd/src/sys/powerpc/powerpc/trap.c 2006/02/08 08:13:37 +++ //depot/projects/smpng/sys/powerpc/powerpc/trap.c 2006/07/24 21:48:42 @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -420,6 +421,8 @@ STOPEVENT(p, S_SCE, narg); + PTRACESTOP_SC(p, td, S_PT_SCE); + error = (*callp->sy_call)(td, params); CTR3(KTR_SYSC, "syscall: p=%s %s ret=%x", p->p_comm, @@ -467,6 +470,19 @@ if ((callp->sy_narg & SYF_MPSAFE) == 0) mtx_unlock(&Giant); + /* + * Check for misbehavior. + */ + KASSERT(td->td_critnest == 0, + ("System call %s returning in a critical section", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???")); + KASSERT(td->td_locks == 0, + ("System call %s returning with %d locks held", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???", + td->td_locks)); + WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); + #ifdef KTRACE if (KTRPOINT(td, KTR_SYSRET)) ktrsysret(code, error, td->td_retval[0]); @@ -477,10 +493,7 @@ */ STOPEVENT(p, S_SCX, code); - WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", - (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); - mtx_assert(&sched_lock, MA_NOTOWNED); - mtx_assert(&Giant, MA_NOTOWNED); + PTRACESTOP_SC(p, td, S_PT_SCX); } static int --- //depot/vendor/freebsd/src/sys/sparc64/sparc64/trap.c 2006/05/16 14:36:16 +++ //depot/projects/smpng/sys/sparc64/sparc64/trap.c 2006/07/24 20:19:06 @@ -648,6 +648,19 @@ mtx_unlock(&Giant); /* + * Check for misbehavior. + */ + KASSERT(td->td_critnest == 0, + ("System call %s returning in a critical section", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???")); + KASSERT(td->td_locks == 0, + ("System call %s returning with %d locks held", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???", + td->td_locks)); + WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", + (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); + + /* * Handle reschedule and other end-of-syscall issues */ userret(td, tf); @@ -664,9 +677,4 @@ STOPEVENT(p, S_SCX, code); PTRACESTOP_SC(p, td, S_PT_SCX); - - WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", - (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); - mtx_assert(&sched_lock, MA_NOTOWNED); - mtx_assert(&Giant, MA_NOTOWNED); }