]> git.lizzy.rs Git - rust.git/commitdiff
sanitize MXCSR/FPU control registers
authorRaoul Strackx <raoul.strackx@fortanix.com>
Fri, 7 Feb 2020 09:49:47 +0000 (10:49 +0100)
committerJethro Beekman <jethro@fortanix.com>
Mon, 10 Feb 2020 19:57:30 +0000 (20:57 +0100)
src/libstd/sys/sgx/abi/entry.S

index 7c273a8a83d302c3c29e60dcf97880cb340d061f..a08caec3c2b35743be9d37713d70a5c772d868cd 100644 (file)
@@ -30,6 +30,14 @@ IMAGE_BASE:
 
 /*  We can store a bunch of data in the gap between MXCSR and the XSAVE header */
 
+/* MXCSR initialization value for ABI */
+.Lmxcsr_init:
+    .int 0x1f80
+
+/* x87 FPU control word initialization value for ABI */
+.Lfpucw_init:
+    .int 0x037f
+
 /*  The following symbols point at read-only data that will be filled in by the */
 /*  post-linker. */
 
@@ -173,6 +181,9 @@ sgx_entry:
     mov %gs:tcsls_last_rsp,%r11
     test %r11,%r11
     jnz .Lusercall_ret
+/*  reset user state */
+    ldmxcsr .Lmxcsr_init(%rip)
+    fldcw .Lfpucw_init(%rip)
 /*  setup stack */
     mov %gs:tcsls_tos,%rsp /*  initially, RSP is not set to the correct value */
                            /*  here. This is fixed below under "adjust stack". */