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 #![feature(cfi_encoding)] 23 24 #[allow(dead_code)] 25 #[allow(clippy::cast_lossless)] 26 #[allow(clippy::ptr_as_ptr)] 27 #[allow(clippy::ref_as_ptr)] 28 #[allow(clippy::undocumented_unsafe_blocks)] 29 #[cfg_attr(CONFIG_RUSTC_HAS_UNNECESSARY_TRANSMUTES, allow(unnecessary_transmutes))] 30 #[cfg_attr( 31 CONFIG_RUSTC_HAS_SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS, 32 allow(suspicious_runtime_symbol_definitions) 33 )] 34 mod bindings_raw { 35 use pin_init::{MaybeZeroable, Zeroable}; 36 37 // Manual definition for blocklisted types. 38 type __kernel_size_t = usize; 39 type __kernel_ssize_t = isize; 40 type __kernel_ptrdiff_t = isize; 41 42 // `bindgen` doesn't automatically do this, see 43 // <https://github.com/rust-lang/rust-bindgen/issues/3196> 44 // 45 // SAFETY: `__BindgenBitfieldUnit<Storage>` is a newtype around `Storage`. 46 unsafe impl<Storage> Zeroable for __BindgenBitfieldUnit<Storage> where Storage: Zeroable {} 47 48 // Use glob import here to expose all helpers. 49 // Symbols defined within the module will take precedence to the glob import. 50 pub use super::bindings_helper::*; 51 include!(concat!( 52 env!("OBJTREE"), 53 "/rust/bindings/bindings_generated.rs" 54 )); 55 } 56 57 // When both a directly exposed symbol and a helper exists for the same function, 58 // the directly exposed symbol is preferred and the helper becomes dead code, so 59 // ignore the warning here. 60 #[allow(dead_code)] 61 mod bindings_helper { 62 // Import the generated bindings for types. 63 use super::bindings_raw::*; 64 include!(concat!( 65 env!("OBJTREE"), 66 "/rust/bindings/bindings_helpers_generated.rs" 67 )); 68 } 69 70 pub use bindings_raw::*; 71 72 pub const compat_ptr_ioctl: Option< 73 unsafe extern "C" fn(*mut file, ffi::c_uint, ffi::c_ulong) -> ffi::c_long, 74 > = { 75 #[cfg(CONFIG_COMPAT)] 76 { 77 Some(bindings_raw::compat_ptr_ioctl) 78 } 79 #[cfg(not(CONFIG_COMPAT))] 80 { 81 None 82 } 83 }; 84