rrt0/
lib.rs

1#![feature(core_intrinsics)]
2#![feature(global_asm)]
3#![feature(lang_items)]
4#![warn(rust_2018_idioms)]
5#![allow(unused_attributes)]
6#![no_std]
7
8mod math;
9mod platforms;
10
11pub use crate::platforms::*;
12use core::panic::PanicInfo;
13
14/// This is the executable start function, which directly follows the entry point.
15#[cfg_attr(not(test), lang = "start")]
16#[cfg(not(test))]
17extern "C" fn start<T>(user_main: *const (), _argc: isize, _argv: *const *const u8) -> !
18where
19    T: Termination,
20{
21    let user_main: fn() -> T = unsafe { core::mem::transmute(user_main) };
22    user_main();
23
24    panic!("main() cannot return");
25}
26
27/// Termination trait required for the start function.
28#[cfg_attr(not(test), lang = "termination")]
29trait Termination {}
30
31/// This implementation does the bare minimum to satisfy the executable start function.
32impl Termination for () {}
33
34/// This function is called on panic.
35#[cfg_attr(not(test), panic_handler)]
36#[no_mangle]
37fn panic(_info: &PanicInfo<'_>) -> ! {
38    #[allow(clippy::empty_loop)]
39    loop {}
40}
41
42/// Error handler personality language item (current no-op, to satisfy clippy).
43#[cfg_attr(not(test), lang = "eh_personality")]
44#[no_mangle]
45extern "C" fn rust_eh_personality() {}