[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
- [PATCH 00/17] Preparatory patches, Sergey Bugaev, 2024/03/27
- [PATCH 04/17] Load 64-bit ELFs on all 64-bit ports, Sergey Bugaev, 2024/03/27
- [PATCH 06/17] kern/syscall_subr.c: Use copyin()/copyout() to access user memory,
Sergey Bugaev <=
- [PATCH 03/17] Use the x86_64 message ABI on all 64-bit ports, Sergey Bugaev, 2024/03/27
- [PATCH 02/17] Disable host_kernel_version() everywhere but on i386, Sergey Bugaev, 2024/03/27
- [PATCH 08/17] ipc: Turn ipc_entry_lookup_failed() into a macro, Sergey Bugaev, 2024/03/27
- [PATCH 11/17] tests: Fix halt(), Sergey Bugaev, 2024/03/27
- [PATCH 09/17] Move copy{in,out}msg declarations to copy_user.h, Sergey Bugaev, 2024/03/27