1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:57:34 +00:00

Kernel: Make self-contained locking smart pointers their own classes

Until now, our kernel has reimplemented a number of AK classes to
provide automatic internal locking:

- RefPtr
- NonnullRefPtr
- WeakPtr
- Weakable

This patch renames the Kernel classes so that they can coexist with
the original AK classes:

- RefPtr => LockRefPtr
- NonnullRefPtr => NonnullLockRefPtr
- WeakPtr => LockWeakPtr
- Weakable => LockWeakable

The goal here is to eventually get rid of the Lock* classes in favor of
using external locking.
This commit is contained in:
Andreas Kling 2022-08-19 20:53:40 +02:00
parent e475263113
commit 11eee67b85
360 changed files with 1703 additions and 1672 deletions

View file

@ -67,7 +67,7 @@ auto AsyncDeviceRequest::get_request_result() const -> RequestResult
return m_result;
}
void AsyncDeviceRequest::add_sub_request(NonnullRefPtr<AsyncDeviceRequest> sub_request)
void AsyncDeviceRequest::add_sub_request(NonnullLockRefPtr<AsyncDeviceRequest> sub_request)
{
// Sub-requests cannot be for the same device
VERIFY(&m_device != &sub_request->m_device);

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/IntrusiveList.h>
#include <AK/NonnullRefPtr.h>
#include <Kernel/Library/NonnullLockRefPtr.h>
#include <Kernel/Memory/ScopedAddressSpaceSwitcher.h>
#include <Kernel/Process.h>
#include <Kernel/Thread.h>
@ -58,7 +58,7 @@ public:
virtual StringView name() const = 0;
virtual void start() = 0;
void add_sub_request(NonnullRefPtr<AsyncDeviceRequest>);
void add_sub_request(NonnullLockRefPtr<AsyncDeviceRequest>);
[[nodiscard]] RequestWaitResult wait(Time* = nullptr);
@ -142,14 +142,14 @@ private:
AsyncDeviceRequest* m_parent_request { nullptr };
RequestResult m_result { Pending };
IntrusiveListNode<AsyncDeviceRequest, RefPtr<AsyncDeviceRequest>> m_list_node;
IntrusiveListNode<AsyncDeviceRequest, LockRefPtr<AsyncDeviceRequest>> m_list_node;
using AsyncDeviceSubRequestList = IntrusiveList<&AsyncDeviceRequest::m_list_node>;
AsyncDeviceSubRequestList m_sub_requests_pending;
AsyncDeviceSubRequestList m_sub_requests_complete;
WaitQueue m_queue;
NonnullRefPtr<Process> m_process;
NonnullLockRefPtr<Process> m_process;
void* m_private { nullptr };
mutable Spinlock m_lock { LockRank::None };
};

View file

@ -20,9 +20,9 @@ static constexpr u16 pcm_fixed_sample_rate = 48000;
static constexpr u16 pcm_sample_rate_minimum = 8000;
static constexpr u16 pcm_sample_rate_maximum = 48000;
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<AC97>> AC97::try_create(PCI::DeviceIdentifier const& pci_device_identifier)
UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<AC97>> AC97::try_create(PCI::DeviceIdentifier const& pci_device_identifier)
{
auto ac97 = adopt_nonnull_ref_or_enomem(new (nothrow) AC97(pci_device_identifier));
auto ac97 = adopt_nonnull_lock_ref_or_enomem(new (nothrow) AC97(pci_device_identifier));
if (!ac97.is_error())
TRY(ac97.value()->initialize());
return ac97;
@ -166,7 +166,7 @@ void AC97::set_pcm_output_volume(u8 left_channel, u8 right_channel, Muted mute)
m_io_mixer_base.offset(NativeAudioMixerRegister::SetPCMOutputVolume).out(volume_value);
}
RefPtr<AudioChannel> AC97::audio_channel(u32 index) const
LockRefPtr<AudioChannel> AC97::audio_channel(u32 index) const
{
if (index == 0)
return m_audio_channel;

View file

@ -26,7 +26,7 @@ class AC97 final
, public IRQHandler {
public:
static ErrorOr<NonnullRefPtr<AC97>> try_create(PCI::DeviceIdentifier const&);
static ErrorOr<NonnullLockRefPtr<AC97>> try_create(PCI::DeviceIdentifier const&);
virtual ~AC97() override;
@ -161,7 +161,7 @@ private:
ErrorOr<void> write_single_buffer(UserOrKernelBuffer const&, size_t, size_t);
// ^AudioController
virtual RefPtr<AudioChannel> audio_channel(u32 index) const override;
virtual LockRefPtr<AudioChannel> audio_channel(u32 index) const override;
virtual ErrorOr<size_t> write(size_t channel_index, UserOrKernelBuffer const& data, size_t length) override;
virtual void detect_hardware_audio_channels(Badge<AudioManagement>) override;
virtual ErrorOr<void> set_pcm_output_sample_rate(size_t channel_index, u32 samples_per_second_rate) override;
@ -180,7 +180,7 @@ private:
AC97Channel m_pcm_out_channel;
u32 m_sample_rate { 0 };
bool m_variable_rate_pcm_supported { false };
RefPtr<AudioChannel> m_audio_channel;
LockRefPtr<AudioChannel> m_audio_channel;
};
}

