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