This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: [patch 3.4/3.5] libffi & libjava port for hppa-linux
> Well, it does in libgcj. The handler in libgcj is written in C++, and
> called in exactly the same way.
> Show me your code.
here you go. thanks.
randolph
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/ucontext.h>
using namespace std;
void sighandler(int sig)
{
void **_p = (void **)&sig;
volatile struct sigcontext_struct *_regs = (struct sigcontext_struct *)++_p;
_regs->eip += 2;
cout << "In signal handler; sig = " << sig << endl;
throw sig;
}
void dosigsegv(void)
{
char *p = 0;
void *faultaddr = &&here;
printf("Triggering SIGSEGV at %p\n", faultaddr);
here:
*p = 0;
}
int main(int argc, char **argv)
{
try {
struct sigaction sact;
memset(&sact, 0, sizeof(struct sigaction));
sact.sa_handler = sighandler;
sigaction(SIGSEGV, &sact, NULL);
cout << "Signal handler installed. Waiting 1 seconds" << endl;
sleep(1);
#if 1
{
char *p = 0;
*p = 0;
}
#else
dosigsegv();
#endif
}
catch (int sig)
{
cout << "OK; caught expected exception; sig = " << sig << endl;
}
catch (...)
{
cout << "Oops, got some other exception" << endl;
}
return 0;
}
--
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/