From 403bc25412357fd14b4164ec5b0c0a8f189d176c Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Tue, 30 Apr 2024 13:17:22 -0700 Subject: [PATCH] Make MXCSR editable by signal handlers on Windows It's now possible to recover from floating point exception traps. --- libc/intrin/ntcontext2linux.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libc/intrin/ntcontext2linux.c b/libc/intrin/ntcontext2linux.c index a57caf33b..bf9d3df15 100644 --- a/libc/intrin/ntcontext2linux.c +++ b/libc/intrin/ntcontext2linux.c @@ -48,6 +48,7 @@ textwindows void _ntcontext2linux(ucontext_t *ctx, const struct NtContext *cr) { ctx->uc_mcontext.fs = cr->SegFs; ctx->uc_mcontext.fpregs = &ctx->__fpustate; __repmovsb(&ctx->__fpustate, &cr->FltSave, sizeof(ctx->__fpustate)); + ctx->__fpustate.mxcsr = cr->MxCsr; } textwindows void _ntlinux2context(struct NtContext *cr, const ucontext_t *ctx) { @@ -74,6 +75,7 @@ textwindows void _ntlinux2context(struct NtContext *cr, const ucontext_t *ctx) { cr->SegCs = ctx->uc_mcontext.cs; cr->SegGs = ctx->uc_mcontext.gs; cr->SegFs = ctx->uc_mcontext.fs; + cr->MxCsr = ctx->__fpustate.mxcsr; __repmovsb(&cr->FltSave, &ctx->__fpustate, sizeof(ctx->__fpustate)); }