mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:22:43 +00:00 
			
		
		
		
	 d1371d66f7
			
		
	
	
		d1371d66f7
		
	
	
	
	
		
			
			This patch switches away from {Nonnull,}LockRefPtr to the non-locking
smart pointers throughout the kernel.
I've looked at the handful of places where these were being persisted
and I don't see any race situations.
Note that the process file descriptor table (Process::m_fds) was already
guarded via MutexProtected.
		
	
			
		
			
				
	
	
		
			86 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			86 lines
		
	
	
	
		
			2.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <AK/Singleton.h>
 | |
| #include <Kernel/Devices/Device.h>
 | |
| #include <Kernel/Devices/DeviceManagement.h>
 | |
| #include <Kernel/FileSystem/InodeMetadata.h>
 | |
| #include <Kernel/FileSystem/SysFS/Component.h>
 | |
| #include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/BlockDevicesDirectory.h>
 | |
| #include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/CharacterDevicesDirectory.h>
 | |
| #include <Kernel/Sections.h>
 | |
| 
 | |
| namespace Kernel {
 | |
| 
 | |
| Device::Device(MajorNumber major, MinorNumber minor)
 | |
|     : m_major(major)
 | |
|     , m_minor(minor)
 | |
| {
 | |
| }
 | |
| 
 | |
| void Device::before_will_be_destroyed_remove_from_device_management()
 | |
| {
 | |
|     DeviceManagement::the().before_device_removal({}, *this);
 | |
|     m_state = State::BeingRemoved;
 | |
| }
 | |
| 
 | |
| void Device::after_inserting_add_to_device_management()
 | |
| {
 | |
|     DeviceManagement::the().after_inserting_device({}, *this);
 | |
| }
 | |
| 
 | |
| ErrorOr<void> Device::after_inserting()
 | |
| {
 | |
|     after_inserting_add_to_device_management();
 | |
|     VERIFY(!m_sysfs_component);
 | |
|     auto sys_fs_component = SysFSDeviceComponent::must_create(*this);
 | |
|     m_sysfs_component = sys_fs_component;
 | |
|     after_inserting_add_to_device_identifier_directory();
 | |
|     return {};
 | |
| }
 | |
| 
 | |
| void Device::will_be_destroyed()
 | |
| {
 | |
|     VERIFY(m_sysfs_component);
 | |
|     before_will_be_destroyed_remove_from_device_identifier_directory();
 | |
|     before_will_be_destroyed_remove_from_device_management();
 | |
| }
 | |
| 
 | |
| Device::~Device()
 | |
| {
 | |
|     VERIFY(m_state == State::BeingRemoved);
 | |
| }
 | |
| 
 | |
| ErrorOr<NonnullOwnPtr<KString>> Device::pseudo_path(OpenFileDescription const&) const
 | |
| {
 | |
|     return KString::formatted("device:{},{}", major(), minor());
 | |
| }
 | |
| 
 | |
| ErrorOr<NonnullRefPtr<OpenFileDescription>> Device::open(int options)
 | |
| {
 | |
|     TRY(Process::current().jail().with([&](auto const& my_jail) -> ErrorOr<void> {
 | |
|         if (my_jail && !is_openable_by_jailed_processes())
 | |
|             return Error::from_errno(EPERM);
 | |
|         return {};
 | |
|     }));
 | |
|     return File::open(options);
 | |
| }
 | |
| 
 | |
| void Device::process_next_queued_request(Badge<AsyncDeviceRequest>, AsyncDeviceRequest const& completed_request)
 | |
| {
 | |
|     SpinlockLocker lock(m_requests_lock);
 | |
|     VERIFY(!m_requests.is_empty());
 | |
|     VERIFY(m_requests.first().ptr() == &completed_request);
 | |
|     m_requests.remove(m_requests.begin());
 | |
|     if (!m_requests.is_empty()) {
 | |
|         auto* next_request = m_requests.first().ptr();
 | |
|         next_request->do_start(move(lock));
 | |
|     }
 | |
| 
 | |
|     evaluate_block_conditions();
 | |
| }
 | |
| 
 | |
| }
 |