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>);
|
pub struct Device(RefCell<DeviceInner>);
|
||||||
|
|
||||||
impl Device {
|
impl Device {
|
||||||
pub fn new(mac: EthernetAddress) -> Device {
|
pub fn new() -> Device {
|
||||||
let mut inner = DeviceInner::new();
|
Device(RefCell::new(DeviceInner::new()))
|
||||||
inner.init(mac);
|
}
|
||||||
Device(RefCell::new(inner))
|
|
||||||
|
// 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 RxToken = RxToken<'a>;
|
||||||
type TxToken = TxToken<'a>;
|
type TxToken = TxToken<'a>;
|
||||||
|
|
||||||
|
|
|
@ -164,8 +164,9 @@ fn main() {
|
||||||
println!("MAC {} IP {}", hardware_addr, ip_addrs[0]);
|
println!("MAC {} IP {}", hardware_addr, ip_addrs[0]);
|
||||||
let mut neighbor_cache_storage = [None; 8];
|
let mut neighbor_cache_storage = [None; 8];
|
||||||
let neighbor_cache = NeighborCache::new(&mut neighbor_cache_storage[..]);
|
let neighbor_cache = NeighborCache::new(&mut neighbor_cache_storage[..]);
|
||||||
let device = ethmac::Device::new(hardware_addr);
|
let mut device = ethmac::Device::new();
|
||||||
let mut iface = EthernetInterfaceBuilder::new(device)
|
unsafe { device.init(hardware_addr) };
|
||||||
|
let mut iface = EthernetInterfaceBuilder::new(&mut device)
|
||||||
.ethernet_addr(hardware_addr)
|
.ethernet_addr(hardware_addr)
|
||||||
.neighbor_cache(neighbor_cache)
|
.neighbor_cache(neighbor_cache)
|
||||||
.ip_addrs(&mut ip_addrs[..])
|
.ip_addrs(&mut ip_addrs[..])
|
||||||
|
|
Loading…
Reference in New Issue