summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-10-18 14:13:43 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-10-18 14:13:43 +0200
commit2f37fa487dcd8ee5e661ad3bbc0455ddaaa865fe (patch)
treebf29f9a657d74f26ce6ad11b1847b2d181a0fb26 /Kernel
parent2305dee455874ee08c6e77df83132a3bd314c858 (diff)
downloadserenity-2f37fa487dcd8ee5e661ad3bbc0455ddaaa865fe.zip
Kernel: Keep TTY names in character buffers instead of Strings
Just going over some little unnecessary little kmalloc allocations.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Process.cpp3
-rw-r--r--Kernel/TTY/SlavePTY.cpp4
-rw-r--r--Kernel/TTY/SlavePTY.h4
-rw-r--r--Kernel/TTY/TTY.cpp37
-rw-r--r--Kernel/TTY/TTY.h2
-rw-r--r--Kernel/TTY/VirtualConsole.cpp4
-rw-r--r--Kernel/TTY/VirtualConsole.h4
7 files changed, 27 insertions, 31 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 84f02cef54..7dbe1cbab0 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -966,7 +966,8 @@ int Process::sys$ttyname_r(int fd, char* buffer, ssize_t size)
auto tty_name = description->tty()->tty_name();
if (size < tty_name.length() + 1)
return -ERANGE;
- strcpy(buffer, tty_name.characters());
+ memcpy(buffer, tty_name.characters_without_null_termination(), tty_name.length());
+ buffer[tty_name.length()] = '\0';
return 0;
}
diff --git a/Kernel/TTY/SlavePTY.cpp b/Kernel/TTY/SlavePTY.cpp
index 129eb00e07..63a9932241 100644
--- a/Kernel/TTY/SlavePTY.cpp
+++ b/Kernel/TTY/SlavePTY.cpp
@@ -10,7 +10,7 @@ SlavePTY::SlavePTY(MasterPTY& master, unsigned index)
, m_master(master)
, m_index(index)
{
- m_tty_name = String::format("/dev/pts/%u", m_index);
+ ksprintf(m_tty_name, "/dev/pts/%u", m_index);
set_uid(current->process().uid());
set_gid(current->process().gid());
DevPtsFS::register_slave_pty(*this);
@@ -25,7 +25,7 @@ SlavePTY::~SlavePTY()
DevPtsFS::unregister_slave_pty(*this);
}
-String SlavePTY::tty_name() const
+StringView SlavePTY::tty_name() const
{
return m_tty_name;
}
diff --git a/Kernel/TTY/SlavePTY.h b/Kernel/TTY/SlavePTY.h
index 9bf1c5f9cc..03bd892f19 100644
--- a/Kernel/TTY/SlavePTY.h
+++ b/Kernel/TTY/SlavePTY.h
@@ -14,7 +14,7 @@ public:
private:
// ^TTY
- virtual String tty_name() const override;
+ virtual StringView tty_name() const override;
virtual ssize_t on_tty_write(const u8*, ssize_t) override;
// ^CharacterDevice
@@ -29,5 +29,5 @@ private:
RefPtr<MasterPTY> m_master;
unsigned m_index;
- String m_tty_name;
+ char m_tty_name[32];
};
diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp
index f3931a43ed..1e71a7547e 100644
--- a/Kernel/TTY/TTY.cpp
+++ b/Kernel/TTY/TTY.cpp
@@ -62,17 +62,17 @@ void TTY::emit(u8 ch)
{
if (should_generate_signals()) {
if (ch == m_termios.c_cc[VINTR]) {
- dbgprintf("%s: VINTR pressed!\n", tty_name().characters());
+ dbg() << tty_name() << ": VINTR pressed!";
generate_signal(SIGINT);
return;
}
if (ch == m_termios.c_cc[VQUIT]) {
- dbgprintf("%s: VQUIT pressed!\n", tty_name().characters());
+ dbg() << tty_name() << ": VQUIT pressed!";
generate_signal(SIGQUIT);
return;
}
if (ch == m_termios.c_cc[VSUSP]) {
- dbgprintf("%s: VSUSP pressed!\n", tty_name().characters());
+ dbg() << tty_name() << ": VSUSP pressed!";
generate_signal(SIGTSTP);
return;
}
@@ -84,10 +84,10 @@ void TTY::generate_signal(int signal)
{
if (!pgid())
return;
- dbgprintf("%s: Send signal %d to everyone in pgrp %d\n", tty_name().characters(), signal, pgid());
+ dbg() << tty_name() << ": Send signal " << signal << " to everyone in pgrp " << pgid();
InterruptDisabler disabler; // FIXME: Iterate over a set of process handles instead?
Process::for_each_in_pgrp(pgid(), [&](auto& process) {
- dbgprintf("%s: Send signal %d to %d\n", tty_name().characters(), signal, process.pid());
+ dbg() << tty_name() << ": Send signal " << signal << " to " << process;
process.send_signal(signal, nullptr);
return IterationDecision::Continue;
});
@@ -96,22 +96,17 @@ void TTY::generate_signal(int signal)
void TTY::set_termios(const termios& t)
{
m_termios = t;
- dbgprintf("%s set_termios: ECHO=%u, ISIG=%u, ICANON=%u\n",
- tty_name().characters(),
- should_echo_input(),
- should_generate_signals(),
- in_canonical_mode());
- dbgprintf("%s set_termios: ECHOE=%u, ECHOK=%u, ECHONL=%u\n",
- tty_name().characters(),
- (m_termios.c_lflag & ECHOE) != 0,
- (m_termios.c_lflag & ECHOK) != 0,
- (m_termios.c_lflag & ECHONL) != 0);
- dbgprintf("%s set_termios: ISTRIP=%u, ICRNL=%u, INLCR=%u, IGNCR=%u\n",
- tty_name().characters(),
- (m_termios.c_iflag & ISTRIP) != 0,
- (m_termios.c_iflag & ICRNL) != 0,
- (m_termios.c_iflag & INLCR) != 0,
- (m_termios.c_iflag & IGNCR) != 0);
+ dbg() << tty_name() << " set_termios: "
+ << "ECHO=" << should_echo_input()
+ << ", ISIG=" << should_generate_signals()
+ << ", ICANON=" << in_canonical_mode()
+ << ", ECHOE=" << ((m_termios.c_lflag & ECHOE) != 0)
+ << ", ECHOK=" << ((m_termios.c_lflag & ECHOK) != 0)
+ << ", ECHONL=" << ((m_termios.c_lflag & ECHONL) != 0)
+ << ", ISTRIP=" << ((m_termios.c_iflag & ISTRIP) != 0)
+ << ", ICRNL=" << ((m_termios.c_iflag & ICRNL) != 0)
+ << ", INLCR=" << ((m_termios.c_iflag & INLCR) != 0)
+ << ", IGNCR=" << ((m_termios.c_iflag & IGNCR) != 0);
}
int TTY::ioctl(FileDescription&, unsigned request, unsigned arg)
diff --git a/Kernel/TTY/TTY.h b/Kernel/TTY/TTY.h
index 55768b0f72..6a9d47fa2f 100644
--- a/Kernel/TTY/TTY.h
+++ b/Kernel/TTY/TTY.h
@@ -18,7 +18,7 @@ public:
virtual int ioctl(FileDescription&, unsigned request, unsigned arg) override final;
virtual String absolute_path(const FileDescription&) const override { return tty_name(); }
- virtual String tty_name() const = 0;
+ virtual StringView tty_name() const = 0;
unsigned short rows() const { return m_rows; }
unsigned short columns() const { return m_columns; }
diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp
index 653fd4d3df..f8586077d4 100644
--- a/Kernel/TTY/VirtualConsole.cpp
+++ b/Kernel/TTY/VirtualConsole.cpp
@@ -41,7 +41,7 @@ VirtualConsole::VirtualConsole(unsigned index, InitialContents initial_contents)
: TTY(4, index)
, m_index(index)
{
- m_tty_name = String::format("/dev/tty%u", m_index);
+ ksprintf(m_tty_name, "/dev/tty%u", m_index);
set_size(80, 25);
m_horizontal_tabs = static_cast<u8*>(kmalloc(columns()));
for (unsigned i = 0; i < columns(); ++i)
@@ -541,7 +541,7 @@ ssize_t VirtualConsole::on_tty_write(const u8* data, ssize_t size)
return size;
}
-String VirtualConsole::tty_name() const
+StringView VirtualConsole::tty_name() const
{
return m_tty_name;
}
diff --git a/Kernel/TTY/VirtualConsole.h b/Kernel/TTY/VirtualConsole.h
index e9211b2142..b663d61b81 100644
--- a/Kernel/TTY/VirtualConsole.h
+++ b/Kernel/TTY/VirtualConsole.h
@@ -32,7 +32,7 @@ private:
// ^TTY
virtual ssize_t on_tty_write(const u8*, ssize_t) override;
- virtual String tty_name() const override;
+ virtual StringView tty_name() const override;
// ^CharacterDevice
virtual const char* class_name() const override { return "VirtualConsole"; }
@@ -87,5 +87,5 @@ private:
Vector<u8> m_parameters;
Vector<u8> m_intermediates;
u8* m_horizontal_tabs { nullptr };
- String m_tty_name;
+ char m_tty_name[32];
};