home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.aix:11737 bit.listserv.aix-l:1746 bit.listserv.power-l:324
- Newsgroups: bull.sys.aix,comp.unix.aix,bit.listserv.aix-l,bit.listserv.power-l
- Path: sparky!uunet!newsgate.watson.ibm.com!yktnews!admin!yktnews!lucien
- From: lucien@watson.ibm.com (Lucien Van Elsen)
- Subject: Re: How to get more info about SIGSEGV
- Sender: news@watson.ibm.com (NNTP News Poster)
- Message-ID: <LUCIEN.92Nov19142240@fionavar.watson.ibm.com>
- In-Reply-To: mwarren@rws1.ma30.bull.com's message of Tue, 17 Nov 1992 16:30:09 GMT
- Date: Thu, 19 Nov 1992 19:22:40 GMT
- Disclaimer: This posting represents the poster's views, not necessarily those of IBM
- References: <1992Nov17.163009.11601@mips2.ma30.bull.com>
- Nntp-Posting-Host: fionavar.watson.ibm.com
- Organization: IBM T.J Watson Research Center
- Lines: 83
-
- mwarren@rws1.ma30.bull.com (Mark Warren) writes:
-
- >We have a program that can (in normal operation) perform a read or
- >write access to a non-existent (un-mapped) virtual address, or a write
- >to a read-only address. We can tell when it occurs by catching
- >SIGSEGV, but it is very to tell within the program whether the fault
- >occurred due to a write to a read-only address, or due to a write (or
- >read) to an un-mapped address. Also, we have a hard time determining
- >the offending address.
- >
- >Is there any way we can interrogate any kernel service to determine
- >this information from within the SIGSEGV handler?
-
- You don't need to deal with the kernel directly to determine this- the
- information you need is passed to the signal handler in the sigcontext
- struct. You can look at the scp->sc_jmpbuf.jmp_context.excp_type to
- determine what exception caused the SIGSEGV, and at the jmp_context.iar to
- determine which instruction caused it. An example and program are below:
-
- fionavar /u/lucien/test/sigcontext)./sigc prot
- protection fault
- Error at address 100005d4
-
- fionavar /u/lucien/test/sigcontext)./sigc addr
- invalid address
- Error at address 1000060c
-
-
- ----- sigc.c -----
-
- #include <sys/errno.h>
- #include <sys/types.h>
- #include <sys/except.h>
- #include <sys/signal.h>
-
- void
- sig_handler(signal, code, scp)
- int signal, code;
- struct sigcontext *scp;
- {
-
- switch (scp->sc_jmpbuf.jmp_context.excp_type) {
- case EXCEPT_PROT:
- printf("protection fault\n");
- break;
- case EXCEPT_INV_ADDR:
- case EFAULT:
- printf("invalid address\n");
- break;
- default:
- printf("Unknown exception %d:\n",scp->sc_jmpbuf.jmp_context.excp_type);
- break;
- }
- printf("Error at address %x\n",scp->sc_jmpbuf.jmp_context.iar);
- exit(0);
- }
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- struct sigaction action;
- char *p;
-
- action.sa_flags = 0;
- sigemptyset(&action.sa_mask);
- action.sa_handler = sig_handler;
-
- sigaction(SIGSEGV, &action, NULL);
-
- if(!strcmp("prot",argv[1])) {
- p = NULL;
- *p = '\0';
- }
- if(!strcmp("addr",argv[1])) {
- p = (char *) 0x80000000;
- *p = '\0';
- }
- }
- --
- -----------------------------------------------------------------------
- Lucien Van Elsen IBM Research
- lucien@watson.ibm.com Project Agora
-