]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #89068 - bjorn3:restructure_rt2, r=joshtriplett
authorMatthias Krüger <matthias.krueger@famsik.de>
Sun, 31 Oct 2021 12:20:04 +0000 (13:20 +0100)
committerGitHub <noreply@github.com>
Sun, 31 Oct 2021 12:20:04 +0000 (13:20 +0100)
Restructure std::rt (part 2)

A couple more cleanups on top of https://github.com/rust-lang/rust/pull/89011

Blocked on #89011

library/std/src/io/mod.rs
library/std/src/rt.rs
library/std/src/sys/unix/stack_overflow.rs
src/test/ui/rt-explody-panic-payloads.rs

index abe29ba0f7caa379c339c2fde186777cfe3d17f2..0f276e89794d890aafce8ef26f33acf943e6195b 100644 (file)
 
 const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
 
-pub(crate) fn cleanup() {
-    stdio::cleanup()
-}
+pub(crate) use stdio::cleanup;
 
 struct Guard<'a> {
     buf: &'a mut Vec<u8>,
index 121c214780d2d5e5ba371de3cd49c167ef4fbf6b..08e58257572b24fcfddeb1a18be409b6b124c8a6 100644 (file)
@@ -128,8 +128,7 @@ fn lang_start_internal(
     let ret_code = panic::catch_unwind(move || panic::catch_unwind(main).unwrap_or(101) as isize)
         .map_err(move |e| {
             mem::forget(e);
-            rtprintpanic!("drop of the panic payload panicked");
-            sys::abort_internal()
+            rtabort!("drop of the panic payload panicked");
         });
     panic::catch_unwind(cleanup).map_err(rt_abort)?;
     ret_code
index db1a2a26a8903c21797fce7449b14749c400aec6..1e8d1137ac8b865f1a8bbb8a74d57baec9ded908 100644 (file)
@@ -6,7 +6,7 @@
 pub use self::imp::init;
 
 pub struct Handler {
-    _data: *mut libc::c_void,
+    data: *mut libc::c_void,
 }
 
 impl Handler {
@@ -15,14 +15,14 @@ pub unsafe fn new() -> Handler {
     }
 
     fn null() -> Handler {
-        Handler { _data: crate::ptr::null_mut() }
+        Handler { data: crate::ptr::null_mut() }
     }
 }
 
 impl Drop for Handler {
     fn drop(&mut self) {
         unsafe {
-            drop_handler(self);
+            drop_handler(self.data);
         }
     }
 }
@@ -134,12 +134,12 @@ pub unsafe fn init() {
         }
 
         let handler = make_handler();
-        MAIN_ALTSTACK.store(handler._data, Ordering::Relaxed);
+        MAIN_ALTSTACK.store(handler.data, Ordering::Relaxed);
         mem::forget(handler);
     }
 
     pub unsafe fn cleanup() {
-        Handler { _data: MAIN_ALTSTACK.load(Ordering::Relaxed) };
+        drop_handler(MAIN_ALTSTACK.load(Ordering::Relaxed));
     }
 
     unsafe fn get_stackp() -> *mut libc::c_void {
@@ -176,14 +176,14 @@ pub unsafe fn make_handler() -> Handler {
         if stack.ss_flags & SS_DISABLE != 0 {
             stack = get_stack();
             sigaltstack(&stack, ptr::null_mut());
-            Handler { _data: stack.ss_sp as *mut libc::c_void }
+            Handler { data: stack.ss_sp as *mut libc::c_void }
         } else {
             Handler::null()
         }
     }
 
-    pub unsafe fn drop_handler(handler: &mut Handler) {
-        if !handler._data.is_null() {
+    pub unsafe fn drop_handler(data: *mut libc::c_void) {
+        if !data.is_null() {
             let stack = libc::stack_t {
                 ss_sp: ptr::null_mut(),
                 ss_flags: SS_DISABLE,
@@ -196,7 +196,7 @@ pub unsafe fn drop_handler(handler: &mut Handler) {
             sigaltstack(&stack, ptr::null_mut());
             // We know from `get_stackp` that the alternate stack we installed is part of a mapping
             // that started one page earlier, so walk back a page and unmap from there.
-            munmap(handler._data.sub(page_size()), SIGSTKSZ + page_size());
+            munmap(data.sub(page_size()), SIGSTKSZ + page_size());
         }
     }
 }
@@ -220,5 +220,5 @@ pub unsafe fn make_handler() -> super::Handler {
         super::Handler::null()
     }
 
-    pub unsafe fn drop_handler(_handler: &mut super::Handler) {}
+    pub unsafe fn drop_handler(_data: *mut libc::c_void) {}
 }
index 1d3a2ff82845ef74b6769045d765fc5e02b1c5e1..dc193582c6a50bec8fe0184eb0a6a5bcc6fecc52 100644 (file)
@@ -25,6 +25,6 @@ fn main() {
     println!("{:#?}", output);
     let stderr = std::str::from_utf8(&output.stderr);
     assert!(stderr.map(|v| {
-        v.ends_with("drop of the panic payload panicked")
+        v.ends_with("fatal runtime error: drop of the panic payload panicked\n")
     }).unwrap_or(false));
 }