forked from M-Labs/ionpak-thermostat
Fix DMA writing to dangling pointers in ethmac.
This commit is contained in:
parent
83629cac49
commit
f067d0fee9
|
@ -355,14 +355,17 @@ impl DeviceInner {
|
|||
pub struct Device(RefCell<DeviceInner>);
|
||||
|
||||
impl Device {
|
||||
pub fn new(mac: EthernetAddress) -> Device {
|
||||
let mut inner = DeviceInner::new();
|
||||
inner.init(mac);
|
||||
Device(RefCell::new(inner))
|
||||
pub fn new() -> Device {
|
||||
Device(RefCell::new(DeviceInner::new()))
|
||||
}
|
||||
|
||||
// After `init` is called, `Device` shall not be moved.
|
||||
pub unsafe fn init(&mut self, mac: EthernetAddress) {
|
||||
self.0.borrow_mut().init(mac);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> phy::Device<'a> for Device {
|
||||
impl<'a, 'b> phy::Device<'a> for &'b mut Device {
|
||||
type RxToken = RxToken<'a>;
|
||||
type TxToken = TxToken<'a>;
|
||||
|
||||
|
|
|
@ -164,8 +164,9 @@ fn main() {
|
|||
println!("MAC {} IP {}", hardware_addr, ip_addrs[0]);
|
||||
let mut neighbor_cache_storage = [None; 8];
|
||||
let neighbor_cache = NeighborCache::new(&mut neighbor_cache_storage[..]);
|
||||
let device = ethmac::Device::new(hardware_addr);
|
||||
let mut iface = EthernetInterfaceBuilder::new(device)
|
||||
let mut device = ethmac::Device::new();
|
||||
unsafe { device.init(hardware_addr) };
|
||||
let mut iface = EthernetInterfaceBuilder::new(&mut device)
|
||||
.ethernet_addr(hardware_addr)
|
||||
.neighbor_cache(neighbor_cache)
|
||||
.ip_addrs(&mut ip_addrs[..])
|
||||
|
|
Loading…
Reference in New Issue