flash store: remove transmute

pull/49/head
topquark12 2021-01-13 17:13:18 +08:00
parent a6466c847a
commit cef9cf6f48
1 changed files with 1 additions and 10 deletions

View File

@ -20,9 +20,7 @@ pub struct FlashBackend {
} }
unsafe fn get_offset() -> usize { unsafe fn get_offset() -> usize {
let config = core::mem::transmute::<*const usize, usize>(&_config_start); (&_config_start as *const usize as usize) - (&_flash_start as *const usize as usize)
let flash = core::mem::transmute::<*const usize, usize>(&_flash_start);
config - flash
} }
impl StoreBackend for FlashBackend { impl StoreBackend for FlashBackend {
@ -30,13 +28,6 @@ impl StoreBackend for FlashBackend {
fn data(&self) -> &Self::Data { fn data(&self) -> &Self::Data {
unsafe { unsafe {
// This works
// let config = core::mem::transmute::<*const usize, usize>(&_config_start);
// let flash = core::mem::transmute::<*const usize, usize>(&_flash_start);
// let config_offset = config - flash;
// This doesn't
// let config_offset = (&_config_start - &_flash_start) as usize;
&self.flash.read()[get_offset()..(get_offset() + FLASH_SECTOR_SIZE)] &self.flash.read()[get_offset()..(get_offset() + FLASH_SECTOR_SIZE)]
} }
} }