@@ -1312,16 +1312,17 @@ pub fn init_env_logger(env: &str) {
13121312 tracing:: subscriber:: set_global_default ( subscriber) . unwrap ( ) ;
13131313}
13141314
1315+ #[ cfg( unix) ]
13151316extern "C" {
1316- // Only available in glibc
13171317 fn backtrace_symbols_fd ( buffer : * const * mut libc:: c_void , size : libc:: c_int , fd : libc:: c_int ) ;
13181318}
13191319
13201320#[ cfg( unix) ]
1321- fn print_stack_trace ( _: libc:: c_int ) {
1321+ extern "C" fn print_stack_trace ( _: libc:: c_int ) {
1322+ const MAX_FRAMES : usize = 256 ;
1323+ static mut STACK_TRACE : [ * mut libc:: c_void ; MAX_FRAMES ] = [ std:: ptr:: null_mut ( ) ; MAX_FRAMES ] ;
13221324 unsafe {
1323- static mut STACK_TRACE : [ * mut libc:: c_void ; 256 ] = [ std:: ptr:: null_mut ( ) ; 256 ] ;
1324- let depth = libc:: backtrace ( STACK_TRACE . as_mut_ptr ( ) , 256 ) ;
1325+ let depth = libc:: backtrace ( STACK_TRACE . as_mut_ptr ( ) , MAX_FRAMES as i32 ) ;
13251326 if depth == 0 {
13261327 return ;
13271328 }
@@ -1332,35 +1333,34 @@ fn print_stack_trace(_: libc::c_int) {
13321333#[ cfg( unix) ]
13331334// When an error signal (such as SIGABRT or SIGSEGV) is delivered to the
13341335// process, print a stack trace and then exit.
1335- fn print_stack_trace_on_error_signal ( ) {
1336+ fn install_signal_handler ( ) {
13361337 unsafe {
13371338 const ALT_STACK_SIZE : usize = libc:: MINSIGSTKSZ + 64 * 1024 ;
13381339 let mut alt_stack: libc:: stack_t = std:: mem:: zeroed ( ) ;
13391340 alt_stack. ss_sp =
1340- std:: alloc:: alloc ( std:: alloc:: Layout :: from_size_align_unchecked ( ALT_STACK_SIZE , 1 ) )
1341+ std:: alloc:: alloc ( std:: alloc:: Layout :: from_size_align ( ALT_STACK_SIZE , 1 ) . unwrap ( ) )
13411342 as * mut libc:: c_void ;
13421343 alt_stack. ss_size = ALT_STACK_SIZE ;
13431344 libc:: sigaltstack ( & mut alt_stack, std:: ptr:: null_mut ( ) ) ;
13441345
13451346 let mut sa: libc:: sigaction = std:: mem:: zeroed ( ) ;
1346- sa. sa_sigaction =
1347- print_stack_trace as fn ( libc:: c_int ) as * mut libc:: c_void as libc:: sighandler_t ;
1347+ sa. sa_sigaction = print_stack_trace as libc:: sighandler_t ;
13481348 sa. sa_flags = libc:: SA_NODEFER | libc:: SA_RESETHAND | libc:: SA_ONSTACK ;
13491349 libc:: sigemptyset ( & mut sa. sa_mask ) ;
13501350 libc:: sigaction ( libc:: SIGSEGV , & sa, std:: ptr:: null_mut ( ) ) ;
13511351 }
13521352}
13531353
1354- #[ cfg( windows ) ]
1354+ #[ cfg( not ( unix ) ) ]
13551355// When an error signal (such as SIGABRT or SIGSEGV) is delivered to the
13561356// process, print a stack trace and then exit.
1357- fn print_stack_trace_on_error_signal ( ) { }
1357+ fn install_signal_handler ( ) { }
13581358
13591359pub fn main ( ) -> ! {
13601360 let start_time = Instant :: now ( ) ;
13611361 let start_rss = get_resident_set_size ( ) ;
13621362 init_rustc_env_logger ( ) ;
1363- print_stack_trace_on_error_signal ( ) ;
1363+ install_signal_handler ( ) ;
13641364 let mut callbacks = TimePassesCallbacks :: default ( ) ;
13651365 install_ice_hook ( ) ;
13661366 let exit_code = catch_with_exit_code ( || {
0 commit comments