Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Feb 2002 15:27:14 -0500
From:      Dan Eischen <eischen@vigrid.com>
To:        Matthew Dillon <dillon@apollo.backplane.com>
Cc:        Peter Wemm <peter@wemm.org>, arch@FreeBSD.ORG
Subject:   Re: MFC makecontext(), getcontext(), setcontext()?, also would be nice  to have some cleanups
Message-ID:  <3C6EC0A2.419FDA74@vigrid.com>
References:  <20020206195918.6350039F1@overcee.wemm.org> <200202161842.g1GIgFF89658@apollo.backplane.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Matthew Dillon wrote:
> 
>     It would be nice if getcontext() and setcontext() could be told
>     not to screw around with the signal mask, similar to what sigsetjmp()
>     and siglongjmp() do if the savemask is empty.  Perhaps something like
>     this:
> 
      [...]
>     (make same change in both setcontext() and getcontext())
> 
>     This way these calls could be used to replace the alternate signal
>     stack, sigsetjmp()/setlongjmp() junk that has to be done now in
>     roll-your-own threads systems.

Yeah, I originally thought about also making _getcontext and
_setcontext, similar to _setjmp/_longjmp which don't change
the signal mask.

The current implementation of these functions in libc will be
replaced with a system call as soon as I incorporate bde's
comments wrt FPU state handling.  They simply become:

       .weak CNAME(getcontext)
       .set CNAME(getcontext),CNAME(__getcontext)
ENTRY(__getcontext)
       popl    %ecx            /* save return address */
       movl    0(%esp), %eax   /* get ucp */
       pushl   $0              /* NULL */
       pushl   %eax            /* ucp */
       pushl   $0              /* leave slot for return address */
       movl    $SYS_getsetcontext, %eax
       KERNCALL
       addl    $8, %esp
       movl    %ecx, 0(%esp)   /* return to address saved in %ecx */
       jb      1f
       xorl    %eax, %eax      /* always returns 0 upon success */
       ret
1:
       PIC_PROLOGUE
       jmp     PIC_PLT(HIDENAME(cerror))

and similar for setcontext and swapcontext.

We do need the something similar to the current implementation
for the threads library though.  For KSE threads, we may actually
need to know when XXX_setcontext() is done so we can clear an
"in scheduler" or "context in use" flag.  I was just going to
add these functions to the threads library, but perhaps we can
find something that isn't just useful for the threads library.
I was thinking along the lines of:

  _thr_setcontext(const ucontext_t *ucp, long *done)

We can do away with "done" in the threads library, but it would
probably mean copying an interrupted context before resuming it
(so the context doesn't get clobbered if the thread gets interrupted
in the middle of resuming it).

-- 
Dan Eischen

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?3C6EC0A2.419FDA74>