aboutsummaryrefslogtreecommitdiff
path: root/ctr-std/src/rt.rs
diff options
context:
space:
mode:
authorFenrir <[email protected]>2018-01-21 14:06:28 -0700
committerFenrirWolf <[email protected]>2018-01-21 19:16:33 -0700
commit23be3f4885688e5e0011005e2295c75168854c0a (patch)
treedd0850f9c73c489e114a761d5c0757f3dbec3a65 /ctr-std/src/rt.rs
parentUpdate CI for Rust nightly-2017-12-01 + other fixes (diff)
downloadctru-rs-23be3f4885688e5e0011005e2295c75168854c0a.tar.xz
ctru-rs-23be3f4885688e5e0011005e2295c75168854c0a.zip
Recreate ctr-std from latest nightly
Diffstat (limited to 'ctr-std/src/rt.rs')
-rw-r--r--ctr-std/src/rt.rs63
1 files changed, 43 insertions, 20 deletions
diff --git a/ctr-std/src/rt.rs b/ctr-std/src/rt.rs
index 735509b..9dbaf78 100644
--- a/ctr-std/src/rt.rs
+++ b/ctr-std/src/rt.rs
@@ -22,31 +22,54 @@
issue = "0")]
#![doc(hidden)]
-use panic;
-use sys_common::thread_info;
-use thread::Thread;
-use mem;
-// Reexport some of our utilities which are expected by other crates.
-pub use panicking::{begin_panic, begin_panic_fmt};
+// Re-export some of our utilities which are expected by other crates.
+pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count};
-//TODO: Handle argc/argv arguments
-#[lang = "start"]
-#[allow(unused_variables)]
-fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize {
- let failed = unsafe {
- let thread = Thread::new(Some("main".to_owned()));
+// To reduce the generated code of the new `lang_start`, this function is doing
+// the real work.
+#[cfg(not(test))]
+fn lang_start_internal(main: &(Fn() -> i32 + Sync + ::panic::RefUnwindSafe),
+ argc: isize, argv: *const *const u8) -> isize {
+ use panic;
+ use sys;
+ use sys_common;
+ use sys_common::thread_info;
+ use thread::Thread;
+
+ sys::init();
+
+ unsafe {
+ let main_guard = sys::thread::guard::init();
+ sys::stack_overflow::init();
- thread_info::set(None, thread);
+ // Next, set up the current Thread with the guard information we just
+ // created. Note that this isn't necessary in general for new threads,
+ // but we just do this to name the main thread and to give it correct
+ // info about the stack bounds.
+ let thread = Thread::new(Some("main".to_owned()));
+ thread_info::set(main_guard, thread);
- let res = panic::catch_unwind(mem::transmute::<_, fn()>(main));
+ // Store our args if necessary in a squirreled away location
+ sys::args::init(argc, argv);
- res.is_err()
- };
+ // Let's run some code!
+ #[cfg(feature = "backtrace")]
+ let exit_code = panic::catch_unwind(|| {
+ ::sys_common::backtrace::__rust_begin_short_backtrace(move || main())
+ });
+ #[cfg(not(feature = "backtrace"))]
+ let exit_code = panic::catch_unwind(move || main());
- if failed {
- 101
- } else {
- 0
+ sys_common::cleanup();
+ exit_code.unwrap_or(101) as isize
}
}
+
+#[cfg(not(test))]
+#[lang = "start"]
+fn lang_start<T: ::termination::Termination + 'static>
+ (main: fn() -> T, argc: isize, argv: *const *const u8) -> isize
+{
+ lang_start_internal(&move || main().report(), argc, argv)
+}