@@ -78,6 +78,15 @@ pub mod pretty;
78
78
#[ macro_use]
79
79
mod print;
80
80
mod session_diagnostics;
81
+ #[ cfg( all( unix, any( target_env = "gnu" , target_os = "macos" ) ) ) ]
82
+ mod signal_handler;
83
+
84
+ #[ cfg( not( all( unix, any( target_env = "gnu" , target_os = "macos" ) ) ) ) ]
85
+ mod signal_handler {
86
+ /// On platforms which don't support our signal handler's requirements,
87
+ /// simply use the default signal handler provided by std.
88
+ pub ( super ) fn install ( ) { }
89
+ }
81
90
82
91
use crate :: session_diagnostics:: {
83
92
RLinkEmptyVersionNumber , RLinkEncodingVersionMismatch , RLinkRustcVersionMismatch ,
@@ -1427,72 +1436,6 @@ pub fn init_env_logger(handler: &EarlyErrorHandler, env: &str) {
1427
1436
}
1428
1437
}
1429
1438
1430
- #[ cfg( all( unix, any( target_env = "gnu" , target_os = "macos" ) ) ) ]
1431
- mod signal_handler {
1432
- extern "C" {
1433
- fn backtrace_symbols_fd (
1434
- buffer : * const * mut libc:: c_void ,
1435
- size : libc:: c_int ,
1436
- fd : libc:: c_int ,
1437
- ) ;
1438
- }
1439
-
1440
- extern "C" fn print_stack_trace ( _: libc:: c_int ) {
1441
- const MAX_FRAMES : usize = 256 ;
1442
- static mut STACK_TRACE : [ * mut libc:: c_void ; MAX_FRAMES ] =
1443
- [ std:: ptr:: null_mut ( ) ; MAX_FRAMES ] ;
1444
- unsafe {
1445
- let depth = libc:: backtrace ( STACK_TRACE . as_mut_ptr ( ) , MAX_FRAMES as i32 ) ;
1446
- if depth == 0 {
1447
- return ;
1448
- }
1449
- backtrace_symbols_fd ( STACK_TRACE . as_ptr ( ) , depth, 2 ) ;
1450
- }
1451
- }
1452
-
1453
- /// When an error signal (such as SIGABRT or SIGSEGV) is delivered to the
1454
- /// process, print a stack trace and then exit.
1455
- pub ( super ) fn install ( ) {
1456
- use std:: alloc:: { alloc, Layout } ;
1457
-
1458
- unsafe {
1459
- let alt_stack_size: usize = min_sigstack_size ( ) + 64 * 1024 ;
1460
- let mut alt_stack: libc:: stack_t = std:: mem:: zeroed ( ) ;
1461
- alt_stack. ss_sp = alloc ( Layout :: from_size_align ( alt_stack_size, 1 ) . unwrap ( ) ) . cast ( ) ;
1462
- alt_stack. ss_size = alt_stack_size;
1463
- libc:: sigaltstack ( & alt_stack, std:: ptr:: null_mut ( ) ) ;
1464
-
1465
- let mut sa: libc:: sigaction = std:: mem:: zeroed ( ) ;
1466
- sa. sa_sigaction = print_stack_trace as libc:: sighandler_t ;
1467
- sa. sa_flags = libc:: SA_NODEFER | libc:: SA_RESETHAND | libc:: SA_ONSTACK ;
1468
- libc:: sigemptyset ( & mut sa. sa_mask ) ;
1469
- libc:: sigaction ( libc:: SIGSEGV , & sa, std:: ptr:: null_mut ( ) ) ;
1470
- }
1471
- }
1472
-
1473
- /// Modern kernels on modern hardware can have dynamic signal stack sizes.
1474
- #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
1475
- fn min_sigstack_size ( ) -> usize {
1476
- const AT_MINSIGSTKSZ : core:: ffi:: c_ulong = 51 ;
1477
- let dynamic_sigstksz = unsafe { libc:: getauxval ( AT_MINSIGSTKSZ ) } ;
1478
- // If getauxval couldn't find the entry, it returns 0,
1479
- // so take the higher of the "constant" and auxval.
1480
- // This transparently supports older kernels which don't provide AT_MINSIGSTKSZ
1481
- libc:: MINSIGSTKSZ . max ( dynamic_sigstksz as _ )
1482
- }
1483
-
1484
- /// Not all OS support hardware where this is needed.
1485
- #[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ]
1486
- fn min_sigstack_size ( ) -> usize {
1487
- libc:: MINSIGSTKSZ
1488
- }
1489
- }
1490
-
1491
- #[ cfg( not( all( unix, any( target_env = "gnu" , target_os = "macos" ) ) ) ) ]
1492
- mod signal_handler {
1493
- pub ( super ) fn install ( ) { }
1494
- }
1495
-
1496
1439
pub fn main ( ) -> ! {
1497
1440
let start_time = Instant :: now ( ) ;
1498
1441
let start_rss = get_resident_set_size ( ) ;
0 commit comments