Kevin Lawton wrote:
>
> BTW, I needed a setjmp/longjmp for exceptions processing.
> The ones from <setjmp.h> seem to need linking with libc,
> so I implemented my own for use in the monitor. Seems
> to work OK so far.
>
> Can someone look at the included code and tell me if I'm overlooking
> something, just in case?
well, other than that jumps between different asms are not supported :)
i didn't see anything obviously wrong (the gcc in/out constraints
should be a/b/c/d, not eax/ebx/ecx/edx, but that is harmless (as "e" and
"x" are not defined). Note the clobber contraints should be the full
register name).
Do you need _different_ (ie other than 0/1) values returned by
setjmp()? If not the gcc builtins may be something to consider.
Your code modified to use them below.
#include <stdio.h>
typedef struct {
long blah[5];
} vm_jmp_buf_t;
vm_jmp_buf_t vm_jmp_buf;
void f1(void);
void f2(void);
void f3(void);
#define SetJmp(jmp_buf) __builtin_setjmp(&jmp_buf)
#define LongJmp(jmp_buf, ret) __builtin_longjmp(&jmp_buf,ret)
int
main()
{
unsigned ret = 0;
if ( (ret=SetJmp(vm_jmp_buf)) ) {
printf("setjmp returns %u from longjmp\n", ret);
return 0;
}
printf("setjmp buffer filled\n");
f1();
return 0;
}
void
f1(void)
{
f2();
}
void
f2(void)
{
f3();
}
void
f3(void)
{
printf("f3 calling LongJmp\n");
LongJmp(vm_jmp_buf, 1);
printf("humm... code after LongJmp executed\n");
}