Skip to content

Commit 7539fc4

Browse files
Petre Eftimepetreeftime
Petre Eftime
authored andcommitted
regenerate driver-bindings with Default
Use latest version of bindgen (0.62) and add Default to implementations. This fixes `clippy::derivable_impls` warning and rust-lang/rust-bindgen#1651. Signed-off-by: Petre Eftime <[email protected]>
1 parent 11633c0 commit 7539fc4

File tree

4 files changed

+20
-37
lines changed

4 files changed

+20
-37
lines changed

driver-bindings/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Supported Linux versions:
3737
Generate bindings for a new Linux version:
3838

3939
```
40-
bindgen --allowlist-type "ne_.*" --allowlist-var "NE_ERR_.*" -o bindings.rs \
40+
bindgen --with-derive-default --allowlist-type "ne_.*" --allowlist-var "NE_ERR_.*" -o bindings.rs \
4141
/usr/src/kernels/$(uname -r)/include/uapi/linux/nitro_enclaves.h -- \
4242
-fretain-comments-from-system-headers -fparse-all-comments
4343
```

driver-bindings/src/bindings.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* automatically generated by rust-bindgen 0.59.2 */
1+
/* automatically generated by rust-bindgen 0.62.0 */
22

33
pub const NE_ERR_VCPU_ALREADY_USED: u32 = 256;
44
pub const NE_ERR_VCPU_NOT_IN_CPU_POOL: u32 = 257;
@@ -28,13 +28,15 @@ pub type __u64 = ::std::os::raw::c_ulonglong;
2828
#[doc = " @memory_offset:\tOffset in enclave memory where to start placing the"]
2929
#[doc = "\t\t\tenclave image (out)."]
3030
#[repr(C)]
31-
#[derive(Debug, Copy, Clone)]
31+
#[derive(Debug, Default, Copy, Clone)]
3232
pub struct ne_image_load_info {
3333
pub flags: __u64,
3434
pub memory_offset: __u64,
3535
}
3636
#[test]
3737
fn bindgen_test_layout_ne_image_load_info() {
38+
const UNINIT: ::std::mem::MaybeUninit<ne_image_load_info> = ::std::mem::MaybeUninit::uninit();
39+
let ptr = UNINIT.as_ptr();
3840
assert_eq!(
3941
::std::mem::size_of::<ne_image_load_info>(),
4042
16usize,
@@ -46,7 +48,7 @@ fn bindgen_test_layout_ne_image_load_info() {
4648
concat!("Alignment of ", stringify!(ne_image_load_info))
4749
);
4850
assert_eq!(
49-
unsafe { &(*(::std::ptr::null::<ne_image_load_info>())).flags as *const _ as usize },
51+
unsafe { ::std::ptr::addr_of!((*ptr).flags) as usize - ptr as usize },
5052
0usize,
5153
concat!(
5254
"Offset of field: ",
@@ -56,9 +58,7 @@ fn bindgen_test_layout_ne_image_load_info() {
5658
)
5759
);
5860
assert_eq!(
59-
unsafe {
60-
&(*(::std::ptr::null::<ne_image_load_info>())).memory_offset as *const _ as usize
61-
},
61+
unsafe { ::std::ptr::addr_of!((*ptr).memory_offset) as usize - ptr as usize },
6262
8usize,
6363
concat!(
6464
"Offset of field: ",
@@ -75,14 +75,17 @@ fn bindgen_test_layout_ne_image_load_info() {
7575
#[doc = " @userspace_addr:\tThe start address of the userspace allocated memory of"]
7676
#[doc = "\t\t\tthe memory region to set for an enclave (in)."]
7777
#[repr(C)]
78-
#[derive(Debug, Copy, Clone)]
78+
#[derive(Debug, Default, Copy, Clone)]
7979
pub struct ne_user_memory_region {
8080
pub flags: __u64,
8181
pub memory_size: __u64,
8282
pub userspace_addr: __u64,
8383
}
8484
#[test]
8585
fn bindgen_test_layout_ne_user_memory_region() {
86+
const UNINIT: ::std::mem::MaybeUninit<ne_user_memory_region> =
87+
::std::mem::MaybeUninit::uninit();
88+
let ptr = UNINIT.as_ptr();
8689
assert_eq!(
8790
::std::mem::size_of::<ne_user_memory_region>(),
8891
24usize,
@@ -94,7 +97,7 @@ fn bindgen_test_layout_ne_user_memory_region() {
9497
concat!("Alignment of ", stringify!(ne_user_memory_region))
9598
);
9699
assert_eq!(
97-
unsafe { &(*(::std::ptr::null::<ne_user_memory_region>())).flags as *const _ as usize },
100+
unsafe { ::std::ptr::addr_of!((*ptr).flags) as usize - ptr as usize },
98101
0usize,
99102
concat!(
100103
"Offset of field: ",
@@ -104,9 +107,7 @@ fn bindgen_test_layout_ne_user_memory_region() {
104107
)
105108
);
106109
assert_eq!(
107-
unsafe {
108-
&(*(::std::ptr::null::<ne_user_memory_region>())).memory_size as *const _ as usize
109-
},
110+
unsafe { ::std::ptr::addr_of!((*ptr).memory_size) as usize - ptr as usize },
110111
8usize,
111112
concat!(
112113
"Offset of field: ",
@@ -116,9 +117,7 @@ fn bindgen_test_layout_ne_user_memory_region() {
116117
)
117118
);
118119
assert_eq!(
119-
unsafe {
120-
&(*(::std::ptr::null::<ne_user_memory_region>())).userspace_addr as *const _ as usize
121-
},
120+
unsafe { ::std::ptr::addr_of!((*ptr).userspace_addr) as usize - ptr as usize },
122121
16usize,
123122
concat!(
124123
"Offset of field: ",
@@ -134,13 +133,16 @@ fn bindgen_test_layout_ne_user_memory_region() {
134133
#[doc = "\t\t\tinput, the CID is autogenerated by the hypervisor and"]
135134
#[doc = "\t\t\treturned back as output by the driver (in / out)."]
136135
#[repr(C)]
137-
#[derive(Debug, Copy, Clone)]
136+
#[derive(Debug, Default, Copy, Clone)]
138137
pub struct ne_enclave_start_info {
139138
pub flags: __u64,
140139
pub enclave_cid: __u64,
141140
}
142141
#[test]
143142
fn bindgen_test_layout_ne_enclave_start_info() {
143+
const UNINIT: ::std::mem::MaybeUninit<ne_enclave_start_info> =
144+
::std::mem::MaybeUninit::uninit();
145+
let ptr = UNINIT.as_ptr();
144146
assert_eq!(
145147
::std::mem::size_of::<ne_enclave_start_info>(),
146148
16usize,
@@ -152,7 +154,7 @@ fn bindgen_test_layout_ne_enclave_start_info() {
152154
concat!("Alignment of ", stringify!(ne_enclave_start_info))
153155
);
154156
assert_eq!(
155-
unsafe { &(*(::std::ptr::null::<ne_enclave_start_info>())).flags as *const _ as usize },
157+
unsafe { ::std::ptr::addr_of!((*ptr).flags) as usize - ptr as usize },
156158
0usize,
157159
concat!(
158160
"Offset of field: ",
@@ -162,9 +164,7 @@ fn bindgen_test_layout_ne_enclave_start_info() {
162164
)
163165
);
164166
assert_eq!(
165-
unsafe {
166-
&(*(::std::ptr::null::<ne_enclave_start_info>())).enclave_cid as *const _ as usize
167-
},
167+
unsafe { ::std::ptr::addr_of!((*ptr).enclave_cid) as usize - ptr as usize },
168168
8usize,
169169
concat!(
170170
"Offset of field: ",

driver-bindings/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,5 @@
77
#![allow(missing_docs)]
88
#![allow(non_camel_case_types)]
99

10-
// Keep this until https://github.com/rust-lang/rust-bindgen/issues/1651 is fixed.
11-
#[cfg_attr(test, allow(deref_nullptr))]
1210
mod bindings;
1311
pub use self::bindings::*;
14-
mod wrappers;
15-
pub use self::wrappers::*;

driver-bindings/src/wrappers.rs

-13
This file was deleted.

0 commit comments

Comments
 (0)