mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 12:22:44 +00:00 
			
		
		
		
	 ed6c1f53af
			
		
	
	
		ed6c1f53af
		
	
	
	
	
		
			
			This ensures we safely handle interrupts (which can call virtual functions), so they don't happen in the constructor - this pattern can lead to a crash, if we are still in the constructor context because not all methods are available for usage (some are pure virtual, so it's possible to call __cxa_pure_virtual). Also, under some conditions like adding a PCI device via PCI-passthrough mechanism in QEMU, it became exposed to the eye that the code asserts on RNG::handle_device_config_change(). That device has no configuration but if the hypervisor still misbehaves and tries to configure it, we should simply return false to indicate nothing happened.
		
			
				
	
	
		
			39 lines
		
	
	
	
		
			970 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
	
		
			970 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, the SerenityOS developers.
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/RefCounted.h>
 | |
| #include <Kernel/Bus/VirtIO/Device.h>
 | |
| #include <Kernel/Devices/CharacterDevice.h>
 | |
| #include <Kernel/Random.h>
 | |
| 
 | |
| namespace Kernel::VirtIO {
 | |
| 
 | |
| #define REQUESTQ 0
 | |
| 
 | |
| class RNG final
 | |
|     : public RefCounted<RNG>
 | |
|     , public VirtIO::Device {
 | |
| public:
 | |
|     static NonnullRefPtr<RNG> must_create(PCI::Address address);
 | |
|     virtual StringView purpose() const override { return class_name(); }
 | |
|     virtual ~RNG() override = default;
 | |
| 
 | |
|     virtual void initialize() override;
 | |
| 
 | |
| private:
 | |
|     virtual StringView class_name() const override { return "VirtIOConsole"; }
 | |
|     explicit RNG(PCI::Address);
 | |
|     virtual bool handle_device_config_change() override;
 | |
|     virtual void handle_queue_update(u16 queue_index) override;
 | |
|     void request_entropy_from_host();
 | |
| 
 | |
|     OwnPtr<Memory::Region> m_entropy_buffer;
 | |
|     EntropySource m_entropy_source;
 | |
| };
 | |
| 
 | |
| }
 |