summary refs log tree commit diff
path: root/library/std/src/sys/hermit
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-04-25 04:45:39 +0000
committerbors <bors@rust-lang.org>2021-04-25 04:45:39 +0000
commit5da10c01214a3d3ebec65b8ba6effada92a0673f (patch)
tree94bbe380b059b6f77025a1e7c8d290f62390998e /library/std/src/sys/hermit
parentf7c468fe9a1448b1f6ceee6a4c831fe6122a54f0 (diff)
parent7171fec13f3a3091f702a8e55f495ad1563dc4cd (diff)
downloadrust-5da10c01214a3d3ebec65b8ba6effada92a0673f.tar.gz
rust-5da10c01214a3d3ebec65b8ba6effada92a0673f.zip
Auto merge of #84115 - CDirkx:rt, r=m-ou-se
Rework `init` and `cleanup`

This PR reworks the code in `std` that runs before and after `main` and centralizes this code respectively in the functions `init` and `cleanup` in both `sys_common` and `sys`. This makes is easy to see what code is executed during initialization and cleanup on each platform just by looking at e.g. `sys::windows::init`.

Full list of changes:
- new module `rt` in `sys_common` to contain `init` and `cleanup` and the runtime macros.
- `at_exit` and the mechanism to register exit handlers has been completely removed. In practice this was only used for closing sockets on windows and flushing stdout, which have been moved to `cleanup`.
- <s>On windows `alloc` and `net` initialization is now done in `init`, this saves a runtime check in every allocation and network use.</s>
Diffstat (limited to 'library/std/src/sys/hermit')
-rw-r--r--library/std/src/sys/hermit/mod.rs13
-rw-r--r--library/std/src/sys/hermit/stack_overflow.rs5
2 files changed, 10 insertions, 8 deletions
diff --git a/library/std/src/sys/hermit/mod.rs b/library/std/src/sys/hermit/mod.rs
index 56497162c03..a70d1db7ca6 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;
@@ -96,9 +95,17 @@ pub extern "C" fn __rust_abort() {
     abort_internal();
 }
 
-#[cfg(not(test))]
-pub fn init() {
+// SAFETY: must be called only once during runtime initialization.
+// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
+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.
+// NOTE: this is not guaranteed to run, for example when the program aborts.
+pub unsafe fn cleanup() {
+    args::cleanup();
 }
 
 #[cfg(not(test))]
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 121fe42011d..00000000000
--- a/library/std/src/sys/hermit/stack_overflow.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-#[inline]
-pub unsafe fn init() {}
-
-#[inline]
-pub unsafe fn cleanup() {}