]> git.lizzy.rs Git - rust.git/blobdiff - src/libpanic_unwind/gcc.rs
std: Avoid panics in rust_eh_personality
[rust.git] / src / libpanic_unwind / gcc.rs
index 84abc6bc4a5132e248470e31ad231cf1e12b8aa5..aadbeb96b2d235a255c8981c445de957fb39223c 100644 (file)
@@ -156,7 +156,10 @@ fn rust_exception_class() -> uw::_Unwind_Exception_Class {
     if version != 1 {
         return uw::_URC_FATAL_PHASE1_ERROR;
     }
-    let eh_action = find_eh_action(context);
+    let eh_action = match find_eh_action(context) {
+        Ok(action) => action,
+        Err(_) => return uw::_URC_FATAL_PHASE1_ERROR,
+    };
     if actions as i32 & uw::_UA_SEARCH_PHASE as i32 != 0 {
         match eh_action {
             EHAction::None |
@@ -219,7 +222,10 @@ fn rust_exception_class() -> uw::_Unwind_Exception_Class {
     // _Unwind_Context in our libunwind bindings and fetch the required data from there directly,
     // bypassing DWARF compatibility functions.
 
-    let eh_action = find_eh_action(context);
+    let eh_action = match find_eh_action(context) {
+        Ok(action) => action,
+        Err(_) => return uw::_URC_FAILURE,
+    };
     if search_phase {
         match eh_action {
             EHAction::None |
@@ -260,7 +266,9 @@ fn __gnu_unwind_frame(exception_object: *mut uw::_Unwind_Exception,
     }
 }
 
-unsafe fn find_eh_action(context: *mut uw::_Unwind_Context) -> EHAction {
+unsafe fn find_eh_action(context: *mut uw::_Unwind_Context)
+    -> 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);