Date: Thu, 15 Nov 2001 09:06:20 -0500 (EST)
From: Robert Watson <rwatson@FreeBSD.ORG>
To: Matthew Dillon <dillon@apollo.backplane.com>
Cc: Alfred Perlstein <bright@mu.org>, Greg Lehey <grog@FreeBSD.ORG>, Bruce Evans <bde@zeta.org.au>, Peter Wemm <peter@wemm.org>, freebsd-arch@FreeBSD.ORG
Subject: Re: cur{thread/proc}, or not.
Message-ID: <Pine.NEB.3.96L.1011115090027.87678A-100000@fledge.watson.org>
In-Reply-To: <200111150518.fAF5IMW18730@apollo.backplane.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 14 Nov 2001, Matthew Dillon wrote:
>
> :If you want to see why curproc sucks then please investigate what
> :happens when you NDINIT a nameidata with another thread pointer
> :other than your own, then perform a vn_open. kablooey!
> :
> :My recent addition of vn_open_cred and modification of nfs_lock.c
> :was to get around this badness of the API.
> :
> :--
> :-Alfred Perlstein [alfred@freebsd.org]
>
> I'm not sure this is a fair argument. Just about all the code
> in the system taking a struct thread * pointer assumes that the
> thread is the current thread and so avoid much of the locking that
> they would normally have to do on it. Passing some other thread
> to a good chunk of this code will have very weird broken results.
In my mind, that is in fact the primary argument *to* use curproc instead
of passing around process and thread pointers. If the routine implicitly
assumes curproc or curthread for locking/referencing purposes, either
there needs to be a way to assert that:
int
foobar(struct thread *td, int arg)
{
PROMISE_ME_ITS_CURTHREAD_OR_DIE_HORRIBLY(td);
arg += td->td_only_safe_to_read_without_lock_if_curthread;
/*
* Contrived example a little less contrived:
* return (td->td_ucred->cr_uid == arg);
*/
return (arg);
}
or, we simply need to use curthread and curproc, and not allow anything
else to be passed in.
int
foobar(int arg)
{
arg += curthread->td_only_safe_to_read_without_lock_if_curthread;
return (arg);
}
Robert N M Watson FreeBSD Core Team, TrustedBSD Project
robert@fledge.watson.org NAI Labs, Safeport Network Services
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.NEB.3.96L.1011115090027.87678A-100000>
