2015-09-08 15:53:46 -07:00
|
|
|
//! Runtime services
|
|
|
|
//!
|
|
|
|
//! The `rt` module provides a narrow set of runtime services,
|
|
|
|
//! including the global heap (exported in `heap`) and unwinding and
|
|
|
|
//! backtrace support. The APIs in this module are highly unstable,
|
|
|
|
//! and should be considered as private implementation details for the
|
|
|
|
//! time being.
|
|
|
|
|
2019-11-27 10:29:00 -08:00
|
|
|
#![unstable(
|
|
|
|
feature = "rt",
|
|
|
|
reason = "this public module should not exist and is highly likely \
|
|
|
|
to disappear",
|
2019-12-21 13:16:18 +02:00
|
|
|
issue = "none"
|
2019-11-27 10:29:00 -08:00
|
|
|
)]
|
2015-09-08 15:53:46 -07:00
|
|
|
#![doc(hidden)]
|
|
|
|
|
2018-01-12 16:41:25 -05:00
|
|
|
// Re-export some of our utilities which are expected by other crates.
|
2020-05-26 17:38:22 +02:00
|
|
|
pub use crate::panicking::{begin_panic, begin_panic_fmt, panic_count};
|
2015-09-08 15:53:46 -07:00
|
|
|
|
2017-12-24 00:15:38 +01:00
|
|
|
// To reduce the generated code of the new `lang_start`, this function is doing
|
|
|
|
// the real work.
|
2018-01-01 17:53:47 -08:00
|
|
|
#[cfg(not(test))]
|
2019-11-27 10:29:00 -08:00
|
|
|
fn lang_start_internal(
|
|
|
|
main: &(dyn Fn() -> i32 + Sync + crate::panic::RefUnwindSafe),
|
|
|
|
argc: isize,
|
|
|
|
argv: *const *const u8,
|
|
|
|
) -> isize {
|
2019-02-11 04:23:21 +09:00
|
|
|
use crate::panic;
|
|
|
|
use crate::sys_common;
|
2017-12-03 22:16:24 +01:00
|
|
|
|
2021-04-11 07:05:39 +02:00
|
|
|
sys_common::rt::init(argc, argv);
|
|
|
|
let exit_code = panic::catch_unwind(main);
|
|
|
|
sys_common::rt::cleanup();
|
2017-12-03 22:16:24 +01:00
|
|
|
|
2021-04-11 07:05:39 +02:00
|
|
|
exit_code.unwrap_or(101) as isize
|
2017-12-03 22:16:24 +01:00
|
|
|
}
|
|
|
|
|
2018-01-01 17:53:47 -08:00
|
|
|
#[cfg(not(test))]
|
2017-12-24 00:15:38 +01:00
|
|
|
#[lang = "start"]
|
2019-11-27 10:29:00 -08:00
|
|
|
fn lang_start<T: crate::process::Termination + 'static>(
|
|
|
|
main: fn() -> T,
|
|
|
|
argc: isize,
|
|
|
|
argv: *const *const u8,
|
|
|
|
) -> isize {
|
2020-08-04 22:18:20 +01:00
|
|
|
lang_start_internal(
|
|
|
|
&move || crate::sys_common::backtrace::__rust_begin_short_backtrace(main).report(),
|
|
|
|
argc,
|
|
|
|
argv,
|
|
|
|
)
|
2017-12-24 00:15:38 +01:00
|
|
|
}
|