about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristiaan Dirkx <christiaan@dirkx.email>2021-04-11 23:48:10 +0200
committerChristiaan Dirkx <christiaan@dirkx.email>2021-04-22 18:00:12 +0200
commit11445c10ab630a6ad8526f3fc5bcea1badad2964 (patch)
treef16c4f9a517ad55c4f36b79bd9194a9832f3478f
parentcf470197addb37146eb2e0d16f14dd14293d91f0 (diff)
downloadrust-11445c10ab630a6ad8526f3fc5bcea1badad2964.tar.gz
rust-11445c10ab630a6ad8526f3fc5bcea1badad2964.zip
Move most init to `sys::init`
-rw-r--r--library/std/src/sys/hermit/mod.rs4
-rw-r--r--library/std/src/sys/hermit/stack_overflow.rs2
-rw-r--r--library/std/src/sys/sgx/mod.rs7
-rw-r--r--library/std/src/sys/sgx/stack_overflow.rs2
-rw-r--r--library/std/src/sys/unix/mod.rs44
-rw-r--r--library/std/src/sys/unsupported/args.rs2
-rw-r--r--library/std/src/sys/unsupported/common.rs2
-rw-r--r--library/std/src/sys/unsupported/mod.rs1
-rw-r--r--library/std/src/sys/unsupported/stack_overflow.rs1
-rw-r--r--library/std/src/sys/wasi/args.rs2
-rw-r--r--library/std/src/sys/wasi/mod.rs2
-rw-r--r--library/std/src/sys/wasm/args.rs4
-rw-r--r--library/std/src/sys/wasm/mod.rs2
-rw-r--r--library/std/src/sys/windows/args.rs2
-rw-r--r--library/std/src/sys/windows/mod.rs4
-rw-r--r--library/std/src/sys_common/rt.rs7
16 files changed, 31 insertions, 57 deletions
diff --git a/library/std/src/sys/hermit/mod.rs b/library/std/src/sys/hermit/mod.rs
index 3da865021f3..77c068e1a97 100644
--- a/library/std/src/sys/hermit/mod.rs
+++ b/library/std/src/sys/hermit/mod.rs
@@ -37,7 +37,6 @@ pub mod pipe;
 #[path = "../unsupported/process.rs"]
 pub mod process;
 pub mod rwlock;
-pub mod stack_overflow;
 pub mod stdio;
 pub mod thread;
 pub mod thread_local_dtor;
@@ -97,8 +96,9 @@ pub extern "C" fn __rust_abort() {
 }
 
 // SAFETY: must be called only once during runtime initialization.
