Why the setjmp and longjmp I wrote can not work?
- From: "Zheng Da" <spamtrap@xxxxxxxxxx>
- Date: 6 Nov 2005 05:31:36 -0800
I wrote a program as follow:
#include <stdio.h>
typedef struct __myjmp_buf
{
int efp;
int epc;
}myjmp_buf;
int mysetjmp(myjmp_buf env)
{
int reval=0;
__asm__("movl %%ebp,%0":"=r"(env[0].efp));
__asm__("movl $1f,%0\n\t"
"1:"
:"=r"(env[0].epc));
return reval;
}
void mylongjmp(myjmp_buf env , int val)
{
__asm__("movl %1,-4(%0)\n\t"
"movl %0,%%ebp\n\t"
"jmp %2"
::"r"(env[0].efp),
"r"(val),
"r"(env[0].epc));
}
myjmp_buf buf;
int test()
{
int i=0;
i++;
mylongjmp(buf , 1);
return 0;
}
int main()
{
if(mysetjmp(buf))
{
printf("return success\n");
}
printf("pc:%x,fp:%x\n" , buf[0].epc , buf[0].efp);
printf("main address:%x\n" , main);
test();
exit(0);
}
When the computer execute jmp %2, and gives me a segment fault.
I do not know why the address I save is a invalid address, and wonder
to know what should I do if I want that mysetjmp and mylongjmp can work
like setjmp and longjmp.
There is no error to compile it in my system but a warning "indirect
jmp
without '*' ", and I do not know what the warning means.
My platform is x86, the system I use is Fedora core1, and I compile the
program with gcc.
.
- Follow-Ups:
- Re: Why the setjmp and longjmp I wrote can not work?
- From: Tim Roberts
- Re: Why the setjmp and longjmp I wrote can not work?
- From: Timothy Baldwin
- Re: Why the setjmp and longjmp I wrote can not work?
- Prev by Date: Re: ps/2 mouse w/o int33
- Next by Date: Create assembly obj to link with Windows objs
- Previous by thread: ps/2 mouse w/o int33
- Next by thread: Re: Why the setjmp and longjmp I wrote can not work?
- Index(es):
Relevant Pages
|
|