mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:08:13 +00:00
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.
This commit is contained in:
parent
67067904f5
commit
84c0f98fb2
1 changed files with 8 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue