xref: /relibc/src/lib.rs (revision 7016e5c833af9fe4182462e6a86e498cd5e8c738)
1 #![no_std]
2 #![allow(non_camel_case_types)]
3 #![allow(non_upper_case_globals)]
4 #![allow(unused_variables)]
5 #![feature(alloc_error_handler)]
6 #![feature(allocator_api)]
7 #![feature(array_chunks)]
8 #![feature(asm_const)]
9 #![feature(box_into_pin)]
10 #![feature(c_variadic)]
11 #![feature(const_btree_new)]
12 #![feature(core_intrinsics)]
13 #![feature(lang_items)]
14 #![feature(linkage)]
15 #![feature(stmt_expr_attributes)]
16 #![feature(str_internals)]
17 #![feature(thread_local)]
18 #![allow(clippy::cast_lossless)]
19 #![allow(clippy::cast_ptr_alignment)]
20 #![allow(clippy::derive_hash_xor_eq)]
21 #![allow(clippy::eval_order_dependence)]
22 #![allow(clippy::mut_from_ref)]
23 // TODO: fix these
24 #![warn(unaligned_references)]
25 
26 #[macro_use]
27 extern crate alloc;
28 extern crate cbitset;
29 extern crate core_io;
30 extern crate goblin;
31 #[macro_use]
32 extern crate lazy_static;
33 extern crate memchr;
34 #[macro_use]
35 extern crate memoffset;
36 extern crate posix_regex;
37 extern crate rand;
38 
39 #[cfg(target_os = "linux")]
40 #[macro_use]
41 extern crate sc;
42 
43 // TODO: fix this: adjust to dragonos sc
44 #[cfg(target_os = "dragonos")]
45 #[macro_use]
46 extern crate dsc;
47 
48 #[cfg(target_os = "redox")]
49 extern crate syscall;
50 
51 #[cfg(target_os = "redox")]
52 extern crate spin;
53 
54 #[macro_use]
55 mod macros;
56 pub mod c_str;
57 pub mod c_vec;
58 pub mod cxa;
59 pub mod db;
60 pub mod fs;
61 pub mod header;
62 pub mod io;
63 pub mod ld_so;
64 pub mod platform;
65 pub mod start;
66 pub mod sync;
67 
68 use crate::platform::{Allocator, Pal, Sys, NEWALLOCATOR};
69 
70 #[global_allocator]
71 static ALLOCATOR: Allocator = NEWALLOCATOR;
72 
73 #[no_mangle]
74 pub extern "C" fn relibc_panic(pi: &::core::panic::PanicInfo) -> ! {
75     use core::fmt::Write;
76 
77     let mut w = platform::FileWriter(2);
78     let _ = w.write_fmt(format_args!("RELIBC PANIC: {}\n", pi));
79 
80     Sys::exit(1);
81 }
82 
83 #[cfg(not(test))]
84 #[panic_handler]
85 #[linkage = "weak"]
86 #[no_mangle]
87 pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! {
88     relibc_panic(pi)
89 }
90 
91 #[cfg(not(test))]
92 #[lang = "eh_personality"]
93 #[no_mangle]
94 #[linkage = "weak"]
95 pub extern "C" fn rust_eh_personality() {}
96 
97 #[cfg(not(test))]
98 #[alloc_error_handler]
99 #[linkage = "weak"]
100 #[no_mangle]
101 pub extern "C" fn rust_oom(layout: ::core::alloc::Layout) -> ! {
102     use core::fmt::Write;
103 
104     let mut w = platform::FileWriter(2);
105     let _ = w.write_fmt(format_args!(
106         "RELIBC OOM: {} bytes aligned to {} bytes\n",
107         layout.size(),
108         layout.align()
109     ));
110 
111     Sys::exit(1);
112 }
113 
114 #[cfg(not(test))]
115 #[allow(non_snake_case)]
116 #[linkage = "weak"]
117 #[no_mangle]
118 pub extern "C" fn _Unwind_Resume() -> ! {
119     use core::fmt::Write;
120 
121     let mut w = platform::FileWriter(2);
122     let _ = w.write_str("_Unwind_Resume\n");
123 
124     Sys::exit(1);
125 }
126