Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit efaa272

Browse files
eternalcometAsakuraMizu
authored andcommitted
fix[addr_space]: ensure data is copied to kernel address space before convert VA to PA (#52)
Underlying driver assumes a linear mapping between virtual address and physical address when converting them, which is only present in kernel address space. So under circumstance related to physical address, we should copy the buffer to kernel space. - `sys_write` will finally call `axfs::dev::Disk::write_one` in dev.rs, which will use the buffer directly. - read from stdin will finally call `console_read_bytes`, which will also use the buffer directly.
1 parent a64a069 commit efaa272

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

modules/axfs/src/dev.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ impl Disk {
7070
pub fn write_one(&mut self, buf: &[u8]) -> DevResult<usize> {
7171
let write_size = if self.offset == 0 && buf.len() >= BLOCK_SIZE {
7272
// whole block
73-
self.dev.write_block(self.block_id, &buf[0..BLOCK_SIZE])?;
73+
// copy data to kernel address space
74+
// Because underlying driver assumes a linear mapping between virtual address and
75+
// physical address when converting them, which is only present in kernel address space.
76+
let data = buf[0..BLOCK_SIZE].to_vec();
77+
self.dev.write_block(self.block_id, &data)?;
7478
self.block_id += 1;
7579
BLOCK_SIZE
7680
} else {

0 commit comments

Comments
 (0)