John Ripley writes:
> Have you tried implementing a program that handles SIGBUS? It's a bloody
> nightmare that will drive you insane (especially if you plan on using
> threads).
> I think I have previously sent an example pseudo-program demonstrating
> this. But for other viewers in linux-kernel who may have missed it:
Based on your pseudo-code:
--------
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <setjmp.h>
#define SIZE 500000000
volatile caddr_t bad_addr;
jmp_buf env;
void sigbus_action(int sig, siginfo_t *siginfo, void *dummy)
{
if (siginfo) {
bad_addr = siginfo->si_addr;
}
longjmp(env, 1);
}
int main()
{
char *p;
struct sigaction sa;
int i;
sa.sa_sigaction = &sigbus_action;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
sigaction(SIGBUS, &sa, NULL);
p = (char*)mmap(NULL, SIZE, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (p == (char*)-1) {
printf("Couldn't mmap memory: %m\n");
return 1;
}
if (setjmp(env)) goto bailout;
for(i=0; i<SIZE; i++) *p++ = i;
printf("Success\n");
return 0;
bailout:
printf("Error accessing address %p\n", (void*)bad_addr);
return 1;
}
--------
When I tried this with a 2.2.14 kernel, the process was just killed
though, without any chance of fixing things up.
-- Olaf WeberDo not meddle in the affairs of sysadmins, for they are quick to anger and have no need for subtlety.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Fri Mar 31 2000 - 21:00:28 EST