Troube handling signals in Solaris 2.3

Troube handling signals in Solaris 2.3

Post by Casper H.S. D » Wed, 24 Jan 1996 04:00:00




>I am have trouble handling integer divide by zero exceptions.
>When I execute the following program, it does not terminate.
>Could someone tell me what I'm doing wrong?

After you catch an exception and handle it, you need to continue.

What you do is restarting the divide by zero instruction and you
get a new exception.

You need to change the PC and nPC fields in the context.
PC=nPC and nPC = nPC + 4;

Her's how:

#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <stddef.h>
#include <ucontext.h>

void
handler (int sig, siginfo_t *info, void *ctxt)
{
    struct ucontext *context = ctxt;

    fprintf(stderr,"SIGBUS at %x, pc = %x\n", info->si_addr,
            context->uc_mcontext.gregs[REG_PC]);

    /* skip offending instruction */
    context->uc_mcontext.gregs[REG_PC] = context->uc_mcontext.gregs[REG_nPC];
    context->uc_mcontext.gregs[REG_nPC] +=4;

Quote:}

main(void)
{

    struct sigaction sa;
    volatile int *foo = (int*) 1;

    sa.sa_flags = SA_SIGINFO | SA_NODEFER;
    sa.sa_sigaction = handler;
    sigemptyset(&sa.sa_mask);

    sigaction(SIGBUS, &sa, 0);

    *foo = 0;

Quote:}

Casper

--
Casper Dik - Sun Microsystems - via my guest account at the University

Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

Troube handling signals in Solaris 2.3

Post by Roderick Mot » Wed, 24 Jan 1996 04:00:00


I am have trouble handling integer divide by zero exceptions.
When I execute the following program, it does not terminate.
Could someone tell me what I'm doing wrong?

  #include <stdio.h>
  #include <sys/signal.h>
  #include <siginfo.h>
  #include <ucontext.h>

  extern void handler(int sig, siginfo_t *sip, ucontext_t *uap);

  main()
  {
    int x, y, z;
    struct sigaction svec;

    sigfillset(&(svec.sa_mask));
    svec.sa_flags = SA_SIGINFO;                
    svec.sa_handler = (handler);
    sigaction(SIGFPE, &svec, NULL);

    x = 5;
    y = 0;
    printf("performing division\n");
    z = x/y;
    printf("division completed\n");
  }

  void handler(int sig, siginfo_t *info, ucontext_t *context)
  {
    printf("handling error\n");
    if (info->si_code == FPE_INTDIV && sig == SIGFPE)
      {printf("integer division by zero\nfsr = %x\n",context->uc_mcontext.fpregs.fpu_fsr);
      }
    else
    if (sig == SIGFPE)
      printf("Some kind of FP exception\n");
  }

The output is

performing division
handling error
integer division by zero
fsr = ef7fd428
handling error
integer division by zero
fsr = ef7fd428
        .
        .
        .

In addition, I noticed that the floating point status register is different
if I compile the program with the treads library. The output of the program
compiled with the thread library is as follows.

performing division
handling error
integer division by zero
fsr = ef7fd42c
handling error
integer division by zero
fsr = ef7fd42c
handling error
integer division by zero
fsr = ef7fd42c
        .
        .
        .

What am I doing wrong?

Rod
--
-Rod

 
 
 

1. HELP: Solaris 2.3 <---> Solaris 2.3 PPP link problems

Hi all,

We are attempting to link up two Solaris 2.3 networks via PPP and we are
running into some problems.  The link initialy comes up and we are able to ping
both sides for about 30 seconds or so and then nothing.  Does anyone have a
clue what could be hapening? We are stumped here.

Thanx,

- Steve
--
=============================================================================
 Always going where no one has gone before...

=============================================================================

2. Dual-homing (?) sun boxes

3. HELP: Solaris 2.3 <---> Solaris 2.3 PPP link Problems

4. Need a.out compiler

5. Handling Internet addressing for UUCP hosts under Solaris 2.3

6. SunOS X.X: isp,esp and fas

7. signal based socket I/O porting from SunOS to Solaris 2.3 (question)

8. pthread arguments, just how many?

9. xemacs signal ABRT on solaris 2.3

10. Signals on UNIX solaris 2.3

11. Signal functions in Solaris 2.3

12. Solaris 2.3 signals

13. Signal handling: signal() vs. sigaction()