mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:42:45 +00:00 
			
		
		
		
	 c6e23e45c5
			
		
	
	
		c6e23e45c5
		
	
	
	
	
		
			
			Currently, writing anything to `/dev/mouse0` or `/dev/keyboard0` causes the Kernel to panic. The reason for this is that `[Mouse,Keyboard]Device::write` always returns 0, which is explicitly prohibited by `VERIFY` macro in `Process::sys$write`. The fix seems trivial; `write` should return EINVAL instead (as is the case with, for example, `KCOVDevice`).
		
			
				
	
	
		
			43 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/CircularQueue.h>
 | |
| #include <AK/DoublyLinkedList.h>
 | |
| #include <AK/Types.h>
 | |
| #include <Kernel/API/KeyCode.h>
 | |
| #include <Kernel/API/MousePacket.h>
 | |
| #include <Kernel/Devices/CharacterDevice.h>
 | |
| #include <Kernel/Devices/HID/HIDDevice.h>
 | |
| #include <Kernel/Interrupts/IRQHandler.h>
 | |
| #include <Kernel/Random.h>
 | |
| 
 | |
| namespace Kernel {
 | |
| 
 | |
| class MouseDevice : public HIDDevice {
 | |
| public:
 | |
|     virtual ~MouseDevice() override;
 | |
| 
 | |
|     // ^CharacterDevice
 | |
|     virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
 | |
|     virtual bool can_read(const OpenFileDescription&, size_t) const override;
 | |
|     virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
 | |
|     virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; }
 | |
| 
 | |
|     // ^HIDDevice
 | |
|     virtual Type instrument_type() const override { return Type::Mouse; }
 | |
| 
 | |
| protected:
 | |
|     MouseDevice();
 | |
|     // ^CharacterDevice
 | |
|     virtual StringView class_name() const override { return "MouseDevice"; }
 | |
| 
 | |
|     mutable Spinlock m_queue_lock;
 | |
|     CircularQueue<MousePacket, 100> m_queue;
 | |
| };
 | |
| 
 | |
| }
 |