mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 16:48:26 +02:00 
			
		
		
		
	 de7cd3e4d6
			
		
	
	
		de7cd3e4d6
		
	
	
	
	
		
			
			Macros and auto-generated code should use absolute paths, `::core::...` and `::kernel::...`, for core and kernel references. This prevents issues where user-defined modules named `core` or `kernel` could be picked up instead of the `core` or `kernel` crates. Thus clean some references up. Suggested-by: Benno Lossin <benno.lossin@proton.me> Closes: https://github.com/Rust-for-Linux/linux/issues/1150 Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/20250519164615.3310844-1-igor.korotin.linux@gmail.com [ Applied `rustfmt`. Reworded slightly. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
		
			
				
	
	
		
			48 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| // SPDX-License-Identifier: GPL-2.0
 | |
| 
 | |
| //! Foreign function interface (FFI) types.
 | |
| //!
 | |
| //! This crate provides mapping from C primitive types to Rust ones.
 | |
| //!
 | |
| //! The Rust [`core`] crate provides [`core::ffi`], which maps integer types to the platform default
 | |
| //! C ABI. The kernel does not use [`core::ffi`], so it can customise the mapping that deviates from
 | |
| //! the platform default.
 | |
| 
 | |
| #![no_std]
 | |
| 
 | |
| macro_rules! alias {
 | |
|     ($($name:ident = $ty:ty;)*) => {$(
 | |
|         #[allow(non_camel_case_types, missing_docs)]
 | |
|         pub type $name = $ty;
 | |
| 
 | |
|         // Check size compatibility with `core`.
 | |
|         const _: () = assert!(
 | |
|             ::core::mem::size_of::<$name>() == ::core::mem::size_of::<::core::ffi::$name>()
 | |
|         );
 | |
|     )*}
 | |
| }
 | |
| 
 | |
| alias! {
 | |
|     // `core::ffi::c_char` is either `i8` or `u8` depending on architecture. In the kernel, we use
 | |
|     // `-funsigned-char` so it's always mapped to `u8`.
 | |
|     c_char = u8;
 | |
| 
 | |
|     c_schar = i8;
 | |
|     c_uchar = u8;
 | |
| 
 | |
|     c_short = i16;
 | |
|     c_ushort = u16;
 | |
| 
 | |
|     c_int = i32;
 | |
|     c_uint = u32;
 | |
| 
 | |
|     // In the kernel, `intptr_t` is defined to be `long` in all platforms, so we can map the type to
 | |
|     // `isize`.
 | |
|     c_long = isize;
 | |
|     c_ulong = usize;
 | |
| 
 | |
|     c_longlong = i64;
 | |
|     c_ulonglong = u64;
 | |
| }
 | |
| 
 | |
| pub use core::ffi::c_void;
 |