Skip to content

Commit 7b718c7

Browse files
committed
rust: use feature(core_ffi_c) and feature(c_size_t) to replace c_types contents
This allows us to remove most of the contents we manually maintained in `c_types`. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 7e956ca commit 7b718c7

File tree

3 files changed

+4
-111
lines changed

3 files changed

+4
-111
lines changed

rust/kernel/c_types.rs

Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -7,113 +7,4 @@
77
//! C's standard integer types may differ in width depending on
88
//! the architecture, thus we need to conditionally compile those.
99
10-
#![allow(non_camel_case_types)]
11-
12-
#[cfg(any(target_arch = "arm", target_arch = "x86", target_arch = "riscv32",))]
13-
mod c {
14-
/// C `void` type.
15-
pub type c_void = core::ffi::c_void;
16-
17-
/// C `char` type.
18-
pub type c_char = i8;
19-
20-
/// C `signed char` type.
21-
pub type c_schar = i8;
22-
23-
/// C `unsigned char` type.
24-
pub type c_uchar = u8;
25-
26-
/// C `short` type.
27-
pub type c_short = i16;
28-
29-
/// C `unsigned short` type.
30-
pub type c_ushort = u16;
31-
32-
/// C `int` type.
33-
pub type c_int = i32;
34-
35-
/// C `unsigned int` type.
36-
pub type c_uint = u32;
37-
38-
/// C `long` type.
39-
pub type c_long = i32;
40-
41-
/// C `unsigned long` type.
42-
pub type c_ulong = u32;
43-
44-
/// C `long long` type.
45-
pub type c_longlong = i64;
46-
47-
/// C `unsigned long long` type.
48-
pub type c_ulonglong = u64;
49-
50-
/// C `ssize_t` type (typically defined in `<sys/types.h>` by POSIX).
51-
///
52-
/// For some 32-bit architectures like this one, the kernel defines it as
53-
/// `int`, i.e. it is an [`i32`].
54-
pub type c_ssize_t = isize;
55-
56-
/// C `size_t` type (typically defined in `<stddef.h>`).
57-
///
58-
/// For some 32-bit architectures like this one, the kernel defines it as
59-
/// `unsigned int`, i.e. it is an [`u32`].
60-
pub type c_size_t = usize;
61-
}
62-
63-
#[cfg(any(
64-
target_arch = "aarch64",
65-
target_arch = "x86_64",
66-
target_arch = "powerpc64",
67-
target_arch = "riscv64",
68-
))]
69-
mod c {
70-
/// C `void` type.
71-
pub type c_void = core::ffi::c_void;
72-
73-
/// C `char` type.
74-
pub type c_char = i8;
75-
76-
/// C `signed char` type.
77-
pub type c_schar = i8;
78-
79-
/// C `unsigned char` type.
80-
pub type c_uchar = u8;
81-
82-
/// C `short` type.
83-
pub type c_short = i16;
84-
85-
/// C `unsigned short` type.
86-
pub type c_ushort = u16;
87-
88-
/// C `int` type.
89-
pub type c_int = i32;
90-
91-
/// C `unsigned int` type.
92-
pub type c_uint = u32;
93-
94-
/// C `long` type.
95-
pub type c_long = i64;
96-
97-
/// C `unsigned long` type.
98-
pub type c_ulong = u64;
99-
100-
/// C `long long` type.
101-
pub type c_longlong = i64;
102-
103-
/// C `unsigned long long` type.
104-
pub type c_ulonglong = u64;
105-
106-
/// C `ssize_t` type (typically defined in `<sys/types.h>` by POSIX).
107-
///
108-
/// For 64-bit architectures like this one, the kernel defines it as
109-
/// `long`, i.e. it is an [`i64`].
110-
pub type c_ssize_t = isize;
111-
112-
/// C `size_t` type (typically defined in `<stddef.h>`).
113-
///
114-
/// For 64-bit architectures like this one, the kernel defines it as
115-
/// `unsigned long`, i.e. it is an [`u64`].
116-
pub type c_size_t = usize;
117-
}
118-
119-
pub use c::*;
10+
pub use core::ffi::*;

rust/kernel/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#![feature(const_ptr_offset_from)]
2020
#![feature(const_refs_to_cell)]
2121
#![feature(const_trait_impl)]
22+
#![feature(core_ffi_c)]
23+
#![feature(c_size_t)]
2224
#![feature(doc_cfg)]
2325
#![feature(generic_associated_types)]
2426
#![feature(ptr_metadata)]

scripts/Makefile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ $(obj)/%.lst: $(src)/%.c FORCE
275275
# Compile Rust sources (.rs)
276276
# ---------------------------------------------------------------------------
277277

278-
rust_allowed_features := allocator_api,bench_black_box,concat_idents,generic_associated_types
278+
rust_allowed_features := allocator_api,bench_black_box,concat_idents,core_ffi_c,generic_associated_types
279279

280280
rust_common_cmd = \
281281
RUST_MODFILE=$(modfile) $(RUSTC_OR_CLIPPY) $(rust_flags) \

0 commit comments

Comments
 (0)