From c3c2f34c2f89156769d37bc8b450ace9ff7fdbe9 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Tue, 30 Aug 2022 16:18:51 +0000 Subject: [PATCH 1/5] virtio-bindings: regenerate with bindgen 0.60.1 Signed-off-by: Alyssa Ross --- crates/virtio-bindings/CONTRIBUTING.md | 4 +- crates/virtio-bindings/src/virtio_blk.rs | 958 +++++++++++++--------- crates/virtio-bindings/src/virtio_net.rs | 817 +++++++++++------- crates/virtio-bindings/src/virtio_ring.rs | 540 +++++++----- 4 files changed, 1426 insertions(+), 893 deletions(-) diff --git a/crates/virtio-bindings/CONTRIBUTING.md b/crates/virtio-bindings/CONTRIBUTING.md index 18c4653..1b3da2f 100644 --- a/crates/virtio-bindings/CONTRIBUTING.md +++ b/crates/virtio-bindings/CONTRIBUTING.md @@ -4,9 +4,9 @@ ### Bindgen The bindings are currently generated using -[bindgen](https://crates.io/crates/bindgen) version 0.49.0: +[bindgen](https://crates.io/crates/bindgen) version 0.60.1: ```bash -cargo install bindgen --vers 0.49.0 +cargo install bindgen --vers 0.60.1 ``` ### Linux Kernel diff --git a/crates/virtio-bindings/src/virtio_blk.rs b/crates/virtio-bindings/src/virtio_blk.rs index 80ddab0..94daca3 100644 --- a/crates/virtio-bindings/src/virtio_blk.rs +++ b/crates/virtio-bindings/src/virtio_blk.rs @@ -1,4 +1,4 @@ -/* automatically generated by rust-bindgen */ +/* automatically generated by rust-bindgen 0.60.1 */ pub const __BITS_PER_LONG: u32 = 64; pub const __FD_SETSIZE: u32 = 1024; @@ -83,16 +83,23 @@ fn bindgen_test_layout___kernel_fd_set() { 8usize, concat!("Alignment of ", stringify!(__kernel_fd_set)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__kernel_fd_set>())).fds_bits as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__kernel_fd_set), - "::", - stringify!(fds_bits) - ) - ); + fn test_field_fds_bits() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::<__kernel_fd_set>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fds_bits) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__kernel_fd_set), + "::", + stringify!(fds_bits) + ) + ); + } + test_field_fds_bits(); } pub type __kernel_sighandler_t = ::std::option::Option; @@ -133,16 +140,23 @@ fn bindgen_test_layout___kernel_fsid_t() { 4usize, concat!("Alignment of ", stringify!(__kernel_fsid_t)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__kernel_fsid_t>())).val as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__kernel_fsid_t), - "::", - stringify!(val) - ) - ); + fn test_field_val() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::<__kernel_fsid_t>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__kernel_fsid_t), + "::", + stringify!(val) + ) + ); + } + test_field_val(); } pub type __kernel_off_t = __kernel_long_t; pub type __kernel_loff_t = ::std::os::raw::c_longlong; @@ -214,45 +228,60 @@ fn bindgen_test_layout_virtio_blk_config_virtio_blk_geometry() { stringify!(virtio_blk_config_virtio_blk_geometry) ) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).cylinders as *const _ - as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config_virtio_blk_geometry), - "::", - stringify!(cylinders) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).heads as *const _ - as usize - }, - 2usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config_virtio_blk_geometry), - "::", - stringify!(heads) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).sectors as *const _ - as usize - }, - 3usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config_virtio_blk_geometry), - "::", - stringify!(sectors) - ) - ); + fn test_field_cylinders() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cylinders) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config_virtio_blk_geometry), + "::", + stringify!(cylinders) + ) + ); + } + test_field_cylinders(); + fn test_field_heads() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).heads) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config_virtio_blk_geometry), + "::", + stringify!(heads) + ) + ); + } + test_field_heads(); + fn test_field_sectors() { + assert_eq!( + unsafe { + let uninit = + ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sectors) as usize - ptr as usize + }, + 3usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config_virtio_blk_geometry), + "::", + stringify!(sectors) + ) + ); + } + test_field_sectors(); } #[test] fn bindgen_test_layout_virtio_blk_config() { @@ -266,215 +295,329 @@ fn bindgen_test_layout_virtio_blk_config() { 1usize, concat!("Alignment of ", stringify!(virtio_blk_config)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).capacity as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(capacity) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).size_max as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(size_max) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).seg_max as *const _ as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(seg_max) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).geometry as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(geometry) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).blk_size as *const _ as usize }, - 20usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(blk_size) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).physical_block_exp as *const _ as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(physical_block_exp) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).alignment_offset as *const _ as usize - }, - 25usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(alignment_offset) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).min_io_size as *const _ as usize }, - 26usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(min_io_size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).opt_io_size as *const _ as usize }, - 28usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(opt_io_size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).wce as *const _ as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(wce) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).unused as *const _ as usize }, - 33usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(unused) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).num_queues as *const _ as usize }, - 34usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(num_queues) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).max_discard_sectors as *const _ as usize - }, - 36usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(max_discard_sectors) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).max_discard_seg as *const _ as usize - }, - 40usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(max_discard_seg) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).discard_sector_alignment as *const _ - as usize - }, - 44usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(discard_sector_alignment) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).max_write_zeroes_sectors as *const _ - as usize - }, - 48usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(max_write_zeroes_sectors) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).max_write_zeroes_seg as *const _ as usize - }, - 52usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(max_write_zeroes_seg) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).write_zeroes_may_unmap as *const _ - as usize - }, - 56usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(write_zeroes_may_unmap) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).unused1 as *const _ as usize }, - 57usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_config), - "::", - stringify!(unused1) - ) - ); + fn test_field_capacity() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).capacity) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(capacity) + ) + ); + } + test_field_capacity(); + fn test_field_size_max() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).size_max) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(size_max) + ) + ); + } + test_field_size_max(); + fn test_field_seg_max() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).seg_max) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(seg_max) + ) + ); + } + test_field_seg_max(); + fn test_field_geometry() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).geometry) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(geometry) + ) + ); + } + test_field_geometry(); + fn test_field_blk_size() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).blk_size) as usize - ptr as usize + }, + 20usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(blk_size) + ) + ); + } + test_field_blk_size(); + fn test_field_physical_block_exp() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).physical_block_exp) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(physical_block_exp) + ) + ); + } + test_field_physical_block_exp(); + fn test_field_alignment_offset() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).alignment_offset) as usize - ptr as usize + }, + 25usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(alignment_offset) + ) + ); + } + test_field_alignment_offset(); + fn test_field_min_io_size() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).min_io_size) as usize - ptr as usize + }, + 26usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(min_io_size) + ) + ); + } + test_field_min_io_size(); + fn test_field_opt_io_size() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).opt_io_size) as usize - ptr as usize + }, + 28usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(opt_io_size) + ) + ); + } + test_field_opt_io_size(); + fn test_field_wce() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).wce) as usize - ptr as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(wce) + ) + ); + } + test_field_wce(); + fn test_field_unused() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).unused) as usize - ptr as usize + }, + 33usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(unused) + ) + ); + } + test_field_unused(); + fn test_field_num_queues() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).num_queues) as usize - ptr as usize + }, + 34usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(num_queues) + ) + ); + } + test_field_num_queues(); + fn test_field_max_discard_sectors() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_discard_sectors) as usize - ptr as usize + }, + 36usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(max_discard_sectors) + ) + ); + } + test_field_max_discard_sectors(); + fn test_field_max_discard_seg() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_discard_seg) as usize - ptr as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(max_discard_seg) + ) + ); + } + test_field_max_discard_seg(); + fn test_field_discard_sector_alignment() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).discard_sector_alignment) as usize - ptr as usize + }, + 44usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(discard_sector_alignment) + ) + ); + } + test_field_discard_sector_alignment(); + fn test_field_max_write_zeroes_sectors() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_write_zeroes_sectors) as usize - ptr as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(max_write_zeroes_sectors) + ) + ); + } + test_field_max_write_zeroes_sectors(); + fn test_field_max_write_zeroes_seg() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_write_zeroes_seg) as usize - ptr as usize + }, + 52usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(max_write_zeroes_seg) + ) + ); + } + test_field_max_write_zeroes_seg(); + fn test_field_write_zeroes_may_unmap() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).write_zeroes_may_unmap) as usize - ptr as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(write_zeroes_may_unmap) + ) + ); + } + test_field_write_zeroes_may_unmap(); + fn test_field_unused1() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).unused1) as usize - ptr as usize + }, + 57usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_config), + "::", + stringify!(unused1) + ) + ); + } + test_field_unused1(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialEq)] @@ -495,36 +638,57 @@ fn bindgen_test_layout_virtio_blk_outhdr() { 8usize, concat!("Alignment of ", stringify!(virtio_blk_outhdr)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).type_ as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_outhdr), - "::", - stringify!(type_) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).ioprio as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_outhdr), - "::", - stringify!(ioprio) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).sector as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_outhdr), - "::", - stringify!(sector) - ) - ); + fn test_field_type() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).type_) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_outhdr), + "::", + stringify!(type_) + ) + ); + } + test_field_type(); + fn test_field_ioprio() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).ioprio) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_outhdr), + "::", + stringify!(ioprio) + ) + ); + } + test_field_ioprio(); + fn test_field_sector() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sector) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_outhdr), + "::", + stringify!(sector) + ) + ); + } + test_field_sector(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialEq)] @@ -545,43 +709,57 @@ fn bindgen_test_layout_virtio_blk_discard_write_zeroes() { 8usize, concat!("Alignment of ", stringify!(virtio_blk_discard_write_zeroes)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).sector as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_discard_write_zeroes), - "::", - stringify!(sector) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).num_sectors as *const _ - as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_discard_write_zeroes), - "::", - stringify!(num_sectors) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).flags as *const _ as usize - }, - 12usize, - concat!( - "Offset of field: ", - stringify!(virtio_blk_discard_write_zeroes), - "::", - stringify!(flags) - ) - ); + fn test_field_sector() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sector) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_discard_write_zeroes), + "::", + stringify!(sector) + ) + ); + } + test_field_sector(); + fn test_field_num_sectors() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).num_sectors) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_discard_write_zeroes), + "::", + stringify!(num_sectors) + ) + ); + } + test_field_num_sectors(); + fn test_field_flags() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flags) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(virtio_blk_discard_write_zeroes), + "::", + stringify!(flags) + ) + ); + } + test_field_flags(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialEq)] @@ -603,44 +781,72 @@ fn bindgen_test_layout_virtio_scsi_inhdr() { 4usize, concat!("Alignment of ", stringify!(virtio_scsi_inhdr)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).errors as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(virtio_scsi_inhdr), - "::", - stringify!(errors) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).data_len as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(virtio_scsi_inhdr), - "::", - stringify!(data_len) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).sense_len as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(virtio_scsi_inhdr), - "::", - stringify!(sense_len) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).residual as *const _ as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(virtio_scsi_inhdr), - "::", - stringify!(residual) - ) - ); + fn test_field_errors() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).errors) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(virtio_scsi_inhdr), + "::", + stringify!(errors) + ) + ); + } + test_field_errors(); + fn test_field_data_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).data_len) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(virtio_scsi_inhdr), + "::", + stringify!(data_len) + ) + ); + } + test_field_data_len(); + fn test_field_sense_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).sense_len) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(virtio_scsi_inhdr), + "::", + stringify!(sense_len) + ) + ); + } + test_field_sense_len(); + fn test_field_residual() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).residual) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(virtio_scsi_inhdr), + "::", + stringify!(residual) + ) + ); + } + test_field_residual(); } diff --git a/crates/virtio-bindings/src/virtio_net.rs b/crates/virtio-bindings/src/virtio_net.rs index c788791..479392e 100644 --- a/crates/virtio-bindings/src/virtio_net.rs +++ b/crates/virtio-bindings/src/virtio_net.rs @@ -1,20 +1,20 @@ -/* automatically generated by rust-bindgen */ +/* automatically generated by rust-bindgen 0.60.1 */ #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); impl __IncompleteArrayField { #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { __IncompleteArrayField(::std::marker::PhantomData, []) } #[inline] - pub unsafe fn as_ptr(&self) -> *const T { - ::std::mem::transmute(self) + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T } #[inline] - pub unsafe fn as_mut_ptr(&mut self) -> *mut T { - ::std::mem::transmute(self) + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { @@ -30,12 +30,6 @@ impl ::std::fmt::Debug for __IncompleteArrayField { fmt.write_str("__IncompleteArrayField") } } -impl ::std::clone::Clone for __IncompleteArrayField { - #[inline] - fn clone(&self) -> Self { - Self::new() - } -} pub const __BITS_PER_LONG: u32 = 64; pub const __FD_SETSIZE: u32 = 1024; pub const VIRTIO_ID_NET: u32 = 1; @@ -250,16 +244,23 @@ fn bindgen_test_layout___kernel_fd_set() { 8usize, concat!("Alignment of ", stringify!(__kernel_fd_set)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__kernel_fd_set>())).fds_bits as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__kernel_fd_set), - "::", - stringify!(fds_bits) - ) - ); + fn test_field_fds_bits() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::<__kernel_fd_set>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fds_bits) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__kernel_fd_set), + "::", + stringify!(fds_bits) + ) + ); + } + test_field_fds_bits(); } pub type __kernel_sighandler_t = ::std::option::Option; @@ -300,16 +301,23 @@ fn bindgen_test_layout___kernel_fsid_t() { 4usize, concat!("Alignment of ", stringify!(__kernel_fsid_t)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__kernel_fsid_t>())).val as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__kernel_fsid_t), - "::", - stringify!(val) - ) - ); + fn test_field_val() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::<__kernel_fsid_t>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__kernel_fsid_t), + "::", + stringify!(val) + ) + ); + } + test_field_val(); } pub type __kernel_off_t = __kernel_long_t; pub type __kernel_loff_t = ::std::os::raw::c_longlong; @@ -352,36 +360,57 @@ fn bindgen_test_layout_ethhdr() { 1usize, concat!("Alignment of ", stringify!(ethhdr)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).h_dest as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(ethhdr), - "::", - stringify!(h_dest) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).h_source as *const _ as usize }, - 6usize, - concat!( - "Offset of field: ", - stringify!(ethhdr), - "::", - stringify!(h_source) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).h_proto as *const _ as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(ethhdr), - "::", - stringify!(h_proto) - ) - ); + fn test_field_h_dest() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).h_dest) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(ethhdr), + "::", + stringify!(h_dest) + ) + ); + } + test_field_h_dest(); + fn test_field_h_source() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).h_source) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(ethhdr), + "::", + stringify!(h_source) + ) + ); + } + test_field_h_source(); + fn test_field_h_proto() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).h_proto) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(ethhdr), + "::", + stringify!(h_proto) + ) + ); + } + test_field_h_proto(); } #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone, PartialEq)] @@ -405,68 +434,108 @@ fn bindgen_test_layout_virtio_net_config() { 1usize, concat!("Alignment of ", stringify!(virtio_net_config)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).mac as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_config), - "::", - stringify!(mac) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).status as *const _ as usize }, - 6usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_config), - "::", - stringify!(status) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).max_virtqueue_pairs as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_config), - "::", - stringify!(max_virtqueue_pairs) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).mtu as *const _ as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_config), - "::", - stringify!(mtu) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).speed as *const _ as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_config), - "::", - stringify!(speed) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).duplex as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_config), - "::", - stringify!(duplex) - ) - ); + fn test_field_mac() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mac) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_config), + "::", + stringify!(mac) + ) + ); + } + test_field_mac(); + fn test_field_status() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).status) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_config), + "::", + stringify!(status) + ) + ); + } + test_field_status(); + fn test_field_max_virtqueue_pairs() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).max_virtqueue_pairs) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_config), + "::", + stringify!(max_virtqueue_pairs) + ) + ); + } + test_field_max_virtqueue_pairs(); + fn test_field_mtu() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).mtu) as usize - ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_config), + "::", + stringify!(mtu) + ) + ); + } + test_field_mtu(); + fn test_field_speed() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).speed) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_config), + "::", + stringify!(speed) + ) + ); + } + test_field_speed(); + fn test_field_duplex() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).duplex) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_config), + "::", + stringify!(duplex) + ) + ); + } + test_field_duplex(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialEq)] @@ -491,76 +560,125 @@ fn bindgen_test_layout_virtio_net_hdr_v1() { 2usize, concat!("Alignment of ", stringify!(virtio_net_hdr_v1)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).flags as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr_v1), - "::", - stringify!(flags) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).gso_type as *const _ as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr_v1), - "::", - stringify!(gso_type) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).hdr_len as *const _ as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr_v1), - "::", - stringify!(hdr_len) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).gso_size as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr_v1), - "::", - stringify!(gso_size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).csum_start as *const _ as usize }, - 6usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr_v1), - "::", - stringify!(csum_start) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).csum_offset as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr_v1), - "::", - stringify!(csum_offset) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).num_buffers as *const _ as usize }, - 10usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr_v1), - "::", - stringify!(num_buffers) - ) - ); + fn test_field_flags() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flags) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr_v1), + "::", + stringify!(flags) + ) + ); + } + test_field_flags(); + fn test_field_gso_type() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).gso_type) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr_v1), + "::", + stringify!(gso_type) + ) + ); + } + test_field_gso_type(); + fn test_field_hdr_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hdr_len) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr_v1), + "::", + stringify!(hdr_len) + ) + ); + } + test_field_hdr_len(); + fn test_field_gso_size() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).gso_size) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr_v1), + "::", + stringify!(gso_size) + ) + ); + } + test_field_gso_size(); + fn test_field_csum_start() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).csum_start) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr_v1), + "::", + stringify!(csum_start) + ) + ); + } + test_field_csum_start(); + fn test_field_csum_offset() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).csum_offset) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr_v1), + "::", + stringify!(csum_offset) + ) + ); + } + test_field_csum_offset(); + fn test_field_num_buffers() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).num_buffers) as usize - ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr_v1), + "::", + stringify!(num_buffers) + ) + ); + } + test_field_num_buffers(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialEq)] @@ -584,66 +702,108 @@ fn bindgen_test_layout_virtio_net_hdr() { 2usize, concat!("Alignment of ", stringify!(virtio_net_hdr)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).flags as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr), - "::", - stringify!(flags) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).gso_type as *const _ as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr), - "::", - stringify!(gso_type) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).hdr_len as *const _ as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr), - "::", - stringify!(hdr_len) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).gso_size as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr), - "::", - stringify!(gso_size) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).csum_start as *const _ as usize }, - 6usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr), - "::", - stringify!(csum_start) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).csum_offset as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr), - "::", - stringify!(csum_offset) - ) - ); + fn test_field_flags() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flags) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr), + "::", + stringify!(flags) + ) + ); + } + test_field_flags(); + fn test_field_gso_type() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).gso_type) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr), + "::", + stringify!(gso_type) + ) + ); + } + test_field_gso_type(); + fn test_field_hdr_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hdr_len) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr), + "::", + stringify!(hdr_len) + ) + ); + } + test_field_hdr_len(); + fn test_field_gso_size() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).gso_size) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr), + "::", + stringify!(gso_size) + ) + ); + } + test_field_gso_size(); + fn test_field_csum_start() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).csum_start) as usize - ptr as usize + }, + 6usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr), + "::", + stringify!(csum_start) + ) + ); + } + test_field_csum_start(); + fn test_field_csum_offset() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).csum_offset) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr), + "::", + stringify!(csum_offset) + ) + ); + } + test_field_csum_offset(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialEq)] @@ -663,28 +823,40 @@ fn bindgen_test_layout_virtio_net_hdr_mrg_rxbuf() { 2usize, concat!("Alignment of ", stringify!(virtio_net_hdr_mrg_rxbuf)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).hdr as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr_mrg_rxbuf), - "::", - stringify!(hdr) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).num_buffers as *const _ as usize - }, - 10usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_hdr_mrg_rxbuf), - "::", - stringify!(num_buffers) - ) - ); + fn test_field_hdr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).hdr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr_mrg_rxbuf), + "::", + stringify!(hdr) + ) + ); + } + test_field_hdr(); + fn test_field_num_buffers() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).num_buffers) as usize - ptr as usize + }, + 10usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_hdr_mrg_rxbuf), + "::", + stringify!(num_buffers) + ) + ); + } + test_field_num_buffers(); } #[repr(C, packed)] #[derive(Debug, Default, Copy, Clone, PartialEq)] @@ -704,30 +876,43 @@ fn bindgen_test_layout_virtio_net_ctrl_hdr() { 1usize, concat!("Alignment of ", stringify!(virtio_net_ctrl_hdr)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).class as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_ctrl_hdr), - "::", - stringify!(class) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).cmd as *const _ as usize }, - 1usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_ctrl_hdr), - "::", - stringify!(cmd) - ) - ); + fn test_field_class() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).class) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_ctrl_hdr), + "::", + stringify!(class) + ) + ); + } + test_field_class(); + fn test_field_cmd() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).cmd) as usize - ptr as usize + }, + 1usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_ctrl_hdr), + "::", + stringify!(cmd) + ) + ); + } + test_field_cmd(); } pub type virtio_net_ctrl_ack = __u8; #[repr(C, packed)] -#[derive(Default)] pub struct virtio_net_ctrl_mac { pub entries: __virtio32, pub macs: __IncompleteArrayField<[__u8; 6usize]>, @@ -745,6 +930,15 @@ fn bindgen_test_layout_virtio_net_ctrl_mac() { concat!("Alignment of ", stringify!(virtio_net_ctrl_mac)) ); } +impl Default for virtio_net_ctrl_mac { + fn default() -> Self { + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } + } +} #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialEq)] pub struct virtio_net_ctrl_mq { @@ -762,16 +956,21 @@ fn bindgen_test_layout_virtio_net_ctrl_mq() { 2usize, concat!("Alignment of ", stringify!(virtio_net_ctrl_mq)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).virtqueue_pairs as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(virtio_net_ctrl_mq), - "::", - stringify!(virtqueue_pairs) - ) - ); + fn test_field_virtqueue_pairs() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).virtqueue_pairs) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(virtio_net_ctrl_mq), + "::", + stringify!(virtqueue_pairs) + ) + ); + } + test_field_virtqueue_pairs(); } diff --git a/crates/virtio-bindings/src/virtio_ring.rs b/crates/virtio-bindings/src/virtio_ring.rs index 0d51550..13fa409 100644 --- a/crates/virtio-bindings/src/virtio_ring.rs +++ b/crates/virtio-bindings/src/virtio_ring.rs @@ -1,20 +1,20 @@ -/* automatically generated by rust-bindgen */ +/* automatically generated by rust-bindgen 0.60.1 */ #[repr(C)] #[derive(Default)] pub struct __IncompleteArrayField(::std::marker::PhantomData, [T; 0]); impl __IncompleteArrayField { #[inline] - pub fn new() -> Self { + pub const fn new() -> Self { __IncompleteArrayField(::std::marker::PhantomData, []) } #[inline] - pub unsafe fn as_ptr(&self) -> *const T { - ::std::mem::transmute(self) + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T } #[inline] - pub unsafe fn as_mut_ptr(&mut self) -> *mut T { - ::std::mem::transmute(self) + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T } #[inline] pub unsafe fn as_slice(&self, len: usize) -> &[T] { @@ -30,12 +30,6 @@ impl ::std::fmt::Debug for __IncompleteArrayField { fmt.write_str("__IncompleteArrayField") } } -impl ::std::clone::Clone for __IncompleteArrayField { - #[inline] - fn clone(&self) -> Self { - Self::new() - } -} pub const _STDINT_H: u32 = 1; pub const _FEATURES_H: u32 = 1; pub const _DEFAULT_SOURCE: u32 = 1; @@ -190,16 +184,23 @@ fn bindgen_test_layout___fsid_t() { 4usize, concat!("Alignment of ", stringify!(__fsid_t)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__fsid_t>())).__val as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__fsid_t), - "::", - stringify!(__val) - ) - ); + fn test_field___val() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::<__fsid_t>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).__val) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__fsid_t), + "::", + stringify!(__val) + ) + ); + } + test_field___val(); } pub type __clock_t = ::std::os::raw::c_long; pub type __rlim_t = ::std::os::raw::c_ulong; @@ -271,16 +272,23 @@ fn bindgen_test_layout___kernel_fd_set() { 8usize, concat!("Alignment of ", stringify!(__kernel_fd_set)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__kernel_fd_set>())).fds_bits as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__kernel_fd_set), - "::", - stringify!(fds_bits) - ) - ); + fn test_field_fds_bits() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::<__kernel_fd_set>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).fds_bits) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__kernel_fd_set), + "::", + stringify!(fds_bits) + ) + ); + } + test_field_fds_bits(); } pub type __kernel_sighandler_t = ::std::option::Option; @@ -321,16 +329,23 @@ fn bindgen_test_layout___kernel_fsid_t() { 4usize, concat!("Alignment of ", stringify!(__kernel_fsid_t)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::<__kernel_fsid_t>())).val as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(__kernel_fsid_t), - "::", - stringify!(val) - ) - ); + fn test_field_val() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::<__kernel_fsid_t>::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).val) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__kernel_fsid_t), + "::", + stringify!(val) + ) + ); + } + test_field_val(); } pub type __kernel_off_t = __kernel_long_t; pub type __kernel_loff_t = ::std::os::raw::c_longlong; @@ -374,46 +389,74 @@ fn bindgen_test_layout_vring_desc() { 8usize, concat!("Alignment of ", stringify!(vring_desc)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).addr as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(vring_desc), - "::", - stringify!(addr) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).len as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(vring_desc), - "::", - stringify!(len) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).flags as *const _ as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(vring_desc), - "::", - stringify!(flags) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).next as *const _ as usize }, - 14usize, - concat!( - "Offset of field: ", - stringify!(vring_desc), - "::", - stringify!(next) - ) - ); + fn test_field_addr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(vring_desc), + "::", + stringify!(addr) + ) + ); + } + test_field_addr(); + fn test_field_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(vring_desc), + "::", + stringify!(len) + ) + ); + } + test_field_len(); + fn test_field_flags() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flags) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(vring_desc), + "::", + stringify!(flags) + ) + ); + } + test_field_flags(); + fn test_field_next() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize + }, + 14usize, + concat!( + "Offset of field: ", + stringify!(vring_desc), + "::", + stringify!(next) + ) + ); + } + test_field_next(); } #[repr(C)] #[derive(Debug, Default)] @@ -453,26 +496,40 @@ fn bindgen_test_layout_vring_used_elem() { 4usize, concat!("Alignment of ", stringify!(vring_used_elem)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).id as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(vring_used_elem), - "::", - stringify!(id) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).len as *const _ as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(vring_used_elem), - "::", - stringify!(len) - ) - ); + fn test_field_id() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(vring_used_elem), + "::", + stringify!(id) + ) + ); + } + test_field_id(); + fn test_field_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(vring_used_elem), + "::", + stringify!(len) + ) + ); + } + test_field_len(); } #[repr(C)] #[derive(Debug, Default)] @@ -480,7 +537,6 @@ pub struct vring_used { pub flags: __virtio16, pub idx: __virtio16, pub ring: __IncompleteArrayField, - pub __bindgen_align: [u32; 0usize], } #[test] fn bindgen_test_layout_vring_used() { @@ -515,50 +571,82 @@ fn bindgen_test_layout_vring() { 8usize, concat!("Alignment of ", stringify!(vring)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).num as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(vring), - "::", - stringify!(num) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).desc as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(vring), - "::", - stringify!(desc) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).avail as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(vring), - "::", - stringify!(avail) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).used as *const _ as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(vring), - "::", - stringify!(used) - ) - ); + fn test_field_num() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).num) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(vring), + "::", + stringify!(num) + ) + ); + } + test_field_num(); + fn test_field_desc() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).desc) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(vring), + "::", + stringify!(desc) + ) + ); + } + test_field_desc(); + fn test_field_avail() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).avail) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(vring), + "::", + stringify!(avail) + ) + ); + } + test_field_avail(); + fn test_field_used() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).used) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(vring), + "::", + stringify!(used) + ) + ); + } + test_field_used(); } impl Default for vring { fn default() -> Self { - unsafe { ::std::mem::zeroed() } + let mut s = ::std::mem::MaybeUninit::::uninit(); + unsafe { + ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1); + s.assume_init() + } } } #[repr(C)] @@ -579,28 +667,40 @@ fn bindgen_test_layout_vring_packed_desc_event() { 2usize, concat!("Alignment of ", stringify!(vring_packed_desc_event)) ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).off_wrap as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(vring_packed_desc_event), - "::", - stringify!(off_wrap) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).flags as *const _ as usize }, - 2usize, - concat!( - "Offset of field: ", - stringify!(vring_packed_desc_event), - "::", - stringify!(flags) - ) - ); + fn test_field_off_wrap() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).off_wrap) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(vring_packed_desc_event), + "::", + stringify!(off_wrap) + ) + ); + } + test_field_off_wrap(); + fn test_field_flags() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flags) as usize - ptr as usize + }, + 2usize, + concat!( + "Offset of field: ", + stringify!(vring_packed_desc_event), + "::", + stringify!(flags) + ) + ); + } + test_field_flags(); } #[repr(C)] #[derive(Debug, Default, Copy, Clone, PartialEq)] @@ -622,44 +722,72 @@ fn bindgen_test_layout_vring_packed_desc() { 8usize, concat!("Alignment of ", stringify!(vring_packed_desc)) ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).addr as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(vring_packed_desc), - "::", - stringify!(addr) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).len as *const _ as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(vring_packed_desc), - "::", - stringify!(len) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).id as *const _ as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(vring_packed_desc), - "::", - stringify!(id) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).flags as *const _ as usize }, - 14usize, - concat!( - "Offset of field: ", - stringify!(vring_packed_desc), - "::", - stringify!(flags) - ) - ); + fn test_field_addr() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).addr) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(vring_packed_desc), + "::", + stringify!(addr) + ) + ); + } + test_field_addr(); + fn test_field_len() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(vring_packed_desc), + "::", + stringify!(len) + ) + ); + } + test_field_len(); + fn test_field_id() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(vring_packed_desc), + "::", + stringify!(id) + ) + ); + } + test_field_id(); + fn test_field_flags() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).flags) as usize - ptr as usize + }, + 14usize, + concat!( + "Offset of field: ", + stringify!(vring_packed_desc), + "::", + stringify!(flags) + ) + ); + } + test_field_flags(); } -- 2.37.1