View file

@ -13,7 +13,7 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<AudioChannel> AudioChannel::must_create(AudioController const& controller, size_t channel_index)
UNMAP_AFTER_INIT NonnullLockRefPtr<AudioChannel> AudioChannel::must_create(AudioController const& controller, size_t channel_index)
{
auto audio_device_or_error = DeviceManagement::try_create_device<AudioChannel>(controller, channel_index);
// FIXME: Find a way to propagate errors

View file

@ -20,7 +20,7 @@ class AudioChannel final
friend class DeviceManagement;
public:
static NonnullRefPtr<AudioChannel> must_create(AudioController const&, size_t channel_index);
static NonnullLockRefPtr<AudioChannel> must_create(AudioController const&, size_t channel_index);
virtual ~AudioChannel() override = default;
// ^CharacterDevice
@ -37,7 +37,7 @@ private:
// ^CharacterDevice
virtual StringView class_name() const override { return "AudioChannel"sv; }
WeakPtr<AudioController> m_controller;
LockWeakPtr<AudioController> m_controller;
const size_t m_channel_index;
};
}

View file

@ -8,12 +8,12 @@
#include <AK/IntrusiveList.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Weakable.h>
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Bus/PCI/Device.h>
#include <Kernel/Devices/Audio/Channel.h>
#include <Kernel/Devices/Device.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Library/LockWeakable.h>
#include <Kernel/Locking/Mutex.h>
#include <Kernel/Memory/PhysicalPage.h>
#include <Kernel/PhysicalAddress.h>
@ -24,13 +24,13 @@ namespace Kernel {
class AudioManagement;
class AudioController
: public AtomicRefCounted<AudioController>
, public Weakable<AudioController> {
, public LockWeakable<AudioController> {
friend class AudioManagement;
public:
virtual ~AudioController() = default;
virtual RefPtr<AudioChannel> audio_channel(u32 index) const = 0;
virtual LockRefPtr<AudioChannel> audio_channel(u32 index) const = 0;
virtual ErrorOr<size_t> write(size_t channel_index, UserOrKernelBuffer const& data, size_t length) = 0;
virtual void detect_hardware_audio_channels(Badge<AudioManagement>) = 0;
@ -40,6 +40,6 @@ public:
virtual ErrorOr<u32> get_pcm_output_sample_rate(size_t channel_index) = 0;
private:
IntrusiveListNode<AudioController, RefPtr<AudioController>> m_node;
IntrusiveListNode<AudioController, LockRefPtr<AudioController>> m_node;
};
}

View file

@ -10,10 +10,10 @@
#include <AK/Error.h>
#include <AK/IntrusiveList.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Time.h>
#include <AK/Types.h>
#include <Kernel/Devices/Audio/Controller.h>
#include <Kernel/Library/LockRefPtr.h>
namespace Kernel {

View file

@ -7,8 +7,8 @@
#pragma once
#include <AK/IntegralMath.h>
#include <AK/Weakable.h>
#include <Kernel/Devices/Device.h>
#include <Kernel/Library/LockWeakable.h>
namespace Kernel {

View file

@ -16,7 +16,7 @@
static Kernel::Spinlock g_console_lock { LockRank::None };
UNMAP_AFTER_INIT NonnullRefPtr<ConsoleDevice> ConsoleDevice::must_create()
UNMAP_AFTER_INIT NonnullLockRefPtr<ConsoleDevice> ConsoleDevice::must_create()
{
auto device_or_error = DeviceManagement::try_create_device<ConsoleDevice>();
VERIFY(!device_or_error.is_error());

View file

@ -16,7 +16,7 @@ class ConsoleDevice final : public CharacterDevice {
friend class DeviceManagement;
public:
static NonnullRefPtr<ConsoleDevice> must_create();
static NonnullLockRefPtr<ConsoleDevice> must_create();
virtual ~ConsoleDevice() override;

View file

@ -18,13 +18,13 @@
#include <AK/Error.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/RefPtr.h>
#include <Kernel/Devices/AsyncDeviceRequest.h>
#include <Kernel/FileSystem/DeviceFileTypes.h>
#include <Kernel/FileSystem/File.h>
#include <Kernel/FileSystem/SysFS/Registry.h>
#include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/DeviceComponent.h>
#include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/SymbolicLinkDeviceComponent.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/UnixTypes.h>
namespace Kernel {
@ -53,9 +53,9 @@ public:
void process_next_queued_request(Badge<AsyncDeviceRequest>, AsyncDeviceRequest const&);
template<typename AsyncRequestType, typename... Args>
ErrorOr<NonnullRefPtr<AsyncRequestType>> try_make_request(Args&&... args)
ErrorOr<NonnullLockRefPtr<AsyncRequestType>> try_make_request(Args&&... args)
{
auto request = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AsyncRequestType(*this, forward<Args>(args)...)));
auto request = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) AsyncRequestType(*this, forward<Args>(args)...)));
SpinlockLocker lock(m_requests_lock);
bool was_empty = m_requests.is_empty();
m_requests.append(request);
@ -89,15 +89,15 @@ private:
State m_state { State::Normal };
Spinlock m_requests_lock { LockRank::None };
DoublyLinkedList<RefPtr<AsyncDeviceRequest>> m_requests;
DoublyLinkedList<LockRefPtr<AsyncDeviceRequest>> m_requests;
protected:
// FIXME: This pointer will be eventually removed after all nodes in /sys/dev/block/ and
// /sys/dev/char/ are symlinks.
RefPtr<SysFSDeviceComponent> m_sysfs_component;
LockRefPtr<SysFSDeviceComponent> m_sysfs_component;
RefPtr<SysFSSymbolicLinkDeviceComponent> m_symlink_sysfs_component;
RefPtr<SysFSDirectory> m_sysfs_device_directory;
LockRefPtr<SysFSSymbolicLinkDeviceComponent> m_symlink_sysfs_component;
LockRefPtr<SysFSDirectory> m_sysfs_device_directory;
};
}

