Skip to content

Commit 0e77ea5

Browse files
Benjamin LermanCQ Bot
authored andcommitted
[starnix] Regenerate linux uapi bindings.
The rust binding generator has updated and changed the way opaque blobs are generated. This updates our generator to still allow these blobs to be handled by zerocopy Change-Id: Ic6ec8037540e915b11d60048787d0e9ea5ce96bc Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1359331 Reviewed-by: Kevin Lindkvist <[email protected]> Fuchsia-Auto-Submit: Benjamin Lerman <[email protected]> Commit-Queue: Benjamin Lerman <[email protected]>
1 parent a5f5aeb commit 0e77ea5

File tree

7 files changed

+220
-125
lines changed

7 files changed

+220
-125
lines changed

src/starnix/kernel/signals/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,13 +704,13 @@ pub struct SignalEventValue(pub u64);
704704

705705
impl From<sigval_t> for SignalEventValue {
706706
fn from(value: sigval_t) -> Self {
707-
SignalEventValue(unsafe { value._bindgen_opaque_blob })
707+
SignalEventValue(zerocopy::transmute!(unsafe { value._bindgen_opaque_blob }))
708708
}
709709
}
710710

711711
impl From<SignalEventValue> for sigval_t {
712712
fn from(value: SignalEventValue) -> Self {
713-
Self { _bindgen_opaque_blob: value.0 }
713+
Self { _bindgen_opaque_blob: zerocopy::transmute!(value.0) }
714714
}
715715
}
716716

