at master 1.3 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2 3//! Foreign function interface (FFI) types. 4//! 5//! This crate provides mapping from C primitive types to Rust ones. 6//! 7//! The Rust [`core`] crate provides [`core::ffi`], which maps integer types to the platform default 8//! C ABI. The kernel does not use [`core::ffi`], so it can customise the mapping that deviates from 9//! the platform default. 10 11#![no_std] 12 13macro_rules! alias { 14 ($($name:ident = $ty:ty;)*) => {$( 15 #[allow(non_camel_case_types, missing_docs)] 16 pub type $name = $ty; 17 18 // Check size compatibility with `core`. 19 const _: () = assert!( 20 ::core::mem::size_of::<$name>() == ::core::mem::size_of::<::core::ffi::$name>() 21 ); 22 )*} 23} 24 25alias! { 26 // `core::ffi::c_char` is either `i8` or `u8` depending on architecture. In the kernel, we use 27 // `-funsigned-char` so it's always mapped to `u8`. 28 c_char = u8; 29 30 c_schar = i8; 31 c_uchar = u8; 32 33 c_short = i16; 34 c_ushort = u16; 35 36 c_int = i32; 37 c_uint = u32; 38 39 // In the kernel, `intptr_t` is defined to be `long` in all platforms, so we can map the type to 40 // `isize`. 41 c_long = isize; 42 c_ulong = usize; 43 44 c_longlong = i64; 45 c_ulonglong = u64; 46} 47 48pub use core::ffi::c_void; 49 50pub use core::ffi::CStr;