diff --git a/kernel/include/kernel/Terminal/PseudoTerminal.h b/kernel/include/kernel/Terminal/PseudoTerminal.h index e3f0d5c9..26b0446b 100644 --- a/kernel/include/kernel/Terminal/PseudoTerminal.h +++ b/kernel/include/kernel/Terminal/PseudoTerminal.h @@ -51,8 +51,6 @@ namespace Kernel class PseudoTerminalSlave final : public TTY, public BAN::Weakable { public: - static BAN::ErrorOr> create(BAN::String&& name, mode_t, uid_t, gid_t); - BAN::StringView name() const override { return m_name; } uint32_t height() const override { return m_height; } @@ -64,16 +62,12 @@ namespace Kernel void putchar_impl(uint8_t ch) override; private: - PseudoTerminalSlave(BAN::UniqPtr, BAN::String&& name, mode_t, uid_t, gid_t); + PseudoTerminalSlave(BAN::String&& name, mode_t, uid_t, gid_t); private: BAN::String m_name; BAN::WeakPtr m_master; - BAN::UniqPtr m_buffer; - size_t m_buffer_tail { 0 }; - size_t m_buffer_size { 0 }; - uint32_t m_width { 0 }; uint32_t m_height { 0 }; diff --git a/kernel/kernel/Terminal/PseudoTerminal.cpp b/kernel/kernel/Terminal/PseudoTerminal.cpp index 503f1534..73c1a0d5 100644 --- a/kernel/kernel/Terminal/PseudoTerminal.cpp +++ b/kernel/kernel/Terminal/PseudoTerminal.cpp @@ -20,14 +20,8 @@ namespace Kernel )); auto pts_master = TRY(BAN::RefPtr::create(BAN::move(pts_master_buffer), mode, uid, gid)); - auto pts_slave_buffer = TRY(VirtualRange::create_to_vaddr_range( - PageTable::kernel(), - KERNEL_OFFSET, static_cast(-1), - 16 * PAGE_SIZE, - PageTable::Flags::ReadWrite | PageTable::Flags::Present, true - )); auto pts_slave_name = TRY(BAN::String::formatted("pts{}", s_pts_slave_number++)); - auto pts_slave = TRY(BAN::RefPtr::create(BAN::move(pts_slave_buffer), BAN::move(pts_slave_name), 0610, uid, gid)); + auto pts_slave = TRY(BAN::RefPtr::create(BAN::move(pts_slave_name), 0610, uid, gid)); pts_master->m_slave = TRY(pts_slave->get_weak_ptr()); pts_slave->m_master = TRY(pts_master->get_weak_ptr()); @@ -67,15 +61,12 @@ namespace Kernel { SpinLockGuard _(m_buffer_lock); - if (m_buffer_size == m_buffer->size()) - { - dwarnln("PseudoTerminalMaster buffer full"); - m_buffer_tail = (m_buffer_tail + 1) % m_buffer->size(); - m_buffer_size--; - } + reinterpret_cast(m_buffer->vaddr())[(m_buffer_tail + m_buffer_size) % m_buffer->size()] = ch; - *reinterpret_cast(m_buffer->vaddr() + (m_buffer_tail + m_buffer_size) % m_buffer->size()) = ch; - m_buffer_size++; + if (m_buffer_size < m_buffer->size()) + m_buffer_size++; + else + m_buffer_tail = (m_buffer_tail + 1) % m_buffer->size(); } BAN::ErrorOr PseudoTerminalMaster::read_impl(off_t, BAN::ByteSpan buffer) @@ -91,11 +82,11 @@ namespace Kernel const size_t to_copy = BAN::Math::min(buffer.size(), m_buffer_size); - if (m_buffer_tail + to_copy < m_buffer->size()) + if (m_buffer_tail + to_copy <= m_buffer->size()) memcpy(buffer.data(), reinterpret_cast(m_buffer->vaddr() + m_buffer_tail), to_copy); else { - const size_t before_wrap = m_buffer_size - m_buffer_tail; + const size_t before_wrap = m_buffer->size() - m_buffer_tail; const size_t after_wrap = to_copy - before_wrap; memcpy(buffer.data(), reinterpret_cast(m_buffer->vaddr() + m_buffer_tail), before_wrap); @@ -121,10 +112,9 @@ namespace Kernel return buffer.size(); } - PseudoTerminalSlave::PseudoTerminalSlave(BAN::UniqPtr buffer, BAN::String&& name, mode_t mode, uid_t uid, gid_t gid) + PseudoTerminalSlave::PseudoTerminalSlave(BAN::String&& name, mode_t mode, uid_t uid, gid_t gid) : TTY(mode, uid, gid) , m_name(BAN::move(name)) - , m_buffer(BAN::move(buffer)) {} void PseudoTerminalSlave::clear()