• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Google Inc. All rights reserved
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files
6  * (the "Software"), to deal in the Software without restriction,
7  * including without limitation the rights to use, copy, modify, merge,
8  * publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 //! Rust support library for the Trusty kernel
25 
26 #![no_std]
27 #![feature(cfg_version)]
28 // C string literals were stabilized in Rust 1.77
29 #![cfg_attr(not(version("1.77")), feature(c_str_literals))]
30 #![deny(unsafe_op_in_unsafe_fn)]
31 
32 use alloc::format;
33 use core::ffi::CStr;
34 use core::panic::PanicInfo;
35 
36 mod sys {
37     #![allow(unused)]
38     #![allow(non_camel_case_types)]
39     #![allow(non_upper_case_globals)]
40     use num_derive::FromPrimitive;
41     include!(env!("BINDGEN_INC_FILE"));
42 }
43 
44 pub mod err;
45 pub mod init;
46 pub mod ipc;
47 pub mod log;
48 pub mod mmu;
49 pub mod sync;
50 pub mod thread;
51 pub mod vmm;
52 
53 pub use sys::paddr_t;
54 pub use sys::status_t;
55 pub use sys::vaddr_t;
56 pub use sys::Error;
57 
58 #[panic_handler]
handle_panic(info: &PanicInfo) -> !59 fn handle_panic(info: &PanicInfo) -> ! {
60     let panic_message = format!("{info}\0");
61     let panic_message_c = CStr::from_bytes_with_nul(panic_message.as_bytes())
62         .expect("Unexpected null byte in panic message");
63     // SAFETY: Calling C function with string pointers that outlive the call
64     unsafe { sys::_panic(c"Rust in Trusty kernel %s\n".as_ptr(), panic_message_c.as_ptr()) }
65 }
66