@@ -1312,16 +1312,17 @@ pub fn init_env_logger(env: &str) {
1312
1312
tracing:: subscriber:: set_global_default ( subscriber) . unwrap ( ) ;
1313
1313
}
1314
1314
1315
+ #[ cfg( unix) ]
1315
1316
extern "C" {
1316
- // Only available in glibc
1317
1317
fn backtrace_symbols_fd ( buffer : * const * mut libc:: c_void , size : libc:: c_int , fd : libc:: c_int ) ;
1318
1318
}
1319
1319
1320
1320
#[ 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 ] ;
1322
1324
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 ) ;
1325
1326
if depth == 0 {
1326
1327
return ;
1327
1328
}
@@ -1332,35 +1333,34 @@ fn print_stack_trace(_: libc::c_int) {
1332
1333
#[ cfg( unix) ]
1333
1334
// When an error signal (such as SIGABRT or SIGSEGV) is delivered to the
1334
1335
// process, print a stack trace and then exit.
1335
- fn print_stack_trace_on_error_signal ( ) {
1336
+ fn install_signal_handler ( ) {
1336
1337
unsafe {
1337
1338
const ALT_STACK_SIZE : usize = libc:: MINSIGSTKSZ + 64 * 1024 ;
1338
1339
let mut alt_stack: libc:: stack_t = std:: mem:: zeroed ( ) ;
1339
1340
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 ( ) )
1341
1342
as * mut libc:: c_void ;
1342
1343
alt_stack. ss_size = ALT_STACK_SIZE ;
1343
1344
libc:: sigaltstack ( & mut alt_stack, std:: ptr:: null_mut ( ) ) ;
1344
1345
1345
1346
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 ;
1348
1348
sa. sa_flags = libc:: SA_NODEFER | libc:: SA_RESETHAND | libc:: SA_ONSTACK ;
1349
1349
libc:: sigemptyset ( & mut sa. sa_mask ) ;
1350
1350
libc:: sigaction ( libc:: SIGSEGV , & sa, std:: ptr:: null_mut ( ) ) ;
1351
1351
}
1352
1352
}
1353
1353
1354
- #[ cfg( windows ) ]
1354
+ #[ cfg( not ( unix ) ) ]
1355
1355
// When an error signal (such as SIGABRT or SIGSEGV) is delivered to the
1356
1356
// process, print a stack trace and then exit.
1357
- fn print_stack_trace_on_error_signal ( ) { }
1357
+ fn install_signal_handler ( ) { }
1358
1358
1359
1359
pub fn main ( ) -> ! {
1360
1360
let start_time = Instant :: now ( ) ;
1361
1361
let start_rss = get_resident_set_size ( ) ;
1362
1362
init_rustc_env_logger ( ) ;
1363
- print_stack_trace_on_error_signal ( ) ;
1363
+ install_signal_handler ( ) ;
1364
1364
let mut callbacks = TimePassesCallbacks :: default ( ) ;
1365
1365
install_ice_hook ( ) ;
1366
1366
let exit_code = catch_with_exit_code ( || {
0 commit comments