mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-09 13:26:48 +00:00
Use volatile copy in VmReader/VmWriter
This commit is contained in:
parent
72e726295f
commit
b7a3f1a540
@ -5,6 +5,7 @@
|
|||||||
#![feature(const_mut_refs)]
|
#![feature(const_mut_refs)]
|
||||||
#![feature(const_ptr_sub_ptr)]
|
#![feature(const_ptr_sub_ptr)]
|
||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
|
#![feature(core_intrinsics)]
|
||||||
#![feature(coroutines)]
|
#![feature(coroutines)]
|
||||||
#![feature(fn_traits)]
|
#![feature(fn_traits)]
|
||||||
#![feature(generic_const_exprs)]
|
#![feature(generic_const_exprs)]
|
||||||
@ -18,6 +19,7 @@
|
|||||||
// The `generic_const_exprs` feature is incomplete however required for the page table
|
// The `generic_const_exprs` feature is incomplete however required for the page table
|
||||||
// const generic implementation. We are using this feature in a conservative manner.
|
// const generic implementation. We are using this feature in a conservative manner.
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
#![allow(internal_features)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
|
@ -193,12 +193,13 @@ pub struct KernelSpace;
|
|||||||
/// - If one of the memory represents typed memory, these two virtual
|
/// - If one of the memory represents typed memory, these two virtual
|
||||||
/// memory ranges and their corresponding physical pages should _not_ overlap.
|
/// memory ranges and their corresponding physical pages should _not_ overlap.
|
||||||
///
|
///
|
||||||
/// Operation on typed memory may be safe only if it is plain-old-data. Otherwise
|
/// Operation on typed memory may be safe only if it is plain-old-data. Otherwise,
|
||||||
/// the safety requirements of [`core::ptr::copy`] should also be considered.
|
/// the safety requirements of [`core::ptr::copy`] should also be considered,
|
||||||
|
/// except for the requirement that no concurrent access is allowed.
|
||||||
///
|
///
|
||||||
/// [valid]: core::ptr#safety
|
/// [valid]: core::ptr#safety
|
||||||
unsafe fn memcpy(src: *const u8, dst: *mut u8, len: usize) {
|
unsafe fn memcpy(dst: *mut u8, src: *const u8, len: usize) {
|
||||||
core::ptr::copy(src, dst, len);
|
core::intrinsics::volatile_copy_memory(dst, src, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copies `len` bytes from `src` to `dst`.
|
/// Copies `len` bytes from `src` to `dst`.
|
||||||
@ -217,7 +218,7 @@ unsafe fn memcpy(src: *const u8, dst: *mut u8, len: usize) {
|
|||||||
/// should _not_ overlap if the kernel space memory represent typed memory.
|
/// should _not_ overlap if the kernel space memory represent typed memory.
|
||||||
///
|
///
|
||||||
/// [valid]: core::ptr#safety
|
/// [valid]: core::ptr#safety
|
||||||
unsafe fn memcpy_fallible(src: *const u8, dst: *mut u8, len: usize) -> usize {
|
unsafe fn memcpy_fallible(dst: *mut u8, src: *const u8, len: usize) -> usize {
|
||||||
let failed_bytes = __memcpy_fallible(dst, src, len);
|
let failed_bytes = __memcpy_fallible(dst, src, len);
|
||||||
len - failed_bytes
|
len - failed_bytes
|
||||||
}
|
}
|
||||||
@ -272,7 +273,7 @@ macro_rules! impl_read_fallible {
|
|||||||
// not overlap with user space memory range in physical address level if it
|
// not overlap with user space memory range in physical address level if it
|
||||||
// represents typed memory.
|
// represents typed memory.
|
||||||
let copied_len = unsafe {
|
let copied_len = unsafe {
|
||||||
let copied_len = memcpy_fallible(self.cursor, writer.cursor, copy_len);
|
let copied_len = memcpy_fallible(writer.cursor, self.cursor, copy_len);
|
||||||
self.cursor = self.cursor.add(copied_len);
|
self.cursor = self.cursor.add(copied_len);
|
||||||
writer.cursor = writer.cursor.add(copied_len);
|
writer.cursor = writer.cursor.add(copied_len);
|
||||||
copied_len
|
copied_len
|
||||||
@ -353,7 +354,7 @@ impl<'a> VmReader<'a, KernelSpace> {
|
|||||||
// writer's available space, and will not overlap if one of them represents
|
// writer's available space, and will not overlap if one of them represents
|
||||||
// typed memory.
|
// typed memory.
|
||||||
unsafe {
|
unsafe {
|
||||||
memcpy(self.cursor, writer.cursor, copy_len);
|
memcpy(writer.cursor, self.cursor, copy_len);
|
||||||
self.cursor = self.cursor.add(copy_len);
|
self.cursor = self.cursor.add(copy_len);
|
||||||
writer.cursor = writer.cursor.add(copy_len);
|
writer.cursor = writer.cursor.add(copy_len);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user