src/starnix/lib/linux_uapi/generate.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@
3636
"""
3737
)
3838

39+
for s in [8, 16, 144, 272]:
40+
RAW_LINES += (
41+
"""
42+
// SAFETY: The IntoBytes implementation is safe because the array size is a
43+
// multiple of 8, so there is no padding.
44+
unsafe impl IntoBytes for __BindgenOpaqueArray8<[u8; %dusize]> {
45+
fn only_derive_is_allowed_to_implement_this_trait() {
46+
}
47+
}
48+
"""
49+
% s
50+
)
51+
3952
PTR_TYPES = """
4053
#[repr(transparent)]
4154
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, Ord, PartialOrd, IntoBytes, FromBytes, KnownLayout, Immutable)]
@@ -107,7 +120,6 @@
107120
Self { addr: ur.addr.into(), _phantom: Default::default() }
108121
}
109122
}
110-
111123
"""
112124

113125
# Tell bindgen not to produce records for these types.
@@ -142,6 +154,14 @@
142154
r"__BindgenUnionField",
143155
["IntoBytes", "FromBytes", "KnownLayout", "Immutable"],
144156
),
157+
(
158+
r"__BindgenOpaqueArray$",
159+
["IntoBytes", "FromBytes", "KnownLayout", "Immutable"],
160+
),
161+
(
162+
r"__BindgenOpaqueArray8$",
163+
["FromBytes", "KnownLayout", "Immutable"],
164+
),
145165
(
146166
r"__sifields__bindgen_ty_(2|3|7)",
147167
["IntoBytes", "FromBytes", "KnownLayout", "Immutable"],

src/starnix/lib/linux_uapi/src/arm.rs

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@
1919
use crate::fscrypt_key_specifier;
2020
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
2121

22+
// SAFETY: The IntoBytes implementation is safe because the array size is a
23+
// multiple of 8, so there is no padding.
24+
unsafe impl IntoBytes for __BindgenOpaqueArray8<[u8; 8usize]> {
25+
fn only_derive_is_allowed_to_implement_this_trait() {}
26+
}
27+
28+
// SAFETY: The IntoBytes implementation is safe because the array size is a
29+
// multiple of 8, so there is no padding.
30+
unsafe impl IntoBytes for __BindgenOpaqueArray8<[u8; 16usize]> {
31+
fn only_derive_is_allowed_to_implement_this_trait() {}
32+
}
33+
34+
// SAFETY: The IntoBytes implementation is safe because the array size is a
35+
// multiple of 8, so there is no padding.
36+
unsafe impl IntoBytes for __BindgenOpaqueArray8<[u8; 144usize]> {
37+
fn only_derive_is_allowed_to_implement_this_trait() {}
38+
}
39+
40+
// SAFETY: The IntoBytes implementation is safe because the array size is a
41+
// multiple of 8, so there is no padding.
42+
unsafe impl IntoBytes for __BindgenOpaqueArray8<[u8; 272usize]> {
43+
fn only_derive_is_allowed_to_implement_this_trait() {}
44+
}
45+
2246
#[repr(C)]
2347
#[derive(
2448
Copy,
@@ -147,6 +171,24 @@ where
147171
}
148172
}
149173
}
174+
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
175+
#[repr(C)]
176+
#[derive(FromBytes, Immutable, IntoBytes, KnownLayout)]
177+
pub struct __BindgenOpaqueArray<T>(pub T);
178+
impl<T: Copy + Default, const N: usize> Default for __BindgenOpaqueArray<[T; N]> {
179+
fn default() -> Self {
180+
Self([<T as Default>::default(); N])
181+
}
182+
}
183+
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
184+
#[repr(C, align(8))]
185+
#[derive(FromBytes, Immutable, KnownLayout)]
186+
pub struct __BindgenOpaqueArray8<T>(pub T);
187+
impl<T: Copy + Default, const N: usize> Default for __BindgenOpaqueArray8<[T; N]> {
188+
fn default() -> Self {
189+
Self([<T as Default>::default(); N])
190+
}
191+
}
150192
#[repr(transparent)]
151193
#[derive(Default, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
152194
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
@@ -10547,7 +10589,7 @@ pub struct io_uring_sqe__bindgen_ty_6 {
1054710589
pub __bindgen_anon_1: __BindgenUnionField<io_uring_sqe__bindgen_ty_6__bindgen_ty_1>,
1054810590
pub optval: __BindgenUnionField<__u64>,
1054910591
pub cmd: __BindgenUnionField<[__u8; 0usize]>,
10550-
pub bindgen_union_field: [u64; 2usize],
10592+
pub bindgen_union_field: __BindgenOpaqueArray8<[u8; 16usize]>,
1055110593
}
1055210594
#[repr(C)]
1055310595
#[derive(Debug, Default, Copy, Clone, IntoBytes, FromBytes, KnownLayout, Immutable)]
@@ -10844,7 +10886,7 @@ pub struct io_uring_buf_ring {
1084410886
pub struct io_uring_buf_ring__bindgen_ty_1 {
1084510887
pub __bindgen_anon_1: __BindgenUnionField<io_uring_buf_ring__bindgen_ty_1__bindgen_ty_1>,
1084610888
pub __bindgen_anon_2: __BindgenUnionField<io_uring_buf_ring__bindgen_ty_1__bindgen_ty_2>,
10847-
pub bindgen_union_field: [u64; 2usize],
10889+
pub bindgen_union_field: __BindgenOpaqueArray8<[u8; 16usize]>,
1084810890
}
1084910891
#[repr(C)]
1085010892
#[derive(Debug, Default, Copy, Clone, IntoBytes, FromBytes, KnownLayout, Immutable)]
@@ -11770,41 +11812,27 @@ impl Default for group_source_req {
1177011812
}
1177111813
#[repr(C)]
1177211814
#[repr(align(4))]
11815+
#[derive(Debug, Default, Copy, Clone, IntoBytes, FromBytes, KnownLayout, Immutable)]
1177311816
pub struct group_filter {
11774-
pub _bindgen_opaque_blob: [u32; 67usize],
11817+
pub _bindgen_opaque_blob: __BindgenOpaqueArray<[u32; 67usize]>,
1177511818
}
1177611819
#[repr(C)]
1177711820
#[repr(align(4))]
11778-
pub struct group_filter__bindgen_ty_1 {
11779-
pub _bindgen_opaque_blob: [u32; 67usize],
11821+
#[derive(Copy, Clone)]
11822+
pub union group_filter__bindgen_ty_1 {
11823+
pub _bindgen_opaque_blob: __BindgenOpaqueArray<[u32; 67usize]>,
1178011824
}
1178111825
#[repr(C)]
1178211826
#[repr(align(4))]
11827+
#[derive(Debug, Default, Copy, Clone, IntoBytes, FromBytes, KnownLayout, Immutable)]
1178311828
pub struct group_filter__bindgen_ty_1__bindgen_ty_1 {
11784-
pub _bindgen_opaque_blob: [u32; 67usize],
11785-
}
11786-
impl Default for group_filter__bindgen_ty_1__bindgen_ty_1 {
11787-
fn default() -> Self {
11788-
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
11789-
unsafe {
11790-
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
11791-
s.assume_init()
11792-
}
11793-
}
11829+
pub _bindgen_opaque_blob: __BindgenOpaqueArray<[u32; 67usize]>,
1179411830
}
1179511831
#[repr(C)]
1179611832
#[repr(align(4))]
11833+
#[derive(Debug, Default, Copy, Clone, IntoBytes, FromBytes, KnownLayout, Immutable)]
1179711834
pub struct group_filter__bindgen_ty_1__bindgen_ty_2 {
11798-
pub _bindgen_opaque_blob: [u32; 35usize],
11799-
}
11800-
impl Default for group_filter__bindgen_ty_1__bindgen_ty_2 {
11801-
fn default() -> Self {
11802-
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
11803-
unsafe {
11804-
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
11805-
s.assume_init()
11806-
}
11807-
}
11835+
pub _bindgen_opaque_blob: __BindgenOpaqueArray<[u32; 35usize]>,
1180811836
}
1180911837
impl Default for group_filter__bindgen_ty_1 {
1181011838
fn default() -> Self {
@@ -11815,15 +11843,6 @@ impl Default for group_filter__bindgen_ty_1 {
1181511843
}
1181611844
}
1181711845
}
11818-
impl Default for group_filter {
11819-
fn default() -> Self {
11820-
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
11821-
unsafe {
11822-
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
11823-
s.assume_init()
11824-
}
11825-
}
11826-
}
1182711846
#[repr(C)]
1182811847
#[derive(Debug, Default, Copy, Clone, IntoBytes, FromBytes, KnownLayout, Immutable)]
1182911848
pub struct in_pktinfo {
@@ -19445,7 +19464,7 @@ pub struct fastrpc_ioctl_capability {
1944519464
#[repr(align(8))]
1944619465
#[derive(Debug, Default)]
1944719466
pub struct StdAtomicI64 {
19448-
pub _bindgen_opaque_blob: u64,
19467+
pub _bindgen_opaque_blob: __BindgenOpaqueArray8<[u8; 8usize]>,
1944919468
}
1945019469
#[repr(C)]
1945119470
#[repr(align(4))]
@@ -19457,7 +19476,7 @@ pub struct StdAtomicU32 {
1945719476
#[repr(align(8))]
1945819477
#[derive(Debug, Default)]
1945919478
pub struct StdAtomicU64 {
19460-
pub _bindgen_opaque_blob: u64,
19479+
pub _bindgen_opaque_blob: __BindgenOpaqueArray8<[u8; 8usize]>,
1946119480
}
1946219481
#[repr(C)]
1946319482
#[derive(Debug, Default)]

src/starnix/lib/linux_uapi/src/arm64.rs

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@
1919
use crate::fscrypt_key_specifier;
2020
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
2121

22+
// SAFETY: The IntoBytes implementation is safe because the array size is a
23+
// multiple of 8, so there is no padding.
24+
unsafe impl IntoBytes for __BindgenOpaqueArray8<[u8; 8usize]> {
25+
fn only_derive_is_allowed_to_implement_this_trait() {}
26+
}
27+
28+
// SAFETY: The IntoBytes implementation is safe because the array size is a
29+
// multiple of 8, so there is no padding.
30+
unsafe impl IntoBytes for __BindgenOpaqueArray8<[u8; 16usize]> {
31+
fn only_derive_is_allowed_to_implement_this_trait() {}
32+
}
33+
34+
// SAFETY: The IntoBytes implementation is safe because the array size is a
35+
// multiple of 8, so there is no padding.
36+
unsafe impl IntoBytes for __BindgenOpaqueArray8<[u8; 144usize]> {
37+
fn only_derive_is_allowed_to_implement_this_trait() {}
38+
}
39+
40+
// SAFETY: The IntoBytes implementation is safe because the array size is a
41+
// multiple of 8, so there is no padding.
42+
unsafe impl IntoBytes for __BindgenOpaqueArray8<[u8; 272usize]> {
43+
fn only_derive_is_allowed_to_implement_this_trait() {}
44+
}
45+
2246
#[repr(transparent)]
2347
#[derive(
2448
Debug,
@@ -272,6 +296,15 @@ where
272296
}
273297
}
274298
}
299+
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
300+
#[repr(C, align(8))]
301+
#[derive(FromBytes, Immutable, KnownLayout)]
302+
pub struct __BindgenOpaqueArray8<T>(pub T);
303+
impl<T: Copy + Default, const N: usize> Default for __BindgenOpaqueArray8<[T; N]> {
304+
fn default() -> Self {
305+
Self([<T as Default>::default(); N])
306+
}
307+
}
275308
#[repr(transparent)]
276309
#[derive(Default, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
277310
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>, [T; 0]);
@@ -10714,7 +10747,7 @@ pub struct io_uring_sqe__bindgen_ty_6 {
1071410747
pub __bindgen_anon_1: __BindgenUnionField<io_uring_sqe__bindgen_ty_6__bindgen_ty_1>,
1071510748
pub optval: __BindgenUnionField<__u64>,
1071610749
pub cmd: __BindgenUnionField<[__u8; 0usize]>,
10717-
pub bindgen_union_field: [u64; 2usize],
10750+
pub bindgen_union_field: __BindgenOpaqueArray8<[u8; 16usize]>,
1071810751
}
1071910752
#[repr(C)]
1072010753
#[derive(Debug, Default, Copy, Clone, IntoBytes, FromBytes, KnownLayout, Immutable)]
@@ -11011,7 +11044,7 @@ pub struct io_uring_buf_ring {
1101111044
pub struct io_uring_buf_ring__bindgen_ty_1 {
1101211045
pub __bindgen_anon_1: __BindgenUnionField<io_uring_buf_ring__bindgen_ty_1__bindgen_ty_1>,
1101311046
pub __bindgen_anon_2: __BindgenUnionField<io_uring_buf_ring__bindgen_ty_1__bindgen_ty_2>,
11014-
pub bindgen_union_field: [u64; 2usize],
11047+
pub bindgen_union_field: __BindgenOpaqueArray8<[u8; 16usize]>,
1101511048
}
1101611049
#[repr(C)]
1101711050
#[derive(Debug, Default, Copy, Clone, IntoBytes, FromBytes, KnownLayout, Immutable)]
@@ -11939,33 +11972,27 @@ impl Default for group_source_req {
1193911972
}
1194011973
#[repr(C)]
1194111974
#[repr(align(8))]
11975+
#[derive(Debug, Default, Copy, Clone, IntoBytes, FromBytes, KnownLayout, Immutable)]
1194211976
pub struct group_filter {
11943-
pub _bindgen_opaque_blob: [u64; 34usize],
11977+
pub _bindgen_opaque_blob: __BindgenOpaqueArray8<[u8; 272usize]>,
1194411978
}
1194511979
#[repr(C)]
1194611980
#[repr(align(8))]
11947-
pub struct group_filter__bindgen_ty_1 {
11948-
pub _bindgen_opaque_blob: [u64; 34usize],
11981+
#[derive(Copy, Clone)]
11982+
pub union group_filter__bindgen_ty_1 {
11983+
pub _bindgen_opaque_blob: __BindgenOpaqueArray8<[u8; 272usize]>,
1194911984
}
1195011985
#[repr(C)]
1195111986
#[repr(align(8))]
11987+
#[derive(Debug, Default, Copy, Clone, IntoBytes, FromBytes, KnownLayout, Immutable)]
1195211988
pub struct group_filter__bindgen_ty_1__bindgen_ty_1 {
11953-
pub _bindgen_opaque_blob: [u64; 34usize],
11954-
}
11955-
impl Default for group_filter__bindgen_ty_1__bindgen_ty_1 {
11956-
fn default() -> Self {
11957-
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
11958-
unsafe {
11959-
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
11960-
s.assume_init()
11961-
}
11962-
}
11989+
pub _bindgen_opaque_blob: __BindgenOpaqueArray8<[u8; 272usize]>,
1196311990
}
1196411991
#[repr(C)]
1196511992
#[repr(align(8))]
1196611993
#[derive(Debug, Default, Copy, Clone, IntoBytes, FromBytes, KnownLayout, Immutable)]
1196711994
pub struct group_filter__bindgen_ty_1__bindgen_ty_2 {
11968-
pub _bindgen_opaque_blob: [u64; 18usize],
11995+
pub _bindgen_opaque_blob: __BindgenOpaqueArray8<[u8; 144usize]>,
1196911996
}
1197011997
impl Default for group_filter__bindgen_ty_1 {
1197111998
fn default() -> Self {
@@ -11976,15 +12003,6 @@ impl Default for group_filter__bindgen_ty_1 {
1197612003
}
1197712004
}
1197812005
}
11979-
impl Default for group_filter {
11980-
fn default() -> Self {
11981-
let mut s = ::std::mem::MaybeUninit::<Self>::uninit();
11982-
unsafe {
11983-
::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
11984-
s.assume_init()
11985-
}
11986-
}
11987-
}
1198812006
#[repr(C)]
1198912007
#[derive(Debug, Default, Copy, Clone, IntoBytes, FromBytes, KnownLayout, Immutable)]
1199012008
pub struct in_pktinfo {
@@ -16277,7 +16295,7 @@ pub struct seccomp_notif_addfd {
1627716295
#[repr(align(8))]
1627816296
#[derive(Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
1627916297
pub union sigval {
16280-
pub _bindgen_opaque_blob: u64,
16298+
pub _bindgen_opaque_blob: __BindgenOpaqueArray8<[u8; 8usize]>,
1628116299
}
1628216300
impl Default for sigval {
1628316301
fn default() -> Self {
@@ -22922,7 +22940,7 @@ pub struct fastrpc_ioctl_capability {
2292222940
#[repr(align(8))]
2292322941
#[derive(Debug, Default)]
2292422942
pub struct StdAtomicI64 {
22925-
pub _bindgen_opaque_blob: u64,
22943+
pub _bindgen_opaque_blob: __BindgenOpaqueArray8<[u8; 8usize]>,
2292622944
}
2292722945
#[repr(C)]
2292822946
#[repr(align(4))]
@@ -22934,7 +22952,7 @@ pub struct StdAtomicU32 {
2293422952
#[repr(align(8))]
2293522953
#[derive(Debug, Default)]
2293622954
pub struct StdAtomicU64 {
22937-
pub _bindgen_opaque_blob: u64,
22955+
pub _bindgen_opaque_blob: __BindgenOpaqueArray8<[u8; 8usize]>,
2293822956
}
2293922957
#[repr(C)]
2294022958
#[derive(Debug, Default)]

src/starnix/lib/linux_uapi/src/arm_manual.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ impl From<crate::arch32::sigval> for crate::sigval {
250250
fn from(sigval: crate::arch32::sigval) -> Self {
251251
// SAFETY: This is safe because the union has a single field.
252252
let bindgen_opaque_blob = unsafe { sigval._bindgen_opaque_blob };
253-
Self { _bindgen_opaque_blob: bindgen_opaque_blob.into() }
253+
let bindgen_opaque_blob_as_u64: u64 = bindgen_opaque_blob.into();
254+
Self { _bindgen_opaque_blob: zerocopy::transmute!(bindgen_opaque_blob_as_u64) }
254255
}
255256
}
256257

@@ -259,7 +260,8 @@ impl TryFrom<crate::sigval> for crate::arch32::sigval {
259260
fn try_from(sigval: crate::sigval) -> Result<Self, ()> {
260261
// SAFETY: This is safe because the union has a single field.
261262
let bindgen_opaque_blob = unsafe { sigval._bindgen_opaque_blob };
262-
Ok(Self { _bindgen_opaque_blob: bindgen_opaque_blob.try_into().map_err(|_| ())? })
263+
let bindgen_opaque_blob_as_u64: u64 = zerocopy::transmute!(bindgen_opaque_blob);
264+
Ok(Self { _bindgen_opaque_blob: bindgen_opaque_blob_as_u64.try_into().map_err(|_| ())? })
263265
}
264266
}
265267

0 commit comments

Comments
 (0)