]> git.lizzy.rs Git - rust.git/blob - library/std/src/rt.rs
Auto merge of #84325 - jsha:ephemeral-collapse, r=GuillaumeGomez
[rust.git] / library / std / src / rt.rs
1 //! Runtime services
2 //!
3 //! The `rt` module provides a narrow set of runtime services,
4 //! including the global heap (exported in `heap`) and unwinding and
5 //! backtrace support. The APIs in this module are highly unstable,
6 //! and should be considered as private implementation details for the
7 //! time being.
8
9 #![unstable(
10     feature = "rt",
11     reason = "this public module should not exist and is highly likely \
12               to disappear",
13     issue = "none"
14 )]
15 #![doc(hidden)]
16
17 // Re-export some of our utilities which are expected by other crates.
18 pub use crate::panicking::{begin_panic, begin_panic_fmt, panic_count};
19
20 // To reduce the generated code of the new `lang_start`, this function is doing
21 // the real work.
22 #[cfg(not(test))]
23 fn lang_start_internal(
24     main: &(dyn Fn() -> i32 + Sync + crate::panic::RefUnwindSafe),
25     argc: isize,
26     argv: *const *const u8,
27 ) -> isize {
28     use crate::panic;
29     use crate::sys_common;
30
31     // SAFETY: Only called once during runtime initialization.
32     unsafe { sys_common::rt::init(argc, argv) };
33
34     let exit_code = panic::catch_unwind(main);
35
36     sys_common::rt::cleanup();
37
38     exit_code.unwrap_or(101) as isize
39 }
40
41 #[cfg(not(test))]
42 #[lang = "start"]
43 fn lang_start<T: crate::process::Termination + 'static>(
44     main: fn() -> T,
45     argc: isize,
46     argv: *const *const u8,
47 ) -> isize {
48     lang_start_internal(
49         &move || crate::sys_common::backtrace::__rust_begin_short_backtrace(main).report(),
50         argc,
51         argv,
52     )
53 }