sel4_newlib/
lib.rs
1#![no_std]
10
11#[allow(unused_imports)]
12use core::ffi::{c_char, c_int, c_uint};
13
14mod errno;
15mod heap;
16
17pub use heap::StaticHeap;
18
19extern "C" {
20 #[link_name = "srand"]
21 fn newlib_srand(seed: c_uint);
22}
23
24pub fn srand(seed: c_uint) {
25 unsafe {
26 newlib_srand(seed);
27 }
28}
29
30#[cfg(feature = "_exit")]
31mod impl_exit {
32 use super::*;
33
34 use sel4_panicking_env::abort;
35
36 #[no_mangle]
37 extern "C" fn _exit(rc: c_int) -> ! {
38 abort!("_exit({})", rc)
39 }
40}
41
42#[cfg(feature = "_write")]
43mod impl_write {
44 use super::*;
45
46 use core::slice;
47
48 use sel4_panicking_env::debug_put_char;
49
50 #[no_mangle]
51 extern "C" fn _write(file: c_int, ptr: *const c_char, len: c_int) -> c_int {
52 match file {
53 1 | 2 => {
54 let bytes =
55 unsafe { slice::from_raw_parts(ptr.cast::<u8>(), len.try_into().unwrap()) };
56 for &b in bytes {
57 debug_put_char(b);
58 }
59 len
60 }
61 _ => {
62 #[cfg(feature = "log")]
63 {
64 log::warn!("_write({}, {:#x?}, {})", file, ptr, len);
65 }
66 errno::set_errno(errno::values::ENOENT);
67 -1
68 }
69 }
70 }
71}