Glynn Clements <glynn(a)sensei.co.uk> writes:
Hrvoje Niksic wrote:
> (In fact, on *real* Unixes, we could simply use sigaction() to trap
> SIGSEGV and have the handler check whether the SEGV was caused by
> modifying a pure cons, and signal an error in that case. Of course,
> this would not work on Linux.)
Why?
Because I am unable to make this trivial program (or a variation
thereof) to compile and run on Linux:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <siginfo.h>
void
segv_handler (int sig, siginfo_t *sip, void *ignored)
{
printf ("Fault address: 0x%p\n", sip->si_addr);
exit (0);
}
int
main (void)
{
struct sigaction act;
sigaction (SIGSEGV, NULL, &act);
act.sa_handler = segv_handler;
sigemptyset (&act.sa_mask);
act.sa_flags = SA_SIGINFO;
sigaction (SIGSEGV, &act, NULL);
*(char *)0xdeadbeef = 'x';
return 0; /* unreached */
}