目前,我正在为 ARM 编写信号处理程序以提供尽可能多的调试信息。为了测试目的,我造成了不同的灾难。正如预期的那样,我收到的信号是 SIGFPE
,但 si_code 与我预期的不同。我想知道,为什么整数除以零的 si_code 设置为 SI_TKILL
而不是 FPE_INTDIV
或任何其他 SIGFPE
ARM 上的 si_code。
以下函数用于导致错误:
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
是可能且有效的。
关于linux - SI_TKILL si_code 在 ARM 上用于零除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54533276/