summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/debug.cpp
diff options
context:
space:
mode:
authorMax Wipfli <mail@maxwipfli.ch>2021-06-23 17:55:08 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-24 10:29:09 +0200
commit84c0f98fb243ac535787d931c7ed9b5fbc6cb6f5 (patch)
treeea9d8905359c9fdd133a914727a75ec5a46437ec /Kernel/Syscalls/debug.cpp
parent67067904f53c06d6808febabc7f3425dab929729 (diff)
downloadserenity-84c0f98fb243ac535787d931c7ed9b5fbc6cb6f5.zip
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.
Diffstat (limited to 'Kernel/Syscalls/debug.cpp')
-rw-r--r--Kernel/Syscalls/debug.cpp22
1 files 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 <Kernel/IO.h>
#include <Kernel/KSyms.h>
#include <Kernel/Process.h>
#include <Kernel/UserOrKernelBuffer.h>
+#include <Kernel/kstdio.h>
namespace Kernel {
@@ -19,26 +19,20 @@ KResultOr<int> Process::sys$dump_backtrace()
KResultOr<int> Process::sys$dbgputch(u8 ch)
{
- IO::out8(IO::BOCHS_DEBUG_PORT, ch);
+ dbgputch(ch);
return 0;
}
KResultOr<size_t> Process::sys$dbgputstr(Userspace<const u8*> characters, size_t size)
{
- if (size <= 0)
+ if (size == 0)
return 0;
- if (size > NumericLimits<ssize_t>::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<char const*>(characters.unsafe_userspace_ptr()), size);
+ if (result.is_error())
+ return result.error();
+ dbgputstr(reinterpret_cast<const char*>(result.value()->characters()), size);
+ return size;
}
}