Implementing TLS: step 1

Daniel Eischen eischen at vigrid.com
Fri Jun 20 00:06:41 PDT 2003


On Thu, 19 Jun 2003, Marcel Moolenaar wrote:

> On Fri, Jun 20, 2003 at 01:08:46AM -0400, Daniel Eischen wrote:
> > > > set_mcontext() implemented in machdep.c, though.  It looks
> > > > like you do (although nothing is done with clear_ret in
> > > > get_mcontext()).
> > > 
> > > We cannot do anything with clear_ret, because it's based on
> > > assumptions that don't hold in ia64.
> > 
> > How do return values from syscalls get passed back?
> 
> trapframe, as normal. The point is that return registers are not
> part of the context and are not saved in the trapframe on entry
> to the kernel. The trapframe basicly contains garbage that we don't
> save. Hence, clearing is meaningless.
> 
> > > BTW: there's no race that can't be plugged if TP doesn't point
> > > to the mailbox. All we need is an atomic compare-exchange and
> > > a retry loop...
> > 
> > Ok, the only problem might be something being deallocated
> > out from under you.  For instance, a KSE goes away (gets
> > deallocated) while your thread is continued on another
> > KSE and you are still dereferencing something that may no
> > longer be valid.
> 
> But isn't that a generic problem and not specific to whether the
> thread pointer points to the curthread mailbox?

Not currently because current KSE access is atomic.  When a
KSE goes away, it is done under a lock and all of its threads
have either gone away also, or have had their "what KSE am
I currently running on" pointers migrated to the main (initial)
KSE.  So there are no references to the KSE any longer (at
least, that's the idea).  Depending on how one were to
implement setting the KSE mailbox on ia64 and how TLS,
TCB, and KSE pointers were set up, it might be possible
to reference a KSE mailbox after it was deallocated.  I
don't know what you have in mind, so it may not be a problem.

Also note that there are both thread and KSE mailboxen.
The km_curthread that must be set to NULL is in the
KSE mailbox.  So if all you have is TP(offset 8) pointing
to the thread TCB/mailbox, you still have another pointer
from the thread to the KSE (includes the mailbox).  So
you have to atomically set curthread->curkse->km_curthread
to NULL.  The thing that can change out from under you
is curthread->curkse, not curthread->curkse->km_curthread.


-- 
Dan Eischen



More information about the freebsd-threads mailing list