2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2019-01-15 05:30:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-30 17:26:19 +00:00
|
|
|
#include <AK/Badge.h>
|
2019-04-03 10:36:40 +00:00
|
|
|
#include <Kernel/Devices/CharacterDevice.h>
|
2023-02-24 18:10:59 +00:00
|
|
|
#include <Kernel/Library/DoubleBuffer.h>
|
2019-01-15 05:30:19 +00:00
|
|
|
|
2020-02-16 00:27:42 +00:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-01-15 05:30:19 +00:00
|
|
|
class SlavePTY;
|
|
|
|
|
|
|
|
class MasterPTY final : public CharacterDevice {
|
|
|
|
public:
|
2022-08-19 18:53:40 +00:00
|
|
|
static ErrorOr<NonnullLockRefPtr<MasterPTY>> try_create(unsigned index);
|
2019-01-15 05:30:19 +00:00
|
|
|
virtual ~MasterPTY() override;
|
|
|
|
|
2019-01-16 12:36:10 +00:00
|
|
|
unsigned index() const { return m_index; }
|
2022-04-01 17:58:27 +00:00
|
|
|
ErrorOr<size_t> on_slave_write(UserOrKernelBuffer const&, size_t);
|
2019-01-24 23:13:54 +00:00
|
|
|
bool can_write_from_slave() const;
|
2019-01-30 17:26:19 +00:00
|
|
|
void notify_slave_closed(Badge<SlavePTY>);
|
2019-02-05 11:27:32 +00:00
|
|
|
bool is_closed() const { return m_closed; }
|
2019-01-15 05:30:19 +00:00
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(OpenFileDescription const&) const override;
|
2019-08-10 16:10:36 +00:00
|
|
|
|
2019-01-15 05:30:19 +00:00
|
|
|
private:
|
2022-02-15 19:41:41 +00:00
|
|
|
explicit MasterPTY(unsigned index, NonnullOwnPtr<DoubleBuffer> buffer);
|
2022-12-02 09:33:57 +00:00
|
|
|
|
|
|
|
// ^Device
|
|
|
|
virtual bool is_openable_by_jailed_processes() const override { return true; }
|
|
|
|
|
2019-01-21 01:33:01 +00:00
|
|
|
// ^CharacterDevice
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
2022-04-01 17:58:27 +00:00
|
|
|
virtual ErrorOr<size_t> 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;
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> close() override;
|
2019-02-05 11:27:32 +00:00
|
|
|
virtual bool is_master_pty() const override { return true; }
|
2021-11-07 23:51:39 +00:00
|
|
|
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
|
2021-10-02 22:24:00 +00:00
|
|
|
virtual StringView class_name() const override { return "MasterPTY"sv; }
|
2019-01-21 01:33:01 +00:00
|
|
|
|
2022-08-19 18:53:40 +00:00
|
|
|
LockRefPtr<SlavePTY> m_slave;
|
2019-01-15 05:30:19 +00:00
|
|
|
unsigned m_index;
|
2019-02-05 11:27:32 +00:00
|
|
|
bool m_closed { false };
|
2021-08-01 08:54:09 +00:00
|
|
|
NonnullOwnPtr<DoubleBuffer> m_buffer;
|
2019-01-15 05:30:19 +00:00
|
|
|
};
|
2020-02-16 00:27:42 +00:00
|
|
|
|
|
|
|
}
|