Review for libpthread support

Daniel Eischen eischen at vigrid.com
Mon Oct 6 07:51:43 PDT 2003


On Sun, 5 Oct 2003, Jake Burkholder wrote:

> On Sunday 05 October 2003 13:46, Daniel Eischen wrote:
> > What if a thread gets interrupted while using locals?  _thr_setcontext()
> > is suppose to be able to resume a thread that was interrupted anywhere.
> > What if some library function used locals, thread T1 had a page
> > fault, and it's context was exported back to libpthread?  The
> > library may run other threads before resuming T1 again.
> 
> They're part of T1's context.  They'll get saved on T1's stack on entry to the 
> kernel to handle the page fault.

One other question.  _thr_getcontext() and _thr_setcontext() are similar
to setjmp/longjmp in that _thr_getcontext() has to return 0 when it is
called normally, and 1 when it returns as a result of a _thr_setcontext()
to the saved context.

What register holds the return value for a function?  Is it %o0?
And where is this stored in the context?  I don't think that the
same method as used for setjmp/longjmp can be used here because
_thr_setcontext() has to be able to return to a context that
was interrupted, not only a context that was generated by
_thr_getcontext() -- so you can't always set the return register
in _thr_setcontext().

The other archs store 1 for the return register in the saved context
and then clear it before returning.  A thr_setcontext() just loads
the return register to what has been saved in the context.

So far we have:

  ENTRY(__thr_getcontext)
          add     %o7, 8, %o1
          add     %o1, 4, %o2
          stx     %sp, [%o0 + MC_OUT + (6 * 8)]
          stx     %o1, [%o0 + MC_TPC]
          stx     %o2, [%o0 + MC_TNPC]
          retl
          clr     %o0               /* ??? */
  END(__thr_getcontext)

          .weak   CNAME(_thr_setcontext)
          .set    CNAME(_thr_setcontext),CNAME(__thr_setcontext)
  ENTRY(__thr_setcontext)
          save    %sp, -CCFSZ, %sp
          flushw
          mov     %i0, %l0
          mov     %i1, %l1
          mov     %i2, %l2
          ldx     [%l0 + MC_GLOBAL + (1 * 8)], %g1
          ldx     [%l0 + MC_GLOBAL + (2 * 8)], %g2
          ldx     [%l0 + MC_GLOBAL + (3 * 8)], %g3
          ldx     [%l0 + MC_GLOBAL + (4 * 8)], %g4
          ldx     [%l0 + MC_GLOBAL + (5 * 8)], %g5
          ldx     [%l0 + MC_GLOBAL + (6 * 8)], %g6
          ldx     [%l0 + MC_GLOBAL + (7 * 8)], %g7
          ldx     [%l0 + MC_OUT + (0 * 8)], %i0
          ldx     [%l0 + MC_OUT + (3 * 8)], %i3
          ldx     [%l0 + MC_OUT + (4 * 8)], %i4
          ldx     [%l0 + MC_OUT + (5 * 8)], %i5
          ldx     [%l0 + MC_OUT + (6 * 8)], %i6
          ldx     [%l0 + MC_OUT + (7 * 8)], %i7
          ldx     [%l0 + MC_TPC], %l4
          ldx     [%l0 + MC_TNPC], %l3
          brz     %l1, 1f
          nop
          stx     %l1, [%l2]
  1:      jmpl    %l3, %g0
          return  %l4
  END(__thr_setcontext)

Thanks,

-- 
Dan Eischen



More information about the freebsd-sparc64 mailing list