lib.rs 2.4 KB

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