]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: Do not restore xstate when it is not initialized
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 21 Apr 2025 17:42:27 +0000 (19:42 +0200)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 21 Apr 2025 17:43:36 +0000 (19:43 +0200)
If the process has never used fp before getting a signal, xstate is set
(and thus the x87 state is not initialized) but xstate->initialized is still
0, and we should not restore anything.

sysdeps/mach/hurd/i386/sigreturn.c
sysdeps/mach/hurd/x86_64/sigreturn.c

index 37fa9840706f715e835f8119096ee8805a8fd3d3..dc57d6122c2bbcf72c8df8139cf8b016187b6bd0 100644 (file)
@@ -126,24 +126,27 @@ __sigreturn (struct sigcontext *scp)
     ss->sigaltstack.ss_flags &= ~SS_ONSTACK;
 
 #ifdef i386_XFLOAT_STATE
-  if ((scp->xstate) && (scp->xstate->initialized))
+  if (scp->xstate)
     {
-      unsigned eax, ebx, ecx, edx;
-      __cpuid_count(0xd, 0, eax, ebx, ecx, edx);
-      switch (scp->xstate->fp_save_kind)
-        {
-        case 0: // FNSAVE
-          asm volatile("frstor %0" : : "m" (scp->xstate->hw_state));
-          break;
-        case 1: // FXSAVE
-          asm volatile("fxrstor %0" : : "m" (scp->xstate->hw_state),    \
-                       "a" (eax), "d" (edx));
-          break;
-        default: // XSAVE, XSAVEOPT, XSAVEC, XSAVES
-          asm volatile("xrstor %0" : : "m" (scp->xstate->hw_state),     \
-                       "a" (eax), "d" (edx));
-          break;
-        }
+      if (scp->xstate->initialized)
+       {
+         unsigned eax, ebx, ecx, edx;
+         __cpuid_count(0xd, 0, eax, ebx, ecx, edx);
+         switch (scp->xstate->fp_save_kind)
+           {
+           case 0: // FNSAVE
+             asm volatile("frstor %0" : : "m" (scp->xstate->hw_state));
+             break;
+           case 1: // FXSAVE
+             asm volatile("fxrstor %0" : : "m" (scp->xstate->hw_state),    \
+                          "a" (eax), "d" (edx));
+             break;
+           default: // XSAVE, XSAVEOPT, XSAVEC, XSAVES
+             asm volatile("xrstor %0" : : "m" (scp->xstate->hw_state),     \
+                          "a" (eax), "d" (edx));
+             break;
+           }
+       }
     }
   else
 #endif
index dff8e76dc8413cb538df040ed4453fb8f19ce1af..773c00f86d3923e83c0ba8e11f59b42cb99ca00e 100644 (file)
@@ -119,24 +119,27 @@ __sigreturn (struct sigcontext *scp)
     ss->sigaltstack.ss_flags &= ~SS_ONSTACK;
 
 #ifdef i386_XFLOAT_STATE
-  if ((scp->xstate) && (scp->xstate->initialized))
+  if (scp->xstate)
     {
-      unsigned eax, ebx, ecx, edx;
-      __cpuid_count(0xd, 0, eax, ebx, ecx, edx);
-      switch (scp->xstate->fp_save_kind)
-        {
-        case 0: // FNSAVE
-          asm volatile("frstor %0" : : "m" (scp->xstate->hw_state));
-          break;
-        case 1: // FXSAVE
-          asm volatile("fxrstor %0" : : "m" (scp->xstate->hw_state),    \
-                       "a" (eax), "d" (edx));
-          break;
-        default: // XSAVE, XSAVEOPT, XSAVEC, XSAVES
-          asm volatile("xrstor %0" : : "m" (scp->xstate->hw_state),     \
-                       "a" (eax), "d" (edx));
-          break;
-        }
+      if (scp->xstate->initialized)
+       {
+         unsigned eax, ebx, ecx, edx;
+         __cpuid_count(0xd, 0, eax, ebx, ecx, edx);
+         switch (scp->xstate->fp_save_kind)
+           {
+           case 0: // FNSAVE
+             asm volatile("frstor %0" : : "m" (scp->xstate->hw_state));
+             break;
+           case 1: // FXSAVE
+             asm volatile("fxrstor %0" : : "m" (scp->xstate->hw_state),    \
+                          "a" (eax), "d" (edx));
+             break;
+           default: // XSAVE, XSAVEOPT, XSAVEC, XSAVES
+             asm volatile("xrstor %0" : : "m" (scp->xstate->hw_state),     \
+                          "a" (eax), "d" (edx));
+             break;
+           }
+       }
     }
   else
 #endif