From 4177e6be8b00259e103e23fb4c90ba155a8d752b Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 25 Aug 2023 10:05:40 +0300 Subject: [PATCH] Kernel: Remove KDSETMODE and KDGETMODE ioctl options from the TTY class These options are not relevant and are actually meaningless on pure TTY devices, as they are meant to be effective only for the VirtualConsole devices. This also removes the virtual marking from two methods because they're no longer declared in the TTY class as well. --- Kernel/TTY/TTY.cpp | 13 ------------- Kernel/TTY/TTY.h | 5 +---- Kernel/TTY/VirtualConsole.cpp | 21 +++++++++++++++++++++ Kernel/TTY/VirtualConsole.h | 6 +++--- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp index 419a528a28..90db0b50c9 100644 --- a/Kernel/TTY/TTY.cpp +++ b/Kernel/TTY/TTY.cpp @@ -562,19 +562,6 @@ ErrorOr TTY::ioctl(OpenFileDescription&, unsigned request, Userspace(arg.ptr()); - if (mode != KD_TEXT && mode != KD_GRAPHICS) - return EINVAL; - - set_graphical(mode == KD_GRAPHICS); - return {}; - } - case KDGETMODE: { - auto mode_ptr = static_ptr_cast(arg); - int mode = (is_graphical()) ? KD_GRAPHICS : KD_TEXT; - return copy_to_user(mode_ptr, &mode); - } } return EINVAL; } diff --git a/Kernel/TTY/TTY.h b/Kernel/TTY/TTY.h index 67343462dc..c6e004b000 100644 --- a/Kernel/TTY/TTY.h +++ b/Kernel/TTY/TTY.h @@ -25,7 +25,7 @@ public: virtual ErrorOr write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override; virtual bool can_read(OpenFileDescription const&, u64) const override; virtual bool can_write(OpenFileDescription const&, u64) const override; - virtual ErrorOr ioctl(OpenFileDescription&, unsigned request, Userspace arg) override final; + virtual ErrorOr ioctl(OpenFileDescription&, unsigned request, Userspace arg) override; unsigned short rows() const { return m_rows; } unsigned short columns() const { return m_columns; } @@ -48,9 +48,6 @@ public: virtual ErrorOr> pseudo_name() const = 0; - virtual bool is_graphical() const { return false; } - virtual void set_graphical(bool) { } - protected: virtual ErrorOr on_tty_write(UserOrKernelBuffer const&, size_t) = 0; void set_size(unsigned short columns, unsigned short rows); diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp index f7718a63fc..5ff9aac7a5 100644 --- a/Kernel/TTY/VirtualConsole.cpp +++ b/Kernel/TTY/VirtualConsole.cpp @@ -194,6 +194,27 @@ UNMAP_AFTER_INIT VirtualConsole::~VirtualConsole() VERIFY_NOT_REACHED(); } +ErrorOr VirtualConsole::ioctl(OpenFileDescription& description, unsigned request, Userspace arg) +{ + TRY(Process::current().require_promise(Pledge::tty)); + switch (request) { + case KDSETMODE: { + auto mode = static_cast(arg.ptr()); + if (mode != KD_TEXT && mode != KD_GRAPHICS) + return EINVAL; + + set_graphical(mode == KD_GRAPHICS); + return {}; + } + case KDGETMODE: { + auto mode_ptr = static_ptr_cast(arg); + int mode = (is_graphical()) ? KD_GRAPHICS : KD_TEXT; + return copy_to_user(mode_ptr, &mode); + } + } + return TTY::ioctl(description, request, arg); +} + static inline Graphics::Console::Color ansi_color_to_standard_vga_color(VT::Color::ANSIColor color) { switch (color) { diff --git a/Kernel/TTY/VirtualConsole.h b/Kernel/TTY/VirtualConsole.h index beae1ddb22..cfb1e4f296 100644 --- a/Kernel/TTY/VirtualConsole.h +++ b/Kernel/TTY/VirtualConsole.h @@ -77,9 +77,8 @@ public: void refresh_after_resolution_change(); - // ^TTY - virtual bool is_graphical() const override { return m_graphical; } - virtual void set_graphical(bool graphical) override; + bool is_graphical() const { return m_graphical; } + void set_graphical(bool graphical); void emit_char(char); @@ -91,6 +90,7 @@ private: // ^TTY virtual ErrorOr> pseudo_name() const override; virtual ErrorOr on_tty_write(UserOrKernelBuffer const&, size_t) override; + virtual ErrorOr ioctl(OpenFileDescription&, unsigned request, Userspace arg) override; virtual void echo(u8) override; // ^TerminalClient