[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 06/17] kern/syscall_subr.c: Use copyin()/copyout() to access
From: |
Samuel Thibault |
Subject: |
Re: [PATCH 06/17] kern/syscall_subr.c: Use copyin()/copyout() to access user memory |
Date: |
Wed, 27 Mar 2024 19:46:35 +0100 |
User-agent: |
NeoMutt/20170609 (1.8.3) |
Sergey Bugaev, le mer. 27 mars 2024 19:18:30 +0300, a ecrit:
> 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.
Yes, but the atomicity of mach_print is really useful when debugging
issues with several translators etc.
Could you make it use a buffer so we get atomicity for e.g. a hundred
characters?
Samuel
> ---
> 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 05/17] gsync: Use copyin()/copyout() to access user memory, Sergey Bugaev, 2024/03/27
- [PATCH 01/17] elf-load: Respect PT_GNU_STACK, 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, 2024/03/27
- Re: [PATCH 06/17] kern/syscall_subr.c: Use copyin()/copyout() to access user memory,
Samuel Thibault <=
- [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