View file

@ -9,7 +9,7 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<DeviceControlDevice> DeviceControlDevice::must_create()
UNMAP_AFTER_INIT NonnullLockRefPtr<DeviceControlDevice> DeviceControlDevice::must_create()
{
auto device_control_device_or_error = DeviceManagement::try_create_device<DeviceControlDevice>();
// FIXME: Find a way to propagate errors

View file

@ -14,7 +14,7 @@ class DeviceControlDevice final : public CharacterDevice {
friend class DeviceManagement;
public:
static NonnullRefPtr<DeviceControlDevice> must_create();
static NonnullLockRefPtr<DeviceControlDevice> must_create();
virtual ~DeviceControlDevice() override;
private:

View file

@ -8,9 +8,7 @@
#include <AK/Badge.h>
#include <AK/Error.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Time.h>
#include <AK/Types.h>
#include <Kernel/API/DeviceEvent.h>
@ -21,6 +19,8 @@
#include <Kernel/Devices/Device.h>
#include <Kernel/Devices/DeviceControlDevice.h>
#include <Kernel/Devices/NullDevice.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Library/NonnullLockRefPtrVector.h>
#include <Kernel/UnixTypes.h>
namespace Kernel {
@ -54,7 +54,7 @@ public:
ConsoleDevice& console_device();
template<typename DeviceType, typename... Args>
static inline ErrorOr<NonnullRefPtr<DeviceType>> try_create_device(Args&&... args) requires(requires(Args... args) { DeviceType::try_create(args...); })
static inline ErrorOr<NonnullLockRefPtr<DeviceType>> try_create_device(Args&&... args) requires(requires(Args... args) { DeviceType::try_create(args...); })
{
auto device = TRY(DeviceType::try_create(forward<Args>(args)...));
device->after_inserting();
@ -62,17 +62,17 @@ public:
}
template<typename DeviceType, typename... Args>
static inline ErrorOr<NonnullRefPtr<DeviceType>> try_create_device(Args&&... args)
static inline ErrorOr<NonnullLockRefPtr<DeviceType>> try_create_device(Args&&... args)
{
auto device = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) DeviceType(forward<Args>(args)...)));
auto device = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) DeviceType(forward<Args>(args)...)));
device->after_inserting();
return device;
}
private:
RefPtr<NullDevice> m_null_device;
RefPtr<ConsoleDevice> m_console_device;
RefPtr<DeviceControlDevice> m_device_control_device;
LockRefPtr<NullDevice> m_null_device;
LockRefPtr<ConsoleDevice> m_console_device;
LockRefPtr<DeviceControlDevice> m_device_control_device;
// FIXME: Once we have a singleton for managing many sound cards, remove this from here
SpinlockProtected<HashMap<u64, Device*>> m_devices { LockRank::None };

