Date: Sat, 09 Feb 2002 22:29:19 -0800 From: Julian Elischer <julian@elischer.org> To: current@freebsd.org Subject: final ucred patch Message-ID: <3C66133F.43D243E0@elischer.org>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3C66133F.43D243E0>
