Compare commits
3 Commits
a3f41fd4d9
...
a82f00cb70
Author | SHA1 | Date |
---|---|---|
Bananymous | a82f00cb70 | |
Bananymous | 1838ea5c30 | |
Bananymous | a356d90445 |
|
@ -153,8 +153,13 @@ namespace BAN
|
|||
return emplace(move(key), forward<Args>(args)...);
|
||||
auto& bucket = get_bucket(key);
|
||||
for (Entry& entry : bucket)
|
||||
{
|
||||
if (entry.key == key)
|
||||
{
|
||||
entry.value = T(forward<Args>(args)...);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
TRY(bucket.emplace_back(move(key), forward<Args>(args)...));
|
||||
m_size++;
|
||||
return {};
|
||||
|
|
|
@ -62,10 +62,12 @@ namespace Kernel
|
|||
void putchar_impl(uint8_t ch) override;
|
||||
|
||||
private:
|
||||
PseudoTerminalSlave(BAN::String&& name, mode_t, uid_t, gid_t);
|
||||
PseudoTerminalSlave(BAN::String&& name, uint32_t number, mode_t, uid_t, gid_t);
|
||||
~PseudoTerminalSlave();
|
||||
|
||||
private:
|
||||
BAN::String m_name;
|
||||
const BAN::String m_name;
|
||||
const uint32_t m_number;
|
||||
|
||||
BAN::WeakPtr<PseudoTerminalMaster> m_master;
|
||||
uint32_t m_width { 0 };
|
||||
|
|
|
@ -1790,13 +1790,13 @@ namespace Kernel
|
|||
LockGuard _(m_process_lock);
|
||||
TRY(validate_pointer_access(buffer, buffer_len, true));
|
||||
|
||||
auto inode = TRY(m_open_file_descriptors.inode_of(fildes));
|
||||
if (TRY(m_open_file_descriptors.path_of(fildes)) != "<ptmx>"_sv)
|
||||
return BAN::Error::from_errno(ENOTTY);
|
||||
|
||||
auto inode = TRY(m_open_file_descriptors.inode_of(fildes));
|
||||
auto ptsname = TRY(static_cast<PseudoTerminalMaster*>(inode.ptr())->ptsname());
|
||||
|
||||
const size_t to_copy = BAN::Math::min(ptsname.size() + 1, buffer_len);
|
||||
const size_t to_copy = BAN::Math::min(ptsname.size(), buffer_len - 1);
|
||||
memcpy(buffer, ptsname.data(), to_copy);
|
||||
buffer[to_copy] = '\0';
|
||||
|
||||
|
|
|
@ -2,16 +2,41 @@
|
|||
#include <kernel/FS/DevFS/FileSystem.h>
|
||||
#include <kernel/Terminal/PseudoTerminal.h>
|
||||
|
||||
#include <BAN/ScopeGuard.h>
|
||||
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
BAN::Atomic<uint32_t> s_pts_master_minor = 0;
|
||||
BAN::Atomic<uint32_t> s_pts_slave_number = 0;
|
||||
static BAN::Atomic<uint32_t> s_pts_master_minor = 0;
|
||||
|
||||
static SpinLock s_pts_slave_bitmap_lock;
|
||||
static uint64_t s_pts_slave_bitmap = 0;
|
||||
|
||||
BAN::ErrorOr<BAN::RefPtr<PseudoTerminalMaster>> PseudoTerminalMaster::create(mode_t mode, uid_t uid, gid_t gid)
|
||||
{
|
||||
size_t pts_slave_number = 0;
|
||||
{
|
||||
SpinLockGuard _(s_pts_slave_bitmap_lock);
|
||||
for (pts_slave_number = 0; pts_slave_number < sizeof(s_pts_slave_bitmap) * 8; pts_slave_number++)
|
||||
{
|
||||
if (s_pts_slave_bitmap & ((uint64_t)1 << pts_slave_number))
|
||||
continue;
|
||||
s_pts_slave_bitmap |= (uint64_t)1 << pts_slave_number;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pts_slave_number >= sizeof(s_pts_slave_bitmap) * 8)
|
||||
return BAN::Error::from_errno(ENODEV);
|
||||
BAN::ScopeGuard slave_number_clearer(
|
||||
[pts_slave_number]()
|
||||
{
|
||||
SpinLockGuard _(s_pts_slave_bitmap_lock);
|
||||
s_pts_slave_bitmap &= ~((uint64_t)1 << pts_slave_number);
|
||||
}
|
||||
);
|
||||
|
||||
auto pts_master_buffer = TRY(VirtualRange::create_to_vaddr_range(
|
||||
PageTable::kernel(),
|
||||
KERNEL_OFFSET, static_cast<vaddr_t>(-1),
|
||||
|
@ -19,9 +44,11 @@ namespace Kernel
|
|||
PageTable::Flags::ReadWrite | PageTable::Flags::Present, true
|
||||
));
|
||||
auto pts_master = TRY(BAN::RefPtr<PseudoTerminalMaster>::create(BAN::move(pts_master_buffer), mode, uid, gid));
|
||||
DevFileSystem::get().remove_from_cache(pts_master);
|
||||
|
||||
auto pts_slave_name = TRY(BAN::String::formatted("pts{}", s_pts_slave_number++));
|
||||
auto pts_slave = TRY(BAN::RefPtr<PseudoTerminalSlave>::create(BAN::move(pts_slave_name), 0610, uid, gid));
|
||||
auto pts_slave_name = TRY(BAN::String::formatted("pts{}", pts_slave_number));
|
||||
auto pts_slave = TRY(BAN::RefPtr<PseudoTerminalSlave>::create(BAN::move(pts_slave_name), pts_slave_number, 0610, uid, gid));
|
||||
slave_number_clearer.disable();
|
||||
|
||||
pts_master->m_slave = TRY(pts_slave->get_weak_ptr());
|
||||
pts_slave->m_master = TRY(pts_master->get_weak_ptr());
|
||||
|
@ -112,11 +139,18 @@ namespace Kernel
|
|||
return buffer.size();
|
||||
}
|
||||
|
||||
PseudoTerminalSlave::PseudoTerminalSlave(BAN::String&& name, mode_t mode, uid_t uid, gid_t gid)
|
||||
PseudoTerminalSlave::PseudoTerminalSlave(BAN::String&& name, uint32_t number, mode_t mode, uid_t uid, gid_t gid)
|
||||
: TTY(mode, uid, gid)
|
||||
, m_name(BAN::move(name))
|
||||
, m_number(number)
|
||||
{}
|
||||
|
||||
PseudoTerminalSlave::~PseudoTerminalSlave()
|
||||
{
|
||||
SpinLockGuard _(s_pts_slave_bitmap_lock);
|
||||
s_pts_slave_bitmap &= ~((uint64_t)1 << m_number);
|
||||
}
|
||||
|
||||
void PseudoTerminalSlave::clear()
|
||||
{
|
||||
const char message[] { '\e', '[', '2', 'J' };
|
||||
|
|
|
@ -48,23 +48,10 @@
|
|||
double func(double a, type b) { return __VA_ARGS__; } \
|
||||
long double func##l(long double a, type b) { return __VA_ARGS__; }
|
||||
|
||||
template<BAN::floating_point T>
|
||||
struct integral_atleast;
|
||||
|
||||
template<BAN::floating_point T> requires(sizeof(T) <= sizeof(uint8_t))
|
||||
struct integral_atleast<T> { using type = uint8_t; };
|
||||
|
||||
template<BAN::floating_point T> requires(sizeof(T) > sizeof(uint8_t) && sizeof(T) <= sizeof(uint16_t))
|
||||
struct integral_atleast<T> { using type = uint16_t; };
|
||||
|
||||
template<BAN::floating_point T> requires(sizeof(T) > sizeof(uint16_t) && sizeof(T) <= sizeof(uint32_t))
|
||||
struct integral_atleast<T> { using type = uint32_t; };
|
||||
|
||||
template<BAN::floating_point T> requires(sizeof(T) > sizeof(uint32_t) && sizeof(T) <= sizeof(uint64_t))
|
||||
struct integral_atleast<T> { using type = uint64_t; };
|
||||
|
||||
template<BAN::floating_point T> requires(sizeof(T) > sizeof(uint64_t) && sizeof(T) <= sizeof(__uint128_t))
|
||||
struct integral_atleast<T> { using type = __uint128_t; };
|
||||
template<BAN::floating_point T> struct float_underlying;
|
||||
template<> struct float_underlying<float> { using type = uint32_t; };
|
||||
template<> struct float_underlying<double> { using type = uint64_t; };
|
||||
template<> struct float_underlying<long double> { using type = uint64_t; };
|
||||
|
||||
template<BAN::integral T, size_t mantissa_bits, size_t exponent_bits, bool integral>
|
||||
struct __FloatDecompose;
|
||||
|
@ -89,7 +76,7 @@ struct __FloatDecompose<T, mantissa_bits, exponent_bits, false>
|
|||
template<BAN::floating_point T>
|
||||
struct FloatDecompose
|
||||
{
|
||||
using value_type = integral_atleast<T>::type;
|
||||
using value_type = float_underlying<T>::type;
|
||||
|
||||
static constexpr size_t mantissa_bits
|
||||
= BAN::is_same_v<T, float> ? FLT_MANT_DIG - 1
|
||||
|
|
Loading…
Reference in New Issue