mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 09:23:25 +00:00
Refactor VmReader/Writer to support both kernel space and user space
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
994427c71a
commit
09b6153d29
@ -114,14 +114,20 @@ impl HasPaddr for Frame {
|
||||
impl<'a> Frame {
|
||||
/// Returns a reader to read data from it.
|
||||
pub fn reader(&'a self) -> VmReader<'a> {
|
||||
// SAFETY: the memory of the page is contiguous and is valid during `'a`.
|
||||
unsafe { VmReader::from_raw_parts(self.as_ptr(), self.size()) }
|
||||
// SAFETY: the memory of the page is untyped, contiguous and is valid during `'a`.
|
||||
// Currently, only slice can generate `VmWriter` with typed memory, and this `Frame` cannot
|
||||
// generate or be generated from an alias slice, so the reader will not overlap with `VmWriter`
|
||||
// with typed memory.
|
||||
unsafe { VmReader::from_kernel_space(self.as_ptr(), self.size()) }
|
||||
}
|
||||
|
||||
/// Returns a writer to write data into it.
|
||||
pub fn writer(&'a self) -> VmWriter<'a> {
|
||||
// SAFETY: the memory of the page is contiguous and is valid during `'a`.
|
||||
unsafe { VmWriter::from_raw_parts_mut(self.as_mut_ptr(), self.size()) }
|
||||
// SAFETY: the memory of the page is untyped, contiguous and is valid during `'a`.
|
||||
// Currently, only slice can generate `VmReader` with typed memory, and this `Frame` cannot
|
||||
// generate or be generated from an alias slice, so the writer will not overlap with `VmReader`
|
||||
// with typed memory.
|
||||
unsafe { VmWriter::from_kernel_space(self.as_mut_ptr(), self.size()) }
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user