mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-29 04:13:24 +00:00
Clone the reader to prevent cursor misplacement in ReadCString
This commit is contained in:
@ -275,12 +275,13 @@ impl_vm_io_once_pointer!(&mut T, "(**self)");
|
||||
impl_vm_io_once_pointer!(Box<T>, "(**self)");
|
||||
impl_vm_io_once_pointer!(Arc<T>, "(**self)");
|
||||
|
||||
/// A marker structure used for [`VmReader`] and [`VmWriter`],
|
||||
/// A marker type used for [`VmReader`] and [`VmWriter`],
|
||||
/// representing whether reads or writes on the underlying memory region are fallible.
|
||||
pub struct Fallible;
|
||||
/// A marker structure used for [`VmReader`] and [`VmWriter`],
|
||||
pub enum Fallible {}
|
||||
|
||||
/// A marker type used for [`VmReader`] and [`VmWriter`],
|
||||
/// representing whether reads or writes on the underlying memory region are infallible.
|
||||
pub struct Infallible;
|
||||
pub enum Infallible {}
|
||||
|
||||
/// Copies `len` bytes from `src` to `dst`.
|
||||
///
|
||||
@ -393,6 +394,20 @@ pub struct VmReader<'a, Fallibility = Fallible> {
|
||||
phantom: PhantomData<(&'a [u8], Fallibility)>,
|
||||
}
|
||||
|
||||
// `Clone` can be implemented for `VmReader`
|
||||
// because it either points to untyped memory or represents immutable references.
|
||||
// Note that we cannot implement `Clone` for `VmWriter`
|
||||
// because it can represent mutable references, which must remain exclusive.
|
||||
impl<Fallibility> Clone for VmReader<'_, Fallibility> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
cursor: self.cursor,
|
||||
end: self.end,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_read_fallible {
|
||||
($reader_fallibility:ty, $writer_fallibility:ty) => {
|
||||
impl<'a> FallibleVmRead<$writer_fallibility> for VmReader<'a, $reader_fallibility> {
|
||||
|
Reference in New Issue
Block a user