如何在信号处理程序中更改FPU上下文(C ++/Linux) [英] How to change FPU context in signal handler (C++/Linux)
问题描述
我写了一个信号处理程序来捕获FPE错误.即使发生这种情况,我也需要继续执行.我收到ucontext_t作为参数,我可以将错误的操作数从0更改为另一个值,但是FPU上下文仍然很糟糕,并且我遇到了无限循环?
I wrote a signal handler to catch FPE errors. I need to continue execution even if this happens. I receive a ucontext_t as parameter, I can change the bad operand from 0 to another value but the FPU context is still bad and I run into an infinite loop ?
有人已经在Linux上操纵过ucontext_t结构吗?
Does someone already manupulate the ucontext_t structure on Linux ?
我终于找到了一种通过清除ucontext_t的状态标志来处理这些情况的方法,如下所示:
I finally found a way to handle these situations by clearing the status flag of ucontext_t like this:
...
const long int cFPUStatusFlag = 0x3F;
aContext->uc_mcontext.fpregs->sw &= ~cFPUStatusFlag;
...
0x3F取反,则将0放置在FPU(x87)的状态寄存器的6位中.这样做意味着在计算后检查FPE异常.
0x3F is negated to put 0 in the 6 bits of the status register of the FPU (x87). Doing this implies to check for FPE exceptions after calculation.
推荐答案
在64位linux内核上,我没有找到实现同一目标的任何方法.
On 64 bits linux kernel, I did not find any way to achieve the same thing.
这篇关于如何在信号处理程序中更改FPU上下文(C ++/Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!