如何更改信号处理程序中的 FPU 上下文 (C++/Linux)

发布于 2024-09-03 05:49:14 字数 413 浏览 3 评论 0原文

我编写了一个信号处理程序来捕获 FPE 错误。即使发生这种情况我也需要继续执行。我收到一个 ucontext_t 作为参数,我可以将错误的操作数从 0 更改为另一个值,但 FPU 上下文仍然错误并且我遇到了无限循环?

有人已经在 Linux 上操纵了 ucontext_t 结构吗?

我最终找到了一种方法来处理这些情况,通过清除 ucontext_t 的状态标志,如下所示:

...
const long int cFPUStatusFlag = 0x3F;
aContext->uc_mcontext.fpregs->sw &= ~cFPUStatusFlag;
...

0x3F 被取反,将 0 放入 FPU (x87) 状态寄存器的 6 位中。这样做意味着在计算后检查 FPE 异常。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瘫痪情歌 2024-09-10 05:49:14

在 64 位 Linux 内核上,我没有找到任何方法来实现同样的事情。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文