-pub unsafe fn init() {
+pub unsafe fn init(argc: isize, argv: *const *const u8) {
     let _ = net::init();
+    args::init(argc, argv);
 }
 
 // SAFETY: must be called only once during runtime cleanup.
diff --git a/library/std/src/sys/hermit/stack_overflow.rs b/library/std/src/sys/hermit/stack_overflow.rs
deleted file mode 100644
index f276799661e..00000000000
--- a/library/std/src/sys/hermit/stack_overflow.rs
+++ /dev/null
@@ -1,2 +0,0 @@
-#[inline]
-pub unsafe fn init() {}
diff --git a/library/std/src/sys/sgx/mod.rs b/library/std/src/sys/sgx/mod.rs
index 9681336631f..25250d060d0 100644
--- a/library/std/src/sys/sgx/mod.rs
+++ b/library/std/src/sys/sgx/mod.rs
@@ -32,7 +32,6 @@ pub mod pipe;
 #[path = "../unsupported/process.rs"]
 pub mod process;
 pub mod rwlock;
-pub mod stack_overflow;
 pub mod stdio;
 pub mod thread;
 pub mod thread_local_key;
@@ -41,7 +40,11 @@ pub mod time;
 pub use crate::sys_common::os_str_bytes as os_str;
 
 // SAFETY: must be called only once during runtime initialization.
-pub unsafe fn init() {}
+pub unsafe fn init(argc: isize, argv: *const *const u8) {
+    unsafe {
+        args::init(argc, argv);
+    }
+}
 
 // SAFETY: must be called only once during runtime cleanup.
 pub unsafe fn cleanup() {}
diff --git a/library/std/src/sys/sgx/stack_overflow.rs b/library/std/src/sys/sgx/stack_overflow.rs
deleted file mode 100644
index 1ca5810e61b..00000000000
--- a/library/std/src/sys/sgx/stack_overflow.rs
+++ /dev/null
@@ -1,2 +0,0 @@
-#[cfg_attr(test, allow(dead_code))]
-pub unsafe fn init() {}
diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs
index fd74c10ecd7..bd9ac32b0d2 100644
--- a/library/std/src/sys/unix/mod.rs
+++ b/library/std/src/sys/unix/mod.rs
@@ -45,7 +45,7 @@ pub mod time;
 pub use crate::sys_common::os_str_bytes as os_str;
 
 // SAFETY: must be called only once during runtime initialization.
-pub unsafe fn init() {
+pub unsafe fn init(argc: isize, argv: *const *const u8) {
     // The standard streams might be closed on application startup. To prevent
     // std::io::{stdin, stdout,stderr} objects from using other unrelated file
     // resources opened later, we reopen standards streams when they are closed.
@@ -60,22 +60,22 @@ pub unsafe fn init() {
     // to prevent this problem.
     reset_sigpipe();
 
-    cfg_if::cfg_if! {
-        if #[cfg(miri)] {
-            // The standard fds are always available in Miri.
-            unsafe fn sanitize_standard_fds() {}
-        } else if #[cfg(not(any(
-            target_os = "emscripten",
-            target_os = "fuchsia",
-            target_os = "vxworks",
-            // The poll on Darwin doesn't set POLLNVAL for closed fds.
-            target_os = "macos",
-            target_os = "ios",
-            target_os = "redox",
-        )))] {
-            // In the case when all file descriptors are open, the poll has been
-            // observed to perform better than fcntl (on GNU/Linux).
-            unsafe fn sanitize_standard_fds() {
+    stack_overflow::init();
+    args::init(argc, argv);
+
+    unsafe fn sanitize_standard_fds() {
+        cfg_if::cfg_if! {
+            if #[cfg(not(any(
+                // The standard fds are always available in Miri.
+                miri,
+                target_os = "emscripten",
+                target_os = "fuchsia",
+                target_os = "vxworks",
+                // The poll on Darwin doesn't set POLLNVAL for closed fds.
+                target_os = "macos",
+                target_os = "ios",
+                target_os = "redox",
+            )))] {
                 use crate::sys::os::errno;
                 let pfds: &mut [_] = &mut [
                     libc::pollfd { fd: 0, events: 0, revents: 0 },
@@ -100,9 +100,7 @@ pub unsafe fn init() {
                         libc::abort();
                     }
                 }
-            }
-        } else if #[cfg(any(target_os = "macos", target_os = "ios", target_os = "redox"))] {
-            unsafe fn sanitize_standard_fds() {
+            } else if #[cfg(any(target_os = "macos", target_os = "ios", target_os = "redox"))] {
                 use crate::sys::os::errno;
                 for fd in 0..3 {
                     if libc::fcntl(fd, libc::F_GETFD) == -1 && errno() == libc::EBADF {
@@ -112,17 +110,13 @@ pub unsafe fn init() {
                     }
                 }
             }
-        } else {
-            unsafe fn sanitize_standard_fds() {}
         }
     }
 
-    #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia")))]
     unsafe fn reset_sigpipe() {
+        #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia")))]
         assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR);
     }
-    #[cfg(any(target_os = "emscripten", target_os = "fuchsia"))]
-    unsafe fn reset_sigpipe() {}
 }
 
 // SAFETY: must be called only once during runtime cleanup.
diff --git a/library/std/src/sys/unsupported/args.rs b/library/std/src/sys/unsupported/args.rs
index f9d41c6cda6..cdb474b5b15 100644
--- a/library/std/src/sys/unsupported/args.rs
+++ b/library/std/src/sys/unsupported/args.rs
@@ -1,7 +1,5 @@
 use crate::ffi::OsString;
 
-pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}
-
 pub struct Args {}
 
 pub fn args() -> Args {
diff --git a/library/std/src/sys/unsupported/common.rs b/library/std/src/sys/unsupported/common.rs
index 5ab22bd3ff4..c60c2a9b8e8 100644
--- a/library/std/src/sys/unsupported/common.rs
+++ b/library/std/src/sys/unsupported/common.rs
@@ -11,7 +11,7 @@ pub use crate::sys_common::os_str_bytes as os_str;
 use crate::os::raw::c_char;
 
 // SAFETY: must be called only once during runtime initialization.
-pub unsafe fn init() {}
+pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}
 
 // SAFETY: must be called only once during runtime cleanup.
 pub unsafe fn cleanup() {}
diff --git a/library/std/src/sys/unsupported/mod.rs b/library/std/src/sys/unsupported/mod.rs
index d9efdec33d9..32ca68ef15b 100644
--- a/library/std/src/sys/unsupported/mod.rs
+++ b/library/std/src/sys/unsupported/mod.rs
@@ -15,7 +15,6 @@ pub mod path;
 pub mod pipe;
 pub mod process;
 pub mod rwlock;
-pub mod stack_overflow;
 pub mod stdio;
 pub mod thread;
 #[cfg(target_thread_local)]
