@@ -45,7 +45,7 @@ pub mod time;
4545pub use crate :: sys_common:: os_str_bytes as os_str;
4646
4747// SAFETY: must be called only once during runtime initialization.
48- pub unsafe fn init ( ) {
48+ pub unsafe fn init ( argc : isize , argv : * const * const u8 ) {
4949 // The standard streams might be closed on application startup. To prevent
5050 // std::io::{stdin, stdout,stderr} objects from using other unrelated file
5151 // resources opened later, we reopen standards streams when they are closed.
@@ -60,22 +60,22 @@ pub unsafe fn init() {
6060 // to prevent this problem.
6161 reset_sigpipe ( ) ;
6262
63- cfg_if :: cfg_if! {
64- if # [ cfg ( miri ) ] {
65- // The standard fds are always available in Miri.
66- unsafe fn sanitize_standard_fds( ) { }
67- } else if # [ cfg ( not ( any (
68- target_os = "emscripten" ,
69- target_os = "fuchsia" ,
70- target_os = "vxworks" ,
71- // The poll on Darwin doesn't set POLLNVAL for closed fds.
72- target_os = "macos " ,
73- target_os = "ios " ,
74- target_os = "redox" ,
75- ) ) ) ] {
76- // In the case when all file descriptors are open, the poll has been
77- // observed to perform better than fcntl (on GNU/Linux).
78- unsafe fn sanitize_standard_fds ( ) {
63+ stack_overflow :: init ( ) ;
64+ args :: init ( argc , argv ) ;
65+
66+ unsafe fn sanitize_standard_fds ( ) {
67+ cfg_if :: cfg_if! {
68+ if # [ cfg ( not ( any (
69+ // The standard fds are always available in Miri.
70+ miri ,
71+ target_os = "emscripten" ,
72+ target_os = "fuchsia " ,
73+ target_os = "vxworks " ,
74+ // The poll on Darwin doesn't set POLLNVAL for closed fds.
75+ target_os = "macos" ,
76+ target_os = "ios" ,
77+ target_os = "redox" ,
78+ ) ) ) ] {
7979 use crate :: sys:: os:: errno;
8080 let pfds: & mut [ _] = & mut [
8181 libc:: pollfd { fd: 0 , events: 0 , revents: 0 } ,
@@ -100,9 +100,7 @@ pub unsafe fn init() {
100100 libc:: abort( ) ;
101101 }
102102 }
103- }
104- } else if #[ cfg( any( target_os = "macos" , target_os = "ios" , target_os = "redox" ) ) ] {
105- unsafe fn sanitize_standard_fds( ) {
103+ } else if #[ cfg( any( target_os = "macos" , target_os = "ios" , target_os = "redox" ) ) ] {
106104 use crate :: sys:: os:: errno;
107105 for fd in 0 ..3 {
108106 if libc:: fcntl( fd, libc:: F_GETFD ) == -1 && errno( ) == libc:: EBADF {
@@ -112,17 +110,13 @@ pub unsafe fn init() {
112110 }
113111 }
114112 }
115- } else {
116- unsafe fn sanitize_standard_fds( ) { }
117113 }
118114 }
119115
120- #[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" ) ) ) ]
121116 unsafe fn reset_sigpipe ( ) {
117+ #[ cfg( not( any( target_os = "emscripten" , target_os = "fuchsia" ) ) ) ]
122118 assert ! ( signal( libc:: SIGPIPE , libc:: SIG_IGN ) != libc:: SIG_ERR ) ;
123119 }
124- #[ cfg( any( target_os = "emscripten" , target_os = "fuchsia" ) ) ]
125- unsafe fn reset_sigpipe ( ) { }
126120}
127121
128122// SAFETY: must be called only once during runtime cleanup.
0 commit comments