View file

@ -12,7 +12,7 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<FullDevice> FullDevice::must_create()
UNMAP_AFTER_INIT NonnullLockRefPtr<FullDevice> FullDevice::must_create()
{
auto full_device_or_error = DeviceManagement::try_create_device<FullDevice>();
// FIXME: Find a way to propagate errors

View file

@ -14,7 +14,7 @@ class FullDevice final : public CharacterDevice {
friend class DeviceManagement;
public:
static NonnullRefPtr<FullDevice> must_create();
static NonnullLockRefPtr<FullDevice> must_create();
virtual ~FullDevice() override;
private:

View file

@ -9,12 +9,12 @@
#include <AK/Atomic.h>
#include <AK/CircularQueue.h>
#include <AK/Error.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/RefPtr.h>
#include <AK/Time.h>
#include <AK/Types.h>
#include <Kernel/API/KeyCode.h>
#include <Kernel/API/MousePacket.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Library/NonnullLockRefPtrVector.h>
#include <Kernel/Locking/Spinlock.h>
#include <Kernel/Locking/SpinlockProtected.h>
#include <Kernel/UnixTypes.h>
@ -61,8 +61,8 @@ private:
size_t m_mouse_minor_number { 0 };
size_t m_keyboard_minor_number { 0 };
KeyboardClient* m_client { nullptr };
RefPtr<I8042Controller> m_i8042_controller;
NonnullRefPtrVector<HIDDevice> m_hid_devices;
LockRefPtr<I8042Controller> m_i8042_controller;
NonnullLockRefPtrVector<HIDDevice> m_hid_devices;
Spinlock m_client_lock { LockRank::None };
};

View file

@ -13,16 +13,16 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<I8042Controller> I8042Controller::initialize()
UNMAP_AFTER_INIT NonnullLockRefPtr<I8042Controller> I8042Controller::initialize()
{
return adopt_ref(*new I8042Controller());
return adopt_lock_ref(*new I8042Controller());
}
RefPtr<MouseDevice> I8042Controller::mouse() const
LockRefPtr<MouseDevice> I8042Controller::mouse() const
{
return m_mouse_device;
}
RefPtr<KeyboardDevice> I8042Controller::keyboard() const
LockRefPtr<KeyboardDevice> I8042Controller::keyboard() const
{
return m_keyboard_device;
}

View file

@ -77,7 +77,7 @@ protected:
{
}
NonnullRefPtr<I8042Controller> m_i8042_controller;
NonnullLockRefPtr<I8042Controller> m_i8042_controller;
};
class PS2KeyboardDevice;
@ -88,7 +88,7 @@ class I8042Controller final : public AtomicRefCounted<I8042Controller> {
friend class PS2MouseDevice;
public:
static NonnullRefPtr<I8042Controller> initialize();
static NonnullLockRefPtr<I8042Controller> initialize();
ErrorOr<void> detect_devices();
@ -132,8 +132,8 @@ public:
bool irq_process_input_buffer(HIDDevice::Type);
RefPtr<MouseDevice> mouse() const;
RefPtr<KeyboardDevice> keyboard() const;
LockRefPtr<MouseDevice> mouse() const;
LockRefPtr<KeyboardDevice> keyboard() const;
// Note: This function exists only for the initialization process of the controller
bool check_existence_via_probing(Badge<HIDManagement>);
@ -157,8 +157,8 @@ private:
bool m_first_port_available { false };
bool m_second_port_available { false };
bool m_is_dual_channel { false };
RefPtr<MouseDevice> m_mouse_device;
RefPtr<KeyboardDevice> m_keyboard_device;
LockRefPtr<MouseDevice> m_mouse_device;
LockRefPtr<KeyboardDevice> m_keyboard_device;
};
}

