forked from M-Labs/zynq-rs
remove undefined behavior in asserts
This commit is contained in:
parent
239bd2e65f
commit
7707399f51
|
@ -1,6 +1,5 @@
|
||||||
use core::{
|
use core::{
|
||||||
ops::{Deref, DerefMut},
|
mem::{align_of, size_of}, ops::{Deref, DerefMut}, panic
|
||||||
mem::{align_of, size_of},
|
|
||||||
};
|
};
|
||||||
use alloc::alloc::{dealloc, Layout, LayoutError};
|
use alloc::alloc::{dealloc, Layout, LayoutError};
|
||||||
use crate::mmu::{L1_PAGE_SIZE, L1Table};
|
use crate::mmu::{L1_PAGE_SIZE, L1Table};
|
||||||
|
@ -20,7 +19,6 @@ impl<T> UncachedSlice<T> {
|
||||||
let layout = Layout::from_size_align(size, align)?;
|
let layout = Layout::from_size_align(size, align)?;
|
||||||
let ptr = unsafe { alloc::alloc::alloc(layout).cast::<T>() };
|
let ptr = unsafe { alloc::alloc::alloc(layout).cast::<T>() };
|
||||||
let start = ptr as usize;
|
let start = ptr as usize;
|
||||||
assert_eq!(start & (L1_PAGE_SIZE - 1), 0);
|
|
||||||
|
|
||||||
for page_start in (start..(start + size)).step_by(L1_PAGE_SIZE) {
|
for page_start in (start..(start + size)).step_by(L1_PAGE_SIZE) {
|
||||||
// non-shareable device
|
// non-shareable device
|
||||||
|
@ -31,10 +29,7 @@ impl<T> UncachedSlice<T> {
|
||||||
l1_section.bufferable = false;
|
l1_section.bufferable = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let slice = unsafe { core::slice::from_raw_parts_mut(ptr, len) };
|
let slice = unsafe { core::slice::from_raw_parts_mut(ptr, len) };
|
||||||
// verify size
|
|
||||||
assert!(unsafe { slice.get_unchecked(len) } as *const _ as usize <= start + size);
|
|
||||||
// initialize
|
// initialize
|
||||||
for e in slice.iter_mut() {
|
for e in slice.iter_mut() {
|
||||||
*e = default();
|
*e = default();
|
||||||
|
|
Loading…
Reference in New Issue