Skip to content

Commit 6c5aa76

Browse files
authored
Rollup merge of #89068 - bjorn3:restructure_rt2, r=joshtriplett
Restructure std::rt (part 2) A couple more cleanups on top of #89011 Blocked on #89011
2 parents 58899c4 + 0cc4cce commit 6c5aa76

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

library/std/src/io/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,7 @@ mod util;
299299

300300
const DEFAULT_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
301301

302-
pub(crate) fn cleanup() {
303-
stdio::cleanup()
304-
}
302+
pub(crate) use stdio::cleanup;
305303

306304
struct Guard<'a> {
307305
buf: &'a mut Vec<u8>,

library/std/src/rt.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ fn lang_start_internal(
128128
let ret_code = panic::catch_unwind(move || panic::catch_unwind(main).unwrap_or(101) as isize)
129129
.map_err(move |e| {
130130
mem::forget(e);
131-
rtprintpanic!("drop of the panic payload panicked");
132-
sys::abort_internal()
131+
rtabort!("drop of the panic payload panicked");
133132
});
134133
panic::catch_unwind(cleanup).map_err(rt_abort)?;
135134
ret_code

library/std/src/sys/unix/stack_overflow.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use self::imp::cleanup;
66
pub use self::imp::init;
77

88
pub struct Handler {
9-
_data: *mut libc::c_void,
9+
data: *mut libc::c_void,
1010
}
1111

1212
impl Handler {
@@ -15,14 +15,14 @@ impl Handler {
1515
}
1616

1717
fn null() -> Handler {
18-
Handler { _data: crate::ptr::null_mut() }
18+
Handler { data: crate::ptr::null_mut() }
1919
}
2020
}
2121

2222
impl Drop for Handler {
2323
fn drop(&mut self) {
2424
unsafe {
25-
drop_handler(self);
25+
drop_handler(self.data);
2626
}
2727
}
2828
}
@@ -134,12 +134,12 @@ mod imp {
134134
}
135135

136136
let handler = make_handler();
137-
MAIN_ALTSTACK.store(handler._data, Ordering::Relaxed);
137+
MAIN_ALTSTACK.store(handler.data, Ordering::Relaxed);
138138
mem::forget(handler);
139139
}
140140

141141
pub unsafe fn cleanup() {
142-
Handler { _data: MAIN_ALTSTACK.load(Ordering::Relaxed) };
142+
drop_handler(MAIN_ALTSTACK.load(Ordering::Relaxed));
143143
}
144144

145145
unsafe fn get_stackp() -> *mut libc::c_void {
@@ -176,14 +176,14 @@ mod imp {
176176
if stack.ss_flags & SS_DISABLE != 0 {
177177
stack = get_stack();
178178
sigaltstack(&stack, ptr::null_mut());
179-
Handler { _data: stack.ss_sp as *mut libc::c_void }
179+
Handler { data: stack.ss_sp as *mut libc::c_void }
180180
} else {
181181
Handler::null()
182182
}
183183
}
184184

185-
pub unsafe fn drop_handler(handler: &mut Handler) {
186-
if !handler._data.is_null() {
185+
pub unsafe fn drop_handler(data: *mut libc::c_void) {
186+
if !data.is_null() {
187187
let stack = libc::stack_t {
188188
ss_sp: ptr::null_mut(),
189189
ss_flags: SS_DISABLE,
@@ -196,7 +196,7 @@ mod imp {
196196
sigaltstack(&stack, ptr::null_mut());
197197
// We know from `get_stackp` that the alternate stack we installed is part of a mapping
198198
// that started one page earlier, so walk back a page and unmap from there.
199-
munmap(handler._data.sub(page_size()), SIGSTKSZ + page_size());
199+
munmap(data.sub(page_size()), SIGSTKSZ + page_size());
200200
}
201201
}
202202
}
@@ -220,5 +220,5 @@ mod imp {
220220
super::Handler::null()
221221
}
222222

223-
pub unsafe fn drop_handler(_handler: &mut super::Handler) {}
223+
pub unsafe fn drop_handler(_data: *mut libc::c_void) {}
224224
}

src/test/ui/rt-explody-panic-payloads.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ fn main() {
2525
println!("{:#?}", output);
2626
let stderr = std::str::from_utf8(&output.stderr);
2727
assert!(stderr.map(|v| {
28-
v.ends_with("drop of the panic payload panicked")
28+
v.ends_with("fatal runtime error: drop of the panic payload panicked\n")
2929
}).unwrap_or(false));
3030
}

0 commit comments

Comments
 (0)