View file

@ -87,7 +87,7 @@ bool PS2KeyboardDevice::handle_irq(RegisterState const&)
return m_i8042_controller->irq_process_input_buffer(HIDDevice::Type::Keyboard);
}
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<PS2KeyboardDevice>> PS2KeyboardDevice::try_to_initialize(I8042Controller const& ps2_controller)
UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<PS2KeyboardDevice>> PS2KeyboardDevice::try_to_initialize(I8042Controller const& ps2_controller)
{
auto keyboard_device = TRY(DeviceManagement::try_create_device<PS2KeyboardDevice>(ps2_controller));

View file

@ -23,7 +23,7 @@ class PS2KeyboardDevice final : public IRQHandler
friend class DeviceManagement;
public:
static ErrorOr<NonnullRefPtr<PS2KeyboardDevice>> try_to_initialize(I8042Controller const&);
static ErrorOr<NonnullLockRefPtr<PS2KeyboardDevice>> try_to_initialize(I8042Controller const&);
virtual ~PS2KeyboardDevice() override;
ErrorOr<void> initialize();

View file

@ -175,7 +175,7 @@ ErrorOr<void> PS2MouseDevice::set_sample_rate(u8 rate)
return {};
}
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<PS2MouseDevice>> PS2MouseDevice::try_to_initialize(I8042Controller const& ps2_controller)
UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<PS2MouseDevice>> PS2MouseDevice::try_to_initialize(I8042Controller const& ps2_controller)
{
auto mouse_device = TRY(DeviceManagement::try_create_device<PS2MouseDevice>(ps2_controller));
TRY(mouse_device->initialize());

View file

@ -20,7 +20,7 @@ class PS2MouseDevice : public IRQHandler
friend class DeviceManagement;
public:
static ErrorOr<NonnullRefPtr<PS2MouseDevice>> try_to_initialize(I8042Controller const&);
static ErrorOr<NonnullLockRefPtr<PS2MouseDevice>> try_to_initialize(I8042Controller const&);
ErrorOr<void> initialize();
virtual ~PS2MouseDevice() override;

View file

@ -11,7 +11,7 @@
namespace Kernel {
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<VMWareMouseDevice>> VMWareMouseDevice::try_to_initialize(I8042Controller const& ps2_controller)
UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<VMWareMouseDevice>> VMWareMouseDevice::try_to_initialize(I8042Controller const& ps2_controller)
{
// FIXME: return the correct error
if (!VMWareBackdoor::the())

View file

@ -18,7 +18,7 @@ namespace Kernel {
class VMWareMouseDevice final : public PS2MouseDevice {
public:
friend class DeviceManagement;
static ErrorOr<NonnullRefPtr<VMWareMouseDevice>> try_to_initialize(I8042Controller const&);
static ErrorOr<NonnullLockRefPtr<VMWareMouseDevice>> try_to_initialize(I8042Controller const&);
virtual ~VMWareMouseDevice() override;
// ^I8042Device

View file

@ -19,7 +19,7 @@ namespace Kernel {
HashMap<ProcessID, KCOVInstance*>* KCOVDevice::proc_instance;
HashMap<ThreadID, KCOVInstance*>* KCOVDevice::thread_instance;
UNMAP_AFTER_INIT NonnullRefPtr<KCOVDevice> KCOVDevice::must_create()
UNMAP_AFTER_INIT NonnullLockRefPtr<KCOVDevice> KCOVDevice::must_create()
{
auto kcov_device_or_error = DeviceManagement::try_create_device<KCOVDevice>();
// FIXME: Find a way to propagate errors
@ -65,7 +65,7 @@ void KCOVDevice::free_process()
delete kcov_instance;
}
ErrorOr<NonnullRefPtr<OpenFileDescription>> KCOVDevice::open(int options)
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> KCOVDevice::open(int options)
{
auto pid = Process::current().pid();
if (proc_instance->get(pid).has_value())

View file

@ -17,13 +17,13 @@ public:
static HashMap<ProcessID, KCOVInstance*>* proc_instance;
static HashMap<ThreadID, KCOVInstance*>* thread_instance;
static NonnullRefPtr<KCOVDevice> must_create();
static NonnullLockRefPtr<KCOVDevice> must_create();
static void free_thread();
static void free_process();
// ^File
ErrorOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
ErrorOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open(int options) override;
protected:
KCOVDevice();

View file

@ -53,7 +53,7 @@ private:
u64 m_buffer_size_in_entries { 0 };
size_t m_buffer_size_in_bytes { 0 };
kcov_pc_t* m_buffer { nullptr };
RefPtr<Memory::AnonymousVMObject> m_vmobject;
LockRefPtr<Memory::AnonymousVMObject> m_vmobject;
// Here to ensure it's not garbage collected at the end of open()
OwnPtr<Memory::Region> m_kernel_region;

View file

@ -14,7 +14,7 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<MemoryDevice> MemoryDevice::must_create()
UNMAP_AFTER_INIT NonnullLockRefPtr<MemoryDevice> MemoryDevice::must_create()
{
auto memory_device_or_error = DeviceManagement::try_create_device<MemoryDevice>();
// FIXME: Find a way to propagate errors

View file

@ -16,7 +16,7 @@ class MemoryDevice final : public CharacterDevice {
friend class DeviceManagement;
public:
static NonnullRefPtr<MemoryDevice> must_create();
static NonnullLockRefPtr<MemoryDevice> must_create();
~MemoryDevice();
virtual ErrorOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;

View file

@ -11,7 +11,7 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<NullDevice> NullDevice::must_initialize()
UNMAP_AFTER_INIT NonnullLockRefPtr<NullDevice> NullDevice::must_initialize()
{
auto null_device_or_error = DeviceManagement::try_create_device<NullDevice>();
// FIXME: Find a way to propagate errors

View file

@ -16,7 +16,7 @@ class NullDevice final : public CharacterDevice {
public:
virtual ~NullDevice() override;
static NonnullRefPtr<NullDevice> must_initialize();
static NonnullLockRefPtr<NullDevice> must_initialize();
private:
NullDevice();

View file

@ -11,7 +11,7 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<RandomDevice> RandomDevice::must_create()
UNMAP_AFTER_INIT NonnullLockRefPtr<RandomDevice> RandomDevice::must_create()
{
auto random_device_or_error = DeviceManagement::try_create_device<RandomDevice>();
// FIXME: Find a way to propagate errors

View file

@ -14,7 +14,7 @@ class RandomDevice final : public CharacterDevice {
friend class DeviceManagement;
public:
static NonnullRefPtr<RandomDevice> must_create();
static NonnullLockRefPtr<RandomDevice> must_create();
virtual ~RandomDevice() override;
private:

View file

@ -11,7 +11,7 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<SelfTTYDevice> SelfTTYDevice::must_create()
UNMAP_AFTER_INIT NonnullLockRefPtr<SelfTTYDevice> SelfTTYDevice::must_create()
{
auto self_tty_device_or_error = DeviceManagement::try_create_device<SelfTTYDevice>();
// FIXME: Find a way to propagate errors
@ -19,14 +19,14 @@ UNMAP_AFTER_INIT NonnullRefPtr<SelfTTYDevice> SelfTTYDevice::must_create()
return self_tty_device_or_error.release_value();
}
ErrorOr<NonnullRefPtr<OpenFileDescription>> SelfTTYDevice::open(int options)
ErrorOr<NonnullLockRefPtr<OpenFileDescription>> SelfTTYDevice::open(int options)
{
// Note: If for some odd reason we try to open this device (early on boot?)
// while there's no current Process assigned, don't fail and return an error.
if (!Process::has_current())
return Error::from_errno(ESRCH);
auto& current_process = Process::current();
RefPtr<TTY> tty = current_process.tty();
LockRefPtr<TTY> tty = current_process.tty();
if (!tty)
return Error::from_errno(ENXIO);
auto description = TRY(OpenFileDescription::try_create(*tty));

View file

@ -14,14 +14,14 @@ class SelfTTYDevice final : public CharacterDevice {
friend class DeviceManagement;
public:
static NonnullRefPtr<SelfTTYDevice> must_create();
static NonnullLockRefPtr<SelfTTYDevice> must_create();
virtual ~SelfTTYDevice() override;
private:
SelfTTYDevice();
// ^CharacterDevice
virtual ErrorOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
virtual ErrorOr<NonnullLockRefPtr<OpenFileDescription>> open(int options) override;
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override;
virtual bool can_read(OpenFileDescription const&, u64) const override;

View file

@ -17,11 +17,11 @@ namespace Kernel {
#define SERIAL_COM3_ADDR 0x3E8
#define SERIAL_COM4_ADDR 0x2E8
UNMAP_AFTER_INIT NonnullRefPtr<SerialDevice> SerialDevice::must_create(size_t com_number)
UNMAP_AFTER_INIT NonnullLockRefPtr<SerialDevice> SerialDevice::must_create(size_t com_number)
{
// FIXME: This way of blindly doing release_value is really not a good thing, find
// a way to propagate errors back.
RefPtr<SerialDevice> serial_device;
LockRefPtr<SerialDevice> serial_device;
switch (com_number) {
case 0: {
serial_device = DeviceManagement::try_create_device<SerialDevice>(IOAddress(SERIAL_COM1_ADDR), 64).release_value();

View file

@ -15,7 +15,7 @@ class SerialDevice final : public CharacterDevice {
friend class DeviceManagement;
public:
static NonnullRefPtr<SerialDevice> must_create(size_t com_number);
static NonnullLockRefPtr<SerialDevice> must_create(size_t com_number);
virtual ~SerialDevice() override;

View file

@ -11,7 +11,7 @@
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<ZeroDevice> ZeroDevice::must_create()
UNMAP_AFTER_INIT NonnullLockRefPtr<ZeroDevice> ZeroDevice::must_create()
{
auto zero_device_or_error = DeviceManagement::try_create_device<ZeroDevice>();
// FIXME: Find a way to propagate errors

View file

@ -14,7 +14,7 @@ class ZeroDevice final : public CharacterDevice {
friend class DeviceManagement;
public:
static NonnullRefPtr<ZeroDevice> must_create();
static NonnullLockRefPtr<ZeroDevice> must_create();
virtual ~ZeroDevice() override;
private: