aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2025-04-21 19:42:27 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2025-04-21 19:43:36 +0200
commit8d54b428cfe98c21049f94c8af3bf302e44091e9 (patch)
tree9583c30ff60f098af4646a564debd9655d7d5259
parentd58ebf51bca1a30e1a07e800e3823f4c96029da0 (diff)
downloadglibc-8d54b428cfe98c21049f94c8af3bf302e44091e9.zip
glibc-8d54b428cfe98c21049f94c8af3bf302e44091e9.tar.gz
glibc-8d54b428cfe98c21049f94c8af3bf302e44091e9.tar.bz2
hurd: Do not restore xstate when it is not initialized
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.
-rw-r--r--sysdeps/mach/hurd/i386/sigreturn.c37
-rw-r--r--sysdeps/mach/hurd/x86_64/sigreturn.c37
2 files changed, 40 insertions, 34 deletions
diff --git a/sysdeps/mach/hurd/i386/sigreturn.c b/sysdeps/mach/hurd/i386/sigreturn.c
index 37fa984..dc57d61 100644
--- a/sysdeps/mach/hurd/i386/sigreturn.c
+++ b/sysdeps/mach/hurd/i386/sigreturn.c
@@ -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
diff --git a/sysdeps/mach/hurd/x86_64/sigreturn.c b/sysdeps/mach/hurd/x86_64/sigreturn.c
index dff8e76..773c00f 100644
--- a/sysdeps/mach/hurd/x86_64/sigreturn.c
+++ b/sysdeps/mach/hurd/x86_64/sigreturn.c
@@ -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