public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* [Linux-ia64] use of setcontext()/getcontext()
@ 2001-09-25 19:35 stefan
  2001-09-26 22:24 ` David Mosberger
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: stefan @ 2001-09-25 19:35 UTC (permalink / raw)
  To: linux-ia64

Hello list,

  I wonder if the above function set can be used to implement something
like what is used to work on other types of machines with
setjmp()/longjmp(). I would like to continue a program at a certain point
of execution with a saved environment. I achieved this by now by the
following algorithm and want to ask if there is any better way.

static __cont_done = 0;

make_continuation {
        __cont_done = 0
	getcontext(ctx)
        if (__cont_done) goto __continuation
	save_both_stacks() // register and normal stack in heap
	return

__continuation:
	return
}

run_continuation {
	restore_both_stacks() // register and normal stack from heap
	__cont_done = 1
	setcontext(ctx)
}

I do not like the static __cont_done in the piece of code. But I do not
know how to determine if the instruction behind the getcontext() call is
due to a normal call to make_continuation() or due to the setcontext() of
run_continuation(). The setjmp() does return something appropiate but I do
not know how to do it with setcontext()/getcontext().
  
Thanks in advance,
	stefan@lkcc.org



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Linux-ia64] use of setcontext()/getcontext()
  2001-09-25 19:35 [Linux-ia64] use of setcontext()/getcontext() stefan
@ 2001-09-26 22:24 ` David Mosberger
  2001-09-27  7:31 ` stefan
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: David Mosberger @ 2001-09-26 22:24 UTC (permalink / raw)
  To: linux-ia64

>>>>> On Tue, 25 Sep 2001 21:35:12 +0200 (CEST), stefan <stefan@lkcc.org> said:

  Stefan> Hello list, I wonder if the above function set can be used
  Stefan> to implement something like what is used to work on other
  Stefan> types of machines with setjmp()/longjmp(). I would like to
  Stefan> continue a program at a certain point of execution with a
  Stefan> saved environment.

From this description, it sounds like you'd want to use swapcontext().
I don't quite understand your pseudo-code though (what's are
save_both_stacks()/restore_both_stacks() supposed to do?).

I do agree though that it would be nice to have a portable and
thread-safe way of determining whether or not a getcontext() is
returning for the first time.  On ia64, I made getcontext() return
this information in register r9, but that's obviously not a portable
solution.

	--david


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Linux-ia64] use of setcontext()/getcontext()
  2001-09-25 19:35 [Linux-ia64] use of setcontext()/getcontext() stefan
  2001-09-26 22:24 ` David Mosberger
@ 2001-09-27  7:31 ` stefan
  2001-09-27 17:38 ` David Mosberger
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: stefan @ 2001-09-27  7:31 UTC (permalink / raw)
  To: linux-ia64

On Wed, 26 Sep 2001, David Mosberger wrote:

> >From this description, it sounds like you'd want to use swapcontext().
> I don't quite understand your pseudo-code though (what's are
> save_both_stacks()/restore_both_stacks() supposed to do?).
> 
> I do agree though that it would be nice to have a portable and
> thread-safe way of determining whether or not a getcontext() is
> returning for the first time.  On ia64, I made getcontext() return
> this information in register r9, but that's obviously not a portable
> solution.

Some more details about the pseudo code:

save_both_stacks:
  ucontext_t ctx;
  long size;
  void *backing_store, *stack;
  getcontext (&ctx);

  /* save backing store */
  size = ctx.uc_mcontext.sc_ar_bsp -
         __libc_ia64_resgister_backing_store_base;
  backing_store = malloc (size);
  memcpy (backing_store, __libc_ia64_register_backing_store_base, size);

  /* save stack */
  size = top_of_stack - (long) &ctx;
  stack = malloc (size);
  memcpy (stack, &ctx, size);

restore_both_stacks:
  /* does the opposite; puts the save data back onto same addresses */

Does this explain it better ?

I guess I can't just read r9 for the above purpose ?

Cheers,
	stefan@lkcc.org



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Linux-ia64] use of setcontext()/getcontext()
  2001-09-25 19:35 [Linux-ia64] use of setcontext()/getcontext() stefan
  2001-09-26 22:24 ` David Mosberger
  2001-09-27  7:31 ` stefan
@ 2001-09-27 17:38 ` David Mosberger
  2001-09-29 16:53 ` stefan
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: David Mosberger @ 2001-09-27 17:38 UTC (permalink / raw)
  To: linux-ia64

>>>>> On Thu, 27 Sep 2001 09:31:25 +0200 (CEST), stefan <stefan@lkcc.org> said:

  stefan> Some more details about the pseudo code:

  stefan> [snip]

  stefan> Does this explain it better ?

Yes, I understand now what you're trying to do.

  stefan> I guess I can't just read r9 for the above purpose ?

I suppose you could.  Since the solution will be platform-dependent no
matter how you slice it, you might just as well rely on the ia64 linux
specific behavior of getcontext().  Below is a code fragment that shows
how swapcontext() can be implemented on ia64 linux.  You can use the
same approach for your case.

	--david

struct rv
  {
    long retval;
    long first_return;
  };

int
swapcontext (ucontext_t *oucp, const ucontext_t *ucp)
{
  struct rv rv = getcontext (oucp);
  if (rv.first_return)
    setcontext (ucp);
  return 0;
}


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Linux-ia64] use of setcontext()/getcontext()
  2001-09-25 19:35 [Linux-ia64] use of setcontext()/getcontext() stefan
                   ` (2 preceding siblings ...)
  2001-09-27 17:38 ` David Mosberger
@ 2001-09-29 16:53 ` stefan
  2001-10-09  6:01 ` stefan
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: stefan @ 2001-09-29 16:53 UTC (permalink / raw)
  To: linux-ia64

On Thu, 27 Sep 2001, David Mosberger wrote:

> struct rv
>   {
>     long retval;
>     long first_return;
>   };
> 
> int
> swapcontext (ucontext_t *oucp, const ucontext_t *ucp)
> {
>   struct rv rv = getcontext (oucp);
>   if (rv.first_return)
>     setcontext (ucp);
>   return 0;
> }

By including <sys/ucontext.h> and declaring getcontext() and setcontext()
by hand it was possible to port the upcoming GNU Guile release 1.6 to
ia64-linux. Thank you very much for your help !

Thanks,
	stefan@lkcc.org



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Linux-ia64] use of setcontext()/getcontext()
  2001-09-25 19:35 [Linux-ia64] use of setcontext()/getcontext() stefan
                   ` (3 preceding siblings ...)
  2001-09-29 16:53 ` stefan
@ 2001-10-09  6:01 ` stefan
  2001-10-10 22:17 ` David Mosberger
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: stefan @ 2001-10-09  6:01 UTC (permalink / raw)
  To: linux-ia64

On Sat, 29 Sep 2001, David Mosberger wrote:

> >>>>> On Sat, 29 Sep 2001 18:53:56 +0200 (CEST), stefan <stefan@lkcc.org> said:
> 
>   stefan> By including <sys/ucontext.h> and declaring getcontext() and
>   stefan> setcontext() by hand it was possible to port the upcoming
>   stefan> GNU Guile release 1.6 to ia64-linux. Thank you very much for
>   stefan> your help !
> 
> Excellent!  Thanks for the good work!

One more question about this: The `ucontext_t' structure seemed to changed
a bit over the weeks. Since when is it known to have the sc_ar_bsp member
(glibc version) ? Also I would like to know if

extern unsigned long __libc_ia64_register_backing_store_base;
or
extern void * __libc_ia64_register_backing_store_base;

is meant to be correct.

Thanks in advance,
	stefan@lkcc.org



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Linux-ia64] use of setcontext()/getcontext()
  2001-09-25 19:35 [Linux-ia64] use of setcontext()/getcontext() stefan
                   ` (4 preceding siblings ...)
  2001-10-09  6:01 ` stefan
@ 2001-10-10 22:17 ` David Mosberger
  2001-10-11 11:26 ` stefan
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: David Mosberger @ 2001-10-10 22:17 UTC (permalink / raw)
  To: linux-ia64

>>>>> On Tue, 9 Oct 2001 08:01:16 +0200 (CEST), stefan <stefan@lkcc.org> said:

  Stefan> One more question about this: The `ucontext_t' structure
  Stefan> seemed to changed a bit over the weeks. Since when is it
  Stefan> known to have the sc_ar_bsp member (glibc version) ?

I thought that member was there pretty much "forever".  However, I did
add sc_rbs_base and sc_loadrs recently.  This is really for
sigcontext, but since ucontext_t is effectively an alias, it would be
affected, too.

  Stefan> Also I would like to know if

  Stefan> extern unsigned long
  Stefan> __libc_ia64_register_backing_store_base; or extern void *
  Stefan> __libc_ia64_register_backing_store_base;

  Stefan> is meant to be correct.

Either one should work.

	--david


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Linux-ia64] use of setcontext()/getcontext()
  2001-09-25 19:35 [Linux-ia64] use of setcontext()/getcontext() stefan
                   ` (5 preceding siblings ...)
  2001-10-10 22:17 ` David Mosberger
@ 2001-10-11 11:26 ` stefan
  2001-10-11 11:33 ` stefan
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: stefan @ 2001-10-11 11:26 UTC (permalink / raw)
  To: linux-ia64

On Wed, 10 Oct 2001, David Mosberger wrote:

>   Stefan> Also I would like to know if
> 
>   Stefan> extern unsigned long
>   Stefan> __libc_ia64_register_backing_store_base; or extern void *
>   Stefan> __libc_ia64_register_backing_store_base;
> 
>   Stefan> is meant to be correct.
> 
> Either one should work.

