mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 19:03:27 +00:00
Replace VmFrame::zero
with VmWriter::fill
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
195c6a0739
commit
12d338dd9b
@ -6,6 +6,7 @@ use core::{
|
||||
marker::PhantomData,
|
||||
ops::{BitAnd, BitOr, Not, Range},
|
||||
};
|
||||
use pod::Pod;
|
||||
|
||||
use crate::{config::PAGE_SIZE, prelude::*, Error};
|
||||
|
||||
@ -57,11 +58,6 @@ impl VmFrameVec {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// zero all internal vm frames
|
||||
pub fn zero(&self) {
|
||||
self.0.iter().for_each(|vm_frame| vm_frame.zero())
|
||||
}
|
||||
|
||||
/// Truncate some frames.
|
||||
///
|
||||
/// If `new_len >= self.len()`, then this method has no effect.
|
||||
@ -228,12 +224,6 @@ impl VmFrame {
|
||||
(self.frame_index() + 1) * PAGE_SIZE
|
||||
}
|
||||
|
||||
/// Fills the frame with zero.
|
||||
pub fn zero(&self) {
|
||||
// Safety: The range of memory is valid for writes of one page data.
|
||||
unsafe { core::ptr::write_bytes(self.as_mut_ptr(), 0, PAGE_SIZE) }
|
||||
}
|
||||
|
||||
fn need_dealloc(&self) -> bool {
|
||||
(*self.frame_index & VmFrameFlags::NEED_DEALLOC.bits()) != 0
|
||||
}
|
||||
@ -418,12 +408,6 @@ impl VmSegment {
|
||||
self.nframes() * PAGE_SIZE
|
||||
}
|
||||
|
||||
/// Fills the page frames with zero.
|
||||
pub fn zero(&self) {
|
||||
// Safety: The range of memory is valid for writes of `self.nbytes()` data.
|
||||
unsafe { core::ptr::write_bytes(self.as_mut_ptr(), 0, self.nbytes()) }
|
||||
}
|
||||
|
||||
fn need_dealloc(&self) -> bool {
|
||||
(self.inner.start_frame_index & VmFrameFlags::NEED_DEALLOC.bits()) != 0
|
||||
}
|
||||
@ -700,6 +684,21 @@ impl<'a> VmWriter<'a> {
|
||||
}
|
||||
copy_len
|
||||
}
|
||||
|
||||
/// Fills the available space by repeating `value`.
|
||||
///
|
||||
/// # Panic
|
||||
///
|
||||
/// The size of the available space must be a multiple of the size of `value`.
|
||||
/// Otherwise, the method would panic.
|
||||
pub fn fill<T: Pod>(&mut self, value: T) {
|
||||
assert!(self.avail() / value.as_bytes().len() > 0);
|
||||
assert!(self.avail() % value.as_bytes().len() == 0);
|
||||
|
||||
while self.avail() > 0 {
|
||||
self.write(&mut value.as_bytes().into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a mut [u8]> for VmWriter<'a> {
|
||||
|
Reference in New Issue
Block a user