mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 18:03:25 +00:00
Clarify some safety conditions of Vm{Reader,Writer}
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
fda0fa0512
commit
562e644375
@ -112,19 +112,19 @@ 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 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.
|
||||
// SAFETY:
|
||||
// - The memory range points to untyped memory.
|
||||
// - The frame is alive during the lifetime `'a`.
|
||||
// - Using `VmReader` and `VmWriter` is the only way to access the frame.
|
||||
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 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.
|
||||
// SAFETY:
|
||||
// - The memory range points to untyped memory.
|
||||
// - The frame is alive during the lifetime `'a`.
|
||||
// - Using `VmReader` and `VmWriter` is the only way to access the frame.
|
||||
unsafe { VmWriter::from_kernel_space(self.as_mut_ptr(), self.size()) }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user