diff --git a/library/std/src/sys/unsupported/stack_overflow.rs b/library/std/src/sys/unsupported/stack_overflow.rs
deleted file mode 100644
index 2461fc2dad7..00000000000
--- a/library/std/src/sys/unsupported/stack_overflow.rs
+++ /dev/null
@@ -1 +0,0 @@
-pub unsafe fn init() {}
diff --git a/library/std/src/sys/wasi/args.rs b/library/std/src/sys/wasi/args.rs
index 7f7f989e2ae..004d47960f7 100644
--- a/library/std/src/sys/wasi/args.rs
+++ b/library/std/src/sys/wasi/args.rs
@@ -5,8 +5,6 @@ use crate::marker::PhantomData;
 use crate::os::wasi::ffi::OsStrExt;
 use crate::vec;
 
-pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}
-
 pub struct Args {
     iter: vec::IntoIter<OsString>,
     _dont_send_or_sync_me: PhantomData<*mut ()>,
diff --git a/library/std/src/sys/wasi/mod.rs b/library/std/src/sys/wasi/mod.rs
index b7b640b174f..2584d35b6ef 100644
--- a/library/std/src/sys/wasi/mod.rs
+++ b/library/std/src/sys/wasi/mod.rs
@@ -42,8 +42,6 @@ pub mod pipe;
 pub mod process;
 #[path = "../unsupported/rwlock.rs"]
 pub mod rwlock;
-#[path = "../unsupported/stack_overflow.rs"]
-pub mod stack_overflow;
 pub mod stdio;
 pub mod thread;
 #[path = "../unsupported/thread_local_dtor.rs"]
diff --git a/library/std/src/sys/wasm/args.rs b/library/std/src/sys/wasm/args.rs
index 987585af2d5..3672227bf66 100644
--- a/library/std/src/sys/wasm/args.rs
+++ b/library/std/src/sys/wasm/args.rs
@@ -2,10 +2,6 @@ use crate::ffi::OsString;
 use crate::marker::PhantomData;
 use crate::vec;
 
-pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
-    // On wasm these should always be null, so there's nothing for us to do here
-}
-
 pub fn args() -> Args {
     Args { iter: Vec::new().into_iter(), _dont_send_or_sync_me: PhantomData }
 }
diff --git a/library/std/src/sys/wasm/mod.rs b/library/std/src/sys/wasm/mod.rs
index 82683c0f624..8705910c73a 100644
--- a/library/std/src/sys/wasm/mod.rs
+++ b/library/std/src/sys/wasm/mod.rs
@@ -35,8 +35,6 @@ pub mod path;
 pub mod pipe;
 #[path = "../unsupported/process.rs"]
 pub mod process;
-#[path = "../unsupported/stack_overflow.rs"]
-pub mod stack_overflow;
 #[path = "../unsupported/stdio.rs"]
 pub mod stdio;
 pub mod thread;
diff --git a/library/std/src/sys/windows/args.rs b/library/std/src/sys/windows/args.rs
index 7ec3c592ada..feddb1ea78e 100644
--- a/library/std/src/sys/windows/args.rs
+++ b/library/std/src/sys/windows/args.rs
@@ -14,8 +14,6 @@ use crate::vec;
 
 use core::iter;
 
-pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}
-
 pub fn args() -> Args {
     unsafe {
         let lp_cmd_line = c::GetCommandLineW();
diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs
index 4563bca93b3..21fec2aa01b 100644
--- a/library/std/src/sys/windows/mod.rs
+++ b/library/std/src/sys/windows/mod.rs
@@ -50,7 +50,9 @@ cfg_if::cfg_if! {
 }
 
 // SAFETY: must be called only once during runtime initialization.
-pub unsafe fn init() {}
+pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
+    stack_overflow::init();
+}
 
 // SAFETY: must be called only once during runtime cleanup.
 pub unsafe fn cleanup() {
diff --git a/library/std/src/sys_common/rt.rs b/library/std/src/sys_common/rt.rs
index 515e754b416..dc20cf0e14a 100644
--- a/library/std/src/sys_common/rt.rs
+++ b/library/std/src/sys_common/rt.rs
@@ -10,20 +10,15 @@ pub fn init(argc: isize, argv: *const *const u8) {
     static INIT: Once = Once::new();
     INIT.call_once(|| unsafe {
         // SAFETY: Only called once during runtime initialization.
-        sys::init();
+        sys::init(argc, argv);
 
         let main_guard = sys::thread::guard::init();
-        sys::stack_overflow::init();
-
         // Next, set up the current Thread with the guard information we just
         // created. Note that this isn't necessary in general for new threads,
         // but we just do this to name the main thread and to give it correct
         // info about the stack bounds.
         let thread = Thread::new(Some("main".to_owned()));
         thread_info::set(main_guard, thread);
-
-        // Store our args if necessary in a squirreled away location
-        sys::args::init(argc, argv);
     });
 }