From 522414f956cafe20918e4b68e2c24fd8fa36049a Mon Sep 17 00:00:00 2001 From: ko1N Date: Sat, 1 Aug 2020 01:20:08 +0200 Subject: [PATCH] Added compile time struct size checks --- Cargo.toml | 6 ++++-- src/fpga.rs | 8 +++++--- src/ft60x.rs | 4 ++-- src/ft60x/chip.rs | 4 +++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b881c88..e8c8744 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,10 @@ readme = "README.md" crate-type = ["lib", "cdylib"] [dependencies] -memflow-core = { path = "../memflow/memflow-core", features = ["plugins"] } -memflow-derive = { path = "../memflow/memflow-derive" } +memflow-core = { git = "ssh://git@github.com/memflow/memflow.git", branch = "dev", features = ["plugins"] } +memflow-derive = { git = "ssh://git@github.com/memflow/memflow.git", branch = "dev" } +#memflow-core = { path = "../memflow/memflow-core", features = ["plugins"] } +#memflow-derive = { path = "../memflow/memflow-derive" } log = { version = "0.4.8", default-features = false } rusb = "0.6.0" dataview = "0.1" diff --git a/src/fpga.rs b/src/fpga.rs index de1303c..621a52c 100644 --- a/src/fpga.rs +++ b/src/fpga.rs @@ -1,7 +1,7 @@ use crate::ft60x::*; -use std::mem::MaybeUninit; -use std::time::Duration; +use core::mem::MaybeUninit; +use core::time::Duration; use log::{info, trace, warn}; @@ -40,6 +40,7 @@ bitfield! { pl_downstream_deemph_source, _: 8; //_, _: 16, 9; } +const _: [(); core::mem::size_of::()] = [(); 2]; bitfield! { pub struct PhyConfigRd(u32); @@ -59,6 +60,7 @@ bitfield! { pl_received_hot_rst, _: 24; //_, _: 31, 25; } +const _: [(); core::mem::size_of::()] = [(); 4]; pub struct Device { ft60: FT60x, @@ -320,7 +322,7 @@ impl Device { #[cfg(test)] mod tests { use super::*; - use std::mem::size_of; + use core::mem::size_of; #[test] fn test_struct_sizes() { diff --git a/src/ft60x.rs b/src/ft60x.rs index c74bd71..88b37fe 100644 --- a/src/ft60x.rs +++ b/src/ft60x.rs @@ -7,8 +7,8 @@ use rusb::{ request_type, DeviceHandle, DeviceList, Direction, GlobalContext, Recipient, RequestType, }; -use std::mem::size_of; -use std::time::Duration; +use core::mem::size_of; +use core::time::Duration; use log::{info, trace}; diff --git a/src/ft60x/chip.rs b/src/ft60x/chip.rs index a19be43..88cac58 100644 --- a/src/ft60x/chip.rs +++ b/src/ft60x/chip.rs @@ -68,6 +68,7 @@ pub struct Config { pub msio_control: u32, pub gpio_control: u32, } +const _: [(); core::mem::size_of::()] = [(); 0x98]; #[repr(C, packed)] #[derive(Copy, Clone, Pod)] @@ -81,6 +82,7 @@ pub struct ControlRequest { unknown3: u32, unknown4: u32, } +const _: [(); core::mem::size_of::()] = [(); 0x14]; impl ControlRequest { pub fn new(idx: u32, pipe: u8, cmd: u8, len: u32) -> Self { @@ -100,7 +102,7 @@ impl ControlRequest { #[cfg(test)] mod tests { use super::*; - use std::mem::size_of; + use core::mem::size_of; #[test] fn test_struct_sizes() {