I know that :-) But how is it initially declared ? I just need to decide
which to chose.

Thanks in advance,
	stefan@lkcc.org



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Linux-ia64] use of setcontext()/getcontext()
  2001-09-25 19:35 [Linux-ia64] use of setcontext()/getcontext() stefan
                   ` (6 preceding siblings ...)
  2001-10-11 11:26 ` stefan
@ 2001-10-11 11:33 ` stefan
  2001-10-15 18:16 ` David Mosberger
  2001-10-15 18:19 ` David Mosberger
  9 siblings, 0 replies; 11+ messages in thread
From: stefan @ 2001-10-11 11:33 UTC (permalink / raw)
  To: linux-ia64

On Wed, 10 Oct 2001, David Mosberger wrote:

> >>>>> On Tue, 9 Oct 2001 08:01:16 +0200 (CEST), stefan <stefan@lkcc.org> said:
> 
>   Stefan> One more question about this: The `ucontext_t' structure
>   Stefan> seemed to changed a bit over the weeks. Since when is it
>   Stefan> known to have the sc_ar_bsp member (glibc version) ?
> 
> I thought that member was there pretty much "forever".  However, I did
> add sc_rbs_base and sc_loadrs recently.  This is really for
> sigcontext, but since ucontext_t is effectively an alias, it would be
> affected, too.

I found some ia64 machine which declares `mcontext_t' in <sys/ucontext.h>
in another way as `sigcontext' in <bits/sigcontext.h>. That is dated on
May 22nd this year. With members like `ar_bsp_base' and `ar_bspstore'...
That is why I ask.

Thanks in advance,
	stefan@lkcc.org



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Linux-ia64] use of setcontext()/getcontext()
  2001-09-25 19:35 [Linux-ia64] use of setcontext()/getcontext() stefan
                   ` (7 preceding siblings ...)
  2001-10-11 11:33 ` stefan
@ 2001-10-15 18:16 ` David Mosberger
  2001-10-15 18:19 ` David Mosberger
  9 siblings, 0 replies; 11+ messages in thread
From: David Mosberger @ 2001-10-15 18:16 UTC (permalink / raw)
  To: linux-ia64

>>>>> On Thu, 11 Oct 2001 13:26:05 +0200 (CEST), stefan <stefan@lkcc.org> said:

  Stefan> On Wed, 10 Oct 2001, David Mosberger wrote: Also I would
  Stefan> like to know if
  >>
  Stefan> extern unsigned long
  Stefan> __libc_ia64_register_backing_store_base; or extern void *
  Stefan> __libc_ia64_register_backing_store_base;
  >>
  Stefan> is meant to be correct.
  >>  Either one should work.

  Stefan> I know that :-) But how is it initially declared ? I just
  Stefan> need to decide which to chose.

Well, it's defined in an assembly file, so there is no initial
declaration.  I'd recommend to declare it as "unsigned long *".  That
way, it would be compatible with the rse.h helper functions (not that
you'd need them... ;-).

	--david


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Linux-ia64] use of setcontext()/getcontext()
  2001-09-25 19:35 [Linux-ia64] use of setcontext()/getcontext() stefan
                   ` (8 preceding siblings ...)
  2001-10-15 18:16 ` David Mosberger
@ 2001-10-15 18:19 ` David Mosberger
  9 siblings, 0 replies; 11+ messages in thread
From: David Mosberger @ 2001-10-15 18:19 UTC (permalink / raw)
  To: linux-ia64

>>>>> On Thu, 11 Oct 2001 13:33:49 +0200 (CEST), stefan <stefan@lkcc.org> said:

  Stefan> I found some ia64 machine which declares `mcontext_t' in
  Stefan> <sys/ucontext.h> in another way as `sigcontext' in
  Stefan> <bits/sigcontext.h>. That is dated on May 22nd this
  Stefan> year. With members like `ar_bsp_base' and `ar_bspstore'...
  Stefan> That is why I ask.

Oh, right.  I had forgotten about that.  Any version of glibc that
comes with setcontext()/getcontext() should have a correct ucontext.h,
but we didn't implement those routines until quite late in the game.
If I recall correctly, they were first supported by glibc-2.2.3, but
there were some nasty bugs, so I think you pretty much have to use
glibc-2.2.4 or newer.

	--david


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2001-10-15 18:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-09-25 19:35 [Linux-ia64] use of setcontext()/getcontext() stefan
2001-09-26 22:24 ` David Mosberger
2001-09-27  7:31 ` stefan
2001-09-27 17:38 ` David Mosberger
2001-09-29 16:53 ` stefan
2001-10-09  6:01 ` stefan
2001-10-10 22:17 ` David Mosberger
2001-10-11 11:26 ` stefan
2001-10-11 11:33 ` stefan
2001-10-15 18:16 ` David Mosberger
2001-10-15 18:19 ` David Mosberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox