From 74bd81f87fdd193ec7d9854ccb69ce76fef98e4f Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 9 Jun 2019 02:23:37 +0200 Subject: [PATCH] eth: add safety asserts --- src/eth/mod.rs | 1 + src/eth/rx.rs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/eth/mod.rs b/src/eth/mod.rs index b7e400f..87a3f27 100644 --- a/src/eth/mod.rs +++ b/src/eth/mod.rs @@ -277,6 +277,7 @@ impl<'rx> Eth<'rx> { pub fn start_rx(&mut self, rx_buffers: [&'rx mut [u8]; rx::DESCS]) { self.rx = Some(rx::DescList::new(rx_buffers)); let list_addr = self.rx.as_ref().unwrap() as *const _ as u32; + assert!(list_addr & 0b11 == 0); self.regs.rx_qbar.write( regs::RxQbar::zeroed() .rx_q_baseaddr(list_addr >> 2) diff --git a/src/eth/rx.rs b/src/eth/rx.rs index b4dd25b..ae4a86b 100644 --- a/src/eth/rx.rs +++ b/src/eth/rx.rs @@ -45,7 +45,9 @@ impl<'a> DescList<'a> { pub fn new(buffers: [&'a mut [u8]; DESCS]) -> Self { let mut list: [DescEntry; DESCS] = unsafe { uninitialized() }; for i in 0..DESCS { + assert!(buffers[i].len() >= 1536); let buffer_addr = &mut buffers[i][0] as *mut _ as u32; + assert!(buffer_addr & 0b11 == 0); list[i].word0.write( DescWord0::zeroed() .used(false)