Skip to content

Commit cf14c35

Browse files
committed
userland: merge aero_rt into aero_std
1 parent 4515a06 commit cf14c35

File tree

6 files changed

+73
-69
lines changed

6 files changed

+73
-69
lines changed

userland/Cargo.lock

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

userland/aero_rt/Cargo.toml

Lines changed: 0 additions & 8 deletions
This file was deleted.

userland/aero_rt/src/lib.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

userland/aero_std/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ authors = ["czapek1337 <[email protected]>"]
55
edition = "2021"
66

77
[dependencies]
8-
aero_rt = { path = "../aero_rt" }
98
aero_syscall = { path = "../../src/aero_syscall" }
109
linked_list_allocator = "0.9"
1110
spin = "0.9"

userland/aero_std/src/lib.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
* along with Aero. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919

20-
#![feature(alloc_error_handler, prelude_import)]
20+
#![feature(alloc_error_handler, lang_items, never_type, prelude_import, start)]
2121
#![no_std]
2222

23-
extern crate aero_rt;
2423
extern crate alloc;
2524

2625
pub mod heap;
2726
pub mod io;
2827
pub mod prelude;
28+
pub mod process;
29+
30+
use aero_syscall::*;
31+
use process::Termination;
2932

3033
#[prelude_import]
3134
pub use prelude::rust_2021::*;
@@ -68,3 +71,32 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! {
6871
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
6972
panic!("Failed allocating memory with layout: {:?}", layout)
7073
}
74+
75+
#[no_mangle]
76+
unsafe extern "C" fn _start(argc: isize, argv: *const *const u8) -> ! {
77+
extern "C" {
78+
fn main(_argc: isize, _argv: *const *const u8) -> isize;
79+
}
80+
81+
sys_exit(main(argc, argv) as usize);
82+
}
83+
84+
#[lang = "start"]
85+
fn lang_start<T: Termination + 'static>(
86+
main: fn() -> T,
87+
_argc: isize,
88+
_argv: *const *const u8,
89+
) -> isize {
90+
main().report() as _
91+
}
92+
93+
#[lang = "eh_personality"]
94+
fn eh_personality() -> ! {
95+
unreachable!();
96+
}
97+
98+
#[no_mangle]
99+
#[allow(non_snake_case)]
100+
fn _Unwind_Resume() -> ! {
101+
unreachable!();
102+
}

userland/aero_std/src/process.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use core::fmt::Debug;
2+
3+
#[lang = "termination"]
4+
pub trait Termination {
5+
fn report(self) -> i32;
6+
}
7+
8+
impl Termination for () {
9+
fn report(self) -> i32 {
10+
0
11+
}
12+
}
13+
14+
impl Termination for ! {
15+
fn report(self) -> i32 {
16+
unreachable!()
17+
}
18+
}
19+
20+
impl<E: Debug> Termination for Result<(), E> {
21+
fn report(self) -> i32 {
22+
match self {
23+
Ok(()) => 0,
24+
Err(err) => Err::<!, _>(err).report(),
25+
}
26+
}
27+
}
28+
29+
impl<E: Debug> Termination for Result<!, E> {
30+
fn report(self) -> i32 {
31+
match self {
32+
Ok(_) => unreachable!(),
33+
Err(err) => {
34+
println!("Error: {:?}", err);
35+
1
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)