Skip to content

Commit 236705f

Browse files
committed
Replace sys_common::util::report_overflow with rterr!
1 parent b987f74 commit 236705f

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ mod imp {
4242
use crate::io;
4343
use crate::mem;
4444
use crate::ptr;
45+
use crate::thread;
4546

4647
use libc::MAP_FAILED;
4748
use libc::{mmap, munmap};
@@ -95,15 +96,16 @@ mod imp {
9596
info: *mut libc::siginfo_t,
9697
_data: *mut libc::c_void,
9798
) {
98-
use crate::sys_common::util::report_overflow;
99-
10099
let guard = thread_info::stack_guard().unwrap_or(0..0);
101100
let addr = siginfo_si_addr(info);
102101

103102
// If the faulting address is within the guard page, then we print a
104103
// message saying so and abort.
105104
if guard.start <= addr && addr < guard.end {
106-
report_overflow();
105+
rterr!(
106+
"\nthread '{}' has overflowed its stack\n",
107+
thread::current().name().unwrap_or("<unknown>")
108+
);
107109
rtabort!("stack overflow");
108110
} else {
109111
// Unregister ourselves by reverting back to the default behavior.

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg_attr(test, allow(dead_code))]
22

33
use crate::sys::c;
4-
use crate::sys_common::util::report_overflow;
4+
use crate::thread;
55

66
pub struct Handler;
77

@@ -24,7 +24,10 @@ extern "system" fn vectored_handler(ExceptionInfo: *mut c::EXCEPTION_POINTERS) -
2424
let code = rec.ExceptionCode;
2525

2626
if code == c::EXCEPTION_STACK_OVERFLOW {
27-
report_overflow();
27+
rterr!(
28+
"\nthread '{}' has overflowed its stack\n",
29+
thread::current().name().unwrap_or("<unknown>")
30+
);
2831
}
2932
c::EXCEPTION_CONTINUE_SEARCH
3033
}

library/std/src/sys_common/util.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
use crate::fmt;
22
use crate::io::prelude::*;
33
use crate::sys::stdio::panic_output;
4-
use crate::thread;
54

65
pub fn dumb_print(args: fmt::Arguments<'_>) {
76
if let Some(mut out) = panic_output() {
87
let _ = out.write_fmt(args);
98
}
109
}
11-
12-
#[allow(dead_code)] // stack overflow detection not enabled on all platforms
13-
pub unsafe fn report_overflow() {
14-
dumb_print(format_args!(
15-
"\nthread '{}' has overflowed its stack\n",
16-
thread::current().name().unwrap_or("<unknown>")
17-
));
18-
}

0 commit comments

Comments
 (0)