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