Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 23 Jun 2014 18:32:22 -0400
From: Rich Felker <>
Subject: Re: getcontext etc was Re: Re: go support (was: Best
 place to discuss other lightweight libraries?)

On Mon, Jun 23, 2014 at 10:09:29PM +0100, Justin Cormack wrote:
> On Wed, Apr 24, 2013 at 2:42 PM, Rich Felker <> wrote:
> >> i tried to build gcc 4.7.2 with go support (--enable-languages=c,c++,go)
> >> and that fails due to a lack of set/getcontext().
> >> (see pkg/gcc472 in sabotage)
> >>
> >> according to rich, adding that to musl requires a non-trivial amount
> >> of arch specific asm.
> >
> > Yes, but it is a wanted feature, so I wouldn't mind it getting done.
> > It was even part of the standard prior to POSIX 2008, and the reason
> > for removing it was stupid. (The reason was that the makecontext
> > function's calling convention is bogus and impossible to support
> > properly, but they could have fixed this by deprecating the use of the
> > variadic arguments in any way except passing a single void* argument,
> > rather than deprecating the whole set of interfaces.)
> Just to revive this post 1.0, it would be very nice indeed to have
> set,get,swapcontext.

One approach to setcontext would be using rt_sigreturn, but I've heard
there are issues using it for setcontext involving the alternate
signal stack. It's the only way to do resuming _async_ (i.e. the
ucontext received by a signal handler for the state it interrupted)
contexts though, so maybe there's some way to make it work. This issue
was discussed recently on libc-alpha (the glibc list).

Otherwise, if async contexts don't need to be supported, these
functions are essentially just mechanical transformations of
sigsetjmp/siglongjmp. I think setcontext could be implemented just as
a transformation of the mcontext_t register values into a jmp_buf,
followed by a call to siglongjmp. For getcontext, you can't just wrap
sigsetjmp since wrapping returns-twice functions is impossible. But
maybe there's some way to make it work without code duplication.


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.