summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-16 02:11:50 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-16 02:11:50 +0100
commit310a5f41997492d203fed6dd7b4ff77ce80f82ff (patch)
tree9958136053756379e54bf2e74cc9795547f5723d /Kernel
parent9c51d9dfcd990ec4bc1707f8c17ee0fd1059d8f0 (diff)
downloadserenity-310a5f41997492d203fed6dd7b4ff77ce80f82ff.zip
Let each MasterPTY create its slave.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/MasterPTY.cpp6
-rw-r--r--Kernel/MasterPTY.h4
-rw-r--r--Kernel/SlavePTY.cpp7
-rw-r--r--Kernel/SlavePTY.h8
-rw-r--r--Kernel/init.cpp23
5 files changed, 18 insertions, 30 deletions
diff --git a/Kernel/MasterPTY.cpp b/Kernel/MasterPTY.cpp
index 138d9bc5b0..7cb6f8b687 100644
--- a/Kernel/MasterPTY.cpp
+++ b/Kernel/MasterPTY.cpp
@@ -3,9 +3,10 @@
MasterPTY::MasterPTY(unsigned index)
: CharacterDevice(10, index)
+ , m_slave(*new SlavePTY(*this, index))
, m_index(index)
{
-
+ VFS::the().register_character_device(m_slave);
}
MasterPTY::~MasterPTY()
@@ -14,7 +15,6 @@ MasterPTY::~MasterPTY()
String MasterPTY::pts_name() const
{
- dbgprintf("MasterPTY::pts_name requested for index %u!\n", m_index);
char buffer[32];
ksprintf(buffer, "/dev/pts%u", m_index);
return buffer;
@@ -27,7 +27,7 @@ ssize_t MasterPTY::read(Process&, byte* buffer, size_t size)
ssize_t MasterPTY::write(Process&, const byte* buffer, size_t size)
{
- m_slave->on_master_write(buffer, size);
+ m_slave.on_master_write(buffer, size);
return size;
}
diff --git a/Kernel/MasterPTY.h b/Kernel/MasterPTY.h
index 822764f57a..0837e250a4 100644
--- a/Kernel/MasterPTY.h
+++ b/Kernel/MasterPTY.h
@@ -6,10 +6,10 @@
class SlavePTY;
class MasterPTY final : public CharacterDevice {
+ AK_MAKE_ETERNAL
public:
explicit MasterPTY(unsigned index);
virtual ~MasterPTY() override;
- void set_slave(SlavePTY& slave) { m_slave = &slave; }
virtual ssize_t read(Process&, byte*, size_t) override;
virtual ssize_t write(Process&, const byte*, size_t) override;
@@ -21,7 +21,7 @@ public:
void on_slave_write(const byte*, size_t);
private:
+ SlavePTY& m_slave;
unsigned m_index;
- SlavePTY* m_slave { nullptr };
DoubleBuffer m_buffer;
};
diff --git a/Kernel/SlavePTY.cpp b/Kernel/SlavePTY.cpp
index 3c0898e28b..c8fa110746 100644
--- a/Kernel/SlavePTY.cpp
+++ b/Kernel/SlavePTY.cpp
@@ -1,8 +1,9 @@
#include "SlavePTY.h"
#include "MasterPTY.h"
-SlavePTY::SlavePTY(unsigned index)
+SlavePTY::SlavePTY(MasterPTY& master, unsigned index)
: TTY(11, index)
+ , m_master(master)
, m_index(index)
{
set_size(80, 25);
@@ -27,10 +28,10 @@ void SlavePTY::on_master_write(const byte* buffer, size_t size)
void SlavePTY::on_tty_write(const byte* data, size_t size)
{
- m_master->on_slave_write(data, size);
+ m_master.on_slave_write(data, size);
}
bool SlavePTY::can_write(Process& process) const
{
- return m_master->can_write(process);
+ return m_master.can_write(process);
}
diff --git a/Kernel/SlavePTY.h b/Kernel/SlavePTY.h
index 312efa740b..773dcee6b4 100644
--- a/Kernel/SlavePTY.h
+++ b/Kernel/SlavePTY.h
@@ -5,10 +5,9 @@
class MasterPTY;
class SlavePTY final : public TTY {
+ AK_MAKE_ETERNAL
public:
- explicit SlavePTY(unsigned index);
virtual ~SlavePTY() override;
- void set_master(MasterPTY& master) { m_master = &master; }
virtual String tty_name() const override;
@@ -19,7 +18,10 @@ protected:
virtual bool can_write(Process&) const override;
private:
+ friend class MasterPTY;
+ SlavePTY(MasterPTY&, unsigned index);
+
+ MasterPTY& m_master;
unsigned m_index;
- MasterPTY* m_master { nullptr };
};
diff --git a/Kernel/init.cpp b/Kernel/init.cpp
index d7c42823f0..2348d53b88 100644
--- a/Kernel/init.cpp
+++ b/Kernel/init.cpp
@@ -23,7 +23,6 @@
#include "Scheduler.h"
#include "PS2MouseDevice.h"
#include "MasterPTY.h"
-#include "SlavePTY.h"
#define SPAWN_GUI_TEST_APP
//#define SPAWN_MULTIPLE_SHELLS
@@ -42,10 +41,6 @@ MasterPTY* ptm0;
MasterPTY* ptm1;
MasterPTY* ptm2;
MasterPTY* ptm3;
-SlavePTY* pts0;
-SlavePTY* pts1;
-SlavePTY* pts2;
-SlavePTY* pts3;
#ifdef STRESS_TEST_SPAWNING
static void spawn_stress() NORETURN;
@@ -66,16 +61,6 @@ static void spawn_stress()
}
#endif
-static void make_pty_pair(unsigned index)
-{
- auto* master = new MasterPTY(index);
- auto* slave = new SlavePTY(index);
- master->set_slave(*slave);
- slave->set_master(*master);
- VFS::the().register_character_device(*master);
- VFS::the().register_character_device(*slave);
-}
-
static void init_stage2() NORETURN;
static void init_stage2()
{
@@ -95,10 +80,10 @@ static void init_stage2()
auto dev_random = make<RandomDevice>();
vfs->register_character_device(*dev_random);
- make_pty_pair(0);
- make_pty_pair(1);
- make_pty_pair(2);
- make_pty_pair(3);
+ VFS::the().register_character_device(*new MasterPTY(0));
+ VFS::the().register_character_device(*new MasterPTY(1));
+ VFS::the().register_character_device(*new MasterPTY(2));
+ VFS::the().register_character_device(*new MasterPTY(3));
vfs->register_character_device(*keyboard);
vfs->register_character_device(*ps2mouse);