]> git.proxmox.com Git - rustc.git/blame - src/libstd/rt.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / libstd / rt.rs
CommitLineData
e9174d1e
SL
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
9cc50fc6 25
e9174d1e
SL
26
27// Reexport some of our utilities which are expected by other crates.
28pub use sys_common::unwind::{begin_unwind, begin_unwind_fmt};
29
92a42be0
SL
30// Rust runtime's startup objects depend on these symbols, so they must be public.
31// Since sys_common isn't public, we have to re-export them here.
32#[cfg(all(target_os="windows", target_arch = "x86", target_env="gnu"))]
33pub use sys_common::unwind::imp::eh_frame_registry::*;
34
e9174d1e
SL
35#[cfg(not(test))]
36#[lang = "start"]
37fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize {
9cc50fc6
SL
38 use borrow::ToOwned;
39 use mem;
40 use panic;
41 use sys;
42 use sys_common;
43 use sys_common::thread_info::{self, NewThread};
44 use thread::Thread;
45
e9174d1e
SL
46 sys::init();
47
48 let failed = unsafe {
49 let main_guard = sys::thread::guard::init();
50 sys::stack_overflow::init();
51
52 // Next, set up the current Thread with the guard information we just
53 // created. Note that this isn't necessary in general for new threads,
54 // but we just do this to name the main thread and to give it correct
55 // info about the stack bounds.
56 let thread: Thread = NewThread::new(Some("<main>".to_owned()));
57 thread_info::set(main_guard, thread);
58
59 // Store our args if necessary in a squirreled away location
60 sys_common::args::init(argc, argv);
61
62 // Let's run some code!
54a0048b 63 let res = panic::catch_unwind(mem::transmute::<_, fn()>(main));
e9174d1e
SL
64 sys_common::cleanup();
65 res.is_err()
66 };
67
68 if failed {
69 101
70 } else {
71 0
72 }
73}