Skip to content

Commit

Permalink
Rollup merge of rust-lang#89068 - bjorn3:restructure_rt2, r=joshtriplett
Browse files Browse the repository at this point in the history
Restructure std::rt (part 2)

A couple more cleanups on top of rust-lang#89011

Blocked on rust-lang#89011
  • Loading branch information
matthiaskrgr committed Oct 31, 2021
2 parents 58899c4 + 0cc4cce commit 6c5aa76
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 1 addition & 3 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,7 @@ mod util;

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>,
Expand Down
3 changes: 1 addition & 2 deletions library/std/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions library/std/src/sys/unix/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub use self::imp::cleanup;
pub use self::imp::init;

pub struct Handler {
_data: *mut libc::c_void,
data: *mut libc::c_void,
}

impl Handler {
Expand All @@ -15,14 +15,14 @@ impl 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);
}
}
}
Expand Down Expand Up @@ -134,12 +134,12 @@ mod imp {
}

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 {
Expand Down Expand Up @@ -176,14 +176,14 @@ mod imp {
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,
Expand All @@ -196,7 +196,7 @@ mod imp {
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());
}
}
}
Expand All @@ -220,5 +220,5 @@ mod imp {
super::Handler::null()
}

pub unsafe fn drop_handler(_handler: &mut super::Handler) {}
pub unsafe fn drop_handler(_data: *mut libc::c_void) {}
}
2 changes: 1 addition & 1 deletion src/test/ui/rt-explody-panic-payloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit 6c5aa76

Please sign in to comment.