about summary refs log tree commit diff
path: root/src/libpanic_unwind
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2019-12-22 17:42:04 -0500
committerMark Rousskov <mark.simulacrum@gmail.com>2019-12-22 17:42:47 -0500
commita06baa56b95674fc626b3c3fd680d6a65357fe60 (patch)
treecd9d867c2ca3cff5c1d6b3bd73377c44649fb075 /src/libpanic_unwind
parent8eb7c58dbb7b32701af113bc58722d0d1fefb1eb (diff)
Format the world
Diffstat (limited to 'src/libpanic_unwind')
-rw-r--r--src/libpanic_unwind/dwarf/eh.rs41
-rw-r--r--src/libpanic_unwind/dwarf/mod.rs2
-rw-r--r--src/libpanic_unwind/emcc.rs38
-rw-r--r--src/libpanic_unwind/gcc.rs31
-rw-r--r--src/libpanic_unwind/hermit.rs10
-rw-r--r--src/libpanic_unwind/lib.rs21
-rw-r--r--src/libpanic_unwind/seh.rs46
7 files changed, 101 insertions, 88 deletions
diff --git a/src/libpanic_unwind/dwarf/eh.rs b/src/libpanic_unwind/dwarf/eh.rs
index 242eb6750b3..302478cfac8 100644
--- a/src/libpanic_unwind/dwarf/eh.rs
+++ b/src/libpanic_unwind/dwarf/eh.rs
@@ -36,8 +36,8 @@ pub const DW_EH_PE_indirect: u8 = 0x80;
 
 #[derive(Copy, Clone)]
 pub struct EHContext<'a> {
-    pub ip: usize, // Current instruction pointer
-    pub func_start: usize, // Address of the current function
+    pub ip: usize,                             // Current instruction pointer
+    pub func_start: usize,                     // Address of the current function
     pub get_text_start: &'a dyn Fn() -> usize, // Get address of the code section
     pub get_data_start: &'a dyn Fn() -> usize, // Get address of the data section
 }
@@ -51,11 +51,13 @@ pub enum EHAction {
 
 pub const USING_SJLJ_EXCEPTIONS: bool = cfg!(all(target_os = "ios", target_arch = "arm"));
 
-pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>, foreign_exception: bool)
-    -> Result<EHAction, ()>
-{
+pub unsafe fn find_eh_action(
+    lsda: *const u8,
+    context: &EHContext<'_>,
+    foreign_exception: bool,
+) -> Result<EHAction, ()> {
     if lsda.is_null() {
-        return Ok(EHAction::None)
+        return Ok(EHAction::None);
     }
 
     let func_start = context.func_start;
@@ -93,10 +95,10 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>, foreign_e
             }
             if ip < func_start + cs_start + cs_len {
                 if cs_lpad == 0 {
-                    return Ok(EHAction::None)
+                    return Ok(EHAction::None);
                 } else {
                     let lpad = lpad_base + cs_lpad;
-                    return Ok(interpret_cs_action(cs_action, lpad, foreign_exception))
+                    return Ok(interpret_cs_action(cs_action, lpad, foreign_exception));
                 }
             }
         }
@@ -121,7 +123,7 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>, foreign_e
                 // Can never have null landing pad for sjlj -- that would have
                 // been indicated by a -1 call site index.
                 let lpad = (cs_lpad + 1) as usize;
-                return Ok(interpret_cs_action(cs_action, lpad, foreign_exception))
+                return Ok(interpret_cs_action(cs_action, lpad, foreign_exception));
             }
         }
     }
@@ -144,25 +146,22 @@ fn interpret_cs_action(cs_action: u64, lpad: usize, foreign_exception: bool) ->
 
 #[inline]
 fn round_up(unrounded: usize, align: usize) -> Result<usize, ()> {
-    if align.is_power_of_two() {
-        Ok((unrounded + align - 1) & !(align - 1))
-    } else {
-        Err(())
-    }
+    if align.is_power_of_two() { Ok((unrounded + align - 1) & !(align - 1)) } else { Err(()) }
 }
 
