How to change FPU context in signal handler (C++/Linux)

自作多情 提交于 2019-12-10 20:05:48

问题


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 ?

Does someone already manupulate the ucontext_t structure on Linux ?

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 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.


回答1:


On 64 bits linux kernel, I did not find any way to achieve the same thing.



来源:https://stackoverflow.com/questions/2942508/how-to-change-fpu-context-in-signal-handler-c-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!