* [Linux-ia64] setjmp/longjmp redux
@ 2001-06-14 19:15 chas williams
2001-06-14 20:06 ` David Mosberger
0 siblings, 1 reply; 2+ messages in thread
From: chas williams @ 2001-06-14 19:15 UTC (permalink / raw)
To: linux-ia64
hi, new to the list but i did a little reading of the archives and it seems
that setjmp/longjmp cant do what i need -- switch the stack.
why do i want to do this? i am working on porting openafs which provides
its own thread library (called lwp) that is implemented with setjmp/longjmp.
what needs to be done in order to make this work? based on my reading
it seems that ar.rnat (???) need to be saved between the context switches?
i dont know much about the ia64 architecture so if someone could give me
some pointers i would be grateful.
the following code works, but only under cc -g. using cc -O fails. i assume
that i am getting 'lucky' using -g.
#include <stdio.h>
#include <setjmp.h>
#include <stdlib.h>
static int rc;
static jmp_buf env;
dump_jmp_buf(jmp_buf a)
{
int i;
long *ptr = (long *)a;
for ( i=0; i < 70; i++)
if (ptr[i] != 0) printf("(%d) 0x%lx\n",i, ptr[i]);
}
main()
{
char *altstack;
unsigned long *patcher;
int stacksize = 16*1024;
altstack = malloc(192*1024);
printf("altstack = %p\n", altstack);
printf("&rc = %p\n", &rc);
rc = setjmp(env);
printf("rc = %d\n", rc);
if (rc = 1)
{
printf("return from longjmp\n");
exit(0);
}
((unsigned long *)env)[0] = (unsigned long *)(altstack + stacksize - 32);
dump_jmp_buf(env);
printf("about to longjmp()...\n");
longjmp(env, 1);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Linux-ia64] setjmp/longjmp redux
2001-06-14 19:15 [Linux-ia64] setjmp/longjmp redux chas williams
@ 2001-06-14 20:06 ` David Mosberger
0 siblings, 0 replies; 2+ messages in thread
From: David Mosberger @ 2001-06-14 20:06 UTC (permalink / raw)
To: linux-ia64
>>>>> On Thu, 14 Jun 2001 15:15:09 -0400, chas williams <chas@cmf.nrl.navy.mil> said:
Chas> hi, new to the list but i did a little reading of the archives
Chas> and it seems that setjmp/longjmp cant do what i need -- switch
Chas> the stack.
Chas> why do i want to do this? i am working on porting openafs
Chas> which provides its own thread library (called lwp) that is
Chas> implemented with setjmp/longjmp. what needs to be done in
Chas> order to make this work? based on my reading it seems that
Chas> ar.rnat (???) need to be saved between the context switches?
Chas> i dont know much about the ia64 architecture so if someone
Chas> could give me some pointers i would be grateful.
For synchronous context switches ("co-routines"), use
makecontext()/setcontext() et al. They have been added to glibc
recently. If you're not familiar with these routines, there is an
example in the glibc source tree in stdlib/tst-setcontext.c.
Additional usage notes can be found in in answer 4.10 of the glibc
FAQ.
--david
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-06-14 20:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-06-14 19:15 [Linux-ia64] setjmp/longjmp redux chas williams
2001-06-14 20:06 ` David Mosberger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox