| 1 | |
| 2 |
|
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 |
|
| 14 | #![no_std]
|
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | #![feature(unsigned_is_multiple_of)]
|
| 21 | |
| 22 | |
| 23 | #![feature(generic_arg_infer)]
|
| 24 | |
| 25 | |
| 26 | #![feature(arbitrary_self_types)]
|
| 27 | #![feature(derive_coerce_pointee)]
|
| 28 | |
| 29 | |
| 30 | #![feature(used_with_arg)]
|
| 31 | |
| 32 | |
| 33 | |
| 34 | #![cfg_attr(CONFIG_RUSTC_HAS_FILE_WITH_NUL, feature(file_with_nul))]
|
| 35 |
|
| 36 | |
| 37 | |
| 38 | #[cfg(not(CONFIG_RUST))]
|
| 39 | compile_error!("Missing kernel configuration for conditional compilation");
|
| 40 |
|
| 41 | |
| 42 | extern crate self as kernel;
|
| 43 |
|
| 44 | pub use ffi;
|
| 45 |
|
| 46 | pub mod acpi;
|
| 47 | pub mod alloc;
|
| 48 | #[cfg(CONFIG_AUXILIARY_BUS)]
|
| 49 | pub mod auxiliary;
|
| 50 | pub mod bitfield;
|
| 51 | pub mod bitmap;
|
| 52 | pub mod bits;
|
| 53 | #[cfg(CONFIG_BLOCK)]
|
| 54 | pub mod block;
|
| 55 | pub mod bug;
|
| 56 | pub mod build_assert;
|
| 57 | pub mod clk;
|
| 58 | #[cfg(CONFIG_CONFIGFS_FS)]
|
| 59 | pub mod configfs;
|
| 60 | pub mod cpu;
|
| 61 | #[cfg(CONFIG_CPU_FREQ)]
|
| 62 | pub mod cpufreq;
|
| 63 | pub mod cpumask;
|
| 64 | pub mod cred;
|
| 65 | pub mod debugfs;
|
| 66 | pub mod device;
|
| 67 | pub mod device_id;
|
| 68 | pub mod devres;
|
| 69 | pub mod dma;
|
| 70 | pub mod driver;
|
| 71 | #[cfg(CONFIG_DRM = "y")]
|
| 72 | pub mod drm;
|
| 73 | pub mod error;
|
| 74 | pub mod faux;
|
| 75 | #[cfg(CONFIG_RUST_FW_LOADER_ABSTRACTIONS)]
|
| 76 | pub mod firmware;
|
| 77 | pub mod fmt;
|
| 78 | pub mod fs;
|
| 79 | #[cfg(CONFIG_RUST_FWCTL_ABSTRACTIONS)]
|
| 80 | pub mod fwctl;
|
| 81 | #[cfg(CONFIG_GPU_BUDDY = "y")]
|
| 82 | pub mod gpu;
|
| 83 | #[cfg(CONFIG_I2C = "y")]
|
| 84 | pub mod i2c;
|
| 85 | pub mod id_pool;
|
| 86 | #[doc(hidden)]
|
| 87 | pub mod impl_flags;
|
| 88 | pub mod init;
|
| 89 | pub mod interop;
|
| 90 | pub mod interrupt;
|
| 91 | pub mod io;
|
| 92 | pub mod ioctl;
|
| 93 | pub mod iommu;
|
| 94 | pub mod iov;
|
| 95 | pub mod irq;
|
| 96 | pub mod jump_label;
|
| 97 | #[cfg(CONFIG_KUNIT)]
|
| 98 | pub mod kunit;
|
| 99 | pub mod list;
|
| 100 | pub mod maple_tree;
|
| 101 | pub mod miscdevice;
|
| 102 | pub mod mm;
|
| 103 | pub mod module;
|
| 104 | pub mod module_param;
|
| 105 | #[cfg(CONFIG_NET)]
|
| 106 | pub mod net;
|
| 107 | pub mod num;
|
| 108 | pub mod of;
|
| 109 | #[cfg(CONFIG_PM_OPP)]
|
| 110 | pub mod opp;
|
| 111 | pub mod page;
|
| 112 | #[cfg(CONFIG_PCI)]
|
| 113 | pub mod pci;
|
| 114 | pub mod pid_namespace;
|
| 115 | pub mod platform;
|
| 116 | pub mod prelude;
|
| 117 | pub mod print;
|
| 118 | pub mod processor;
|
| 119 | pub mod ptr;
|
| 120 | #[cfg(CONFIG_RUST_PWM_ABSTRACTIONS)]
|
| 121 | pub mod pwm;
|
| 122 | pub mod rbtree;
|
| 123 | pub mod regulator;
|
| 124 | pub mod revocable;
|
| 125 | pub mod safety;
|
| 126 | pub mod scatterlist;
|
| 127 | pub mod security;
|
| 128 | pub mod seq_file;
|
| 129 | #[cfg(CONFIG_RUST_SERIAL_DEV_BUS_ABSTRACTIONS)]
|
| 130 | pub mod serdev;
|
| 131 | pub mod sizes;
|
| 132 | #[cfg(CONFIG_SOC_BUS)]
|
| 133 | pub mod soc;
|
| 134 | #[doc(hidden)]
|
| 135 | pub mod std_vendor;
|
| 136 | pub mod str;
|
| 137 | pub mod sync;
|
| 138 | pub mod task;
|
| 139 | pub mod time;
|
| 140 | pub mod tracepoint;
|
| 141 | pub mod transmute;
|
| 142 | pub mod types;
|
| 143 | pub mod uaccess;
|
| 144 | #[cfg(CONFIG_USB = "y")]
|
| 145 | pub mod usb;
|
| 146 | pub mod workqueue;
|
| 147 | pub mod xarray;
|
| 148 |
|
| 149 | #[doc(hidden)]
|
| 150 | pub use bindings;
|
| 151 | pub use macros;
|
| 152 | pub use module::{
|
| 153 | InPlaceModule,
|
| 154 | Module,
|
| 155 | ModuleMetadata,
|
| 156 | ThisModule, |
| 157 | };
|
| 158 | pub use uapi;
|
| 159 |
|
| 160 | |
| 161 | const __LOG_PREFIX: &[u8] = b"rust_kernel\0";
|
| 162 |
|
| 163 | |
| 164 | |
| 165 | #[allow(dead_code)]
|
| 166 | struct LocalModule;
|
| 167 |
|
| 168 | impl ModuleMetadata for LocalModule {
|
| 169 | const NAME: &'static str::CStr = c"rust_kernel";
|
| 170 |
|
| 171 | const THIS_MODULE: ThisModule = {
|
| 172 | |
| 173 | unsafe { ThisModule::from_ptr(core::ptr::null_mut()) }
|
| 174 | };
|
| 175 | }
|
| 176 |
|
| 177 | #[cfg(not(testlib))]
|
| 178 | #[panic_handler]
|
| 179 | fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
|
| 180 | pr_emerg!("{}\n", info);
|
| 181 | |
| 182 | unsafe { bindings::BUG() };
|
| 183 | }
|
| 184 |
|
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | #[macro_export]
|
| 216 | macro_rules! container_of {
|
| 217 | ($field_ptr:expr, $Container:ty, $($fields:tt)*) => {{
|
| 218 | let offset: usize = ::core::mem::offset_of!($Container, $($fields)*);
|
| 219 | let field_ptr = $field_ptr;
|
| 220 | let container_ptr = field_ptr.byte_sub(offset).cast::<$Container>();
|
| 221 | $crate::assert_same_type(field_ptr, (&raw const (*container_ptr).$($fields)*).cast_mut());
|
| 222 | container_ptr
|
| 223 | }}
|
| 224 | }
|
| 225 |
|
| 226 | |
| 227 | #[doc(hidden)]
|
| 228 | pub fn assert_same_type<T>(_: T, _: T) {}
|
| 229 |
|
| 230 | |
| 231 | #[doc(hidden)]
|
| 232 | #[macro_export]
|
| 233 | macro_rules! concat_literals {
|
| 234 | ($( $asm:literal )* ) => {
|
| 235 | ::core::concat!($($asm),*)
|
| 236 | };
|
| 237 | }
|
| 238 |
|
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
| 245 | #[macro_export]
|
| 246 | macro_rules! asm {
|
| 247 | ($($asm:expr),* ; $($rest:tt)*) => {
|
| 248 | ::core::arch::asm!( $($asm)*, options(att_syntax), $($rest)* )
|
| 249 | };
|
| 250 | }
|
| 251 |
|
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
|
| 258 | #[macro_export]
|
| 259 | macro_rules! asm {
|
| 260 | ($($asm:expr),* ; $($rest:tt)*) => {
|
| 261 | ::core::arch::asm!( $($asm)*, $($rest)* )
|
| 262 | };
|
| 263 | }
|
| 264 |
|
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | #[inline]
|
| 296 | pub fn file_from_location<'a>(loc: &'a core::panic::Location<'a>) -> &'a core::ffi::CStr {
|
| 297 | #[cfg(CONFIG_RUSTC_HAS_FILE_AS_C_STR)]
|
| 298 | {
|
| 299 | loc.file_as_c_str()
|
| 300 | }
|
| 301 |
|
| 302 | #[cfg(all(CONFIG_RUSTC_HAS_FILE_WITH_NUL, not(CONFIG_RUSTC_HAS_FILE_AS_C_STR)))]
|
| 303 | {
|
| 304 | loc.file_with_nul()
|
| 305 | }
|
| 306 |
|
| 307 | #[cfg(not(CONFIG_RUSTC_HAS_FILE_WITH_NUL))]
|
| 308 | {
|
| 309 | let _ = loc;
|
| 310 | c"<Location::file_as_c_str() not supported>"
|
| 311 | }
|
| 312 | }
|