Compare commits

..

1 Commits

Author SHA1 Message Date
af42d9b819 fix UB in UncachedSlice 2025-02-07 11:21:46 +08:00
3 changed files with 1 additions and 7 deletions

View File

@ -11,7 +11,6 @@ target_coraz7 = []
target_ebaz4205 = [] target_ebaz4205 = []
target_redpitaya = [] target_redpitaya = []
target_kasli_soc = [] target_kasli_soc = []
target_pynqz2 = []
ipv6 = [ "smoltcp/proto-ipv6" ] ipv6 = [ "smoltcp/proto-ipv6" ]
[dependencies] [dependencies]

View File

@ -12,8 +12,6 @@ pub const PS_CLK: u32 = 33_333_333;
pub const PS_CLK: u32 = 33_333_333; pub const PS_CLK: u32 = 33_333_333;
#[cfg(feature = "target_kasli_soc")] #[cfg(feature = "target_kasli_soc")]
pub const PS_CLK: u32 = 33_333_333; pub const PS_CLK: u32 = 33_333_333;
#[cfg(feature = "target_pynqz2")]
pub const PS_CLK: u32 = 50_000_000;
/// (pll_fdiv_max, (pll_cp, pll_res, lock_cnt)) /// (pll_fdiv_max, (pll_cp, pll_res, lock_cnt))
const PLL_FDIV_LOCK_PARAM: &[(u16, (u8, u8, u16))] = &[ const PLL_FDIV_LOCK_PARAM: &[(u16, (u8, u8, u16))] = &[

View File

@ -19,8 +19,8 @@ impl<T> UncachedSlice<T> {
.max(L1_PAGE_SIZE); .max(L1_PAGE_SIZE);
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>() };
assert!(!ptr.is_null());
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
@ -33,9 +33,6 @@ impl<T> UncachedSlice<T> {
} }
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
for e in slice.iter_mut() { for e in slice.iter_mut() {
*e = default(); *e = default();
} }