| 1 | |
| 2 |
|
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 |
|
| 14 | #![no_std]
|
| 15 | #![feature(allocator_api)]
|
| 16 | #![feature(core_ffi_c)]
|
| 17 |
|
| 18 | |
| 19 | |
| 20 | #[cfg(not(CONFIG_RUST))]
|
| 21 | compile_error!("Missing kernel configuration for conditional compilation");
|
| 22 |
|
| 23 | #[cfg(not(test))]
|
| 24 | #[cfg(not(testlib))]
|
| 25 | mod allocator;
|
| 26 | mod build_assert;
|
| 27 | pub mod error;
|
| 28 | pub mod prelude;
|
| 29 | pub mod print;
|
| 30 | mod static_assert;
|
| 31 | #[doc(hidden)]
|
| 32 | pub mod std_vendor;
|
| 33 | pub mod str;
|
| 34 | pub mod types;
|
| 35 |
|
| 36 | #[doc(hidden)]
|
| 37 | pub use bindings;
|
| 38 | pub use macros;
|
| 39 |
|
| 40 | #[doc(hidden)]
|
| 41 | pub use build_error::build_error;
|
| 42 |
|
| 43 | |
| 44 | const __LOG_PREFIX: &[u8] = b"rust_kernel\0";
|
| 45 |
|
| 46 | |
| 47 | |
| 48 | |
| 49 | pub trait Module: Sized + Sync {
|
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | fn init(module: &'static ThisModule) -> error::Result<Self>;
|
| 57 | }
|
| 58 |
|
| 59 | |
| 60 | |
| 61 | |
| 62 | pub struct ThisModule(*mut bindings::module);
|
| 63 |
|
| 64 | |
| 65 | unsafe impl Sync for ThisModule {}
|
| 66 |
|
| 67 | impl ThisModule {
|
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | pub const unsafe fn from_ptr(ptr: *mut bindings::module) -> ThisModule {
|
| 74 | ThisModule(ptr)
|
| 75 | }
|
| 76 | }
|
| 77 |
|
| 78 | #[cfg(not(any(testlib, test)))]
|
| 79 | #[panic_handler]
|
| 80 | fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
|
| 81 | pr_emerg!("{}\n", info);
|
| 82 | |
| 83 | unsafe { bindings::BUG() };
|
| 84 | |
| 85 | |
| 86 | loop {}
|
| 87 | }
|