From f700958642c58e64ee08dddd7efdb922f1d71f4c Mon Sep 17 00:00:00 2001
From: 4lDO2 <4lDO2@protonmail.com>
Date: Mon, 10 Jul 2023 16:26:52 +0200
Subject: [PATCH] Fix debug: scheme.

---
 src/scheme/debug.rs | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/scheme/debug.rs b/src/scheme/debug.rs
index d794200c..ed4fa4e4 100644
--- a/src/scheme/debug.rs
+++ b/src/scheme/debug.rs
@@ -140,11 +140,19 @@ impl crate::scheme::KernelScheme for DebugScheme {
             let handles = handles();
             *handles.get(&id).ok_or(Error::new(EBADF))?
         };
-        // FIXME
+
         let mut tmp = [0_u8; 512];
-        let count = buf.copy_common_bytes_to_slice(&mut tmp)?;
 
-        Writer::new().write(&tmp[..count]);
+        for chunk in buf.in_variable_chunks(tmp.len()) {
+            let byte_count = chunk.copy_common_bytes_to_slice(&mut tmp)?;
+            let tmp_bytes = &tmp[..byte_count];
+
+            // The reason why a new writer is created for each iteration, is because the page fault
+            // handler in usercopy might use the same lock when printing for debug purposes, and
+            // although it most likely won't, it would be dangerous to rely on that assumption.
+            Writer::new().write(tmp_bytes);
+        }
+
         Ok(buf.len())
     }
     fn kfpath(&self, id: usize, buf: UserSliceWo) -> Result<usize> {
-- 
GitLab