From owner-freebsd-current Sat Feb 9 22:29:31 2002 Delivered-To: freebsd-current@freebsd.org Received: from mta5.snfc21.pbi.net (mta5.snfc21.pbi.net [206.13.28.241]) by hub.freebsd.org (Postfix) with ESMTP id 1D4F637B404 for ; Sat, 9 Feb 2002 22:29:25 -0800 (PST) Received: from elischer.org ([64.164.11.57]) by mta5.snfc21.pbi.net (iPlanet Messaging Server 5.1 (built May 7 2001)) with ESMTP id <0GRB00HL10P0OK@mta5.snfc21.pbi.net> for current@freebsd.org; Sat, 09 Feb 2002 22:29:25 -0800 (PST) Date: Sat, 09 Feb 2002 22:29:19 -0800 From: Julian Elischer Subject: final ucred patch To: current@freebsd.org Message-id: <3C66133F.43D243E0@elischer.org> MIME-version: 1.0 X-Mailer: Mozilla 4.7 [en] (X11; U; FreeBSD 5.0-CURRENT i386) Content-type: multipart/mixed; boundary="Boundary_(ID_TA6w1McSahPHMx8+rAaDoQ)" X-Accept-Language: en, hu Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG This is a multi-part message in MIME format. --Boundary_(ID_TA6w1McSahPHMx8+rAaDoQ) Content-type: text/plain; charset=iso-8859-2 Content-transfer-encoding: 7BIT After comments by jhb and bde  -- +------------------------------------+ ______ _ __ | __--_|\ Julian Elischer | \ U \/ / hard at work in | / \ julian@elischer.org +------>x USA \ a very strange | ( OZ ) \___ ___ | country ! +- X_.---._/ presently in San Francisco \_/ \\ v --Boundary_(ID_TA6w1McSahPHMx8+rAaDoQ) Content-type: text/plain; charset=iso-8859-2; name=thediff Content-transfer-encoding: 7BIT Content-disposition: inline; filename=thediff ? i386/conf/LINT Index: i386/i386/trap.c =================================================================== RCS file: /home/ncvs/src/sys/i386/i386/trap.c,v retrieving revision 1.211 diff -u -r1.211 trap.c --- i386/i386/trap.c 10 Jan 2002 11:49:54 -0000 1.211 +++ i386/i386/trap.c 10 Feb 2002 00:52:58 -0000 @@ -256,9 +256,19 @@ sticks = td->td_kse->ke_sticks; td->td_frame = &frame; KASSERT(td->td_ucred == NULL, ("already have a ucred")); - PROC_LOCK(p); - td->td_ucred = crhold(p->p_ucred); - PROC_UNLOCK(p); + if (td->td_ucred != p->p_ucred) { + if (td->td_ucred) { + mtx_lock(&Giant); + crfree(td->td_ucred); + td->td_ucred = NULL; + mtx_unlock(&Giant); + } + if (p->p_ucred) { + PROC_LOCK(p); + td->td_ucred = crhold(p->p_ucred); + PROC_UNLOCK(p); + } + } switch (type) { case T_PRIVINFLT: /* privileged instruction fault */ @@ -644,10 +654,12 @@ userret(td, &frame, sticks); mtx_assert(&Giant, MA_NOTOWNED); userout: +#ifdef INVARIANTS mtx_lock(&Giant); crfree(td->td_ucred); - mtx_unlock(&Giant); td->td_ucred = NULL; + mtx_unlock(&Giant); +#endif out: return; } @@ -954,9 +966,19 @@ sticks = td->td_kse->ke_sticks; td->td_frame = &frame; KASSERT(td->td_ucred == NULL, ("already have a ucred")); - PROC_LOCK(p); - td->td_ucred = crhold(p->p_ucred); - PROC_UNLOCK(p); + if (td->td_ucred != p->p_ucred) { + if (td->td_ucred) { + mtx_lock(&Giant); + crfree(td->td_ucred); + td->td_ucred = NULL; + mtx_unlock(&Giant); + } + if (p->p_ucred) { + PROC_LOCK(p); + td->td_ucred = crhold(p->p_ucred); + PROC_UNLOCK(p); + } + } params = (caddr_t)frame.tf_esp + sizeof(int); code = frame.tf_eax; orig_tf_eflags = frame.tf_eflags; @@ -1099,10 +1121,14 @@ */ STOPEVENT(p, S_SCX, code); - mtx_lock(&Giant); - crfree(td->td_ucred); - mtx_unlock(&Giant); - td->td_ucred = NULL; +#ifdef INVARIANTS + if (td->td_ucred) { + mtx_lock(&Giant); + crfree(td->td_ucred); + td->td_ucred = NULL; + mtx_unlock(&Giant); + } +#endif #ifdef WITNESS if (witness_list(td)) { panic("system call %s returning with mutex(s) held\n", Index: kern/subr_trap.c =================================================================== RCS file: /home/ncvs/src/sys/kern/subr_trap.c,v retrieving revision 1.206 diff -u -r1.206 subr_trap.c --- kern/subr_trap.c 17 Jan 2002 17:49:23 -0000 1.206 +++ kern/subr_trap.c 10 Feb 2002 00:53:00 -0000 @@ -161,9 +161,19 @@ p->p_stats->p_prof.pr_ticks = 0; } mtx_unlock_spin(&sched_lock); - PROC_LOCK(p); - td->td_ucred = crhold(p->p_ucred); - PROC_UNLOCK(p); + if (td->td_ucred != p->p_ucred) { + if (td->td_ucred) { + mtx_lock(&Giant); + crfree(td->td_ucred); + td->td_ucred = NULL; + mtx_unlock(&Giant); + } + if (p->p_ucred) { + PROC_LOCK(p); + td->td_ucred = crhold(p->p_ucred); + PROC_UNLOCK(p); + } + } if (flags & KEF_OWEUPC && sflag & PS_PROFIL) addupc_task(ke, p->p_stats->p_prof.pr_addr, prticks); if (sflag & PS_ALRMPEND) { @@ -188,10 +198,14 @@ } userret(td, framep, sticks); - mtx_lock(&Giant); - crfree(td->td_ucred); - mtx_unlock(&Giant); - td->td_ucred = NULL; +#ifdef INVARIANTS + if (td->td_ucred) { + mtx_lock(&Giant); + crfree(td->td_ucred); + td->td_ucred = NULL; + mtx_unlock(&Giant); + } +#endif s = cpu_critical_enter(); } mtx_assert(&Giant, MA_NOTOWNED); --Boundary_(ID_TA6w1McSahPHMx8+rAaDoQ)-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message