1 // SPDX-License-Identifier: GPL-2.0 2 3 //! Bindings. 4 //! 5 //! Imports the generated bindings by `bindgen`. 6 //! 7 //! This crate may not be directly used. If you need a kernel C API that is 8 //! not ported or wrapped in the `kernel` crate, then do so first instead of 9 //! using this crate. 10 11 #![no_std] 12 #![allow( 13 clippy::all, 14 missing_docs, 15 non_camel_case_types, 16 non_upper_case_globals, 17 non_snake_case, 18 improper_ctypes, 19 unreachable_pub, 20 unsafe_op_in_unsafe_fn 21 )] 22 23 #[allow(dead_code)] 24 #[allow(clippy::cast_lossless)] 25 #[allow(clippy::ptr_as_ptr)] 26 #[allow(clippy::ref_as_ptr)] 27 #[allow(clippy::undocumented_unsafe_blocks)] 28 #[cfg_attr(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES, allow(unnecessary_transmutes))] 29 mod bindings_raw { 30 use pin_init::{MaybeZeroable, Zeroable}; 31 32 // Manual definition for blocklisted types. 33 type __kernel_size_t = usize; 34 type __kernel_ssize_t = isize; 35 type __kernel_ptrdiff_t = isize; 36 37 // `bindgen` doesn't automatically do this, see 38 // <https://github.com/rust-lang/rust-bindgen/issues/3196> 39 // 40 // SAFETY: `__BindgenBitfieldUnit<Storage>` is a newtype around `Storage`. 41 unsafe impl<Storage> Zeroable for __BindgenBitfieldUnit<Storage> where Storage: Zeroable {} 42 43 // Use glob import here to expose all helpers. 44 // Symbols defined within the module will take precedence to the glob import. 45 pub use super::bindings_helper::*; 46 include!(concat!( 47 env!("OBJTREE"), 48 "/rust/bindings/bindings_generated.rs" 49 )); 50 } 51 52 // When both a directly exposed symbol and a helper exists for the same function, 53 // the directly exposed symbol is preferred and the helper becomes dead code, so 54 // ignore the warning here. 55 #[allow(dead_code)] 56 mod bindings_helper { 57 // Import the generated bindings for types. 58 use super::bindings_raw::*; 59 include!(concat!( 60 env!("OBJTREE"), 61 "/rust/bindings/bindings_helpers_generated.rs" 62 )); 63 } 64 65 pub use bindings_raw::*; 66 67 pub const compat_ptr_ioctl: Option< 68 unsafe extern "C" fn(*mut file, ffi::c_uint, ffi::c_ulong) -> ffi::c_long, 69 > = { 70 #[cfg(CONFIG_COMPAT)] 71 { 72 Some(bindings_raw::compat_ptr_ioctl) 73 } 74 #[cfg(not(CONFIG_COMPAT))] 75 { 76 None 77 } 78 }; 79