-unsafe fn read_encoded_pointer(reader: &mut DwarfReader,
-                               context: &EHContext<'_>,
-                               encoding: u8)
-                               -> Result<usize, ()> {
+unsafe fn read_encoded_pointer(
+    reader: &mut DwarfReader,
+    context: &EHContext<'_>,
+    encoding: u8,
+) -> Result<usize, ()> {
     if encoding == DW_EH_PE_omit {
-        return Err(())
+        return Err(());
     }
 
     // DW_EH_PE_aligned implies it's an absolute pointer value
     if encoding == DW_EH_PE_aligned {
         reader.ptr = round_up(reader.ptr as usize, mem::size_of::<usize>())? as *const u8;
-        return Ok(reader.read::<usize>())
+        return Ok(reader.read::<usize>());
     }
 
     let mut result = match encoding & 0x0F {
@@ -184,7 +183,7 @@ unsafe fn read_encoded_pointer(reader: &mut DwarfReader,
         DW_EH_PE_pcrel => reader.ptr as usize,
         DW_EH_PE_funcrel => {
             if context.func_start == 0 {
-                return Err(())
+                return Err(());
             }
             context.func_start
         }
diff --git a/src/libpanic_unwind/dwarf/mod.rs b/src/libpanic_unwind/dwarf/mod.rs
index 34128e60d36..649bbce52a3 100644
--- a/src/libpanic_unwind/dwarf/mod.rs
+++ b/src/libpanic_unwind/dwarf/mod.rs
@@ -17,7 +17,7 @@ pub struct DwarfReader {
     pub ptr: *const u8,
 }
 
-#[repr(C,packed)]
+#[repr(C, packed)]
 struct Unaligned<T>(T);
 
 impl DwarfReader {
diff --git a/src/libpanic_unwind/emcc.rs b/src/libpanic_unwind/emcc.rs
index 3d0d5a4151e..2098404ee1b 100644
--- a/src/libpanic_unwind/emcc.rs
+++ b/src/libpanic_unwind/emcc.rs
@@ -8,10 +8,10 @@
 
 #![allow(private_no_mangle_fns)]
 
+use alloc::boxed::Box;
 use core::any::Any;
-use core::ptr;
 use core::mem;
-use alloc::boxed::Box;
+use core::ptr;
 use libc::{self, c_int};
 use unwind as uw;
 
@@ -72,12 +72,13 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
 
 #[lang = "eh_personality"]
 #[no_mangle]
-unsafe extern "C" fn rust_eh_personality(version: c_int,
-                                         actions: uw::_Unwind_Action,
-                                         exception_class: uw::_Unwind_Exception_Class,
-                                         exception_object: *mut uw::_Unwind_Exception,
-                                         context: *mut uw::_Unwind_Context)
-                                         -> uw::_Unwind_Reason_Code {
+unsafe extern "C" fn rust_eh_personality(
+    version: c_int,
+    actions: uw::_Unwind_Action,
+    exception_class: uw::_Unwind_Exception_Class,
+    exception_object: *mut uw::_Unwind_Exception,
+    context: *mut uw::_Unwind_Context,
+) -> uw::_Unwind_Reason_Code {
     __gxx_personality_v0(version, actions, exception_class, exception_object, context)
 }
 
@@ -85,13 +86,16 @@ extern "C" {
     fn __cxa_allocate_exception(thrown_size: libc::size_t) -> *mut libc::c_void;
     fn __cxa_begin_catch(thrown_exception: *mut libc::c_void) -> *mut libc::c_void;
     fn __cxa_end_catch();
-    fn __cxa_throw(thrown_exception: *mut libc::c_void,
-                   tinfo: *const TypeInfo,
-                   dest: *mut libc::c_void) -> !;
-    fn __gxx_personality_v0(version: c_int,
-                            actions: uw::_Unwind_Action,
-                            exception_class: uw::_Unwind_Exception_Class,
-                            exception_object: *mut uw::_Unwind_Exception,
-                            context: *mut uw::_Unwind_Context)
-                            -> uw::_Unwind_Reason_Code;
+    fn __cxa_throw(
+        thrown_exception: *mut libc::c_void,
+        tinfo: *const TypeInfo,
+        dest: *mut libc::c_void,
+    ) -> !;
+    fn __gxx_personality_v0(
+        version: c_int,
+        actions: uw::_Unwind_Action,
+        exception_class: uw::_Unwind_Exception_Class,
+        exception_object: *mut uw::_Unwind_Exception,
+        context: *mut uw::_Unwind_Context,
+    ) -> uw::_Unwind_Reason_Code;
 }
diff --git a/src/libpanic_unwind/gcc.rs b/src/libpanic_unwind/gcc.rs
index 4f572fe21b3..e5e8e805b6e 100644
--- a/src/libpanic_unwind/gcc.rs
+++ b/src/libpanic_unwind/gcc.rs
@@ -46,13 +46,13 @@
 
 #![allow(private_no_mangle_fns)]
 
+use alloc::boxed::Box;
 use core::any::Any;
 use core::ptr;
-use alloc::boxed::Box;
 
-use unwind as uw;
+use crate::dwarf::eh::{self, EHAction, EHContext};
 use libc::{c_int, uintptr_t};
-use crate::dwarf::eh::{self, EHContext, EHAction};
+use unwind as uw;
 
 #[repr(C)]
 struct Exception {
@@ -72,8 +72,10 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
     let exception_param = Box::into_raw(exception) as *mut uw::_Unwind_Exception;
     return uw::_Unwind_RaiseException(exception_param) as u32;
 
-    extern "C" fn exception_cleanup(_unwind_code: uw::_Unwind_Reason_Code,
-                                    exception: *mut uw::_Unwind_Exception) {
+    extern "C" fn exception_cleanup(
+        _unwind_code: uw::_Unwind_Reason_Code,
+        exception: *mut uw::_Unwind_Exception,
+    ) {
         unsafe {
             let _: Box<Exception> = Box::from_raw(exception as *mut Exception);
         }
@@ -98,7 +100,6 @@ fn rust_exception_class() -> uw::_Unwind_Exception_Class {
     0x4d4f5a_00_52555354
 }
 
-
 // Register ids were lifted from LLVM's TargetLowering::getExceptionPointerRegister()
 // and TargetLowering::getExceptionSelectorRegister() for each architecture,
 // then mapped to DWARF register numbers via register definition tables
@@ -302,9 +303,10 @@ cfg_if::cfg_if! {
     }
 }
 
-unsafe fn find_eh_action(context: *mut uw::_Unwind_Context, foreign_exception: bool)
-    -> Result<EHAction, ()>
-{
+unsafe fn find_eh_action(
+    context: *mut uw::_Unwind_Context,
+    foreign_exception: bool,
+) -> Result<EHAction, ()> {
     let lsda = uw::_Unwind_GetLanguageSpecificData(context) as *const u8;
     let mut ip_before_instr: c_int = 0;
     let ip = uw::_Unwind_GetIPInfo(context, &mut ip_before_instr);
@@ -320,7 +322,11 @@ unsafe fn find_eh_action(context: *mut uw::_Unwind_Context, foreign_exception: b
 }
 
 // See docs in the `unwind` module.
-#[cfg(all(target_os="windows", any(target_arch = "x86", target_arch = "x86_64"), target_env="gnu"))]
+#[cfg(all(
+    target_os = "windows",
+    any(target_arch = "x86", target_arch = "x86_64"),
+    target_env = "gnu"
+))]
 #[lang = "eh_unwind_resume"]
 #[unwind(allowed)]
 unsafe extern "C" fn rust_eh_unwind_resume(panic_ctx: *mut u8) -> ! {
@@ -343,7 +349,7 @@ unsafe extern "C" fn rust_eh_unwind_resume(panic_ctx: *mut u8) -> ! {
 // implementation of stack unwinding is (for now) deferred to libgcc_eh, however
 // Rust crates use these Rust-specific entry points to avoid potential clashes
 // with any GCC runtime.
-#[cfg(all(target_os="windows", target_arch = "x86", target_env="gnu"))]
+#[cfg(all(target_os = "windows", target_arch = "x86", target_env = "gnu"))]
 pub mod eh_frame_registry {
     extern "C" {
         fn __register_frame_info(eh_frame_begin: *const u8, object: *mut u8);
@@ -356,8 +362,7 @@ pub mod eh_frame_registry {
     }
 
     #[no_mangle]
-    pub unsafe extern "C" fn rust_eh_unregister_frames(eh_frame_begin: *const u8,
-                                                       object: *mut u8) {
+    pub unsafe extern "C" fn rust_eh_unregister_frames(eh_frame_begin: *const u8, object: *mut u8) {
         __deregister_frame_info(eh_frame_begin, object);
     }
 }
diff --git a/src/libpanic_unwind/hermit.rs b/src/libpanic_unwind/hermit.rs
index 8bee6ff09e5..2f53df2861d 100644
--- a/src/libpanic_unwind/hermit.rs
+++ b/src/libpanic_unwind/hermit.rs
@@ -3,19 +3,23 @@
 //! Right now we don't support this, so this is just stubs.
 
 use alloc::boxed::Box;
-use core::ptr;
 use core::any::Any;
+use core::ptr;
 
 pub fn payload() -> *mut u8 {
     ptr::null_mut()
 }
 
 pub unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
-    extern "C" { pub fn __rust_abort() -> !; }
+    extern "C" {
+        pub fn __rust_abort() -> !;
+    }
     __rust_abort();
 }
 
 pub unsafe fn panic(_data: Box<dyn Any + Send>) -> u32 {
-    extern "C" { pub fn __rust_abort() -> !; }
+    extern "C" {
+        pub fn __rust_abort() -> !;
+    }
     __rust_abort();
 }
diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs
index 3a14197c77b..e721162edc0 100644
--- a/src/libpanic_unwind/lib.rs
+++ b/src/libpanic_unwind/lib.rs
@@ -13,9 +13,10 @@
 
 #![no_std]
 #![unstable(feature = "panic_unwind", issue = "32837")]
-#![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
-       issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
-
+#![doc(
+    html_root_url = "https://doc.rust-lang.org/nightly/",
+    issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/"
+)]
 #![feature(core_intrinsics)]
 #![feature(lang_items)]
 #![feature(libc)]
@@ -25,15 +26,14 @@
 #![feature(staged_api)]
 #![feature(std_internals)]
 #![feature(unwind_attributes)]
-
 #![panic_runtime]
 #![feature(panic_runtime)]
 
 use alloc::boxed::Box;
 use core::intrinsics;
 use core::mem;
-use core::raw;
 use core::panic::BoxMeUp;
+use core::raw;
 
 cfg_if::cfg_if! {
     if #[cfg(target_os = "emscripten")] {
@@ -69,11 +69,12 @@ mod dwarf;
 // hairy and tightly coupled, for more information see the compiler's
 // implementation of this.
 #[no_mangle]
-pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
-                                                  data: *mut u8,
-                                                  data_ptr: *mut usize,
-                                                  vtable_ptr: *mut usize)
-                                                  -> u32 {
+pub unsafe extern "C" fn __rust_maybe_catch_panic(
+    f: fn(*mut u8),
+    data: *mut u8,
+    data_ptr: *mut usize,
+    vtable_ptr: *mut usize,
+) -> u32 {
     let mut payload = imp::payload();
     if intrinsics::r#try(f, data, &mut payload as *mut _ as *mut _) == 0 {
         0
diff --git a/src/libpanic_unwind/seh.rs b/src/libpanic_unwind/seh.rs
index ff9a215d339..9a28c47ba94 100644
--- a/src/libpanic_unwind/seh.rs
+++ b/src/libpanic_unwind/seh.rs
@@ -99,8 +99,12 @@ mod imp {
     pub type ptr_t = *mut u8;
 
     macro_rules! ptr {
-        (0) => (core::ptr::null_mut());
-        ($e:expr) => ($e as *mut u8);
+        (0) => {
+            core::ptr::null_mut()
+        };
+        ($e:expr) => {
+            $e as *mut u8
+        };
     }
 }
 
@@ -169,19 +173,13 @@ static mut THROW_INFO: _ThrowInfo = _ThrowInfo {
     pCatchableTypeArray: ptr!(0),
 };
 
-static mut CATCHABLE_TYPE_ARRAY: _CatchableTypeArray = _CatchableTypeArray {
-    nCatchableTypes: 1,
-    arrayOfCatchableTypes: [ptr!(0)],
-};
+static mut CATCHABLE_TYPE_ARRAY: _CatchableTypeArray =
+    _CatchableTypeArray { nCatchableTypes: 1, arrayOfCatchableTypes: [ptr!(0)] };
 
 static mut CATCHABLE_TYPE: _CatchableType = _CatchableType {
     properties: 0,
     pType: ptr!(0),
-    thisDisplacement: _PMD {
-        mdisp: 0,
-        pdisp: -1,
-        vdisp: 0,
-    },
+    thisDisplacement: _PMD { mdisp: 0, pdisp: -1, vdisp: 0 },
     sizeOrOffset: mem::size_of::<[u64; 2]>() as c_int,
     copy_function: ptr!(0),
 };
@@ -245,20 +243,25 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
     //
     // In any case, we basically need to do something like this until we can
     // express more operations in statics (and we may never be able to).
-    atomic_store(&mut THROW_INFO.pCatchableTypeArray as *mut _ as *mut u32,
-                 ptr!(&CATCHABLE_TYPE_ARRAY as *const _) as u32);
-    atomic_store(&mut CATCHABLE_TYPE_ARRAY.arrayOfCatchableTypes[0] as *mut _ as *mut u32,
-                 ptr!(&CATCHABLE_TYPE as *const _) as u32);
-    atomic_store(&mut CATCHABLE_TYPE.pType as *mut _ as *mut u32,
-                 ptr!(&TYPE_DESCRIPTOR as *const _) as u32);
+    atomic_store(
+        &mut THROW_INFO.pCatchableTypeArray as *mut _ as *mut u32,
+        ptr!(&CATCHABLE_TYPE_ARRAY as *const _) as u32,
+    );
+    atomic_store(
+        &mut CATCHABLE_TYPE_ARRAY.arrayOfCatchableTypes[0] as *mut _ as *mut u32,
+        ptr!(&CATCHABLE_TYPE as *const _) as u32,
+    );
+    atomic_store(
+        &mut CATCHABLE_TYPE.pType as *mut _ as *mut u32,
+        ptr!(&TYPE_DESCRIPTOR as *const _) as u32,
+    );
 
     extern "system" {
         #[unwind(allowed)]
         pub fn _CxxThrowException(pExceptionObject: *mut c_void, pThrowInfo: *mut u8) -> !;
     }
 
-    _CxxThrowException(throw_ptr,
-                       &mut THROW_INFO as *mut _ as *mut _);
+    _CxxThrowException(throw_ptr, &mut THROW_INFO as *mut _ as *mut _);
 }
 
 pub fn payload() -> [u64; 2] {
@@ -266,10 +269,7 @@ pub fn payload() -> [u64; 2] {
 }
 
 pub unsafe fn cleanup(payload: [u64; 2]) -> Box<dyn Any + Send> {
-    mem::transmute(raw::TraitObject {
-        data: payload[0] as *mut _,
-        vtable: payload[1] as *mut _,
-    })
+    mem::transmute(raw::TraitObject { data: payload[0] as *mut _, vtable: payload[1] as *mut _ })
 }
 
 // This is required by the compiler to exist (e.g., it's a lang item), but