bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 06/17] kern/syscall_subr.c: Use copyin()/copyout() to access user


From: Sergey Bugaev
Subject: [PATCH 06/17] kern/syscall_subr.c: Use copyin()/copyout() to access user memory
Date: Wed, 27 Mar 2024 19:18:30 +0300

It's not always possible to directly access user memory from kernel
mode. While it's in theory a lot more expensive to fetch each character
to be printed separately, mach_print() is only a debugging facility, and
it's not supposed to be used for printing large amounts of data.
---
 kern/syscall_subr.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/kern/syscall_subr.c b/kern/syscall_subr.c
index e0057d94..0027be29 100644
--- a/kern/syscall_subr.c
+++ b/kern/syscall_subr.c
@@ -43,6 +43,7 @@
 #include <kern/task.h>
 #include <kern/thread.h>
 #include <machine/spl.h>       /* for splsched */
+#include <machine/locore.h>    /* for copyin */
 
 #if    MACH_FIXPRI
 #include <mach/policy.h>
@@ -381,6 +382,14 @@ thread_depress_abort(thread_t thread)
 void
 mach_print(const char *s)
 {
-       printf("%s", s);
+       char    c;
+       while (TRUE) {
+               if (copyin(s, &c, 1))
+                       return;
+               if (c == 0)
+                       break;
+               printf("%c", c);
+               s++;
+       }
 }
 #endif /* MACH_KDB */
-- 
2.44.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]