2

Currently, I am writing a signal handler for ARM to provide as much debug information as I can. For testing purposes, I cause different calamities. The signal I receive isSIGFPE, as expected, but the si_code differs from what I expected. I am wondering, why the si_code for integer division with zero is set to SI_TKILL instead of FPE_INTDIV or any other SIGFPE si_code on ARM.

The following function is used to cause the error:

int divide_by_zero()
{
   int c = 1;
   int b = 0;
   return c / b;
}

Is this the default behavior? Are the si_codes on ARM reduced?

I use the arm-linux-gcc compiler for the target which is provided by Buildroot.

J.Panek
  • 425
  • 5
  • 16

1 Answers1

1

According to POSIX, division by zero yields an undefined result, and on some architectures, it will generate a SIGFPE signal.


On the other hand, the Run-time ABI for the ARM Architecture, 4.3.2 Division by zero:

If an integer or long long division helper function is called upon to divide by 0, it should return as quotient the value returned by a call to __aeabi_idiv0 or __aeabi_ldiv0, respectively. A *divmod helper should return as remainder either 0 or the original numerator.

(Aside: Ideally, a *divmod function should return {infinity, 0} or {0, numerator}, where infinity is an approximation. End aside). The *div0 functions:

 Return the value passed to them as a parameter.

 Or, return a fixed value defined by the execution environment (such as 0).

Or, raise a signal (often SIGFPE) or throw an exception, and do not return.

So implicity, both are indicating that a signal or exception instead of FPE_INTDIV when an integer zero division is performed is possible and valid.

Jose
  • 3,306
  • 1
  • 17
  • 22
  • So I get the expected behavior as described in POSIX and the Run-time ABI for the ARM Architecture. But I thought that the _si_codes_ like `FPE_INTDIV` should provide more information about the caught signal, in this case, `SIGFPE`. – J.Panek Feb 05 '19 at 12:19
  • Is there some way of determining if si_codes will be provided on my ARM architecture when they are not mandatory? – J.Panek Feb 05 '19 at 12:27
  • I don't know, but you can trap and deal with integer division by zero: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.kui0097a/armcc_cjaddjea.htm – Jose Feb 05 '19 at 12:36