2020-01-18 08:38:21 +00:00
|
|
|
/*
|
2021-08-07 13:18:14 +00:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 08:38:21 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2019-01-16 12:36:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-30 17:26:19 +00:00
|
|
|
#include <AK/Badge.h>
|
2019-05-28 09:53:16 +00:00
|
|
|
#include <Kernel/Devices/CharacterDevice.h>
|
2019-01-16 12:36:10 +00:00
|
|
|
|
2020-02-16 00:27:42 +00:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-01-16 12:36:10 +00:00
|
|
|
class MasterPTY;
|
|
|
|
|
|
|
|
class PTYMultiplexer final : public CharacterDevice {
|
|
|
|
public:
|
|
|
|
PTYMultiplexer();
|
|
|
|
virtual ~PTYMultiplexer() override;
|
|
|
|
|
2021-09-10 11:44:46 +00:00
|
|
|
static void initialize();
|
2019-01-30 17:26:19 +00:00
|
|
|
static PTYMultiplexer& the();
|
|
|
|
|
2019-01-16 12:36:10 +00:00
|
|
|
// ^CharacterDevice
|
2023-03-06 18:29:25 +00:00
|
|
|
virtual ErrorOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return 0; }
|
2022-04-01 17:58:27 +00:00
|
|
|
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override { return 0; }
|
|
|
|
virtual bool can_read(OpenFileDescription const&, u64) const override { return true; }
|
|
|
|
virtual bool can_write(OpenFileDescription const&, u64) const override { return true; }
|
2019-01-16 12:36:10 +00:00
|
|
|
|
2019-01-30 17:26:19 +00:00
|
|
|
void notify_master_destroyed(Badge<MasterPTY>, unsigned index);
|
|
|
|
|
2019-01-16 12:36:10 +00:00
|
|
|
private:
|
2019-01-21 01:33:01 +00:00
|
|
|
// ^CharacterDevice
|
2021-10-02 22:24:00 +00:00
|
|
|
virtual StringView class_name() const override { return "PTYMultiplexer"sv; }
|
2019-01-21 01:33:01 +00:00
|
|
|
|
2021-08-07 13:08:32 +00:00
|
|
|
static constexpr size_t max_pty_pairs = 64;
|
2022-11-09 10:39:58 +00:00
|
|
|
SpinlockProtected<Vector<unsigned, max_pty_pairs>, LockRank::None> m_freelist {};
|
2019-01-16 12:36:10 +00:00
|
|
|
};
|
2020-02-16 00:27:42 +00:00
|
|
|
|
|
|
|
}
|