From 81eba30a2934a8d676a87fc74f992b144876fc5a Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Tue, 17 Dec 2024 11:46:36 +0800 Subject: [PATCH] prevent cursor r/w optimization --- src/libio/cursor.rs | 3 +++ src/libio/lib.rs | 1 + 2 files changed, 4 insertions(+) diff --git a/src/libio/cursor.rs b/src/libio/cursor.rs index bd397ac..46ff6d6 100644 --- a/src/libio/cursor.rs +++ b/src/libio/cursor.rs @@ -2,6 +2,7 @@ use alloc::vec::Vec; use core_io::{Error as IoError, Read, Write}; +use core::arch::asm; #[derive(Debug, Clone)] pub struct Cursor { @@ -47,6 +48,7 @@ impl> Read for Cursor { let len = buf.len().min(data.len()); // ``copy_from_slice`` generates AXI bursts, use a regular loop instead for i in 0..len { + unsafe { asm!("", options(preserves_flags, nostack, readonly)); } buf[i] = data[i]; } self.pos += len; @@ -59,6 +61,7 @@ impl Write for Cursor<&mut [u8]> { let data = &mut self.inner[self.pos..]; let len = buf.len().min(data.len()); for i in 0..len { + unsafe { asm!("", options(preserves_flags, nostack, readonly)); } data[i] = buf[i]; } self.pos += len; diff --git a/src/libio/lib.rs b/src/libio/lib.rs index 7abe5c1..70c2384 100644 --- a/src/libio/lib.rs +++ b/src/libio/lib.rs @@ -1,5 +1,6 @@ #![no_std] #![feature(never_type)] +#![feature(asm)] #[cfg(feature = "alloc")] extern crate alloc;