From 84c0f98fb243ac535787d931c7ed9b5fbc6cb6f5 Mon Sep 17 00:00:00 2001 From: Max Wipfli Date: Wed, 23 Jun 2021 17:55:08 +0200 Subject: [PATCH] Kernel: Reimplement the dbgputch and dbgputstr syscalls This rewrites the dbgputch and dbgputstr system calls as wrappers of kstdio.h. This fixes a bug where only the Kernel's debug output was also sent to a serial debugger, while the userspace's debug output was only sent to the Bochs debugger. This also fixes a bug where debug output from one process would sometimes "interrupt" the debug output from another process in the middle of a line. --- Kernel/Syscalls/debug.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/Kernel/Syscalls/debug.cpp b/Kernel/Syscalls/debug.cpp index c3f4872a36..9f17265148 100644 --- a/Kernel/Syscalls/debug.cpp +++ b/Kernel/Syscalls/debug.cpp @@ -4,10 +4,10 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include +#include namespace Kernel { @@ -19,26 +19,20 @@ KResultOr Process::sys$dump_backtrace() KResultOr Process::sys$dbgputch(u8 ch) { - IO::out8(IO::BOCHS_DEBUG_PORT, ch); + dbgputch(ch); return 0; } KResultOr Process::sys$dbgputstr(Userspace characters, size_t size) { - if (size <= 0) + if (size == 0) return 0; - if (size > NumericLimits::max()) - return EINVAL; - - auto buffer = UserOrKernelBuffer::for_user_buffer(characters, size); - if (!buffer.has_value()) - return EFAULT; - return buffer.value().read_buffered<1024>(size, [&](u8 const* buffer, size_t buffer_size) { - for (size_t i = 0; i < buffer_size; ++i) - IO::out8(IO::BOCHS_DEBUG_PORT, buffer[i]); - return buffer_size; - }); + auto result = try_copy_kstring_from_user(reinterpret_cast(characters.unsafe_userspace_ptr()), size); + if (result.is_error()) + return result.error(); + dbgputstr(reinterpret_cast(result.value()->characters()), size); + return size; } }