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