Skip to content

Instantly share code, notes, and snippets.

@bjc
Created July 25, 2019 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjc/ade92539bee7ffe09fb72c6432f1b79a to your computer and use it in GitHub Desktop.
Save bjc/ade92539bee7ffe09fb72c6432f1b79a to your computer and use it in GitHub Desktop.
#[derive(Copy, Clone, Debug, Default, Deserialize, Serialize)]
#[repr(C, packed)]
pub struct USBDeviceDescriptor {
pub b_length: u8,
pub b_descriptor_type: USBDescriptor,
pub bcd_usb: u16,
pub b_device_class: u8,
pub b_device_sub_class: u8,
pub b_device_protocol: u8,
pub b_max_packet_size: u8,
pub id_vendor: u16,
pub id_product: u16,
pub bcd_device: u16,
pub i_manufacturer: u8,
pub i_product: u8,
pub i_serial_number: u8,
pub b_num_configurations: u8,
}
// addr: 0x20007774
let tmp: USBDeviceDescriptor = Default::default();
// addr: 0x20007788
let vol_descr = ::vcell::VolatileCell::new(tmp);
self.control_req(
0,
0,
BMRequestType::get_descr(),
USBRequest::GetDescriptor,
WValue::from((0, USBDescriptor::Device as u8)),
0,
Some(DataBuf::from(&vol_descr)),
)?;
let desc = vol_descr.get();
info!(
" -- len: {}, ver: {:04x}, bMaxPacketSize: {}, bNumConfigurations: {}",
desc.b_length, desc.bcd_usb, desc.b_max_packet_size, desc.b_num_configurations
);
warning: borrow of packed field is unsafe and requires unsafe function or block (error E0133)
--> src/lib.rs:418:28
|
418 | desc.b_length, desc.bcd_usb, desc.b_max_packet_size, desc.b_num_configurations
| ^^^^^^^^^^^^
|
= note: #[warn(safe_packed_borrows)] on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043>
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment