Skip to content

Commit 11445c1

Browse files
committed
Move most init to sys::init
1 parent cf47019 commit 11445c1

File tree

16 files changed

+31
-57
lines changed

16 files changed

+31
-57
lines changed

library/std/src/sys/hermit/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ pub mod pipe;
3737
#[path = "../unsupported/process.rs"]
3838
pub mod process;
3939
pub mod rwlock;
40-
pub mod stack_overflow;
4140
pub mod stdio;
4241
pub mod thread;
4342
pub mod thread_local_dtor;
@@ -97,8 +96,9 @@ pub extern "C" fn __rust_abort() {
9796
}
9897

9998
// SAFETY: must be called only once during runtime initialization.
100-
pub unsafe fn init() {
99+
pub unsafe fn init(argc: isize, argv: *const *const u8) {
101100
let _ = net::init();
101+
args::init(argc, argv);
102102
}
103103

104104
// SAFETY: must be called only once during runtime cleanup.

library/std/src/sys/hermit/stack_overflow.rs

Lines changed: 0 additions & 2 deletions
This file was deleted.

library/std/src/sys/sgx/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ pub mod pipe;
3232
#[path = "../unsupported/process.rs"]
3333
pub mod process;
3434
pub mod rwlock;
35-
pub mod stack_overflow;
3635
pub mod stdio;
3736
pub mod thread;
3837
pub mod thread_local_key;
@@ -41,7 +40,11 @@ pub mod time;
4140
pub use crate::sys_common::os_str_bytes as os_str;
4241

4342
// SAFETY: must be called only once during runtime initialization.
44-
pub unsafe fn init() {}
43+
pub unsafe fn init(argc: isize, argv: *const *const u8) {
44+
unsafe {
45+
args::init(argc, argv);
46+
}
47+
}
4548

4649
// SAFETY: must be called only once during runtime cleanup.
4750
pub unsafe fn cleanup() {}

library/std/src/sys/sgx/stack_overflow.rs

Lines changed: 0 additions & 2 deletions
This file was deleted.

library/std/src/sys/unix/mod.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub mod time;
4545
pub 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.

library/std/src/sys/unsupported/args.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::ffi::OsString;
22

3-
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}
4-
53
pub struct Args {}
64

75
pub fn args() -> Args {

library/std/src/sys/unsupported/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub use crate::sys_common::os_str_bytes as os_str;
1111
use crate::os::raw::c_char;
1212

1313
// SAFETY: must be called only once during runtime initialization.
14-
pub unsafe fn init() {}
14+
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}
1515

1616
// SAFETY: must be called only once during runtime cleanup.
1717
pub unsafe fn cleanup() {}

library/std/src/sys/unsupported/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub mod path;
1515
pub mod pipe;
1616
pub mod process;
1717
pub mod rwlock;
18-
pub mod stack_overflow;
1918
pub mod stdio;
2019
pub mod thread;
2120
#[cfg(target_thread_local)]

library/std/src/sys/unsupported/stack_overflow.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

library/std/src/sys/wasi/args.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use crate::marker::PhantomData;
55
use crate::os::wasi::ffi::OsStrExt;
66
use crate::vec;
77

8-
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}
9-
108
pub struct Args {
119
iter: vec::IntoIter<OsString>,
1210
_dont_send_or_sync_me: PhantomData<*mut ()>,

library/std/src/sys/wasi/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ pub mod pipe;
4242
pub mod process;
4343
#[path = "../unsupported/rwlock.rs"]
4444
pub mod rwlock;
45-
#[path = "../unsupported/stack_overflow.rs"]
46-
pub mod stack_overflow;
4745
pub mod stdio;
4846
pub mod thread;
4947
#[path = "../unsupported/thread_local_dtor.rs"]

library/std/src/sys/wasm/args.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ use crate::ffi::OsString;
22
use crate::marker::PhantomData;
33
use crate::vec;
44

5-
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
6-
// On wasm these should always be null, so there's nothing for us to do here
7-
}
8-
95
pub fn args() -> Args {
106
Args { iter: Vec::new().into_iter(), _dont_send_or_sync_me: PhantomData }
117
}

library/std/src/sys/wasm/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ pub mod path;
3535
pub mod pipe;
3636
#[path = "../unsupported/process.rs"]
3737
pub mod process;
38-
#[path = "../unsupported/stack_overflow.rs"]
39-
pub mod stack_overflow;
4038
#[path = "../unsupported/stdio.rs"]
4139
pub mod stdio;
4240
pub mod thread;

library/std/src/sys/windows/args.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ use crate::vec;
1414

1515
use core::iter;
1616

17-
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}
18-
1917
pub fn args() -> Args {
2018
unsafe {
2119
let lp_cmd_line = c::GetCommandLineW();

library/std/src/sys/windows/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ cfg_if::cfg_if! {
5050
}
5151

5252
// SAFETY: must be called only once during runtime initialization.
53-
pub unsafe fn init() {}
53+
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
54+
stack_overflow::init();
55+
}
5456

5557
// SAFETY: must be called only once during runtime cleanup.
5658
pub unsafe fn cleanup() {

library/std/src/sys_common/rt.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,15 @@ pub fn init(argc: isize, argv: *const *const u8) {
1010
static INIT: Once = Once::new();
1111
INIT.call_once(|| unsafe {
1212
// SAFETY: Only called once during runtime initialization.
13-
sys::init();
13+
sys::init(argc, argv);
1414

1515
let main_guard = sys::thread::guard::init();
16-
sys::stack_overflow::init();
17-
1816
// Next, set up the current Thread with the guard information we just
1917
// created. Note that this isn't necessary in general for new threads,
2018
// but we just do this to name the main thread and to give it correct
2119
// info about the stack bounds.
2220
let thread = Thread::new(Some("main".to_owned()));
2321
thread_info::set(main_guard, thread);
24-
25-
// Store our args if necessary in a squirreled away location
26-
sys::args::init(argc, argv);
2722
});
2823
}
2924

0 commit comments

Comments
 (0)