SI_TKILL si_code 在 ARM 上用于零除

SI_TKILL si_code on ARM for division with zero

目前,我正在为 ARM 编写信号处理程序以提供尽可能多的调试信息。为了测试目的,我造成了不同的灾难。我收到的信号是 SIGFPE,正如预期的那样,但是 si_code 与我预期的不同。我想知道,为什么整数除法为零的 si_code 设置为 SI_TKILL 而不是 FPE_INTDIV 或任何其他 SIGFPE si_code 在 ARM 上。

使用以下函数导致错误:

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

这是默认行为吗? ARM 上的 si_codes 是否减少了?

我使用 arm-linux-gcc 编译器作为 Buildroot 提供的目标。

根据POSIX,除以零会产生未定义的结果,并且在某些架构上,它会生成一个 SIGFPE 信号。


另一方面,Run-time ABI for the ARM Architecture,4.3.2除以零:

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.

如此含蓄,两者都表明当执行整数零除法时,信号或异常而不是 FPE_INTDIV 是可能且有效的。