linux - SI_TKILL si_code 在 ARM 上用于零除

标签 linux arm signals buildroot

目前,我正在为 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/

相关文章:

c++ - qt mysql 连接错误

c++ - LPC1700不会从深度 sleep 中醒来

assembly - ARMV8指令集的CSET指令

再次调用信号处理程序本身

python - 为什么 Python 的 Event.wait() 可以在某些系统上被信号中断,而在其他系统上却不能?

c++ - 有没有办法定位进程的哪一部分使用了最多的内存,只查看生成的核心文件?

linux - 如何找到设备挂载到的目录?

linux - 当 tid 是内核线程时,sched_setaffinity () 调用出错

assembly - asm指令 "ldr"和 "ldr_post"有什么不同?

python - 在系统调用期间捕获/阻塞 SIGINT