Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion modules/axfs/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ impl Disk {
pub fn write_one(&mut self, buf: &[u8]) -> DevResult<usize> {
let write_size = if self.offset == 0 && buf.len() >= BLOCK_SIZE {
// whole block
self.dev.write_block(self.block_id, &buf[0..BLOCK_SIZE])?;
// copy data to kernel address space
// Because underlying driver assumes a linear mapping between virtual address and
// physical address when converting them, which is only present in kernel address space.
let data = buf[0..BLOCK_SIZE].to_vec();
self.dev.write_block(self.block_id, &data)?;
self.block_id += 1;
BLOCK_SIZE
} else {
Expand Down
4 changes: 4 additions & 0 deletions modules/axhal/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ pub struct MemRegion {
/// `paddr = vaddr - PHYS_VIRT_OFFSET`.
#[inline]
pub const fn virt_to_phys(vaddr: VirtAddr) -> PhysAddr {
assert!(
vaddr.as_usize() >= PHYS_VIRT_OFFSET,
"Converted address is invalid, check if the virtual address is in kernel space"
);
pa!(vaddr.as_usize() - PHYS_VIRT_OFFSET)
}

Expand Down
Loading