]> git.lizzy.rs Git - rust.git/blob - src/libstd/rt.rs
Rollup merge of #56914 - glaubitz:ignore-tests, r=alexcrichton
[rust.git] / src / libstd / rt.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Runtime services
12 //!
13 //! The `rt` module provides a narrow set of runtime services,
14 //! including the global heap (exported in `heap`) and unwinding and
15 //! backtrace support. The APIs in this module are highly unstable,
16 //! and should be considered as private implementation details for the
17 //! time being.
18
19 #![unstable(feature = "rt",
20             reason = "this public module should not exist and is highly likely \
21                       to disappear",
22             issue = "0")]
23 #![doc(hidden)]
24
25
26 // Re-export some of our utilities which are expected by other crates.
27 pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count};
28
29 // To reduce the generated code of the new `lang_start`, this function is doing
30 // the real work.
31 #[cfg(not(test))]
32 fn lang_start_internal(main: &(dyn Fn() -> i32 + Sync + ::panic::RefUnwindSafe),
33                        argc: isize, argv: *const *const u8) -> isize {
34     use panic;
35     use sys;
36     use sys_common;
37     use sys_common::thread_info;
38     use thread::Thread;
39
40     sys::init();
41
42     unsafe {
43         let main_guard = sys::thread::guard::init();
44         sys::stack_overflow::init();
45
46         // Next, set up the current Thread with the guard information we just
47         // created. Note that this isn't necessary in general for new threads,
48         // but we just do this to name the main thread and to give it correct
49         // info about the stack bounds.
50         let thread = Thread::new(Some("main".to_owned()));
51         thread_info::set(main_guard, thread);
52
53         // Store our args if necessary in a squirreled away location
54         sys::args::init(argc, argv);
55
56         // Let's run some code!
57         #[cfg(feature = "backtrace")]
58         let exit_code = panic::catch_unwind(|| {
59             ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
60         });
61         #[cfg(not(feature = "backtrace"))]
62         let exit_code = panic::catch_unwind(move || main());
63
64         sys_common::cleanup();
65         exit_code.unwrap_or(101) as isize
66     }
67 }
68
69 #[cfg(not(test))]
70 #[lang = "start"]
71 fn lang_start<T: ::process::Termination + 'static>
72     (main: fn() -> T, argc: isize, argv: *const *const u8) -> isize
73 {
74     lang_start_internal(&move || main().report(), argc, argv)
75 }