about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-02-12 22:43:20 +0000
committerbors <bors@rust-lang.org>2020-02-12 22:43:20 +0000
commit92d8e82f6b571cecb1809a9aa85f8947e84b648d (patch)
tree389649e7fcb8d8ad1709183e482bc0f158441f5f /src/libstd
parenta1912f2e89b77cfe2a0e64b96f444848fe4e2d49 (diff)
parent839adda4be859bac6518d3d3e0f6093defefae65 (diff)
downloadrust-92d8e82f6b571cecb1809a9aa85f8947e84b648d.tar.gz
rust-92d8e82f6b571cecb1809a9aa85f8947e84b648d.zip
Auto merge of #69105 - Dylan-DPC:rollup-n73lh5h, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #67954 (Support new LLVM pass manager)
 - #68981 ( Account for type params on method without parentheses)
 - #69002 (miri: improve and simplify overflow detection)
 - #69038 (Add initial debug fmt for Backtrace)
 - #69040 (Cleanup SGX entry code)
 - #69086 (Update compiler-builtins to 0.1.25)
 - #69095 (Minified theme check)

Failed merges:

r? @ghost
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/backtrace.rs69
-rw-r--r--src/libstd/sys/sgx/abi/entry.S39
2 files changed, 92 insertions, 16 deletions
diff --git a/src/libstd/backtrace.rs b/src/libstd/backtrace.rs
index 5ba1c940251..a1c9aa75d77 100644
--- a/src/libstd/backtrace.rs
+++ b/src/libstd/backtrace.rs
@@ -159,6 +159,69 @@ enum BytesOrWide {
     Wide(Vec<u16>),
 }
 
+impl fmt::Debug for Backtrace {
+    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+        let mut capture = match &self.inner {
+            Inner::Unsupported => return fmt.write_str("unsupported backtrace"),
+            Inner::Disabled => return fmt.write_str("disabled backtrace"),
+            Inner::Captured(c) => c.lock().unwrap(),
+        };
+        capture.resolve();
+
+        let frames = &capture.frames[capture.actual_start..];
+
+        write!(fmt, "Backtrace ")?;
+
+        let mut dbg = fmt.debug_list();
+
+        for frame in frames {
+            if frame.frame.ip().is_null() {
+                continue;
+            }
+
+            dbg.entries(&frame.symbols);
+        }
+
+        dbg.finish()
+    }
+}
+
+impl fmt::Debug for BacktraceSymbol {
+    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(fmt, "{{ ")?;
+
+        if let Some(fn_name) = self.name.as_ref().map(|b| backtrace::SymbolName::new(b)) {
+            write!(fmt, "fn: \"{:#}\"", fn_name)?;
+        } else {
+            write!(fmt, "fn: \"<unknown>\"")?;
+        }
+
+        if let Some(fname) = self.filename.as_ref() {
+            write!(fmt, ", file: {:?}", fname)?;
+        }
+
+        if let Some(line) = self.lineno.as_ref() {
+            write!(fmt, ", line: {:?}", line)?;
+        }
+
+        write!(fmt, " }}")
+    }
+}
+
+impl fmt::Debug for BytesOrWide {
+    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
+        output_filename(
+            fmt,
+            match self {
+                BytesOrWide::Bytes(w) => BytesOrWideString::Bytes(w),
+                BytesOrWide::Wide(w) => BytesOrWideString::Wide(w),
+            },
+            backtrace::PrintFmt::Short,
+            crate::env::current_dir().as_ref().ok(),
+        )
+    }
+}
+
 impl Backtrace {
     /// Returns whether backtrace captures are enabled through environment
     /// variables.
@@ -268,12 +331,6 @@ impl Backtrace {
 
 impl fmt::Display for Backtrace {
     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
-        fmt::Debug::fmt(self, fmt)
-    }
-}
-
-impl fmt::Debug for Backtrace {
-    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
         let mut capture = match &self.inner {
             Inner::Unsupported => return fmt.write_str("unsupported backtrace"),
             Inner::Disabled => return fmt.write_str("disabled backtrace"),
diff --git a/src/libstd/sys/sgx/abi/entry.S b/src/libstd/sys/sgx/abi/entry.S
index a3e059e8131..ed4db287229 100644
--- a/src/libstd/sys/sgx/abi/entry.S
+++ b/src/libstd/sys/sgx/abi/entry.S
@@ -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. */
 
@@ -134,6 +142,19 @@ elf_entry:
     ud2                               /* should not be reached  */
 /*  end elf_entry */
 
+/* This code needs to be called *after* the enclave stack has been setup. */
+/* There are 3 places where this needs to happen, so this is put in a macro. */
+.macro entry_sanitize_final
+/*  Sanitize rflags received from user */
+/*    - DF flag: x86-64 ABI requires DF to be unset at function entry/exit */
+/*    - AC flag: AEX on misaligned memory accesses leaks side channel info */
+    pushfq
+    andq $~0x40400, (%rsp)
+    popfq
+    bt $0,.Laborted(%rip)
+    jc .Lreentry_panic
+.endm
+
 .text
 .global sgx_entry
 .type sgx_entry,function
@@ -150,25 +171,18 @@ sgx_entry:
     stmxcsr %gs:tcsls_user_mxcsr
     fnstcw %gs:tcsls_user_fcw
 
-/*  reset user state */
-/*    - DF flag: x86-64 ABI requires DF to be unset at function entry/exit */
-/*    - AC flag: AEX on misaligned memory accesses leaks side channel info */
-    pushfq
-    andq $~0x40400, (%rsp)
-    popfq
-
 /*  check for debug buffer pointer */
     testb  $0xff,DEBUG(%rip)
     jz .Lskip_debug_init
     mov %r10,%gs:tcsls_debug_panic_buf_ptr
 .Lskip_debug_init:
-/*  check for abort */
-    bt $0,.Laborted(%rip)
-    jc .Lreentry_panic
 /*  check if returning from usercall */
     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". */
@@ -179,6 +193,7 @@ sgx_entry:
     lea IMAGE_BASE(%rip),%rax
     add %rax,%rsp
     mov %rsp,%gs:tcsls_tos
+    entry_sanitize_final
 /*  call tcs_init */
 /*  store caller-saved registers in callee-saved registers */
     mov %rdi,%rbx
@@ -194,7 +209,10 @@ sgx_entry:
     mov %r13,%rdx
     mov %r14,%r8
     mov %r15,%r9
+    jmp .Lafter_init
 .Lskip_init:
+    entry_sanitize_final
+.Lafter_init:
 /*  call into main entry point */
     load_tcsls_flag_secondary_bool cx /* RCX = entry() argument: secondary: bool */
     call entry /* RDI, RSI, RDX, R8, R9 passed in from userspace */
@@ -295,6 +313,7 @@ usercall:
     ldmxcsr (%rsp)
     fldcw 4(%rsp)
     add $8, %rsp
+    entry_sanitize_final
     pop %rbx
     pop %rbp
     pop %r12